PSCF v1.4.0
Analyzer.tpp
1#ifndef RP_ANALYZER_TPP
2#define RP_ANALYZER_TPP
3
4#include "Analyzer.h"
5#include <util/misc/FileMaster.h>
6#include <util/global.h>
7
8namespace Pscf {
9namespace Rp {
10
11 using namespace Util;
12
13 // Static members
14
15 template <int D, class SimT, class SysT>
17
18 /*
19 * Static initialization function.
20 */
21 template <int D, class SimT, class SysT>
24
25 // Non-static member functions
26
27 /*
28 * Constructor.
29 */
30 template <int D, class SimT, class SysT>
33 interval_(1),
34 outputFileName_(""),
35 simulatorPtr_(&simulator),
36 systemPtr_(&system),
37 fileMasterPtr_(nullptr)
38 {}
39
40 /*
41 * Read parameters from stream, default implementation.
42 */
43 template <int D, class SimT, class SysT>
45 {
46 readInterval(in);
48 }
49
50 /*
51 * Read the interval from parameter file, with error checking.
52 */
53 template <int D, class SimT, class SysT>
55 {
56 // Check that baseInterval has a nonzero, positive value
57 if (baseInterval == 0) {
58 UTIL_THROW("baseInterval == 0");
59 }
60 if (baseInterval < 0) {
61 UTIL_THROW("baseInterval < 0");
62 }
63
64 // Optionally read interval value (set to 1 by default)
65 interval_ = 1;
66 ParamComposite::readOptional<long>(in, "interval", interval_);
67
68 // Postconditons
69 if (interval_ == 0) {
70 UTIL_THROW("interval_ == 0");
71 }
72 if (interval_ < 0) {
73 UTIL_THROW("interval_ < 0");
74 }
75 if (interval_ % baseInterval != 0) {
76 UTIL_THROW("interval is not a multiple of baseInterval");
77 }
78 }
79
80 template <int D, class SimT, class SysT>
82 {
83 ParamComposite::read<std::string>(in, "outputFileName",
84 outputFileName_);
85 }
86
87 /*
88 * Set the FileMaster.
89 */
90 template <int D, class SimT, class SysT>
93
94 /*
95 * Get the FileMaster by reference.
96 */
97 template <int D, class SimT, class SysT>
99 {
100 UTIL_CHECK(fileMasterPtr_);
101 return (*fileMasterPtr_);
102 }
103
104 /*
105 * Get the outputFileName string with an added suffix
106 */
107 template <int D, class SimT, class SysT>
108 std::string
109 Analyzer<D,SimT,SysT>::outputFileName(std::string const & suffix) const
110 {
111 std::string filename = outputFileName_;
112 filename += suffix;
113 return filename;
114 }
115
117}
118#endif
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.
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
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
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
ParamComposite()
Constructor.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Class templates for real-valued periodic fields.
PSCF package top-level namespace.