Simpatico  v1.10
LogEnergy.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "LogEnergy.h"
9 #include <ddMd/potentials/pair/PairPotential.h>
10 #ifdef SIMP_BOND
11 #include <ddMd/potentials/bond/BondPotential.h>
12 #endif
13 #ifdef SIMP_ANGLE
14 #include <ddMd/potentials/angle/AnglePotential.h>
15 #endif
16 #ifdef SIMP_DIHEDRAL
17 #include <ddMd/potentials/dihedral/DihedralPotential.h>
18 #endif
19 #include <util/format/Int.h>
20 #include <util/format/Dbl.h>
21 #include <util/mpi/MpiLoader.h>
22 #include <util/misc/ioUtil.h>
23 
24 #include <sstream>
25 
26 namespace DdMd
27 {
28 
29  using namespace Util;
30 
31  /*
32  * Constructor.
33  */
35  : Analyzer(simulation),
36  nSample_(0),
37  isInitialized_(false)
38  { setClassName("LogEnergy"); }
39 
40  /*
41  * Read interval and outputFileName.
42  */
43  void LogEnergy::readParameters(std::istream& in)
44  {
45  readInterval(in);
46  isInitialized_ = true;
47  }
48 
49  /*
50  * Load internal state from an archive.
51  */
53  {
54  loadInterval(ar);
55  MpiLoader<Serializable::IArchive> loader(*this, ar);
56  loader.load(nSample_);
57  isInitialized_ = true;
58  }
59 
60  /*
61  * Save internal state to an archive.
62  */
64  {
65  saveInterval(ar);
66  ar << nSample_;
67  }
68 
69  /*
70  * Reset nSample.
71  */
73  { nSample_ = 0; }
74 
75  /*
76  * Dump configuration to file
77  */
78  void LogEnergy::sample(long iStep)
79  {
80  if (isAtInterval(iStep)) {
81  Simulation& sim = simulation();
84  if (sim.domain().isMaster()) {
85  double kinetic = sim.kineticEnergy();
86  Log::file() << Int(iStep, 10)
87  << Dbl(kinetic, 15);
88  double potential = 0.0;
89  double pair = sim.pairPotential().energy();
90  potential += pair;
91  Log::file() << Dbl(pair, 15);
92  #ifdef SIMP_BOND
93  if (sim.nBondType()) {
94  double bond = sim.bondPotential().energy();
95  potential += bond;
96  Log::file() << Dbl(bond, 15);
97  }
98  #endif
99  #ifdef SIMP_ANGLE
100  if (sim.nAngleType()) {
101  double angle = sim.anglePotential().energy();
102  potential += angle;
103  Log::file() << Dbl(angle, 15);
104  }
105  #endif
106  #ifdef SIMP_DIHEDRAL
107  if (sim.nDihedralType()) {
108  double dihedral = sim.dihedralPotential().energy();
109  potential += dihedral;
110  Log::file() << Dbl(dihedral, 15);
111  }
112  #endif
113  Log::file() << Dbl(kinetic + potential, 20)
114  << std::endl;
115  }
116  ++nSample_;
117  }
118  }
119 
120 }
virtual void readParameters(std::istream &in)
Read dumpPrefix and interval.
Definition: LogEnergy.cpp:43
Abstract base for periodic output and/or analysis actions.
Simulation & simulation()
Get the parent Simulation by reference.
const BondPotential & bondPotential() const
Get the PairPotential by const reference.
void saveInterval(Serializable::OArchive &ar)
Save interval parameter to an archive.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Definition: LogEnergy.cpp:52
double kineticEnergy()
Return precomputed total kinetic energy.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: LogEnergy.cpp:63
LogEnergy(Simulation &simulation)
Constructor.
Definition: LogEnergy.cpp:34
void readInterval(std::istream &in)
Read parameter interval from file.
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
int nBondType()
Get maximum number of bond types.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
Saving / output archive for binary ostream.
int nDihedralType()
Get maximum number of dihedral types.
const DihedralPotential & dihedralPotential() const
Get the DihedralPotential by const reference.
void computePotentialEnergies()
Calculate and store total potential energy on all processors.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
Utility classes for scientific computation.
Definition: accumulators.mod:1
void load(Data &value)
Load and broadcast a single Data value.
Definition: MpiLoader.h:137
Wrapper for an int, for formatted ostream output.
Definition: Int.h:36
virtual void clear()
Clear nSample counter.
Definition: LogEnergy.cpp:72
bool isMaster() const
Is this the master processor (gridRank == 0) ?
Definition: Domain.h:313
const PairPotential & pairPotential() const
Get the PairPotential by const reference.
static std::ostream & file()
Get log ostream by reference.
Definition: Log.cpp:57
double energy() const
Return the total potential, from all processors.
Definition: Potential.cpp:39
Saving archive for binary istream.
Provides methods for MPI-aware loading of data from input archive.
Definition: MpiLoader.h:43
void setClassName(const char *className)
Set class name string.
void loadInterval(Serializable::IArchive &ar)
Load parameter interval from input archive.
const AnglePotential & anglePotential() const
Get the AnglePotential by const reference.
int nAngleType()
Get maximum number of angle types.
void computeKineticEnergy()
Compute total kinetic energy.
Domain & domain()
Get the Domain by reference.
virtual void sample(long iStep)
Dump configuration to file.
Definition: LogEnergy.cpp:78