Simpatico  v1.10
OutputTemperature.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 "OutputTemperature.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("OutputTemperature"); }
29 
30  /*
31  * Read interval and outputFileName.
32  */
33  void OutputTemperature::readParameters(std::istream& in)
34  {
35  readInterval(in);
37 
38  #if 0
39  // Open output file
40  std::string filename;
41  filename = outputFileName();
42  simulation().fileMaster().openOutputFile(filename, outputFile_);
43  #endif
44  isInitialized_ = true;
45  }
46 
47 
48  /*
49  * Load internal state from an archive.
50  */
52  {
53  // Load parameter file parameters
54  loadInterval(ar);
56 
57  // Load other data
58  MpiLoader<Serializable::IArchive> loader(*this, ar);
59  loader.load(nSample_);
60 
61  #if 0
62  // Open output file
63  std::string filename;
64  filename = outputFileName();
65  simulation().fileMaster().openOutputFile(filename, outputFile_);
66  #endif
67  isInitialized_ = true;
68  }
69 
70  /*
71  * Save internal state to an archive.
72  */
74  {
75  saveInterval(ar);
77  ar << nSample_;
78  }
79 
80  /*
81  * Clear nSample counter.
82  */
84  { nSample_ = 0; }
85 
86  /*
87  * Open outputfile
88  */
90  {
91  if (simulation().domain().isMaster()) {
92  std::string filename;
93  filename = outputFileName();
94  simulation().fileMaster().openOutputFile(filename, outputFile_);
95  }
96  }
97 
98  /*
99  * Dump configuration to file
100  */
101  void OutputTemperature::sample(long iStep)
102  {
103  if (isAtInterval(iStep)) {
104  Simulation& sys = simulation();
105  sys.computeKineticEnergy();
106  simulation().atomStorage().computeNAtomTotal(simulation().domain().communicator());
107 
108  if (sys.domain().isMaster()) {
109  double ndof = simulation().atomStorage().nAtomTotal()*3;
110  double T_kinetic = sys.kineticEnergy()*2.0/ndof;
111  outputFile_ << Int(iStep, 10)
112  << Dbl(T_kinetic, 20)
113  << std::endl;
114  }
115 
116  ++nSample_;
117  }
118  }
119 
120 }
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.
int nAtomTotal() const
Get total number of atoms on all processors.
virtual void clear()
Clear nSample counter.
double kineticEnergy()
Return precomputed total kinetic energy.
AtomStorage & atomStorage()
Get the AtomStorage by 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
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.
OutputTemperature(Simulation &simulation)
Constructor.
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.
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
const std::string & outputFileName() const
Return outputFileName string.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
void computeNAtomTotal(MPI::Intracomm &communicator)
Compute the total number of local atoms on all processors.
bool isMaster() const
Is this the master processor (gridRank == 0) ?
Definition: Domain.h:313
virtual void setup()
Setup - open output file.
virtual void readParameters(std::istream &in)
Read interval and output file name.
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 loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void computeKineticEnergy()
Compute total kinetic energy.
Domain & domain()
Get the Domain by reference.
virtual void sample(long iStep)
Dump configuration to file.