void SingleStar::read_from_file(const char* str, int* i1, int* i2) {
	if (MPI_rank() == 0) {
		printf("Reading checkpoint file\n");
	}
	PhysicalConstants::set_cgs();
	char* fname;
	Real omega;
	FILE* fp;
	_3Vec O;
	asprintf(&fname, "checkpoint.%s.%i.bin", str, MPI_rank());
	fp = fopen(fname, "rb");
	if (fp == NULL) {
		printf("Error - Checkpoint file not found!");
		abort();
	}
	free(fname);
//	fread(&refine_floor, sizeof(Real), 1, fp);
	fread(&State::ei_floor, sizeof(Real), 1, fp);
	fread(&State::rho_floor, sizeof(Real), 1, fp);
//	fread(&com_vel_correction, sizeof(_3Vec), 1, fp);
	fread(&O, sizeof(_3Vec), 1, fp);
	fread(&omega, sizeof(Real), 1, fp);
//	set_origin(O);
	fread(&last_dt, sizeof(Real), 1, fp);
	fread(i1, sizeof(int), 1, fp);
	fread(i2, sizeof(int), 1, fp);
	get_root()->read_checkpoint(fp);
	fclose(fp);
	State::set_omega(omega);
	int count = OctNode::get_local_node_cnt();
	for (int i = 0; i < count; i++) {
		dynamic_cast<MultiGrid*>(OctNode::get_local_node(i))->phi_calc_amr_bounds();
	}
#ifdef USE_FMM
	FMM_solve();
#else
	solve_poisson();
#endif
}
Exemplo n.º 2
0
real do_optimize_poisson(FILE *log,       bool bVerbose,
			 t_inputrec *ir,  int natoms,
			 rvec x[],        rvec f[],
			 real charge[],   rvec box,
			 real phi[],      t_commrec *cr,
			 t_nrnb *nrnb,    rvec f_ref[],
			 real phi_ref[],  rvec beta,
			 bool bOld)
{
#define BMIN 1.6
#define DB   0.025
#define NB   (1+(int)((2.1-BMIN)/DB))
  static  bool bFirst  = TRUE;
  static  bool bSecond = TRUE;
  static  t_PSgrid *pot,*rho;
  static  int       maxnit;
  static  real      r1,rc;
  
  real      rmsf[NB][NB][NB],rmsf_min,rrmsf;
  ivec      minimum;
  const     real tol = 1e-2;
  int       i,m,bx,by,bz;
  char      buf[128];
  real      ener;
  
  ener = 0.0;
  
  if (bFirst) {
    maxnit = ir->userint1;

    fprintf(log,"Will use Poisson Solver for long-range electrostatics\n");
    fprintf(log,"Grid size is %d x %d x %d\n",ir->nkx,ir->nky,ir->nkz);

    if ((ir->nkx < 4) || (ir->nky < 4) || (ir->nkz < 4)) 
      fatal_error(0,"Grid must be at least 4 points in all directions");
    
    pot = mk_PSgrid(ir->nkx,ir->nky,ir->nkz);
    rho = mk_PSgrid(ir->nkx,ir->nky,ir->nkz);
    
    r1 = ir->rcoulomb_switch;
    rc = ir->rcoulomb;
    for(m=0; (m<DIM); m++)
      beta[m] = 4.0/3.0;
      
    bFirst = FALSE;
  }

  /* Make the grid empty */
  clear_PSgrid(rho);
  spread_q_poisson(log,bVerbose,TRUE,natoms,x,charge,box,rc,rho,nrnb,
		   bOld,r1);
  
  symmetrize_PSgrid(log,rho,0.0);
  if (bSecond) 
    copy_PSgrid(pot,rho);
  
  /* Second step: solving the poisson equation in real space */
  (void) solve_poisson(log,pot,rho,bVerbose,nrnb,maxnit,tol,box);
  
  symmetrize_PSgrid(log,pot,0.0);
  /* Third and last step: gather the forces, energies and potential
   * from the grid.
   */
#define BETA(n) (BMIN+n*DB)
  /* Optimization of beta in progress */
  for(bx=0; (bx<NB); bx++) {
    beta[XX] = BETA(bx);
    for(by=0; (by<NB); by++) {
      beta[YY] = BETA(by);
      for(bz=0; (bz<NB); bz++) {
	beta[ZZ] = BETA(bz);
	  
	for(i=0; (i<natoms); i++) {
	  phi[i] = 0.0;
	  clear_rvec(f[i]);
	}
	ener = ps_gather_f(log,bVerbose,natoms,x,f,charge,box,
			   phi,pot,beta,nrnb);
	sprintf(buf,"Poisson, beta = %g\n",beta[XX]);
	rmsf[bx][by][bz] = 
	  analyse_diff(log,buf,natoms,f_ref,f,phi_ref,phi,NULL,
		       /*"fcorr.xvg","pcorr.xvg"*/NULL,NULL,NULL,NULL);
      }
    }
  }
  rmsf_min = rmsf[0][0][0];
  minimum[XX] = minimum[YY] = minimum[ZZ] = 0;
  for(bx=0; (bx<NB); bx++) {
    beta[XX] = BETA(bx);
    for(by=0; (by<NB); by++) {
      beta[YY] = BETA(by);
      for(bz=0; (bz<NB); bz++) {
	beta[ZZ] = BETA(bz);
	rrmsf    = rmsf[bx][by][bz];
	
	fprintf(log,"Beta: %6.3f  %6.3f  %6.3f  RMSF: %8.3f\n",
		beta[XX],beta[YY],beta[ZZ],rrmsf);
	if (rrmsf < rmsf_min) {
	  rmsf_min = rrmsf;
	  minimum[XX] = bx;
	  minimum[YY] = by;
	  minimum[ZZ] = bz;
	}
      }
    }
  }
  beta[XX] = BETA(minimum[XX]);
  beta[YY] = BETA(minimum[YY]);
  beta[ZZ] = BETA(minimum[ZZ]);
  fprintf(log,"Minimum RMSF %8.3f at Beta = %6.3f  %6.3f  %6.3f\n",
	  rmsf_min,beta[XX],beta[YY],beta[ZZ]);
  /* Computing optimum once more... */
  for(i=0; (i<natoms); i++) {
    phi[i] = 0.0;
    clear_rvec(f[i]);
  }
  ener = ps_gather_f(log,bVerbose,natoms,x,f,charge,box,phi,pot,beta,nrnb);

  return ener;
}
Exemplo n.º 3
0
real do_poisson(FILE *log,       bool bVerbose,
		t_inputrec *ir,  int natoms,
		rvec x[],        rvec f[],
		real charge[],   rvec box,
		real phi[],      t_commrec *cr,
		t_nrnb *nrnb,    int *nit,   
		bool bOld)
{
  static  bool bFirst  = TRUE;
  static  t_PSgrid *pot,*rho;
  static  int       maxnit;
  static  real      r1,rc;
  static  rvec      beta;
  
  const     real tol = 1e-2;
  int       m;
  real      ener;
  
  ener = 0.0;
  
  if (bFirst) {
    maxnit = ir->userint1;

    fprintf(log,"Will use Poisson Solver for long-range electrostatics\n");
    fprintf(log,"Grid size is %d x %d x %d\n",ir->nkx,ir->nky,ir->nkz);

    if ((ir->nkx < 4) || (ir->nky < 4) || (ir->nkz < 4)) 
      fatal_error(0,"Grid must be at least 4 points in all directions");
    
    pot = mk_PSgrid(ir->nkx,ir->nky,ir->nkz);
    rho = mk_PSgrid(ir->nkx,ir->nky,ir->nkz);
    
    r1 = ir->rcoulomb_switch;
    rc = ir->rcoulomb;
    for(m=0; (m<DIM); m++)
      beta[m] = 1.85;
      
  }

  /* Make the grid empty and spread the charges */
  clear_PSgrid(rho);
  spread_q_poisson(log,bVerbose,TRUE,natoms,x,charge,box,rc,rho,nrnb,bOld,r1);
  
  /* Subtract average charge distribution from each grid point. This does not
   * influence the forces, but it may influence the potential and the energy.
   * On the other hand the charge distribution should sum up to zero if the
   * system is neutral!
   */
  symmetrize_PSgrid(debug,rho,0.0);
  
  /* For the first time we solve the potential we copy the charge distribution to
   * the potential as a start for the solver. Later we use the previous step's
   * solution.
   */
  if (bFirst)
    copy_PSgrid(pot,rho);
  
  /* Second step: solving the poisson equation in real space */
  *nit = solve_poisson(log,pot,rho,bVerbose,nrnb,maxnit,tol,box);
  
  symmetrize_PSgrid(debug,pot,0.0);
  
  /* Third and last step: gather the forces, energies and potential
   * from the grid.
   */
  ener = ps_gather_f(log,bVerbose,natoms,x,f,charge,box,phi,pot,beta,nrnb);
  
  bFirst = FALSE;
  
  return ener;
}