Simpatico  v1.10
OutputBoxdim.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 "OutputBoxdim.h"
9 #include <util/format/Int.h>
10 #include <util/format/Dbl.h>
11 #include <util/mpi/MpiLoader.h>
12 #include <util/misc/ioUtil.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("OutputBoxdim"); }
29 
30  /*
31  * Read interval and outputFileName.
32  */
33  void OutputBoxdim::readParameters(std::istream& in)
34  {
35  readInterval(in);
37 
38  #if 0
39  std::string filename;
40  filename = outputFileName();
41  simulation().fileMaster().openOutputFile(filename, outputFile_);
42  isInitialized_ = true;
43  #endif
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  isInitialized_ = true;
58  }
59 
60  /*
61  * Save internal state to an archive.
62  */
64  {
65  saveInterval(ar);
67  ar << nSample_;
68  }
69 
70  /*
71  * Reset nSample_
72  */
74  { nSample_ = 0; }
75 
76  /*
77  * Open outputfile
78  */
80  {
81  if (simulation().domain().isMaster()) {
82  std::string filename;
83  filename = outputFileName();
84  simulation().fileMaster().openOutputFile(filename, outputFile_);
85  }
86  }
87 
88  /*
89  * Dump configuration to file
90  */
91  void OutputBoxdim::sample(long iStep)
92  {
93  if (isAtInterval(iStep)) {
94  Simulation& sys = simulation();
95  sys.computeVirialStress();
97  if (sys.domain().isMaster()) {
98  Vector L = sys.boundary().lengths();
99  double V = sys.boundary().volume();
100  outputFile_ << Int(iStep, 10)
101  << Dbl(L[0], 20)
102  << Dbl(L[1], 20)
103  << Dbl(L[2], 20)
104  << Dbl(V, 20)
105  << std::endl;
106  }
107 
108  ++nSample_;
109  }
110  }
111 
112 }
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Abstract base for periodic output and/or analysis actions.
Simulation & simulation()
Get the parent Simulation by reference.
A Vector is a Cartesian vector.
Definition: Vector.h:75
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void saveInterval(Serializable::OArchive &ar)
Save interval parameter to an archive.
double volume() const
Return unit cell volume.
const Vector & lengths() const
Get Vector of unit cell lengths by const reference.
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
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
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 sample(long iStep)
Output box dimensions to file.
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.
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.
OutputBoxdim(Simulation &simulation)
Constructor.
Saving archive for binary istream.
Provides methods for MPI-aware loading of data from input archive.
Definition: MpiLoader.h:43
virtual void readParameters(std::istream &in)
Read dumpPrefix and interval.
void setClassName(const char *className)
Set class name string.
void loadInterval(Serializable::IArchive &ar)
Load parameter interval from input archive.
virtual void setup()
Open output file.
Boundary & boundary()
Get the Boundary by reference.
void saveOutputFileName(Serializable::OArchive &ar)
Save output file name to an archive.
Domain & domain()
Get the Domain by reference.
void computeKineticStress()
Calculate and store kinetic stress.