Simpatico  v1.10
OutputPairEnergies.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 "OutputPairEnergies.h"
9 #include <util/misc/FileMaster.h>
10 #include <util/misc/ioUtil.h>
11 #include <util/format/Int.h>
12 #include <util/format/Dbl.h>
13 
14 #include <sstream>
15 
16 namespace DdMd
17 {
18 
19  using namespace Util;
20 
21  /*
22  * Constructor.
23  */
25  : Analyzer(simulation),
26  nSample_(0),
27  isInitialized_(false)
28  { setClassName("OutputPairEnergies"); }
29 
30  /*
31  * Read interval and outputFileName.
32  */
33  void OutputPairEnergies::readParameters(std::istream& in)
34  {
35  readInterval(in);
37 
38  std::string filename;
39  filename = outputFileName();
40  simulation().fileMaster().openOutputFile(filename, outputFile_);
41  isInitialized_ = true;
42  }
43 
44  /*
45  * Load internal state from an archive.
46  */
48  {
49  loadInterval(ar);
51 
52  std::string filename;
53  filename = outputFileName();
54  simulation().fileMaster().openOutputFile(filename, outputFile_);
55  isInitialized_ = true;
56  }
57 
58  /*
59  * Save internal state to an archive.
60  */
62  {
63  saveInterval(ar);
65  }
66 
67 
68 
69  /*
70  * Reset nSample_ counter.
71  */
73  { nSample_ = 0; }
74 
75  /*
76  * Compute and output pair energies at regular intervals.
77  */
78  void OutputPairEnergies::sample(long iStep)
79  {
80  if (isAtInterval(iStep)) {
81  Simulation& sys = simulation();
82  sys.computePairEnergies();
83  if (sys.domain().isMaster()) {
84  DMatrix<double> pair = sys.pairEnergies();
85  for (int i = 0; i < simulation().nAtomType(); ++i){
86  for (int j = 0; j < simulation().nAtomType(); ++j){
87  pair(i,j) = 0.5*( pair(i,j)+pair(j,i) );
88  pair(j,i) = pair(i,j);
89  }
90  }
91  outputFile_ << Int(iStep, 10);
92  for (int i = 0; i < simulation().nAtomType(); ++i){
93  for (int j = 0; j < simulation().nAtomType(); ++j){
94  outputFile_ << Dbl(pair(i,j), 20);
95  }
96  }
97  outputFile_ << std::endl;
98  }
99 
100  ++nSample_;
101  }
102  }
103 
104 }
Abstract base for periodic output and/or analysis actions.
Simulation & simulation()
Get the parent Simulation by reference.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void saveInterval(Serializable::OArchive &ar)
Save interval parameter to an archive.
virtual void sample(long iStep)
Compute and output pair energies periodically.
DMatrix< double > pairEnergies() const
Return precomputed pair energies.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
Definition: FileMaster.cpp:290
void readInterval(std::istream &in)
Read parameter interval from file.
Wrapper for a double precision number, for formatted ostream output.
Definition: Dbl.h:39
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
Saving / output archive for binary ostream.
void loadOutputFileName(Serializable::IArchive &ar)
Load output file name to an archive.
FileMaster & fileMaster()
Get the associated FileMaster by reference.
virtual void clear()
Clear nSample counter.
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 computePairEnergies()
Compute pair energies for each pair of atom types.
Wrapper for an int, for formatted ostream output.
Definition: Int.h:36
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
OutputPairEnergies(Simulation &simulation)
Constructor.
const std::string & outputFileName() const
Return outputFileName string.
bool isMaster() const
Is this the master processor (gridRank == 0) ?
Definition: Domain.h:313
virtual void readParameters(std::istream &in)
Read interval and output file name.
Saving archive for binary istream.
void setClassName(const char *className)
Set class name string.
void loadInterval(Serializable::IArchive &ar)
Load parameter interval from input archive.
int nAtomType()
Get maximum number of atom types.
void saveOutputFileName(Serializable::OArchive &ar)
Save output file name to an archive.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Domain & domain()
Get the Domain by reference.