PSCF v1.5.0
Analyzer.h
1#ifndef RP_ANALYZER_H
2#define RP_ANALYZER_H
3
4#include <util/param/ParamComposite.h> // base class
5
6#include <pscf/backend/TmplDeclare.h>
7#include <string>
8#include <iostream>
9
10// Forward declaration
11namespace Util {
12 class FileMaster;
13}
14namespace Pscf {
15 namespace Rp {
16 template <int D, class T> class System;
17 template <int D, class T> class Simulator;
18 }
19}
20
21namespace Pscf {
22namespace Rp {
23
24 using namespace Util;
25
47 template <int D, class T>
48 class Analyzer : public ParamComposite
49 {
50
51 public:
52
60
64 ~Analyzer() = default;
65
73 virtual void readParameters(std::istream& in);
74
86 virtual void setup()
87 {}
88
98 virtual void sample(long iStep) = 0;
99
105 virtual void output()
106 {}
107
111 int interval() const;
112
118 bool isAtInterval(long counter) const;
119
120 // Static members
121
125 static long baseInterval;
126
130 static void initStatic();
131
132 protected:
133
140
149 void readInterval(std::istream& in);
150
156 void readOutputFileName(std::istream& in);
157
162
167
174
178 std::string const & outputFileName() const;
179
185 std::string outputFileName(std::string const & suffix) const;
186
187 private:
188
190 long interval_;
191
193 std::string outputFileName_;
194
196 Simulator<D,T>* simulatorPtr_;
197
199 System<D,T>* systemPtr_;
200
202 FileMaster* fileMasterPtr_;
203
204 };
205
206 // Inline member functions
207
208 /*
209 * Get the interval value.
210 */
211 template <int D, class T> inline
213 { return interval_; }
214
215 /*
216 * Return true iff counter is a multiple of the interval.
217 */
218 template <int D, class T> inline
219 bool Analyzer<D,T>::isAtInterval(long counter) const
220 { return (counter%interval_ == 0); }
221
222 /*
223 * Get the outputFileName string.
224 */
225 template <int D, class T> inline
226 std::string const & Analyzer<D,T>::outputFileName() const
227 { return outputFileName_; }
228
229 /*
230 * Get the parent Simulator by reference.
231 */
232 template <int D, class T> inline
234 {
235 UTIL_ASSERT(simulatorPtr_);
236 return *simulatorPtr_;
237 }
238
239 /*
240 * Get the parent System by reference.
241 */
242 template <int D, class T> inline
244 {
245 UTIL_ASSERT(systemPtr_);
246 return *systemPtr_;
247 }
248
249 // Explicit instantiation declarations
250 PSCF_TMPL_DECLARE(Analyzer)
251
252} // namespace Rp
253} // namespace Pscf
254#endif
Abstract base for periodic output and/or analysis actions.
Definition Analyzer.h:49
static void initStatic()
Define and initialize baseInterval (initialized to 1).
Definition Analyzer.tpp:22
Analyzer(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
Definition Analyzer.tpp:31
void readInterval(std::istream &in)
Optionally read interval from file, with error checking.
Definition Analyzer.tpp:55
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
Definition Analyzer.h:219
static long baseInterval
The interval for every Analyzer must be a multiple of baseInterval.
Definition Analyzer.h:125
void setFileMaster(FileMaster &fileMaster)
Set the FileMaster to use to open files.
Definition Analyzer.tpp:92
Simulator< D, T > & simulator()
Get the parent Simulator by reference.
Definition Analyzer.h:233
virtual void setup()
Complete any required initialization.
Definition Analyzer.h:86
std::string const & outputFileName() const
Get the outputFileName string.
Definition Analyzer.h:226
~Analyzer()=default
Destructor.
virtual void readParameters(std::istream &in)
Read parameters from archive.
Definition Analyzer.tpp:45
FileMaster & fileMaster()
Get the FileMaster by reference.
Definition Analyzer.tpp:99
virtual void output()
Output any results at the end of the simulation.
Definition Analyzer.h:105
int interval() const
Get the interval value.
Definition Analyzer.h:212
System< D, T > & system()
Get the parent System by reference.
Definition Analyzer.h:243
void readOutputFileName(std::istream &in)
Read outputFileName from file.
Definition Analyzer.tpp:82
virtual void sample(long iStep)=0
Calculate, analyze and/or output a physical quantity.
Simulator< D, T > & simulator()
Get the parent Simulator by reference.
Definition Analyzer.h:233
System< D, T > & system()
Get the parent System by reference.
Definition Analyzer.h:243
Base class for field theoretic PS-FTS simulator.
Definition Simulator.h:93
Base class template for classes that represent a complete system.
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.
Utility classes for scientific computation.