Пример #1
0
Ensure(FFT, can_be_constructed_from_DMDA)
{
    ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,20,2,1,NULL,&da);
    CHKERRV(ierr);
    ierr = scFftCreate(da, &fft);
    assert_that(ierr, is_equal_to(0));
    scFftDestroy(&fft);
    CHKERRV(ierr);
    ierr = DMDestroy(&da);
    CHKERRV(ierr);
}
Пример #2
0
RigidKinematicsSolver::~RigidKinematicsSolver()
{
    PetscErrorCode ierr;
    PetscBool finalized;

    PetscFunctionBeginUser;

    ierr = PetscFinalized(&finalized); CHKERRV(ierr);
    if (finalized) return;

    ierr = destroy(); CHKERRV(ierr);
}  // ~RigidKinematicsSolver
Пример #3
0
// Destructor.
ProbeBase::~ProbeBase()
{
    PetscErrorCode ierr;
    PetscBool finalized;

    PetscFunctionBeginUser;

    ierr = PetscFinalized(&finalized); CHKERRV(ierr);
    if (finalized) return;

    ierr = destroy(); CHKERRV(ierr);
}  // ProbeBase::~ProbeBase
Пример #4
0
void SFieldEndRuns(SField sfv) {
    mySField sf = static_cast<mySField>(sfv);
    assert(sf->running);
    PetscErrorCode ierr;
    ierr = KSPDestroy(&sf->ksp);CHKERRV(ierr);
    ierr = MatDestroy(&sf->J);CHKERRV(ierr);
    ierr = VecDestroy(&sf->F);CHKERRV(ierr);
    ierr = VecDestroy(&sf->U);CHKERRV(ierr);

    delete [] sf->N_multi_idx;
    sf->running = 0;
    sf->N_multi_idx = 0;
}
Пример #5
0
SingleBodyBase::~SingleBodyBase()
{
    PetscErrorCode ierr;
    PetscBool finalized;

    PetscFunctionBeginUser;

    ierr = PetscFinalized(&finalized); CHKERRV(ierr);
    if (finalized) return;

    ierr = DMDestroy(&da); CHKERRV(ierr);
    comm = MPI_COMM_NULL;
}  // ~SingleBodyBase
Пример #6
0
// Destructor.
SolutionBase::~SolutionBase()
{
    PetscErrorCode ierr;
    PetscBool finalized;

    PetscFunctionBeginUser;

    ierr = PetscFinalized(&finalized); CHKERRV(ierr);
    if (finalized) return;

    ierr = VecDestroy(&UGlobal); CHKERRV(ierr);
    ierr = VecDestroy(&pGlobal); CHKERRV(ierr);
    comm = MPI_COMM_NULL;
}  // ~SolutionBase
Пример #7
0
Ensure(FFT, registers_the_right_DM)
{
    ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,20,2,1,NULL,&da);
    CHKERRV(ierr);
    ierr = scFftCreate(da, &fft);
    CHKERRV(ierr);
    DM da1;
    ierr = scFftGetDM(fft, &da1);
    CHKERRV(ierr);
    assert_that(da1, is_equal_to(da));
    ierr = scFftDestroy(&fft);
    CHKERRV(ierr);
    ierr = DMDestroy(&da);
    CHKERRV(ierr);
}
Пример #8
0
static void CholmodErrorHandler(int status,const char *file,int line,const char *message)
{
  PetscErrorCode ierr;

  PetscFunctionBegin;
  if (status > CHOLMOD_OK) {
    ierr = PetscInfo4(static_F,"CHOLMOD warning %d at %s:%d: %s\n",status,file,line,message);CHKERRV(ierr);
  } else if (status == CHOLMOD_OK) { /* Documentation says this can happen, but why? */
    ierr = PetscInfo3(static_F,"CHOLMOD OK at %s:%d: %s\n",file,line,message);CHKERRV(ierr);
  } else {
    ierr = PetscErrorPrintf("CHOLMOD error %d at %s:%d: %s\n",status,file,line,message);CHKERRV(ierr);
  }
  PetscFunctionReturnVoid();
}
Пример #9
0
void destroyArrays(simInfo *data)
{
	PetscErrorCode ierr;
	//ierr = MatDestroy(&C); CHKERRV(ierr);
	//ierr = MatDestroy(&G); CHKERRV(ierr);
	//ierr = ISDestroy(&is[0]); CHKERRV(ierr);
	//ierr = ISDestroy(&is[1]); CHKERRV(ierr);
	//ierr = PetscFree(is); CHKERRV(ierr);
	ierr = VecDestroy(&(data->bc2)); CHKERRV(ierr);
	ierr = VecDestroy(&(data->uPacked)); CHKERRV(ierr);
	ierr = VecDestroy(&(data->pGlobal)); CHKERRV(ierr);
	ierr = VecDestroy(&(data->bc2)); CHKERRV(ierr);
	ierr = DMDestroy(&(data->vda)); CHKERRV(ierr);
	ierr = DMDestroy(&(data->uda)); CHKERRV(ierr);
	ierr = DMDestroy(&(data->pda)); CHKERRV(ierr);
	ierr = DMDestroy(&(data->pack)); CHKERRV(ierr);
}
Пример #10
0
void createArrays(simInfo *data)
{
	PetscErrorCode   ierr;
	PetscInt         *lx, *ly, m, n;
	const PetscInt   *lxu, *lyu;
	
	// Create distributed array and get vectors
	ierr = PetscPrintf(PETSC_COMM_WORLD, "\nCreate staggered U, V and P vectors [DMDACreate2d, DMDAGetInfo, DMDAGetOwnershipRanges, DMCreateGlobalVector]"); CHKERRV(ierr);    hline();
	ierr = DMCompositeCreate(PETSC_COMM_WORLD, &(data->pack)); CHKERRV(ierr);
	
	// create u DA
	ierr = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_GHOSTED, DMDA_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, data->nx-1, data->ny, PETSC_DECIDE, PETSC_DECIDE, 1, 1, NULL, NULL, &(data->uda)); CHKERRV(ierr);
	ierr = DMCompositeAddDM(data->pack, data->uda); CHKERRV(ierr);
	
	// determine process distribution of v
	ierr = DMDAGetInfo(data->uda, NULL, NULL, NULL, NULL, &m, &n, NULL, NULL, NULL, NULL, NULL, NULL, NULL); CHKERRV(ierr);
	ierr = DMDAGetOwnershipRanges(data->uda, &lxu, &lyu, NULL); CHKERRV(ierr);
	ierr = PetscMalloc(m*sizeof(*lx), &lx); CHKERRV(ierr);
	ierr = PetscMalloc(n*sizeof(*ly), &ly); CHKERRV(ierr);
	ierr = PetscMemcpy(lx ,lxu, m*sizeof(*lx)); CHKERRV(ierr);
	ierr = PetscMemcpy(ly ,lyu, n*sizeof(*ly)); CHKERRV(ierr);
	lx[m-1]++;
	
	// create v DA
	ierr = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_GHOSTED, DMDA_BOUNDARY_GHOSTED, DMDA_STENCIL_STAR, data->nx, data->ny, m, n, 1, 1, lx, ly, &(data->pda)); CHKERRV(ierr);
	
	// create vectors p and bc2
	ierr = DMCreateGlobalVector(data->pda, &(data->pGlobal)); CHKERRV(ierr);
	ierr = VecDuplicate(data->pGlobal, &(data->bc2)); CHKERRV(ierr);
	ly[n-1]--;
	
	// create p DA
	ierr = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_GHOSTED, DMDA_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, data->nx, data->ny-1, m, n, 1, 1, lx, ly, &(data->vda)); CHKERRV(ierr);
	ierr = DMCompositeAddDM(data->pack, data->vda); CHKERRV(ierr);
	
	PetscFree(lx);
	PetscFree(ly);
	
	// create vector uPacked
	ierr = DMCreateGlobalVector(data->pack, &(data->uPacked)); CHKERRV(ierr);
}
Пример #11
0
void hline()
{
	PetscErrorCode ierr;
	ierr = PetscPrintf(PETSC_COMM_WORLD, "\n------------------------------------------------------------------------------------------------------------------------\n"); CHKERRV(ierr);
}
Ensure(FourthOrderJacobian, is_consistent_for_gaussian) {
  ierr = checkJacobianPreConsistency(&fixture, waveAtRest, gaussian, 0.0, 0.0, PETSC_TRUE, 5.0e-3, PETSC_FALSE);CHKERRV(ierr);
}
Ensure(FourthOrderJacobian, is_consistent_for_sine_waves) {
  ierr = checkJacobianPreConsistency(&fixture, waveAtRest, sine_wave, 0.0, 0.0, PETSC_TRUE, 1.0e-5, PETSC_FALSE);CHKERRV(ierr);
}
Ensure(FourthOrderJacobian, is_consistent_for_constant_fields) {
  ierr = checkJacobianPreConsistency(&fixture, waveAtRest, constant_func, 0.0, 0.0, PETSC_TRUE, 1.0e-6, PETSC_FALSE);CHKERRV(ierr);
}
Ensure(FourthOrderJacobian, can_be_built) {
  ierr = scJacobianBuildLinearPart(fixture.matFixture.da, fixture.matFixture.m, PETSC_TRUE);CHKERRV(ierr);
  assert_that(ierr, is_equal_to(0));
}
Пример #16
0
void coulomb_trick(PetscErrorCode ierr, params *params)    
{       
	size_t neval;
        PetscReal a,b,abserr,coul_result;
	PetscReal mf2,mu2,th2;
	PetscInt start,end;
	PetscInt rank;
	PetscReal *_mu;
	PetscReal *_th;
  	Vec MU_SEQ;
  	Vec TH_SEQ;
	VecScatter     ctm;
	VecScatter     ctt;

	int_params int_params;

	ierr = PetscPrintf(PETSC_COMM_WORLD,"---Beginning Coulomb Trick---\n");CHKERRV(ierr);
	print_progress_header(ierr);
	int_params.epsabs=1e-4;
	int_params.epsrel=1e-8;
	int_params.N_work=4000;
	int_params.flag_asy=params->flag_asy;
	MPI_Comm_rank(PETSC_COMM_WORLD,&rank);	
	for(PetscInt i=0;i<params->nf;i++)
	{
		int_params.p_bohr.push_back(params->p_bohr[i]);
	}

        gsl_function F;
        F.function = &ct_integrand;
        F.params=&int_params;	

	ierr = VecScatterCreateToAll(params->mu,&ctm,&MU_SEQ);CHKERRV(ierr);
  	ierr = VecScatterBegin(ctm,params->mu,MU_SEQ,INSERT_VALUES,SCATTER_FORWARD);CHKERRV(ierr);
  	ierr = VecScatterEnd(ctm,params->mu,MU_SEQ,INSERT_VALUES,SCATTER_FORWARD);CHKERRV(ierr);
  	ierr = VecGetArray(MU_SEQ,&_mu);CHKERRV(ierr);

        ierr = VecScatterCreateToAll(params->theta,&ctt,&TH_SEQ);CHKERRV(ierr);
        ierr = VecScatterBegin(ctt,params->theta,TH_SEQ,INSERT_VALUES,SCATTER_FORWARD);CHKERRV(ierr);
        ierr = VecScatterEnd(ctt,params->theta,TH_SEQ,INSERT_VALUES,SCATTER_FORWARD);CHKERRV(ierr);
        ierr = VecGetArray(TH_SEQ,&_th);CHKERRV(ierr);
  
	ierr = VecGetOwnershipRange(params->CT,&start,&end);CHKERRV(ierr);
	PetscInt step;
	step=1;
	if(params->Jz==0){step=2;start=start+(start%2);}       
	gsl_integration_cquad_workspace *work = gsl_integration_cquad_workspace_alloc(int_params.N_work);
 	for (PetscInt i=start; i<end; i+=step)
	{

		//if((i-start)%((end-start)/10)==0){ierr = PetscPrintf(PETSC_COMM_SELF,"----Cc: r%d -> %d\\%d\n",rank,(i-start),(end-start));CHKERRV(ierr);}
//		if(params->Jz !=0 || i%2==0){
		get_index(i,&int_params,params);

		int_params.mu2 = _mu[params->nm_tot[int_params.index_f]+int_params.index_m];
		int_params.th2 = _th[params->nt_tot[int_params.index_f]+int_params.index_t];
//	        ierr = PetscPrintf(PETSC_COMM_SELF,"Pts: %d %d %f %f\n",int_params.index_m,int_params.index_t,int_params.mu2,int_params.th2);CHKERRV(ierr);

               	if(int_params.index_s<2){int_params.Jzc = params->Jz;}
		else{int_params.Jzc= -params->Jz;}

//                if (int_params.Jzc !=0 || int_params.index_s%2==0)
//                {

		int_params.mf = params->m[int_params.index_f];

	
		mf2=int_params.mf*int_params.mf;
		mu2=int_params.mu2;
		th2=int_params.th2;		
			
	      	int_params.x2 = (1.0+mu2*th2/sqrt(mf2+mu2*mu2))/2.0;
        	int_params.k2 = mu2*sqrt(1.0-th2*th2);

		a = 0.0;
                b = params->lambda[int_params.index_f]/2.0;

//                if (int_params.Jzc !=0 || int_params.index_s%2==0)
//                {
//	        	gsl_integration_cquad_workspace *work = gsl_integration_cquad_workspace_alloc(int_params.N_work);
	                gsl_integration_cquad(&F,a,b,int_params.epsabs,int_params.epsrel,work,&coul_result,&abserr,&neval);
//                   	gsl_integration_cquad_workspace_free(work);

			ierr  = VecSetValues(params->CT,1,&i,&coul_result,ADD_VALUES);CHKERRV(ierr);
	                if (params->Jz==0)
			{ 
				PetscInt ishift;
				ishift=i+(3-2*int_params.index_s);
	      			ierr  = VecSetValues(params->CT,1,&ishift,&coul_result,ADD_VALUES);CHKERRV(ierr);
			}

//		}
//	        ierr = PetscPrintf(PETSC_COMM_SELF,"Pts: %d %d %f %f %f\n",int_params.index_m,int_params.index_t,int_params.mu2,int_params.th2,coul_result);CHKERRV(ierr);
		if((i-start)%((end-start)/4)==0){ierr = PetscPrintf(PETSC_COMM_SELF,"|");CHKERRV(ierr);}
	}
        gsl_integration_cquad_workspace_free(work);

	ierr = VecRestoreArray(MU_SEQ,&_mu);CHKERRV(ierr);
	ierr = VecScatterDestroy(&ctm);CHKERRV(ierr);
	ierr = VecDestroy(&MU_SEQ);CHKERRV(ierr);

        ierr = VecRestoreArray(TH_SEQ,&_th);CHKERRV(ierr);
	ierr = VecScatterDestroy(&ctt);CHKERRV(ierr);
        ierr = VecDestroy(&TH_SEQ);CHKERRV(ierr);

	ierr = VecAssemblyBegin(params->CT);CHKERRV(ierr);
	ierr = VecAssemblyEnd(params->CT);CHKERRV(ierr);
    	
	ierr = PetscPrintf(PETSC_COMM_WORLD,"\n---Finishing Coulomb Trick---\n");CHKERRV(ierr);
}
Пример #17
0
void read_input(PetscErrorCode ierr, char **argv, params *params)
//void read_input(char **argv,char *ofile_n, PetscInt *nf, PetscInt *Jz, PetscReal *alpha,std::vector<PetscReal> &m,std::vector<PetscInt> &nm,std::vector<PetscInt> &nt,std::vector<PetscReal> &lambda)
{

        std::ifstream ifile;
        std::string ifile_n;
        std::string null;

	PetscReal datar;
	PetscReal datat;
	PetscInt  datai;
	PetscInt  N_mu_tot;
	PetscInt  N_theta_tot;

        ifile_n = argv[1];
        ifile.open(ifile_n.c_str());
        if(!ifile.is_open())
        {
	        ierr = PetscPrintf(PETSC_COMM_WORLD,"---Error:: Initialization File Doesn't Exist---\n");CHKERRV(ierr);
        }

        ifile >> params->ofile_n >> null;
        ifile >> params->nf >> null;
	ifile >> params->Jz >> null;
        ifile >> params->alpha >> null;
        ifile >> params->flag_nm_dis >> null;
        ifile >> params->flag_nt_dis >> null;
        ifile >> params->flag_anni >> null;
        ifile >> params->flag_mix >> null;
        ifile >> params->flag_asy >> null;
        ifile >> params->flag_mumps >> null;
        for(int i=0; i<params->nf; i++)
        {
		ifile >> null;
		
		ifile >> datar >> null;
                params->m.push_back(datar);
                params->p_bohr.push_back(datar*params->alpha/2.0);
		ifile >> datai >> null;
                params->nm.push_back(datai);
		ifile >> datai >> null;
                params->nt.push_back(datai);
		ifile >> datar >> null;
                params->lambda.push_back(datar);
        }
	set_sflags(params);
	ifile.close();

	N_mu_tot=0;
	N_theta_tot=0;
	params->N_tot=0;
	
	datat=0.0;
	datar=0.0;
	for( PetscInt i=0;i<params->nf;i++)
	{
		params->nm_tot.push_back(datar);
		params->nt_tot.push_back(datat);
		N_mu_tot+=params->nm[i];
		N_theta_tot+=params->nt[i];
		params->N_tot+=params->nm[i]*params->nt[i];
		params->N_tot_f.push_back(params->N_tot);
		datar+=params->nm[i];
		datat+=params->nt[i];
	}
	get_outfile_name(params);

	params->hfile.append(params->ofile_n);
        params->hfile.append("_H");

	
	ierr = VecCreate(PETSC_COMM_WORLD,&params->mu);CHKERRV(ierr);
        ierr = VecSetSizes(params->mu,PETSC_DECIDE,N_mu_tot);CHKERRV(ierr);
        ierr = VecSetFromOptions(params->mu);CHKERRV(ierr);

	ierr = VecCreate(PETSC_COMM_WORLD,&params->wmu);CHKERRV(ierr);
        ierr = VecSetSizes(params->wmu,PETSC_DECIDE,N_mu_tot);CHKERRV(ierr);
        ierr = VecSetFromOptions(params->wmu);CHKERRV(ierr);

	ierr = VecCreate(PETSC_COMM_WORLD,&params->theta);CHKERRV(ierr);
        ierr = VecSetSizes(params->theta,PETSC_DECIDE,N_theta_tot);CHKERRV(ierr);
        ierr = VecSetFromOptions(params->theta);CHKERRV(ierr);

	ierr = VecCreate(PETSC_COMM_WORLD,&params->wtheta);CHKERRV(ierr);
        ierr = VecSetSizes(params->wtheta,PETSC_DECIDE,N_theta_tot);CHKERRV(ierr);
        ierr = VecSetFromOptions(params->wtheta);CHKERRV(ierr);

	ierr = VecCreate(PETSC_COMM_WORLD,&params->CT);CHKERRV(ierr);
        ierr = VecSetSizes(params->CT,PETSC_DECIDE,4*params->N_tot);CHKERRV(ierr);
        ierr = VecSetFromOptions(params->CT);CHKERRV(ierr);
}
Ensure(FourthOrderJacobian, is_consistent_for_gaussian_right_moving) {
  ierr = checkJacobianPreConsistency(&fixture, rightMovingWave, gaussian, 0.0, 0.0, PETSC_TRUE, 1.0e0, PETSC_FALSE);CHKERRV(ierr);
}