PSCF v1.5.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 T>
17
18 /*
19 * Static initialization function.
20 */
21 template <int D, class T>
24
25 // Non-static member functions
26
27 /*
28 * Constructor.
29 */
30 template <int D, class T>
34 interval_(1),
35 outputFileName_(""),
36 simulatorPtr_(&simulator),
37 systemPtr_(&system),
38 fileMasterPtr_(nullptr)
39 {}
40
41 /*
42 * Read parameters from stream, default implementation.
43 */
44 template <int D, class T>
45 void Analyzer<D,T>::readParameters(std::istream& in)
46 {
47 readInterval(in);
49 }
50
51 /*
52 * Read the interval from parameter file, with error checking.
53 */
54 template <int D, class T>
55 void Analyzer<D,T>::readInterval(std::istream& in)
56 {
57 // Check that baseInterval has a nonzero, positive value
58 if (baseInterval == 0) {
59 UTIL_THROW("baseInterval == 0");
60 }
61 if (baseInterval < 0) {
62 UTIL_THROW("baseInterval < 0");
63 }
64
65 // Optionally read interval value (set to 1 by default)
66 interval_ = 1;
67 ParamComposite::readOptional<long>(in, "interval", interval_);
68
69 // Postconditons
70 if (interval_ == 0) {
71 UTIL_THROW("interval_ == 0");
72 }
73 if (interval_ < 0) {
74 UTIL_THROW("interval_ < 0");
75 }
76 if (interval_ % baseInterval != 0) {
77 UTIL_THROW("interval is not a multiple of baseInterval");
78 }
79 }
80
81 template <int D, class T>
82 void Analyzer<D,T>::readOutputFileName(std::istream &in)
83 {
84 ParamComposite::read<std::string>(in, "outputFileName",
85 outputFileName_);
86 }
87
88 /*
89 * Set the FileMaster.
90 */
91 template <int D, class T>
94
95 /*
96 * Get the FileMaster by reference.
97 */
98 template <int D, class T>
100 {
101 UTIL_CHECK(fileMasterPtr_);
102 return (*fileMasterPtr_);
103 }
104
105 /*
106 * Get the outputFileName string with an added suffix
107 */
108 template <int D, class T>
109 std::string
110 Analyzer<D,T>::outputFileName(std::string const & suffix) const
111 {
112 std::string filename = outputFileName_;
113 filename += suffix;
114 return filename;
115 }
116
117}
118}
119#endif
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
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
std::string const & outputFileName() const
Get the outputFileName string.
Definition Analyzer.h:226
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
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
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
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
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.