8 #include "EnergyAnalyzer.h" 9 #include <ddMd/simulation/Simulation.h> 10 #include <ddMd/potentials/pair/PairPotential.h> 12 #include <ddMd/potentials/bond/BondPotential.h> 15 #include <ddMd/potentials/angle/AnglePotential.h> 18 #include <ddMd/potentials/dihedral/DihedralPotential.h> 21 #include <ddMd/potentials/external/ExternalPotential.h> 23 #include <util/accumulators/Average.h> 24 #include <util/format/Int.h> 25 #include <util/format/Dbl.h> 26 #include <util/mpi/MpiLoader.h> 27 #include <util/misc/ioUtil.h> 42 kineticAveragePtr_(0),
51 dihedralAveragePtr_(0),
54 externalAveragePtr_(0),
68 readOptional<int>(in,
"nSamplePerBlock", nSamplePerBlock_);
71 if (sim.domain().isMaster()) {
74 kineticAveragePtr_ =
new Average;
79 if (sim.nBondType()) {
85 if (sim.nAngleType()) {
91 if (sim.hasExternal()) {
92 externalAveragePtr_ =
new Average;
98 isInitialized_ =
true;
108 nSamplePerBlock_ = 0;
110 loadParameter<int>(ar,
"nSamplePerBlock", nSamplePerBlock_,
115 if (sim.domain().isMaster()) {
116 totalAveragePtr_ =
new Average;
117 ar >> *totalAveragePtr_;
118 kineticAveragePtr_ =
new Average;
119 ar >> *kineticAveragePtr_;
121 ar >> *pairAveragePtr_;
123 if (sim.nBondType()) {
125 ar >> *bondAveragePtr_;
129 if (sim.nAngleType()) {
130 angleAveragePtr_ =
new Average;
131 ar >> *angleAveragePtr_;
135 if (sim.nDihedralType()) {
136 dihedralAveragePtr_ =
new Average;
137 ar >> *dihedralAveragePtr_;
141 if (sim.hasExternal()) {
142 externalAveragePtr_ =
new Average;
143 ar >> *externalAveragePtr_;
148 isInitialized_ =
true;
158 bool isActive = bool(nSamplePerBlock_);
163 ar << *totalAveragePtr_;
164 ar << *kineticAveragePtr_;
165 ar << *pairAveragePtr_;
168 ar << *bondAveragePtr_;
173 ar << *angleAveragePtr_;
178 ar << *dihedralAveragePtr_;
183 ar << *externalAveragePtr_;
195 totalAveragePtr_->
clear();
196 kineticAveragePtr_->
clear();
197 pairAveragePtr_->
clear();
200 bondAveragePtr_->
clear();
205 angleAveragePtr_->
clear();
210 dihedralAveragePtr_->
clear();
215 externalAveragePtr_->
clear();
227 if (outputFile_.is_open()) {
230 std::string filename;
248 kineticAveragePtr_->
sample(kinetic);
250 double potential = 0.0;
253 pairAveragePtr_->
sample(pair);
259 bondAveragePtr_->
sample(bond);
267 angleAveragePtr_->
sample(angle);
274 potential += dihedral;
275 dihedralAveragePtr_->
sample(dihedral);
282 potential += external;
283 externalAveragePtr_->
sample(external);
287 double total = kinetic + potential;
288 totalAveragePtr_->
sample(total);
294 int beginStep = iStep - (nSamplePerBlock_ - 1)*
interval();
295 outputFile_ <<
Int(beginStep, 12);
296 outputFile_ <<
Dbl(kineticAveragePtr_->blockAverage());
297 outputFile_ <<
Dbl(pairAveragePtr_->blockAverage());
300 outputFile_ <<
Dbl(bondAveragePtr_->blockAverage());
305 outputFile_ <<
Dbl(angleAveragePtr_->blockAverage());
310 outputFile_ <<
Dbl(dihedralAveragePtr_->blockAverage());
315 outputFile_ <<
Dbl(externalAveragePtr_->blockAverage());
318 outputFile_ <<
Dbl(totalAveragePtr_->blockAverage());
335 if (outputFile_.is_open()) {
347 ave = kineticAveragePtr_->
average();
349 outputFile_ <<
"Kinetic " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
350 ave = pairAveragePtr_->
average();
352 outputFile_ <<
"Pair " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
355 ave = bondAveragePtr_->
average();
357 outputFile_ <<
"Bond " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
362 ave = angleAveragePtr_->
average();
364 outputFile_ <<
"Angle " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
369 ave = dihedralAveragePtr_->
average();
371 outputFile_ <<
"Dihedral " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
376 ave = externalAveragePtr_->
average();
378 outputFile_ <<
"External " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
381 ave = totalAveragePtr_->
average();
383 outputFile_ <<
"Total " <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
389 "---------------------------------------------------------------------------------\n";
390 outputFile_ <<
"Kinetic:\n\n";
391 kineticAveragePtr_->
output(outputFile_);
393 "---------------------------------------------------------------------------------\n";
394 outputFile_ <<
"Pair:\n\n";
395 pairAveragePtr_->
output(outputFile_);
399 "---------------------------------------------------------------------------------\n";
400 outputFile_ <<
"Bond:\n\n";
401 bondAveragePtr_->
output(outputFile_);
407 "---------------------------------------------------------------------------------\n";
408 outputFile_ <<
"Angle:\n\n";
409 angleAveragePtr_->
output(outputFile_);
415 "---------------------------------------------------------------------------------\n";
416 outputFile_ <<
"Dihedral:\n\n";
417 dihedralAveragePtr_->
output(outputFile_);
423 "---------------------------------------------------------------------------------\n";
424 outputFile_ <<
"External:\n\n";
425 externalAveragePtr_->
output(outputFile_);
429 "---------------------------------------------------------------------------------\n";
430 outputFile_ <<
"Total:\n\n";
431 totalAveragePtr_->
output(outputFile_);
Abstract base for periodic output and/or analysis actions.
void clear()
Clear all accumulators, set to empty initial state.
Simulation & simulation()
Get the parent Simulation by reference.
bool isBlockComplete() const
Is the current block average complete?
const BondPotential & bondPotential() const
Get the PairPotential by const reference.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
bool isRequired() const
Is this ParamComposite required in the input file?
void saveInterval(Serializable::OArchive &ar)
Save interval parameter to an archive.
Calculates the average and variance of a sampled property.
double average() const
Return the average of all sampled values.
double kineticEnergy()
Return precomputed total kinetic energy.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an input archive.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
void readInterval(std::istream &in)
Read parameter interval from file.
Wrapper for a double precision number, for formatted ostream output.
EnergyAnalyzer(Simulation &simulation)
Constructor.
int nBondType()
Get maximum number of bond types.
double blockingError() const
Return estimated error on average from blocking analysis.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
const ExternalPotential & externalPotential() const
Get the ExternalPotential by reference.
bool isActive() const
Is this parameter active?
Saving / output archive for binary ostream.
void loadOutputFileName(Serializable::IArchive &ar)
Load output file name to an archive.
int nDihedralType()
Get maximum number of dihedral types.
FileMaster & fileMaster()
Get the associated FileMaster by reference.
const DihedralPotential & dihedralPotential() const
Get the DihedralPotential by const reference.
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
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.
virtual void output()
Write file averages and error analysis to file.
Wrapper for an int, for formatted ostream output.
const std::string & outputFileName() const
Return outputFileName string.
void output(std::ostream &out) const
Output final statistical properties to file.
virtual void sample(long iStep)
Write energy to file.
bool isMaster() const
Is this the master processor (gridRank == 0) ?
const PairPotential & pairPotential() const
Get the PairPotential by const reference.
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
double energy() const
Return the total potential, from all processors.
Saving archive for binary istream.
void sample(double value)
Add a sampled value to the ensemble.
virtual void readParameters(std::istream &in)
Read interval and output file name.
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.
int interval() const
Get interval value.
void saveOutputFileName(Serializable::OArchive &ar)
Save output file name to an archive.
void computeKineticEnergy()
Compute total kinetic energy.
Domain & domain()
Get the Domain by reference.
virtual void save(Serializable::OArchive &ar)
Save internal state to an output archive.
static void saveOptional(Serializable::OArchive &ar, Type &value, bool isActive)
Save an optional parameter value to an output archive.
virtual void clear()
Clear nSample counter and all accumulators.
virtual void setup()
Setup before main loop.
bool hasExternal()
Does this simulation have an external potential?