/// Advance the simulation time to t+dt using a leap frog method /// (equivalent to velocity verlet). /// /// Forces must be computed before calling the integrator the first time. /// /// - Advance velocities half time step using forces /// - Advance positions full time step using velocities /// - Update link cells and exchange remote particles /// - Compute forces /// - Update velocities half time step using forces /// /// This leaves positions, velocities, and forces at t+dt, with the /// forces ready to perform the half step velocity update at the top of /// the next call. /// /// After nSteps the kinetic energy is computed for diagnostic output. double timestep(SimFlat* s, int nSteps, real_t dt) { for (int ii=0; ii<nSteps; ++ii) { startTimer(velocityTimer); advanceVelocity(s, s->boxes->nLocalBoxes, 0.5*dt); stopTimer(velocityTimer); startTimer(positionTimer); advancePosition(s, s->boxes->nLocalBoxes, dt); stopTimer(positionTimer); startTimer(redistributeTimer); redistributeAtoms(s); stopTimer(redistributeTimer); startTimer(computeForceTimer); computeForce(s); stopTimer(computeForceTimer); startTimer(velocityTimer); advanceVelocity(s, s->boxes->nLocalBoxes, 0.5*dt); stopTimer(velocityTimer); } kineticEnergy(s); return s->ePotential; }
/// Initialized the main CoMD data stucture, SimFlat, based on command /// line input from the user. Also performs certain sanity checks on /// the input to screen out certain non-sensical inputs. /// /// Simple data members such as the time step dt are initialized /// directly, substructures such as the potential, the link cells, the /// atoms, etc., are initialized by calling additional initialization /// functions (initPotential(), initLinkCells(), initAtoms(), etc.). /// Initialization order is set by the natural dependencies of the /// substructure such as the atoms need the link cells so the link cells /// must be initialized before the atoms. SimFlat* initSimulation(Command cmd) { SimFlat* sim = comdMalloc(sizeof(SimFlat)); sim->nSteps = cmd.nSteps; sim->printRate = cmd.printRate; sim->dt = cmd.dt; sim->domain = NULL; sim->boxes = NULL; sim->atoms = NULL; sim->ePotential = 0.0; sim->eKinetic = 0.0; sim->atomExchange = NULL; sim->pot = initPotential(cmd.doeam, cmd.potDir, cmd.potName, cmd.potType); real_t latticeConstant = cmd.lat; if (cmd.lat < 0.0) latticeConstant = sim->pot->lat; // ensure input parameters make sense. sanityChecks(cmd, sim->pot->cutoff, latticeConstant, sim->pot->latticeType); sim->species = initSpecies(sim->pot); real3 globalExtent; globalExtent[0] = cmd.nx * latticeConstant; globalExtent[1] = cmd.ny * latticeConstant; globalExtent[2] = cmd.nz * latticeConstant; sim->domain = initDecomposition( cmd.xproc, cmd.yproc, cmd.zproc, globalExtent); sim->boxes = initLinkCells(sim->domain, sim->pot->cutoff); sim->atoms = initAtoms(sim->boxes); // create lattice with desired temperature and displacement. createFccLattice(cmd.nx, cmd.ny, cmd.nz, latticeConstant, sim); setTemperature(sim, cmd.temperature); randomDisplacements(sim, cmd.initialDelta); sim->atomExchange = initAtomHaloExchange(sim->domain, sim->boxes); // Forces must be computed before we call the time stepper. startTimer(redistributeTimer); redistributeAtoms(sim); stopTimer(redistributeTimer); startTimer(computeForceTimer); computeForce(sim); stopTimer(computeForceTimer); kineticEnergy(sim); return sim; }
SimFlat* initSimulation(Command cmd) { SimFlat* sim = comdMalloc(sizeof(SimFlat)); sim->nSteps = cmd.nSteps; sim->printRate = cmd.printRate; sim->dt = cmd.dt; sim->domain = NULL; sim->boxes = NULL; sim->atoms = NULL; sim->ePotential = 0.0; sim->eKinetic = 0.0; sim->atomExchange = NULL; sim->pot = initPotential(cmd.doeam, cmd.potDir, cmd.potName, cmd.potType); real_t latticeConstant = cmd.lat; if (cmd.lat < 0.0) latticeConstant = sim->pot->lat; // ensure input parameters make sense. sanityChecks(cmd, sim->pot->cutoff, latticeConstant, sim->pot->latticeType); sim->species = initSpecies(sim->pot); real3 globalExtent; globalExtent[0] = cmd.nx * latticeConstant; globalExtent[1] = cmd.ny * latticeConstant; globalExtent[2] = cmd.nz * latticeConstant; sim->domain = initDecomposition(cmd.xproc, cmd.yproc, cmd.zproc, globalExtent); sim->boxes = initLinkCells(sim->domain, sim->pot->cutoff); sim->atoms = initAtoms(sim->boxes); sim->defInfo = initDeformation(sim, cmd.defGrad); //printf("Got to here\n"); // create lattice with desired temperature and displacement. createFccLattice(cmd.nx, cmd.ny, cmd.nz, latticeConstant, sim); setTemperature(sim,0.0); randomDisplacements(sim, cmd.initialDelta); sim->atomExchange = initAtomHaloExchange(sim->domain, sim->boxes); forwardDeformation(sim); //eamForce(sim); // Procedure for energy density passing from the macrosolver to CoMD //setTemperature(sim,((cmd.energy*latticeVolume*cmd.nx*cmd.ny*cmd.nz-sim->ePotential)/sim->atoms->nGlobal)/(kB_eV * 1.5)); //randomDisplacements(sim, cmd.initialDelta); // Forces must be computed before we call the time stepper. startTimer(redistributeTimer); redistributeAtoms(sim); stopTimer(redistributeTimer); startTimer(computeForceTimer); computeForce(sim); stopTimer(computeForceTimer); double cohmmEnergy=cmd.energy*sim->defInfo->globalVolume; double temperatureFromEnergyDensity=((cohmmEnergy-sim->ePotential)/sim->atoms->nGlobal)/(kB_eV*1.5); setTemperature(sim,temperatureFromEnergyDensity); //uncomment to set temperature according to hmm energy density //setTemperature(sim,cmd.temperature); //uncomment to directly input temperature kineticEnergy(sim); return sim; }