Simpatico  v1.10
VirialStressTensor.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 "VirialStressTensor.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("VirialStressTensor"); }
29 
30  /*
31  * Read interval and outputFileName.
32  */
33  void VirialStressTensor::readParameters(std::istream& in)
34  {
35  readInterval(in);
37 
38  if(simulation().domain().isMaster()) {
39  std::string filename;
40  filename = outputFileName();
42  }
43 
44  isInitialized_ = true;
45  }
46 
47 
48  /*
49  * Load internal state from an archive.
50  */
52  {
53  loadInterval(ar);
55 
56  MpiLoader<Serializable::IArchive> loader(*this, ar);
57  loader.load(nSample_);
58 
59  if (simulation().domain().isMaster()) {
60  std::string filename;
61  filename = outputFileName();
63  }
64 
65  isInitialized_ = true;
66  }
67 
68  /*
69  * Save internal state to an archive.
70  */
72  {
73  saveInterval(ar);
75  ar << nSample_;
76  }
77 
78 
79  /*
80  * Read interval and outputFileName.
81  */
83  {
84  if (!isInitialized_) {
85  UTIL_THROW("Error: Object not initialized");
86  }
87  nSample_ = 0;
88  }
89 
90  /*
91  * Sample the stress tensor.
92  */
93  void VirialStressTensor::sample(long iStep)
94  {
95  if (isAtInterval(iStep)) {
98  if (simulation().domain().isMaster()) {
99  Tensor virial = simulation().virialStress();
100  Tensor kinetic = simulation().kineticStress();
101  Tensor total;
102  total.add(virial, kinetic);
103  outputFile_ << virial(0,0) << "\t" << virial(1,1) << "\t" << virial(2,2)
104  << total(0,0) << "\t" << total(1,1) << "\t" << total(2,2) << "\n";
105  }
106 
107  ++nSample_;
108  }
109  }
110 
111 }
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.
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.
virtual void clear()
Clear nSample counter.
void readInterval(std::istream &in)
Read parameter interval from file.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
Tensor & add(const Tensor &t1, const Tensor &t2)
Add tensors t1 and t2.
Definition: Tensor.h:567
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.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
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
virtual void sample(long iStep)
Sample virial stress to accumulators.
Tensor kineticStress() const
Return total kinetic stress.
const std::string & outputFileName() const
Return outputFileName string.
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
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.
void saveOutputFileName(Serializable::OArchive &ar)
Save output file name to an archive.
Tensor virialStress() const
Return total virial stress.
void computeKineticStress()
Calculate and store kinetic stress.
VirialStressTensor(Simulation &simulation)
Constructor.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.