8 #include "Integrator.h" 9 #include <ddMd/simulation/Simulation.h> 10 #include <ddMd/storage/AtomStorage.h> 11 #include <ddMd/storage/AtomIterator.h> 12 #include <ddMd/storage/GroupStorage.tpp> 13 #include <ddMd/communicate/Exchanger.h> 14 #include <ddMd/analyzers/AnalyzerManager.h> 15 #include <ddMd/potentials/pair/PairPotential.h> 17 #include <ddMd/potentials/bond/BondPotential.h> 20 #include <ddMd/potentials/angle/AnglePotential.h> 23 #include <ddMd/potentials/dihedral/DihedralPotential.h> 26 #include <ddMd/potentials/external/ExternalPotential.h> 29 #include <simp/ensembles/BoundaryEnsemble.h> 31 #include <util/mpi/MpiLoader.h> 32 #include <util/format/Dbl.h> 33 #include <util/format/Int.h> 34 #include <util/format/Bool.h> 67 read<int>(in,
"saveInterval", saveInterval_);
68 if (saveInterval_ > 0) {
71 UTIL_THROW(
"saveInterval is not a multiple of baseInterval");
74 UTIL_THROW(
"Analyzer::baseInterval is not positive");
76 read<std::string>(in,
"saveFileName", saveFileName_);
85 loadParameter<int>(ar,
"saveInterval", saveInterval_);
86 if (saveInterval_ > 0) {
89 UTIL_THROW(
"saveInterval is not a multiple of baseInterval");
92 UTIL_THROW(
"Analyzer::baseInterval is not positive");
94 loadParameter<std::string>(ar,
"saveFileName", saveFileName_);
99 loader.load(isSetup_);
108 if (saveInterval_ > 0) {
139 UTIL_THROW(
"Atom coordinates are not Cartesian");
150 UTIL_THROW(
"Atom coordinates are not Cartesian");
155 timer_.
stamp(ZERO_FORCE);
157 timer_.
stamp(PAIR_FORCE);
161 timer_.
stamp(BOND_FORCE);
167 timer_.
stamp(ANGLE_FORCE);
173 timer_.
stamp(DIHEDRAL_FORCE);
179 timer_.
stamp(EXTERNAL_FORCE);
199 UTIL_THROW(
"Atom coordinates are not Cartesian");
204 timer_.
stamp(ZERO_FORCE);
206 timer_.
stamp(PAIR_FORCE);
210 timer_.
stamp(BOND_FORCE);
216 timer_.
stamp(ANGLE_FORCE);
222 timer_.
stamp(DIHEDRAL_FORCE);
228 timer_.
stamp(EXTERNAL_FORCE);
248 UTIL_THROW(
"Error: Coordinates not Cartesian in isExchangeNeeded");
254 if (sqrt(maxSqDisp) > 0.5*skin) {
262 1, MPI::INT, MPI::MAX);
263 timer_.
stamp(ALLREDUCE);
264 return bool(neededAll);
278 UTIL_THROW(
"Error: Coordinates not Cartesian in isExchangeNeeded");
291 MPI::DOUBLE, MPI::MAX, 0);
292 if (
domain().communicator().Get_rank() == 0) {
294 if (sqrt(maxSqDispAll) > 0.5*skin) {
299 timer_.
stamp(ALLREDUCE);
301 if (sqrt(maxSqDisp) > 0.5*skin) {
314 {
return timer_.
time(); }
319 void Integrator::computeStatistics()
331 if (!
domain().isMaster()) {
332 UTIL_THROW(
"May be called only on domain master");
344 out <<
"Time Statistics" << std::endl;
345 out <<
"nStep " <<
iStep_ << std::endl;
346 out <<
"run time " << time <<
" sec" << std::endl;
347 out <<
"time / nStep " << time/double(
iStep_)
348 <<
" sec" << std::endl;
351 double factor1 = 1.0/double(
iStep_);
352 double factor2 = double(nProc)/(double(
iStep_)*double(nAtomTot));
356 out <<
"T = Time per processor, M = nstep = # steps" << std::endl
357 <<
"P = # procs, N = # atoms (total, all processors)" 358 << std::endl << std::endl;
362 <<
" Percent (%)" << std::endl;
364 <<
Dbl(time*factor1, 12, 6)
366 <<
Dbl(time*factor2, 12, 6)
367 <<
" " <<
Dbl(100.0, 12, 6,
true) << std::endl;
368 double integrate1T = timer().
time(INTEGRATE1);
369 totalT += integrate1T;
371 <<
Dbl(integrate1T*factor1, 12, 6)
373 <<
Dbl(integrate1T*factor2, 12, 6)
374 <<
" " <<
Dbl(100.0*integrate1T/time, 12, 6,
true) << std::endl;
375 double checkT = timer().
time(CHECK);
378 <<
Dbl(checkT*factor1, 12, 6)
380 <<
Dbl(checkT*factor2, 12, 6)
381 <<
" " <<
Dbl(100.0*checkT/time, 12, 6,
true) << std::endl;
382 double allReduceT = timer().
time(ALLREDUCE);
383 totalT += allReduceT;
385 <<
Dbl(allReduceT*factor1, 12, 6)
387 <<
Dbl(allReduceT*factor2, 12, 6)
388 <<
" " <<
Dbl(100.0*allReduceT/time, 12, 6,
true) << std::endl;
389 double transformFT = timer().
time(TRANSFORM_F);
390 totalT += transformFT;
391 out <<
"Transform (forward) " 392 <<
Dbl(transformFT*factor1, 12, 6)
394 <<
Dbl(transformFT*factor2, 12, 6)
395 <<
" " <<
Dbl(100.0*transformFT/time, 12, 6,
true) << std::endl;
396 double exchangeT = timer().
time(EXCHANGE);
399 <<
Dbl(exchangeT*factor1, 12, 6)
401 <<
Dbl(exchangeT*factor2, 12, 6)
402 <<
" " <<
Dbl(100.0*exchangeT/time, 12, 6,
true) << std::endl;
403 double cellListT = timer().
time(CELLLIST);
406 <<
Dbl(cellListT*factor1, 12, 6)
408 <<
Dbl(cellListT*factor2, 12, 6)
409 <<
" " <<
Dbl(100.0*cellListT/time, 12, 6,
true) << std::endl;
410 double transformRT = timer().
time(TRANSFORM_R);
411 totalT += transformRT;
412 out <<
"Transform (reverse) " 413 <<
Dbl(transformRT*factor1, 12, 6)
415 <<
Dbl(transformRT*factor2, 12, 6)
416 <<
" " <<
Dbl(100.0*transformRT/time, 12, 6,
true) << std::endl;
417 double pairListT = timer().
time(PAIRLIST);
420 <<
Dbl(pairListT*factor1, 12, 6)
422 <<
Dbl(pairListT*factor2, 12, 6)
423 <<
" " <<
Dbl(100.0*pairListT/time, 12, 6,
true) << std::endl;
424 double updateT = timer().
time(UPDATE);
427 <<
Dbl(updateT*factor1, 12, 6)
429 <<
Dbl(updateT*factor2, 12, 6)
430 <<
" " <<
Dbl(100.0*updateT/time, 12, 6,
true) << std::endl;
431 double zeroForceT = timer().
time(ZERO_FORCE);
432 totalT += zeroForceT;
433 out <<
"Zero Forces " 434 <<
Dbl(zeroForceT*factor1, 12, 6)
436 <<
Dbl(zeroForceT*factor2, 12, 6)
437 <<
" " <<
Dbl(100.0*zeroForceT/time, 12 , 6,
true) << std::endl;
438 double pairForceT = timer().
time(PAIR_FORCE);
439 totalT += pairForceT;
440 out <<
"Pair Forces " 441 <<
Dbl(pairForceT*factor1, 12, 6)
443 <<
Dbl(pairForceT*factor2, 12, 6)
444 <<
" " <<
Dbl(100.0*pairForceT/time, 12 , 6,
true) << std::endl;
447 double bondForceT = timer().
time(BOND_FORCE);
448 totalT += bondForceT;
449 out <<
"Bond Forces " 450 <<
Dbl(bondForceT*factor1, 12, 6)
452 <<
Dbl(bondForceT*factor2, 12, 6)
453 <<
" " <<
Dbl(100.0*bondForceT/time, 12 , 6,
true) << std::endl;
458 double angleForceT = timer().
time(ANGLE_FORCE);
459 totalT += angleForceT;
460 out <<
"Angle Forces " 461 <<
Dbl(angleForceT*factor1, 12, 6)
463 <<
Dbl(angleForceT*factor2, 12, 6)
464 <<
" " <<
Dbl(100.0*angleForceT/time, 12 , 6,
true) << std::endl;
469 double dihedralForceT = timer().
time(DIHEDRAL_FORCE);
470 totalT += dihedralForceT;
471 out <<
"Dihedral Forces " 472 <<
Dbl(dihedralForceT*factor1, 12, 6)
474 <<
Dbl(dihedralForceT*factor2, 12, 6)
475 <<
" " <<
Dbl(100.0*dihedralForceT/time, 12 , 6,
true) << std::endl;
480 double externalForceT = timer().
time(DIHEDRAL_FORCE);
481 totalT += externalForceT;
482 out <<
"External Forces " 483 <<
Dbl(externalForceT*factor1, 12, 6)
485 <<
Dbl(externalForceT*factor2, 12, 6)
486 <<
" " <<
Dbl(100.0*externalForceT/time, 12 , 6,
true) << std::endl;
489 double integrate2T = timer().
time(INTEGRATE2);
490 totalT += integrate2T;
492 <<
Dbl(integrate2T*factor1, 12, 6)
494 <<
Dbl(integrate2T*factor2, 12, 6)
495 <<
" " <<
Dbl(100.0*integrate2T/time, 12, 6,
true) << std::endl;
496 double analyzerT = timer().
time(ANALYZER);
499 <<
Dbl(analyzerT*factor1, 12, 6)
501 <<
Dbl(analyzerT*factor2, 12, 6)
502 <<
" " <<
Dbl(100.0*analyzerT/time, 12, 6,
true) << std::endl;
503 #ifdef DDMD_MODIFIERS 504 double modifierT = timer().
time(MODIFIER);
507 <<
Dbl(modifierT*factor1, 12, 6)
509 <<
Dbl(modifierT*factor2, 12, 6)
510 <<
" " <<
Dbl(100.0*modifierT/time, 12, 6,
true) << std::endl;
515 double tick = MPI::Wtick();
516 out <<
"Timer resolution " 519 <<
Dbl(tick*
double(nProc)/
double(nAtomTot), 12, 6)
520 <<
" " <<
Dbl(100.0*tick*
double(
iStep_)/time, 12, 6,
true)
526 out <<
"buildCounter " 527 <<
Int(buildCounter, 12)
529 out <<
"steps per build " 530 <<
Dbl(
double(
iStep_)/
double(buildCounter), 12, 6)
virtual void outputStatistics(std::ostream &out)
Output timing statistics from a run.
void loadParameters(Serializable::IArchive &ar)
Load saveInterval and saveFileName from restart archive.
void reduce(MPI::Intracomm &communicator)
Upon return, times on every processor replaced by average over procs.
void makeSnapshot()
Record current positions of all local atoms and lock storage.
PairPotential & pairPotential()
Get the PairPotential.
void computeForcesAndVirial()
Compute forces for all local atoms and virial stress.
int iStep_
Current step number.
void computeForces()
Compute forces for all local atoms, with timing.
Provides access to members of Simulation object.
void transformGenToCart(const Boundary &boundary)
Transform positions from generalized to Cartesian coordinates.
void clearStatistics()
Clear statistical accumulators (call on all processors).
void computeForces()
Compute forces for all local atoms.
int nAtomTotal() const
Get total number of atoms on all processors.
double time() const
Get average time per processor of previous run.
BoundaryEnsemble & boundaryEnsemble()
Get the BoundaryEnsemble.
void clearStatistics()
Clear statistical accumulators (call on all processors).
void readParameters(std::istream &in)
Read saveInterval and saveFileName.
virtual void initDynamicalState()
Set any internal dynamical to default initial values.
int nAngleType()
Get maximum number of angle types.
int nDihedralType()
Get maximum number of dihedral types.
int nBondType()
Get maximum number of bond types.
Boundary & boundary()
Get the Boundary.
void buildPairList()
Build the Verlet Pair list.
virtual void computeForces()=0
Add force contributions to all atomic forces.
AnalyzerManager & analyzerManager()
Return the AnalyzerManager by reference.
void zeroForces()
Set forces for all atoms to zero.
Wrapper for a double precision number, for formatted ostream output.
bool isExchangeNeeded(double skin)
Determine whether an atom exchange and reneighboring is needed.
File containing preprocessor macros for error handling.
Parallel domain decomposition (DD) MD simulation.
Classes used by all simpatico molecular simulations.
GroupStorage< 2 > & bondStorage()
Get the BondStorage.
Main object for a domain-decomposition MD simulation.
void buildCellList()
Build a cell list.
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
Exchanger & exchanger()
Get the Exchanger by reference.
virtual void computeForcesAndStress(MPI::Intracomm &communicator)
Compute forces and stress for all processors.
MPI::Intracomm & communicator() const
Return Cartesian communicator by reference.
ExternalPotential & externalPotential()
Get the ExternalPotential.
void clearStatistics()
Clear statistical accumulators (call on all processors).
Saving / output archive for binary ostream.
GroupStorage< 3 > & angleStorage()
Get the AngleStorage.
AnglePotential & anglePotential()
Get the AnglePotential.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
double time(int id) const
Get accumulated time for interval i, average per processor.
void computeForcesAndVirial()
Compute forces for all local atoms and virial, with timing.
void stamp(int id)
Mark end of interval id.
void setupAtoms()
Setup state of atoms just before integration.
An Integrator numerically integrates the equations of motion.
Utility classes for scientific computation.
GroupStorage< 4 > & dihedralStorage()
Get the angleStorage.
Domain & domain()
Get the Domain.
Wrapper for an int, for formatted ostream output.
Exchanger & exchanger()
Get the Exchanger.
void clearSnapshot()
Clear previous snapshot.
AtomStorage & atomStorage()
Get the AtomStorage.
int buildCounter() const
Return number of times the PairList has been built thus far.
void save(Serializable::OArchive &ar)
Save saveInterval and saveFileName from restart archive.
Simulation & simulation()
Get the parent simulation.
bool reverseUpdateFlag() const
Are forces evaluated by reverse communication (true) or not (false)?
DihedralPotential & dihedralPotential()
Get the DihedralPotential.
BondPotential & bondPotential()
Get the PairPotential.
DdTimer & timer()
Return internal timer by reference.
PairList & pairList()
Get the PairList by reference.
Saving archive for binary istream.
Provides methods for MPI-aware loading of data from input archive.
void clear()
Call clear method of each Analyzer.
bool hasExternal()
Does this simulation have an external potential?
Buffer & buffer()
Get the Buffer by reference.
void exchange()
Exchange local atoms and ghosts.
double maxSqDisplacement()
Return max-squared displacement since the last snapshot.
void reverseUpdate()
Update ghost atom forces.
Integrator(Simulation &simulation)
Constructor.
void clear()
Clear all time statistics.
virtual void clear()
Set integrator to initial state and clears all statistics.
void clearStatistics()
Clear any accumulated usage statistics.