void CSNBListCompressionFix::runEvent() const { double locdt = dt; #ifdef DYNAMO_DEBUG if (boost::math::isnan(dt)) M_throw() << "A NAN system event time has been found"; #endif Sim->dSysTime += locdt; Sim->ptrScheduler->stream(locdt); //dynamics must be updated first Sim->dynamics.stream(locdt); Sim->freestreamAcc += locdt; CGNeighbourList& nblist(dynamic_cast<CGNeighbourList&> (*Sim->dynamics.getGlobals()[cellID])); dout << "Rebuilding the neighbour list named " << nblist.getName() << "\nNColl = " << Sim->eventCount << "\nSys t = " << Sim->dSysTime / Sim->dynamics.units().unitTime() << std::endl; nblist.reinitialise(1.0001 * nblist.getMaxSupportedInteractionLength()); dt = (nblist.getMaxSupportedInteractionLength() / nblist.getMaxInteractionLength() - 1.0) / growthRate - Sim->dSysTime; }
void SysNBListCompressionFix::initialise(size_t nID) { ID = nID; if (!std::tr1::dynamic_pointer_cast<GNeighbourList>(Sim->dynamics.getGlobals()[cellID])) M_throw() << "Have the globals been shuffled? The cellID is no longer a GNeighbourList."; GNeighbourList& nblist(dynamic_cast<GNeighbourList&>(*Sim->dynamics.getGlobals()[cellID])); initialSupportedRange = nblist.getMaxInteractionRange(); dt = (nblist.getMaxSupportedInteractionLength() / initialSupportedRange - 1.0) / growthRate - Sim->dSysTime; dout << "Compression Hack Loaded" << "\nFor global " << nblist.getName() << "\nCompression rate = " << growthRate / Sim->dynamics.units().unitTime() << "\nSim Units compression rate = " << growthRate << "\nMax length of interaction = " << nblist.getMaxSupportedInteractionLength() / Sim->dynamics.units().unitLength() << "\nMaximum supported length = " << nblist.getMaxSupportedInteractionLength() / Sim->dynamics.units().unitLength() << "\nFirst halt scheduled for " << dt / Sim->dynamics.units().unitTime() << std::endl; }
void SysNBListCompressionFix::fixNBlistForOutput() { GNeighbourList& nblist(dynamic_cast<GNeighbourList&> (*Sim->globals[cellID])); nblist.setMaxInteractionRange(initialSupportedRange * (1.0 + growthRate * Sim->systemTime)); }
void SysNBListCompressionFix::runEvent() const { double locdt = dt; #ifdef DYNAMO_DEBUG if (std::isnan(dt)) M_throw() << "A NAN system event time has been found"; #endif Sim->systemTime += locdt; Sim->ptrScheduler->stream(locdt); //dynamics must be updated first Sim->stream(locdt); GNeighbourList& nblist(dynamic_cast<GNeighbourList&> (*Sim->globals[cellID])); dout << "Rebuilding the neighbour list named " << nblist.getName() << "\nNColl = " << Sim->eventCount << "\nSys t = " << Sim->systemTime / Sim->units.unitTime() << std::endl; nblist.setMaxInteractionRange(nblist.getMaxSupportedInteractionLength() * 1.1); dt = (nblist.getMaxSupportedInteractionLength() / initialSupportedRange - 1.0) / growthRate - Sim->systemTime; NEventData SDat; Sim->_sigParticleUpdate(SDat); for (shared_ptr<OutputPlugin>& Ptr : Sim->outputPlugins) Ptr->eventUpdate(*this, SDat, locdt); }
void xedos_hmc(int k) { int old_bin; int new_bin; int boxns = box[k].boxns; double L_initial; double L_final; double U_initial; double U_final; double K_initial; double K_final; double E_initial; double E_final; double vscal[NBOXES]; double beta_old; double beta_new; vscal[k] = 1.0; // initial scale for velocity beta_old = 1.0/sim.kT[k]; beta_new = beta_old; vinit_hyb(k); kinet(k); calcvalue(k); /* ------------------------------------ */ /* Back up coords, force, virial and */ /* energy components. */ /* ------------------------------------ */ for(int l =0; l< boxns; l++){ atom_temp[k][l] = atom[k][l]; atnopbc_temp[k][l] = atnopbc[k][l]; ff_temp[k][l] = ff[k][l]; vv_temp[k][l] = vv[k][l]; } #ifdef PRESSURE pvir_temp[k] = pvir[k]; #endif en_temp[k] = en[k]; U_initial = en[k].potens; K_initial = en[k].kinet; E_initial = U_initial+K_initial; end_to_end(k,SITE1,SITE2); L_initial = ordparam[k].d_nc; old_bin = (int) ((L_initial - sim_dos[k].l_begin)/sim_dos[k].l_width); /* ----------------------------------------------- */ /* Propagate the system with verlet integrator. */ /* ----------------------------------------------- */ for (int j=0;j < sim_hyb.cyc_hybmd; j++){ if(sim.nsteps ==1){ integrate_vverlet(k, vscal[k]); #ifdef DLIST nl_check(0,box[k].boxns,k); if(nl_flag[k] == 1) nblist(k); #endif } else { if(j==0){ force_short(k); for(int l=0; l< box[k].boxns; l++){ ff_long[k][l].x = ff_temp[k][l].x-ff_short[k][l].x; ff_long[k][l].y = ff_temp[k][l].y-ff_short[k][l].y; ff_long[k][l].z = ff_temp[k][l].z-ff_short[k][l].z; } } integrate_dos_mts(k,vscal[k]); #ifdef DLIST nl_check(0,box[k].boxns,k); if(nl_flag[k] == 1) nblist(k); #endif } #ifdef STATUS curr_status(k,7); #endif } /* ----------------------------------------------- */ /* Calculate the properties of the system. */ /* ----------------------------------------------- */ kinet(k); calcvalue(k); U_final = en[k].potens; K_final = en[k].kinet; E_final = U_final+K_final; end_to_end(k,SITE1,SITE2); L_final = ordparam[k].d_nc; #ifdef WALL int beyond_wall_flag = 0; //flag to see if particle moved past wall //for(int i=0; i<wall[k].n; i++){ for(int j=0; j<box[k].boxns; j++){ if(atom[k][j].z < wall[k].z[0]){ beyond_wall_flag = 1; break; } } //} /* ----------------------------------------------- */ /* Check the acceptance of the move. First check */ /* to see if the system moved out of range, then */ /* check to see if it is accepted. */ /* ----------------------------------------------- */ if (L_final >= sim_dos[k].l_begin && L_final < sim_dos[k].l_end && beyond_wall_flag == 0){ #else if (L_final >= sim_dos[k].l_begin && L_final < sim_dos[k].l_end){ #endif new_bin = (int) ((L_final - sim_dos[k].l_begin)/sim_dos[k].l_width); double g_old = dos_interp(k,old_bin,L_initial); double g_new = dos_interp(k,new_bin,L_final); double arg = g_old - g_new + E_initial*beta_old-E_final*beta_new; if (arg>0.0){ dos_hist[k][new_bin].h_of_l ++; dos_hist[k][new_bin].g_of_l += sim_dos[k].mod_f; flat_histogram(k); #ifdef NLIST #ifndef DLIST if(sim_dos[k].dos_acc %sim.nlist==0) nblist(k); // call Nblist every nblist accepted moves #endif #ifdef DLIST nl_check(0, boxns, k); if(nl_flag[k] == 1) nblist(k); #endif #endif sim_dos[k].dos_acc ++; }//accepted else if (exp(arg) > ran2()){ dos_hist[k][new_bin].h_of_l ++; dos_hist[k][new_bin].g_of_l += sim_dos[k].mod_f; flat_histogram(k); #ifdef NLIST #ifndef DLIST if(sim_dos[k].dos_acc %sim.nlist==0) nblist(k); // call Nblist every nblist accepted moves #endif #ifdef DLIST nl_check(0, boxns, k); if(nl_flag[k] == 1) nblist(k); #endif #endif sim_dos[k].dos_acc ++; }//accepted else{ for(int l =0; l< boxns; l++){ atom[k][l] = atom_temp[k][l]; /* Back up coordinates with pdb */ atnopbc[k][l] = atnopbc_temp[k][l]; /* Back up coordinates without pdb */ ff[k][l] = ff_temp[k][l]; /* Back to old force components */ vv[k][l] = vv_temp[k][l]; uu[k][l] = vv[k][l]; } #ifdef PRESSURE pvir[k] = pvir_temp[k]; /* Back to old virial components */ #endif en[k] = en_temp[k]; /* Back to old energy components */ dos_hist[k][old_bin].h_of_l ++; dos_hist[k][old_bin].g_of_l += sim_dos[k].mod_f; flat_histogram(k); end_to_end(k,SITE1,SITE2); // recompute to get back to the old }//rejected } else{ for(int l =0; l< boxns; l++){ atom[k][l] = atom_temp[k][l]; /* Back up coordinates with pdb */ atnopbc[k][l] = atnopbc_temp[k][l]; /* Back up coordinates without pdb */ ff[k][l] = ff_temp[k][l]; /* Back to old force components */ vv[k][l] = vv_temp[k][l]; uu[k][l] = vv[k][l]; } #ifdef PRESSURE pvir[k] = pvir_temp[k]; /* Back to old virial components */ #endif en[k] = en_temp[k]; /* Back to old energy components */ dos_hist[k][old_bin].h_of_l ++; dos_hist[k][old_bin].g_of_l += sim_dos[k].mod_f; flat_histogram(k); end_to_end(k,SITE1,SITE2); // recompute to get back to the old }//rejected calcvalue(k); // needed to update box.variable correctly dos_svalues(k); }
int swap_mpi(unsigned long iter, int flag, int ibox) { int k =ibox; /*------------------------------------------------------*/ /* The energy of this process is saved in e1 whereas */ /* The energy of the partner process is saved in e2 */ /*------------------------------------------------------*/ double e1 = en[k].totals; int old_bin_1 = (int) ((e1 - sim_dos[k].e_begin)/sim_dos[k].e_width); MPI_Status status; if(mpi.my_rank!=mpi.p-1 && flag ==1) { struct msg_swap_request swap_request; swap_request.totals = en[k].totals; swap_request.e_begin = sim_dos[k].e_begin; swap_request.e_end = sim_dos[k].e_end; swap_request.mod_f = sim_dos[k].mod_f; struct msg_swap_accept swap_accept; /* ------------------------------------------------ */ /* If I am not the last process and if my flag ==1 */ /* then send data/swap request to my_rank +1 */ /* ------------------------------------------------ */ MPI_Send(&swap_request,sizeof(swap_request),MPI_CHAR,mpi.my_rank+1,1,MPI_COMM_WORLD); /* ------------------------------------------------ */ /* Receive the information whether move is accepted */ /* or rejected. */ /* ------------------------------------------------ */ MPI_Recv(&swap_accept, sizeof(swap_accept), MPI_CHAR,mpi.my_rank+1,2,MPI_COMM_WORLD,&status); /* ------------------------------------------------ */ /* If move is rejected no more communication needed */ /* ------------------------------------------------ */ if(swap_accept.accept==0){ dos_hist[k][old_bin_1].h_of_e ++; dos_hist[k][old_bin_1].k_of_e += en[k].kinet; if(sim_dos[k].mod_f <MERGE_F && ((iter%(MERGE_N*(unsigned long)sim_hyb.cyc_swap)==0) || (iter%(((unsigned long)(MERGE_N+1))*(unsigned long)sim_hyb.cyc_swap)==0))){ MPI_Send(dos_hist[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank+1,14,MPI_COMM_WORLD); MPI_Recv(dos_hist[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank+1,15,MPI_COMM_WORLD,&status); } return 0; }// is swap not accepted then for the sending box /* ------------------------------------------------ */ /* If move is accepted then create a back up of */ /* of current structures and then receive the data */ /* from the partner process and after that send the */ /* back up info to the partner to complete the swap */ /* ------------------------------------------------ */ else if (swap_accept.accept==1){ for(int i =0; i< box[k].boxns; i++){ atom_temp[k][i] = atom[k][i]; /* Back up coordinates of box k */ atnopbc_temp[k][i] = atnopbc[k][i]; /* Back up coordinates of box k */ ff_temp[k][i] = ff[k][i]; vv_temp[k][i] = vv[k][i]; } /*======================================*/ /* Tranfer data from box k to temp */ /*======================================*/ en_temp[k] = en[k]; MPI_Recv(atom[k], box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank+1,3,MPI_COMM_WORLD,&status); MPI_Recv(atnopbc[k],box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank+1,4,MPI_COMM_WORLD,&status); MPI_Recv(ff[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank+1,5,MPI_COMM_WORLD,&status); MPI_Recv(vv[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank+1,6,MPI_COMM_WORLD,&status); MPI_Recv(&en[k], sizeof(struct energy),MPI_CHAR,mpi.my_rank+1,11,MPI_COMM_WORLD,&status); uu[k] = vv[k]; en[k].totals = swap_accept.totals; int new_bin_1 = (int) ((en[k].totals - sim_dos[k].e_begin)/sim_dos[k].e_width); MPI_Send(atom_temp[k], box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank+1, 7,MPI_COMM_WORLD); MPI_Send(atnopbc_temp[k],box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank+1, 8,MPI_COMM_WORLD); MPI_Send(ff_temp[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank+1, 9,MPI_COMM_WORLD); MPI_Send(vv_temp[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank+1,10,MPI_COMM_WORLD); MPI_Send(&en_temp[k], sizeof(struct energy),MPI_CHAR,mpi.my_rank+1,12,MPI_COMM_WORLD); dos_hist[k][new_bin_1].h_of_e ++; dos_hist[k][new_bin_1].k_of_e += en[k].kinet; #ifdef NLIST nblist(k); #endif if(sim_dos[k].mod_f <MERGE_F && ((iter%(MERGE_N*(unsigned long)sim_hyb.cyc_swap)==0) || (iter%(((unsigned long)(MERGE_N+1))*(unsigned long)sim_hyb.cyc_swap)==0))){ MPI_Send(dos_hist[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank+1,14,MPI_COMM_WORLD); MPI_Recv(dos_hist[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank+1,15,MPI_COMM_WORLD,&status); } return 1; }// if swap accepted then for the sending box }// end of mpi.rank !=p-1 else if(mpi.my_rank!=0 && flag==0) { /* Recv data from my_rank-1 */ struct msg_swap_request swap_request; // swap_request.potens = en[k].potens; // swap_request.e_begin = sim_dos[k].e_begin; // swap_request.e_end = sim_dos[k].e_end; struct msg_swap_accept swap_accept; /* Recv data from my_rank-1 */ MPI_Recv(&swap_request,sizeof(swap_request),MPI_CHAR,mpi.my_rank-1,1,MPI_COMM_WORLD,&status); double e2 = swap_request.totals; double mod_f = swap_request.mod_f; /* ---------------------------------------- */ /* This onwards added later for on the fly */ /* merging of g_of_e */ double e_begin = swap_request.e_begin; double e_end = swap_request.e_end; /* ---------------------------------------- */ if ((e2 >= sim_dos[k].e_begin && e2 < sim_dos[k].e_end) && (e1 >= swap_request.e_begin && e1 < swap_request.e_end)) { swap_accept.accept = 1; swap_accept.totals = e1; MPI_Send(&swap_accept,sizeof(swap_accept), MPI_CHAR,mpi.my_rank-1,2,MPI_COMM_WORLD); MPI_Send(atom[k], box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank-1,3,MPI_COMM_WORLD); MPI_Send(atnopbc[k],box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank-1,4,MPI_COMM_WORLD); MPI_Send(ff[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank-1,5,MPI_COMM_WORLD); MPI_Send(vv[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank-1,6,MPI_COMM_WORLD); MPI_Send(&en[k], sizeof(struct energy),MPI_CHAR,mpi.my_rank-1,11,MPI_COMM_WORLD); en[k].totals = e2; int new_bin_1 = (int) ((en[k].totals - sim_dos[k].e_begin)/sim_dos[k].e_width); MPI_Recv(atom[k], box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank-1, 7,MPI_COMM_WORLD,&status); MPI_Recv(atnopbc[k],box[k].boxns * sizeof(struct atoms),MPI_CHAR,mpi.my_rank-1, 8,MPI_COMM_WORLD,&status); MPI_Recv(ff[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank-1, 9,MPI_COMM_WORLD,&status); MPI_Recv(vv[k], box[k].boxns * sizeof(struct veloc),MPI_CHAR,mpi.my_rank-1,10,MPI_COMM_WORLD,&status); MPI_Recv(&en[k], sizeof(struct energy),MPI_CHAR,mpi.my_rank-1,12,MPI_COMM_WORLD,&status); uu[k] = vv[k]; dos_hist[k][new_bin_1].h_of_e ++; dos_hist[k][new_bin_1].k_of_e += en[k].kinet; #ifdef NLIST nblist(k); #endif if(mod_f<MERGE_F && ((iter%(MERGE_N*(unsigned long)sim_hyb.cyc_swap)==0) || (iter%(((unsigned long)(MERGE_N+1))*(unsigned long)sim_hyb.cyc_swap)==0))){ MPI_Recv(dos_hist_temp[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank-1,14,MPI_COMM_WORLD,&status); if (sim_dos[k].mod_f <MERGE_F) merge_gofe(k,e_begin,e_end, mod_f); MPI_Send(dos_hist_temp[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank-1,15,MPI_COMM_WORLD); } return 1; }//end of accept for receiving box else { swap_accept.accept=0; swap_accept.potens=e2;// e2 belongs to myrank-1 MPI_Send(&swap_accept,sizeof(swap_accept), MPI_CHAR,mpi.my_rank-1,2,MPI_COMM_WORLD); dos_hist[k][old_bin_1].h_of_e ++; dos_hist[k][old_bin_1].k_of_e += en[k].kinet; if(mod_f<MERGE_F && ((iter%(MERGE_N*(unsigned long)sim_hyb.cyc_swap)==0) || (iter%(((unsigned long)(MERGE_N+1))*(unsigned long)sim_hyb.cyc_swap)==0))){ MPI_Recv(dos_hist_temp[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank-1,14,MPI_COMM_WORLD,&status); if (sim_dos[k].mod_f <MERGE_F) merge_gofe(k,e_begin,e_end,mod_f); MPI_Send(dos_hist_temp[k],NBINS*sizeof(struct hist),MPI_CHAR,mpi.my_rank-1,15,MPI_COMM_WORLD); } return 0; }// end of reject for receiving box }// end of rank!=0 loop return 2; }
void mmdos_hmc(int k){ int old_bin; int new_bin; double E_initial; double E_final; double U_initial; double U_final; double K_initial; double K_final; double vscal[NBOXES]; double beta_old; double beta_new; double arg=0.0; double d_of_f = ( 3.0 * box[k].boxns -2.0)* 0.5; double scal = 1.0/( 3.0 * box[k].boxns *0.5 * RG * 0.0010); vscal[k] = 1.0; // initial scale for velocity E_initial = en[k].totals; U_initial = en[k].potens; K_initial = E_initial - U_initial; old_bin = (int) ((E_initial - sim_dos[k].e_begin)/sim_dos[k].e_width); sim.T[k] = K_initial * scal; sim.kT[k] = RG * sim.T[k]*0.001; beta_old = 1.0/sim.kT[k]; beta_new = beta_old; vinit_hyb(k); kinet(k); // what if this kE is not exactly the K_initial then en.total will change too // calcvalue(k); // whether to call this calclvalue and update K_initial and E_initial for(int l =0; l< box[k].boxns; l++){ atom_temp[k][l] = atom[k][l]; /* Back up coordinates with pdb */ atnopbc_temp[k][l] = atnopbc[k][l]; /* Back up coordinates without pdb */ ff_temp[k][l] = ff[k][l]; /* Back up all the force components */ } #ifdef PRESSURE pvir_temp[k] = pvir[k]; /* Back up all the virial components */ #endif en_temp[k] = en[k]; /* Back up all the energy components */ for (int j=0;j < sim_hyb.cyc_hybmd; j++){ integrate_vverlet(k, vscal[k]); #ifdef DLIST nl_check(0,box[k].boxns,k); if(nl_flag[k] == 1) nblist(k); #endif }// j loop ends here /* ----------------------------------------------- */ /* Calculate the properties of the system. */ /* ----------------------------------------------- */ kinet(k); calcvalue(k); E_final = en[k].totals; U_final = en[k].potens; K_final = en[k].kinet; if (E_final >= sim_dos[k].e_begin && E_final < sim_dos[k].e_end){ new_bin = (int) ((E_final - sim_dos[k].e_begin)/sim_dos[k].e_width); arg = dos_hist[k][old_bin].g_of_e - dos_hist[k][new_bin].g_of_e + d_of_f * (log(K_final/K_initial)) - beta_old*(K_final-K_initial); } /* ----------------------------------------------- */ /* If the moves is accepted then accumulate the */ /* calculated values for block averages and error */ /* bars else first return to original values and */ /* then accumulate statistics */ /* ----------------------------------------------- */ if (E_final >= sim_dos[k].e_begin && E_final < sim_dos[k].e_end && arg >0){ dos_hist[k][new_bin].h_of_e ++; dos_hist[k][new_bin].k_of_e +=K_final; #ifdef NLIST if(sim_dos[k].dos_acc %sim.nlist==0) nblist(k); // call Nblist every nblist accepted moves #endif sim_dos[k].dos_acc ++; }//accepted else if (E_final >= sim_dos[k].e_begin && E_final < sim_dos[k].e_end && exp(arg)> ran2()){ dos_hist[k][new_bin].h_of_e ++; dos_hist[k][new_bin].k_of_e +=K_final; #ifdef NLIST if(sim_dos[k].dos_acc %sim.nlist==0) nblist(k); // call Nblist every nblist accepted moves #endif sim_dos[k].dos_acc ++; }//accepted else{ for(int l =0; l< box[k].boxns; l++){ atom[k][l] = atom_temp[k][l]; /* Back up coordinates with pdb */ atnopbc[k][l] = atnopbc_temp[k][l]; /* Back up coordinates without pdb */ ff[k][l] = ff_temp[k][l]; /* Back to old force components */ } #ifdef PRESSURE pvir[k] = pvir_temp[k]; /* Back to old virial components */ #endif en[k] = en_temp[k]; /* Back to old energy components */ dos_hist[k][old_bin].h_of_e ++; dos_hist[k][old_bin].k_of_e += K_initial; }//rejected calcvalue(k); // this calcvalue may lead to a system with not K_initial but asssigned KE in case move rejected svalues(k); }