Simpatico  v1.10
ddMd/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/global.h>
11 
12 namespace DdMd
13 {
14 
15  using namespace Util;
16 
17  // Define and initialize static variable
18  long Analyzer::baseInterval = 1;
19 
21  { Analyzer::baseInterval = 1; }
22 
23  /*
24  * Default constructor.
25  */
27  : ParamComposite(),
28  outputFileName_(),
29  simulationPtr_(&simulation),
30  interval_(1)
31  {}
32 
33  /*
34  * Destructor.
35  */
37  {}
38 
39  /*
40  * Read the interval from parameter file, with error checking.
41  */
42  void Analyzer::readInterval(std::istream &in)
43  {
44 
45  // Check that baseInterval has a nonzero, positive value
46  if (baseInterval == 0) {
47  UTIL_THROW("baseInterval == 0");
48  }
49  if (baseInterval < 0) {
50  UTIL_THROW("baseInterval < 0");
51  }
52 
53  // Read interval value (inherited from Interval)
54  read<long>(in, "interval", interval_);
55 
56  // Check that interval has a nonzero, positive value
57  if (interval_ == 0) {
58  UTIL_THROW("interval_ == 0");
59  }
60  if (interval_ < 0) {
61  UTIL_THROW("interval_ < 0");
62  }
63 
64  // Check that interval is a multiple of baseInterval
65  if (interval_ % baseInterval != 0) {
66  UTIL_THROW("interval is not a multiple of baseInterval");
67  }
68 
69  }
70 
71  /*
72  * Load parameter interval from input archive.
73  */
75  {
76  // Check that baseInterval has a nonzero, positive value
77  if (baseInterval == 0) {
78  UTIL_THROW("baseInterval == 0");
79  }
80  if (baseInterval < 0) {
81  UTIL_THROW("baseInterval < 0");
82  }
83 
84  loadParameter<long>(ar, "interval", interval_);
85 
86  // Check that interval has a nonzero, positive value
87  if (interval_ == 0) {
88  UTIL_THROW("interval_ == 0");
89  }
90  if (interval_ < 0) {
91  UTIL_THROW("interval_ < 0");
92  }
93 
94  // Check that interval is a multiple of baseInterval
95  if (interval_ % baseInterval != 0) {
96  UTIL_THROW("interval is not a multiple of baseInterval");
97  }
98  }
99 
100  /*
101  * Save interval parameter to an archive.
102  */
104  { ar << interval_; }
105 
106  /*
107  * Read output file name and open output file.
108  */
109  void Analyzer::readOutputFileName(std::istream &in)
110  { read<std::string>(in, "outputFileName", outputFileName_); }
111 
112  /*
113  * Load output file name to an archive.
114  */
116  { loadParameter<std::string>(ar, "outputFileName", outputFileName_); }
117 
118  /*
119  * Save output file name to an archive.
120  */
122  { ar << outputFileName_; }
123 
124  /*
125  * Get the outputFileName string with an added suffix
126  */
127  std::string Analyzer::outputFileName(const std::string& suffix) const
128  {
129  std::string filename = outputFileName_;
130  filename += suffix;
131  return filename;
132  }
133 
134 }
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void saveInterval(Serializable::OArchive &ar)
Save interval parameter to an archive.
static void initStatic()
Define and initialize baseInterval.
void readInterval(std::istream &in)
Read parameter interval from file.
File containing preprocessor macros for error handling.
Parallel domain decomposition (DD) MD simulation.
Main object for a domain-decomposition MD simulation.
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
Saving / output archive for binary ostream.
void loadOutputFileName(Serializable::IArchive &ar)
Load output file name to an archive.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual ~Analyzer()
Destructor.
const std::string & outputFileName() const
Return outputFileName string.
Saving archive for binary istream.
void loadInterval(Serializable::IArchive &ar)
Load parameter interval from input archive.
void saveOutputFileName(Serializable::OArchive &ar)
Save output file name to an archive.
An object that can read multiple parameters from file.
Analyzer(Simulation &simulation)
Constructor.