Simpatico  v1.10
ddMd/analyzers/Analyzer.h
1 #ifndef DDMD_ANALYZER_H
2 #define DDMD_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 DdMd
19 {
20 
21  using namespace Util;
22  class Simulation;
23 
49  class Analyzer : public ParamComposite
50  {
51 
52  public:
53 
54  // Non-static Methods
55 
59  Analyzer(Simulation& simulation);
60 
64  virtual ~Analyzer();
65 
77  virtual void setup()
78  {}
79 
90  virtual void clear()
91  {}
92 
102  virtual void sample(long iStep) = 0;
103 
109  virtual void output()
110  {}
111 
118  {}
119 
125  virtual void save(Serializable::OArchive &ar)
126  {}
127 
131  int interval() const;
132 
138  bool isAtInterval(long counter) const;
139 
140  // Static members
141 
145  static long baseInterval;
146 
150  static void initStatic();
151 
152  protected:
153 
163  void readInterval(std::istream &in);
164 
174  void loadInterval(Serializable::IArchive &ar);
175 
181  void saveInterval(Serializable::OArchive &ar);
182 
188  void readOutputFileName(std::istream &in);
189 
195  void loadOutputFileName(Serializable::IArchive &ar);
196 
202  void saveOutputFileName(Serializable::OArchive &ar);
203 
207  Simulation& simulation();
208 
212  const std::string& outputFileName() const;
213 
217  std::string outputFileName(const std::string& suffix) const;
218 
219  private:
220 
222  std::string outputFileName_;
223 
225  Simulation* simulationPtr_;
226 
228  long interval_;
229 
230  };
231 
232  // Inline methods
233 
234  /*
235  * Return interval value.
236  */
237  inline int Analyzer::interval() const
238  { return interval_; }
239 
240  /*
241  * Return true iff the counter parameter is a multiple of the interval.
242  */
243  inline bool Analyzer::isAtInterval(long counter) const
244  { return (counter%interval_ == 0); }
245 
246  /*
247  * Get the outputFileName string.
248  */
249  inline const std::string& Analyzer::outputFileName() const
250  { return outputFileName_; }
251 
252  /*
253  * Get the parent Simulation by reference.
254  */
256  { return *simulationPtr_; }
257 
258 
259 }
260 #endif
Abstract base for periodic output and/or analysis actions.
Simulation & simulation()
Get the parent Simulation by reference.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
virtual void setup()
Setup before simulation.
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.
virtual void output()
Output any results at the end of a simulation.
Saving / output archive for binary ostream.
virtual void clear()
Clear statistical accumulators.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
Utility classes for scientific computation.
Definition: accumulators.mod:1
const std::string & outputFileName() const
Return outputFileName string.
Saving archive for binary istream.
void initStatic()
Guarantee initialization of all static class members in DdMd namespace.
int interval() const
Get interval value.
An object that can read multiple parameters from file.