コード例 #1
0
PetscErrorCode cHamiltonianMatrix::WaveFunctionUpdate(const int k){
  double prefactor, timeT;
	if (k==0) {
		prefactor = 1.0;
	} else {
		prefactor = 2.0;
	}
	PetscScalar coeff;
	//gsl_sf_result tmp;
	//int err;
	double tmp, tmpi,zi,order;
	int n,nz,ierr,kode;
	n=1;kode=1;zi=0;
        
	//	gsl_error_handler_t* old_handler=gsl_set_error_handler_off(); 

	for (int itime = Nt-1; itime >= 0; --itime) {
		timeT = a_scaling*exp(dt*itime-3.0);
		if (timeT*set_gsl_under_flow_ratio+set_gsl_shift_value>=k) { //if GSL underflow error occurs, try to decrease the factor relation, but the price to pay is mostly inaccuracies in small time steps.
			// This is to avoid underflow in GSL error, which means the bessel function is too small to be computed reliably. MATLAB decides this behavior too, by setting it to zero, if it is too small (underflow).
			// using emperical factor relation of discarding the less cases
		  //coeff=prefactor*PetscPowComplex(-1.0*PETSC_i,k)* gsl_sf_bessel_Jn(k,timeT);
		  
		  //open_spec_func: formula
		  order=double(k);
		  zbesj_(&timeT,&zi,&order,&kode,&n,&tmp,&tmpi,&nz,&ierr);
		  coeff=prefactor*PetscPowComplex(-1.0*PETSC_i,k)*tmp;
		  //gsl_bessel: formula
		  //err=gsl_sf_bessel_Jn_e(k,timeT,&tmp);
		  //if (err==0&&isnan(tmp.val)!=1) {
		  //coeff = prefactor*PetscPowComplex(-1.0*PETSC_i,k)* tmp.val;
		  //} else {
		  //break;
		  //}
		  ierr = VecAXPY(WFt[itime],coeff,X3);CHKERRQ(ierr);
   		  //if (rank==0) cout << "k=" << k << " time=" << timeT << " coeff=" << coeff << endl;
		  } // else { 
		  // coefftmp=gsl_sf_bessel_Jn(k,timeT);
		  // if (coefftmp<1e-6){
		// break;
		//} else {
		// coeff=prefactor*PetscPowComplex(-1.0*PETSC_i,k)*coefftmp;
		//}
		//}
		//		ierr = VecAXPY(WFt[itime],coeff,X3);CHKERRQ(ierr);
	}
	//gsl_set_error_handler(old_handler);
	return ierr;
}
コード例 #2
0
ファイル: cbestest.cpp プロジェクト: jbarakat/amos
double complex besselj(double nu, double complex z) {
    int kode=1;
    int n=1;
    double zr=creal(z);
    double zi=cimag(z);
    int nz,ierr;
    double cyr[1],cyi[1];
    double complex res;
    zbesj_(&zr,&zi,&nu,&kode,&n,cyr,cyi,&nz,&ierr);
    if(ierr!=0) {
        printf("error!\n");
    }
    res=cyr[0]+I*cyi[0];
    return res;
}