1#ifndef RP_AVERAGE_LIST_ANALYZER_TPP
2#define RP_AVERAGE_LIST_ANALYZER_TPP
11#include "AverageListAnalyzer.h"
13#include <rp/system/System.h>
14#include <util/format/Int.h>
15#include <util/format/Dbl.h>
16#include <util/misc/FileMaster.h>
17#include <util/misc/ioUtil.h>
27 template <
int D,
class T>
34 hasAccumulators_(false)
40 template <
int D,
class T>
44 nSamplePerOutput_ = 1;
53 template <
int D,
class T>
70 template <
int D,
class T>
83 template <
int D,
class T>
108 template <
int D,
class T>
116 accumulators_.allocate(
nValue);
120 hasAccumulators_ =
true;
124 for (
int i = 0; i < nValue_; ++i) {
125 accumulators_[i].setNSamplePerBlock(nSamplePerOutput_);
134 template <
int D,
class T>
139 for (
int i = 0; i < nValue_; ++i) {
140 accumulators_[i].clear();
147 template <
int D,
class T>
158 template <
int D,
class T>
162 UTIL_CHECK(accumulators_.capacity() == nValue_);
165 for (
int i = 0; i <
nValue(); ++i) {
166 double data =
value(i);
167 accumulators_[i].sample(data);
171 if (nSamplePerOutput_ > 0) {
172 if (accumulators_[0].isBlockComplete()) {
175 int beginStep = iStep - (nSamplePerOutput_ - 1) *
interval;
177 for (
int i = 0; i <
nValue(); ++i) {
178 UTIL_CHECK(accumulators_[i].isBlockComplete());
179 double block = accumulators_[i].blockAverage();
191 template <
int D,
class T>
204 for (
int i = 0; i < nValue_; ++i) {
205 length = names_[i].length();
206 if (length > nameWidth) {
216 for (
int i = 0; i < nValue_; ++i) {
217 ave = accumulators_[i].average();
218 err = accumulators_[i].blockingError();
219 outputFile_ <<
" " << std::left << std::setw(nameWidth)
230 "------------------------------------------------------------------";
231 for (
int i = 0; i < nValue_; ++i) {
246 for (
int i = 0; i < nValue_; ++i) {
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
void setFileMaster(FileMaster &fileMaster)
Set the FileMaster to use to open files.
std::string const & outputFileName() const
Get the outputFileName string.
virtual void readParameters(std::istream &in)
Read parameters from archive.
int interval() const
Get the interval value.
const std::string & name(int i) const
Get name associated with a variable.
void setup() override
Setup before loop.
void outputAccumulators()
Write results of statistical analysis to files.
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.
Simulator< D, T > & simulator()
Get the parent Simulator by reference.
void output() override
Write final results to file after a simulation.
AverageListAnalyzer(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
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.
void updateAccumulators(long iStep)
Add current value to accumulator, output block average if needed.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
virtual void compute()=0
Compute values of sampled quantities.
System< D, T > & system()
Get the parent System by reference.
void readParameters(std::istream &in) override
Read interval, outputFileName and (optionally) nSamplePerOutput.
Base class for field theoretic PS-FTS simulator.
Base class template for classes that represent a complete system.
FileMaster const & fileMaster() const
Get the FileMaster (const).
Dbl()
Default constructor.
Int()
Default constructor.
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.
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.