Simpatico  v1.10
mcMd/analyzers/Analyzer.h
1 #ifndef MCMD_ANALYZER_H
2 #define MCMD_ANALYZER_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/param/ParamComposite.h> // base class
12 #include <util/misc/FileMaster.h> // member variable
13 
14 #include <string>
15 #include <iostream>
16 #include <fstream>
17 
18 namespace McMd
19 {
20 
21  using namespace Util;
22 
52  class Analyzer : public ParamComposite
53  {
54 
55  public:
56 
57  // Non-static Methods
58 
62  Analyzer();
63 
67  virtual ~Analyzer();
68 
76  virtual void readParameters(std::istream& in);
77 
85  virtual void loadParameters(Serializable::IArchive& ar);
86 
94  virtual void save(Serializable::OArchive& ar);
95 
104  template <class Archive>
105  void serialize(Archive& ar, const unsigned int version);
106 
118  virtual void setup()
119  {}
120 
130  virtual void sample(long iStep) = 0;
131 
137  virtual void output()
138  {}
139 
143  int interval() const;
144 
150  bool isAtInterval(long counter) const;
151 
152  // Static members
153 
157  static long baseInterval;
158 
162  static void initStatic();
163 
164  protected:
165 
169  void setFileMaster(FileMaster& fileMaster);
170 
176  void readInterval(std::istream &in);
177 
183  void readOutputFileName(std::istream &in);
184 
190  void loadInterval(Serializable::IArchive& ar);
191 
197  void loadOutputFileName(Serializable::IArchive& ar);
198 
204  FileMaster& fileMaster();
205 
209  const std::string& outputFileName() const;
210 
214  std::string outputFileName(const std::string& suffix) const;
215 
217  std::string outputFileName_;
218 
220  long interval_;
221 
222  private:
223 
225  FileMaster* fileMasterPtr_;
226 
227  };
228 
229  // Inline methods
230 
231  /*
232  * Return interval value.
233  */
234  inline int Analyzer::interval() const
235  { return interval_; }
236 
237  /*
238  * Return true iff the counter parameter is a multiple of the interval.
239  */
240  inline bool Analyzer::isAtInterval(long counter) const
241  { return (counter%interval_ == 0); }
242 
243  /*
244  * Get the outputFileName string.
245  */
246  inline const std::string& Analyzer::outputFileName() const
247  { return outputFileName_; }
248 
249  // Method template
250 
251  /*
252  * Serialize to/from an archive.
253  */
254  template <class Archive>
255  void Analyzer::serialize(Archive& ar, const unsigned int version)
256  {
257  ar & interval_;
258  ar & outputFileName_;
259  }
260 
261 }
262 #endif
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
virtual void setup()
Complete any required initialization.
void initStatic()
Guarantee initialization of all static class members in Util namespace.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
Definition: PairSelector.h:167
Saving / output archive for binary ostream.
long interval_
Number of simulation steps between subsequent actions.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
Abstract base for periodic output and/or analysis actions.
Utility classes for scientific computation.
Definition: accumulators.mod:1
std::string outputFileName_
Base name of output file(s).
A FileMaster manages input and output files for a simulation.
Definition: FileMaster.h:142
virtual void output()
Output any results at the end of the simulation.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
const std::string & outputFileName() const
Return outputFileName string.
int interval() const
Get interval value.
An object that can read multiple parameters from file.