Simpatico  v1.10
mcMd/analyzers/Analyzer.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 "Analyzer.h"
9 #include <util/misc/FileMaster.h>
10 #include <util/archives/Serializable_includes.h>
11 #include <util/global.h>
12 
13 namespace McMd
14 {
15 
16  using namespace Util;
17 
18  // Define and initialize static variable
19  long Analyzer::baseInterval = 0;
20 
22  { Analyzer::baseInterval = 0; }
23 
24  /*
25  * Default constructor.
26  */
28  : ParamComposite(),
29  outputFileName_(),
30  interval_(1),
31  fileMasterPtr_(0)
32  {}
33 
34  /*
35  * Destructor.
36  */
38  {}
39 
40  /*
41  * Read parameters from stream, default implementation.
42  */
43  void Analyzer::readParameters(std::istream& in)
44  {
45  readInterval(in);
47  }
48 
49  /*
50  * Read the interval from parameter file, with error checking.
51  */
52  void Analyzer::readInterval(std::istream &in)
53  {
54  // Check that baseInterval has a nonzero, positive value
55  if (baseInterval == 0) {
56  UTIL_THROW("baseInterval == 0");
57  }
58  if (baseInterval < 0) {
59  UTIL_THROW("baseInterval < 0");
60  }
61 
62  // Read interval value (inherited from Interval)
63  read<long>(in, "interval", interval_);
64 
65  // Postconditons
66  if (interval_ == 0) {
67  UTIL_THROW("interval_ == 0");
68  }
69  if (interval_ < 0) {
70  UTIL_THROW("interval_ < 0");
71  }
72  if (interval_ % baseInterval != 0) {
73  UTIL_THROW("interval is not a multiple of baseInterval");
74  }
75  }
76 
77  void Analyzer::readOutputFileName(std::istream &in)
78  { read<std::string>(in, "outputFileName", outputFileName_); }
79 
80  /*
81  * Load parameters from archive, default implementation.
82  */
84  {
85  loadInterval(ar);
87  }
88 
89  /*
90  * Load parameters from archive, with error checking.
91  */
93  {
94  // Check that Analyzer::baseInterval has a nonzero, positive value
95  if (baseInterval == 0) {
96  UTIL_THROW("baseInterval == 0");
97  }
98  if (baseInterval < 0) {
99  UTIL_THROW("baseInterval < 0");
100  }
101 
102  // Load parameters
103  loadParameter<long>(ar, "interval", interval_);
104 
105  // Postconditons
106  if (interval_ == 0) {
107  UTIL_THROW("interval_ == 0");
108  }
109  if (interval_ < 0) {
110  UTIL_THROW("interval_ < 0");
111  }
112  if (interval_ % baseInterval != 0) {
113  UTIL_THROW("interval is not a multiple of baseInterval");
114  }
115  }
116 
117  /*
118  * Load outputFileName from archive.
119  */
121  { loadParameter<std::string>(ar, "outputFileName", outputFileName_); }
122 
123  /*
124  * Save interval and outputFileName to archive.
125  */
127  {
128  ar & interval_;
129  ar & outputFileName_;
130  }
131 
132  /*
133  * Set the FileMaster.
134  */
136  { fileMasterPtr_ = &fileMaster; }
137 
138  /*
139  * Get the FileMaster by reference.
140  */
142  {
143  assert(fileMasterPtr_);
144  return (*fileMasterPtr_);
145  }
146 
147  /*
148  * Get the outputFileName string with an added suffix
149  */
150  std::string Analyzer::outputFileName(const std::string& suffix) const
151  {
152  std::string filename = outputFileName_;
153  filename += suffix;
154  return filename;
155  }
156 
157 }
static void initStatic()
Define and initialize baseInterval.
virtual void save(Serializable::OArchive &ar)
Load parameters to archive.
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from archive.
void setFileMaster(FileMaster &fileMaster)
Set the FileMaster to use to open files.
File containing preprocessor macros for error handling.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
Saving / output archive for binary ostream.
virtual void readParameters(std::istream &in)
Read parameters from archive.
long interval_
Number of simulation steps between subsequent actions.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
Definition: accumulators.mod:1
std::string outputFileName_
Base name of output file(s).
Analyzer()
Default constructor.
virtual ~Analyzer()
Destructor.
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
FileMaster & fileMaster()
Get the FileMaster by reference.
void loadInterval(Serializable::IArchive &ar)
Load interval from archive, with error checking.
const std::string & outputFileName() const
Return outputFileName string.
void loadOutputFileName(Serializable::IArchive &ar)
Load output file name from archive.
An object that can read multiple parameters from file.