Simpatico  v1.10
OutputPressure.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 "OutputPressure.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("OutputPressure"); }
29 
30  /*
31  * Read interval and outputFileName.
32  */
33  void OutputPressure::readParameters(std::istream& in)
34  {
35  readInterval(in);
37  #if 0
38  std::string filename;
39  filename = outputFileName();
40  simulation().fileMaster().openOutputFile(filename, outputFile_);
41  #endif
42  isInitialized_ = true;
43  }
44 
45 
46  /*
47  * Load internal state from an archive.
48  */
50  {
51  loadInterval(ar);
53 
54  MpiLoader<Serializable::IArchive> loader(*this, ar);
55  loader.load(nSample_);
56 
57  #if 0
58  std::string filename;
59  filename = outputFileName();
60  simulation().fileMaster().openOutputFile(filename, outputFile_);
61  #endif
62  isInitialized_ = true;
63  }
64 
65  /*
66  * Save internal state to an archive.
67  */
69  {
70  saveInterval(ar);
72  ar << nSample_;
73  }
74 
75 
76  /*
77  * Read interval and outputFileName.
78  */
80  { nSample_ = 0; }
81 
82  /*
83  * Open outputfile
84  */
86  {
87  if (simulation().domain().isMaster()) {
88  std::string filename;
89  filename = outputFileName();
90  simulation().fileMaster().openOutputFile(filename, outputFile_);
91  }
92  }
93 
94  /*
95  * Dump configuration to file
96  */
97  void OutputPressure::sample(long iStep)
98  {
99  if (isAtInterval(iStep)) {
100  Simulation& sys = simulation();
101  sys.computeVirialStress();
102  sys.computeKineticStress();
103  if (sys.domain().isMaster()) {
104  double virial = sys.virialPressure();
105  double kinetic = sys.kineticPressure();
106  outputFile_ << Int(iStep, 10)
107  << Dbl(kinetic, 20)
108  << Dbl(virial, 20)
109  << Dbl(kinetic + virial, 20)
110  << std::endl;
111  }
112 
113  ++nSample_;
114  }
115  }
116 
117 }
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 save(Serializable::OArchive &ar)
Save internal state to an archive.
double kineticPressure() const
Return total kinetic pressure.
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.
double virialPressure() const
Return total virial pressure.
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.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
OutputPressure(Simulation &simulation)
Constructor.
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
const std::string & outputFileName() const
Return outputFileName string.
bool isMaster() const
Is this the master processor (gridRank == 0) ?
Definition: Domain.h:313
void computeVirialStress()
Calculate and store all virial stress contributions.
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.
void saveOutputFileName(Serializable::OArchive &ar)
Save output file name to an archive.
virtual void readParameters(std::istream &in)
Read dumpPrefix and interval.
Domain & domain()
Get the Domain by reference.
virtual void sample(long iStep)
Dump configuration to file.
void computeKineticStress()
Calculate and store kinetic stress.
virtual void setup()
Setup - open output file.