/** * \brief This function starts a Spatial Averaging Monte Carlo (SA-MC) simulation. * * \details This function is first in charge of opening all the output (coordinates, trajectory and energy) files.\n * Then the function \b #launch_SPAV starting the simulation is called.\n * In the end it prints results, close the files and goes back to the function \b #main. * * \param dat is a structure containing control parameters common to all simulations. * \param spdat is a structure containing control parameters dedicated to Spatial Averaging simulations. * \param at[] is an array of structures ATOM containing coordinates and other variables. */ void start_spav(DATA *dat, SPDAT *spdat, ATOM at[]) { fprintf(stdout,"SPAV parameters are :\n"); fprintf(stdout,"W_EPSILON = %lf\nM_EPSILON = %d\nN_EPSILON = %d\n\n",spdat->weps,spdat->meps,spdat->neps); // rand numbers related stuff spdat->normalSize=2048; spdat->normalNumbs=malloc(spdat->normalSize*sizeof spdat->normalNumbs); double ener = 0.0 ; uint64_t acc=0; alloc_SAMC(spdat); //open files crdfile=fopen(io.crdtitle_first,"wt"); efile=fopen(io.etitle,"wb"); traj=fopen(io.trajtitle,"wb"); //write ini crds write_xyz(at,dat,0,crdfile); fclose(crdfile); //get E of whole system ener = (*get_ENER)(at,dat,-1); fprintf(stdout,"\nStarting SPAV\n"); fprintf(stdout,"LJ initial energy is : %lf \n\n",ener); //run sp avg simulation acc=launch_SPAV(at,dat,spdat,&ener); fprintf(stdout,"LJ final energy is : %lf\n",ener); fprintf(stdout,"Acceptance ratio is %lf %% \n",100.0*(double)acc/(double)dat->nsteps); fprintf(stdout,"final dmax = %lf\n",dat->d_max); fprintf(stdout,"End of SPAV\n\n"); //write final crds crdfile=fopen(io.crdtitle_last,"wt"); write_xyz(at,dat,dat->nsteps,crdfile); dealloc_SAMC(spdat); fclose(crdfile); fclose(traj); fclose(efile); free(spdat->normalNumbs); }
/** * \brief This function starts a standard Metropolis Monte Carlo simulation. * * \details This function is first in charge of opening all the output (coordinates, trajectory and energy) files.\n * Then the function \b #make_MC_moves starting the simulation is called.\n * In the end it prints results, close the files and goes back to the function \b #main. * * \param dat is a structure containing control parameters common to all simulations. * \param at[] is an array of structures ATOM containing coordinates and other variables. */ void start_classic(DATA *dat, ATOM at[]) { double ener = 0.0 ; uint64_t acc=0; //open required files crdfile=fopen(io.crdtitle_first,"wt"); efile=fopen(io.etitle,"wb"); traj=fopen(io.trajtitle,"wb"); //write initial coordinates write_xyz(at,dat,0,crdfile); fclose(crdfile); //get initial energy of whole system ener = (*get_ENER)(at,dat,-1); fprintf(stdout,"\nStarting METROP Monte-Carlo\n"); fprintf(stdout,"LJ initial energy is : %lf \n\n",ener); //CALL TO MAIN mc FUNCTION acc=make_MC_moves(at,dat,&ener); //simulation finished here fprintf(stdout,"\n\nLJ final energy is : %lf\n",ener); fprintf(stdout,"Acceptance ratio is %lf %% \n",100.0*(double)acc/(double)dat->nsteps); fprintf(stdout,"Final dmax = %lf\n",dat->d_max); fprintf(stdout,"End of METROP Monte-Carlo\n\n"); //write last coordinates crdfile=fopen(io.crdtitle_last,"wt"); write_xyz(at,dat,dat->nsteps,crdfile); fclose(crdfile); fclose(traj); fclose(efile); }
int main(int argc, char** argv) { const char filename[]="10.txt"; // Determine the number of atoms Natoms = get_natoms(filename); // Initialize the positions ! init(Natoms, filename); // Loop over timesteps std::ofstream simFile,enerFile; simFile.open("LDmj_sim.xyz"); enerFile.open("LDmj_sim.ener"); enerFile << "Time step" << std::setw(15) << "time" << std::setw(15) << "PE" << std::setw(15) << "KE" << std::setw(15) << "TE" << std::setw(15) << "Px" << std::setw(15) << "Py" << std::setw(15) << "Pz" << std::setw(15) << std::endl; for(int k=0; k<=1000; k++) { elapsed_time = dt*double(k); // Calculate pair-energy and forces if(k==0) calc_force(); calc_kenergy(); TE=U+KE; std::cout << std::setw(8) << k << std::setw(15) << elapsed_time << std::setw(15) << U << std::setw(15) << KE << std::setw(15) << TE << std::setw(15) << px << std::setw(15) << py << std::setw(15) << pz << std::setw(15) << std::endl; calc_momentum(); write_xyz(simFile, k); dump_stats(enerFile, k); // parameters are computed for (i+1) vv_scheme(); } simFile.close(); enerFile.close(); return 0; }
int main(int argc, char** argv) { // Load the text file const char filename[]="liquid256.txt"; // Determine the number of atoms Natoms = get_natoms(filename); // Initialize the positions ! init(Natoms, filename); // Compute some parameters R2cut = Rcut*Rcut; RIcut = 1/Rcut; RI2cut = 1/R2cut; RI6cut = RI2cut*RI2cut*RI2cut; RI12cut = RI6cut*RI6cut; Vol = lx*ly*lz; // Loop over timesteps std::ofstream simFile,enerFile; simFile.open("LDmj_sim.xyz"); enerFile.open("LDmj_sim.ener"); std::cout << "-------------------------------------------------------------------------------------------------------------------------------" << std::endl; std::cout<< "timestep" << std::setw(12) << "time" << std::setw(12) << "T" << std::setw(12) << "P" << std::setw(12) << "PE" << std::setw(12) << "KE" << std::setw(12) << "TE" << std::setw(15) << "Px" << std::setw(15) << "Py" << std::setw(15) << "Pz" << std::setw(15) << std::endl; std::cout << "-------------------------------------------------------------------------------------------------------------------------------" << std::endl; for(int k=0; k<=100000; k++) { elapsed_time = dt*double(k); // Calculate pair-energy and forces if(k==0) calc_virial_force(); calc_kenergy(); TE=U+KE; calc_inst_temp_pr(); if(k%100 == 0) { std::cout << std::setw(8) << k << std::setw(12) << elapsed_time << std::setw(15) << T << std::setw(15) << P << std::setw(12) << U << std::setw(12) << KE << std::setw(12) << TE << std::setw(15) << px << std::setw(15) << py << std::setw(15) << pz << std::setw(15) << std::endl; calc_momentum(); write_xyz(simFile, k); dump_stats(enerFile, k); } // parameters are computed for (i+1) vv_scheme_nose_hoover(); } simFile.close(); enerFile.close(); return 0; }