1#ifndef RP_AVERAGE_LIST_ANALYZER_TPP
2#define RP_AVERAGE_LIST_ANALYZER_TPP
11#include "AverageListAnalyzer.h"
13#include <util/format/Int.h>
14#include <util/format/Dbl.h>
15#include <util/misc/FileMaster.h>
16#include <util/misc/ioUtil.h>
26 template <
int D,
class T>
28 typename T::Simulator& simulator,
29 typename T::System& system)
30 : AnalyzerT(simulator, system),
33 hasAccumulators_(false)
34 { AnalyzerT::setFileMaster(system.fileMaster()); }
39 template <
int D,
class T>
42 AnalyzerT::readParameters(in);
43 nSamplePerOutput_ = 1;
48 std::string fileName = AnalyzerT::outputFileName(
".dat");
49 system().fileMaster().openOutputFile(fileName,
outputFile_);
58 template <
int D,
class T>
68 template <
int D,
class T>
72 if (AnalyzerT::isAtInterval(iStep)) {
81 template <
int D,
class T>
93 std::string filename = AnalyzerT::outputFileName(
".prm");
94 system().fileMaster().openOutputFile(filename,
outputFile_);
106 template <
int D,
class T>
114 accumulators_.allocate(
nValue);
118 hasAccumulators_ =
true;
122 for (
int i = 0; i < nValue_; ++i) {
123 accumulators_[i].setNSamplePerBlock(nSamplePerOutput_);
132 template <
int D,
class T>
137 for (
int i = 0; i < nValue_; ++i) {
138 accumulators_[i].clear();
145 template <
int D,
class T>
156 template <
int D,
class T>
160 UTIL_CHECK(accumulators_.capacity() == nValue_);
163 for (
int i = 0; i <
nValue(); ++i) {
164 double data =
value(i);
165 accumulators_[i].sample(data);
169 if (nSamplePerOutput_ > 0) {
170 if (accumulators_[0].isBlockComplete()) {
172 int interval = AnalyzerT::interval();
173 int beginStep = iStep - (nSamplePerOutput_ - 1) * interval;
175 for (
int i = 0; i <
nValue(); ++i) {
176 UTIL_CHECK(accumulators_[i].isBlockComplete());
177 double block = accumulators_[i].blockAverage();
189 template <
int D,
class T>
202 for (
int i = 0; i < nValue_; ++i) {
203 length = names_[i].length();
204 if (length > nameWidth) {
211 std::string fileName = AnalyzerT::outputFileName(
".ave");
212 system().fileMaster().openOutputFile(fileName,
outputFile_);
214 for (
int i = 0; i < nValue_; ++i) {
215 ave = accumulators_[i].average();
216 err = accumulators_[i].blockingError();
217 outputFile_ <<
" " << std::left << std::setw(nameWidth)
224 fileName = AnalyzerT::outputFileName(
".aer");
225 system().fileMaster().openOutputFile(fileName,
outputFile_);
228 "------------------------------------------------------------------";
229 for (
int i = 0; i < nValue_; ++i) {
239 fileName = AnalyzerT::outputFileName();
241 system().fileMaster().openOutputFile(fileName,
outputFile_);
244 for (
int i = 0; i < nValue_; ++i) {
const std::string & name(int i) const
Get name associated with a variable.
void setup() override
Setup before loop.
void outputAccumulators()
void sample(long iStep) override
Compute sampled values and update the accumulators.
double value(int i) const
Get current value of a specific variable.
void initializeAccumulators(int nValue)
Initialize Average accumulators and set nValue.
void output() override
Write final results to file after a simulation.
std::ofstream outputFile_
Output file stream.
void clearAccumulators()
Clear internal state of all accumulators.
void setName(int i, std::string name)
Set name of variable.
int nValue() const
Get the number of variables.
AverageListAnalyzer(typename T::Simulator &simulator, typename T::System &system)
Constructor.
void updateAccumulators(long iStep)
int nSamplePerOutput() const
Get value of nSamplePerOutput.
void readParameters(std::istream &in) override
Read interval, outputFileName and (optionally) nSamplePerOutput.
Wrapper for a double precision number, for formatted ostream output.
Wrapper for an int, for formatted ostream output.
virtual void writeParam(std::ostream &out) const
Write all parameters to an output stream.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Class templates for real-valued periodic fields.
PSCF package top-level namespace.