Simpatico  v1.10
mcMd/analyzers/system/ConfigWriter.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 "ConfigWriter.h"
9 #include <util/misc/FileMaster.h>
10 #include <util/archives/Serializable_includes.h>
11 #include <util/misc/ioUtil.h>
12 
13 #include <sstream>
14 
15 namespace McMd
16 {
17 
18  using namespace Util;
19 
20  /*
21  * Constructor.
22  */
24  : SystemAnalyzer<System>(system),
25  nSample_(0),
26  isInitialized_(false)
27  { setClassName("ConfigWriter"); }
28 
29  /*
30  * Read interval and outputFileName.
31  */
32  void ConfigWriter::readParameters(std::istream& in)
33  {
34  readInterval(in);
36  isInitialized_ = true;
37  }
38 
39  /*
40  * Load state from an archive.
41  */
43  {
45  ar & nSample_;
46  isInitialized_ = true;
47  }
48 
49  /*
50  * Save state to archive.
51  */
53  { ar & *this; }
54 
55  /*
56  * Read interval and outputFileName.
57  */
59  { nSample_ = 0; }
60 
61  /*
62  * Dump configuration to file
63  */
64  void ConfigWriter::sample(long iStep)
65  {
66  if (isAtInterval(iStep)) {
67 
68  // Construct new fileName: outputFileName + toString(nSample)
69  std::string filename;
70  filename = outputFileName();
71  filename += toString(nSample_);
72 
73  // Open output file, write data, and close file
74  fileMaster().openOutputFile(filename, outputFile_);
75  system().writeConfig(outputFile_);
76  outputFile_.close();
77  ++nSample_;
78 
79  }
80  }
81 
82 }
std::string toString(int n)
Return string representation of an integer.
Definition: ioUtil.cpp:52
virtual void loadParameters(Serializable::IArchive &ar)
Load state from 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 parameters from archive.
ConfigWriter(System &system)
Constructor.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
System & system()
Return reference to parent system.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
virtual void save(Serializable::OArchive &ar)
Save state to archive.
Saving / output archive for binary ostream.
void readInterval(std::istream &in)
Read interval from file, with error checking.
virtual void readParameters(std::istream &in)
Read dumpPrefix and interval.
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual void sample(long iStep)
Dump configuration to file.
Template for Analyzer associated with one System.
virtual void setup()
Clear nSample counter.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setClassName(const char *className)
Set class name string.
FileMaster & fileMaster()
Get the FileMaster by reference.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
const std::string & outputFileName() const
Return outputFileName string.
void writeConfig(std::ostream &out)
Write system configuration to a specified ostream.
Definition: System.cpp:836