PSCF v1.4.0
fts/analyzer/Analyzer.h
1#ifndef RP_ANALYZER_H
2#define RP_ANALYZER_H
3
4#include <util/param/ParamComposite.h> // base class
5#include <string>
6#include <iostream>
7
8// Forward declaration
9namespace Util {
10 class FileMaster;
11}
12
13namespace Pscf {
14namespace Rp {
15
16 using namespace Util;
17
44 template <int D, class SimT, class SysT>
45 class Analyzer : public ParamComposite
46 {
47
48 public:
49
50 // Protected constructor and destructor (see below).
51
59 virtual void readParameters(std::istream& in);
60
72 virtual void setup()
73 {}
74
84 virtual void sample(long iStep) = 0;
85
91 virtual void output()
92 {}
93
97 int interval() const;
98
104 bool isAtInterval(long counter) const;
105
106 // Static members
107
111 static long baseInterval;
112
116 static void initStatic();
117
118 protected:
119
126 Analyzer(SimT& simulator, SysT& system);
127
131 ~Analyzer() = default;
132
139
148 void readInterval(std::istream& in);
149
155 void readOutputFileName(std::istream& in);
156
160 SimT& simulator();
161
165 SysT& system();
166
173
177 std::string const & outputFileName() const;
178
184 std::string outputFileName(std::string const & suffix) const;
185
186 private:
187
189 long interval_;
190
192 std::string outputFileName_;
193
195 SimT* simulatorPtr_;
196
198 SysT* systemPtr_;
199
201 FileMaster* fileMasterPtr_;
202
203 };
204
205 // Inline member functions
206
207 /*
208 * Get the interval value.
209 */
210 template <int D, class SimT, class SysT> inline
212 { return interval_; }
213
214 /*
215 * Return true iff counter is a multiple of the interval.
216 */
217 template <int D, class SimT, class SysT> inline
218 bool Analyzer<D,SimT,SysT>::isAtInterval(long counter) const
219 { return (counter%interval_ == 0); }
220
221 /*
222 * Get the outputFileName string.
223 */
224 template <int D, class SimT, class SysT> inline
225 std::string const & Analyzer<D,SimT,SysT>::outputFileName() const
226 { return outputFileName_; }
227
228 /*
229 * Get the parent Simulator by reference.
230 */
231 template <int D, class SimT, class SysT> inline
233 {
234 UTIL_ASSERT(simulatorPtr_);
235 return *simulatorPtr_;
236 }
237
238 /*
239 * Get the parent System by reference.
240 */
241 template <int D, class SimT, class SysT> inline
243 {
244 UTIL_ASSERT(systemPtr_);
245 return *systemPtr_;
246 }
247
248} // namespace Rp
249} // namespace Pscf
250#endif
int interval() const
Get the interval value.
void readInterval(std::istream &in)
Optionally read interval from file, with error checking.
Definition Analyzer.tpp:54
FileMaster & fileMaster()
Get the FileMaster by reference.
Definition Analyzer.tpp:98
virtual void readParameters(std::istream &in)
Read parameters from archive.
Definition Analyzer.tpp:44
void readOutputFileName(std::istream &in)
Read outputFileName from file.
Definition Analyzer.tpp:81
SimT & simulator()
Get the parent Simulator by reference.
virtual void setup()
Complete any required initialization.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
~Analyzer()=default
Destructor.
virtual void sample(long iStep)=0
Calculate, analyze and/or output a physical quantity.
Analyzer(SimT &simulator, SysT &system)
Constructor.
Definition Analyzer.tpp:31
std::string const & outputFileName() const
Get the outputFileName string.
void setFileMaster(FileMaster &fileMaster)
Set the FileMaster to use to open files.
Definition Analyzer.tpp:91
virtual void output()
Output any results at the end of the simulation.
SysT & system()
Get the parent System by reference.
static long baseInterval
The interval for every Analyzer must be a multiple of baseInterval.
static void initStatic()
Define and initialize baseInterval (initialized to 1).
Definition Analyzer.tpp:22
A FileMaster manages input and output files for a simulation.
Definition FileMaster.h:143
ParamComposite()
Constructor.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Class templates for real-valued periodic fields.
PSCF package top-level namespace.
Utility classes for scientific computation.