1#ifndef RPG_AVERAGE_LIST_ANALYZER_TPP
2#define RPG_AVERAGE_LIST_ANALYZER_TPP
11#include "AverageListAnalyzer.h"
13#include <rpg/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>
34 hasAccumulators_(false)
51 nSamplePerOutput_ = 1;
55 system().fileMaster().openOutputFile(fileName, outputFile_);
102 if (outputFile_.is_open()) {
129 accumulators_.allocate(
nValue);
133 hasAccumulators_ =
true;
137 for (
int i = 0; i < nValue_; ++i) {
138 accumulators_[i].setNSamplePerBlock(nSamplePerOutput_);
152 for (
int i = 0; i < nValue_; ++i) {
153 accumulators_[i].clear();
172 UTIL_CHECK(accumulators_.capacity() == nValue_);
175 for (
int i = 0; i <
nValue(); ++i) {
176 double data =
value(i);
177 accumulators_[i].sample(data);
181 if (nSamplePerOutput_ > 0) {
182 if (accumulators_[0].isBlockComplete()) {
184 int beginStep = iStep - (nSamplePerOutput_ - 1)*
interval();
185 outputFile_ <<
Int(beginStep);
186 for (
int i = 0; i <
nValue(); ++i) {
187 UTIL_CHECK(accumulators_[i].isBlockComplete());
188 double block = accumulators_[i].blockAverage();
189 outputFile_ <<
Dbl(block);
206 if (outputFile_.is_open()) {
213 for (
int i = 0; i < nValue_; ++i) {
214 length = names_[i].length();
215 if (length > nameWidth) {
223 system().fileMaster().openOutputFile(fileName, outputFile_);
225 for (
int i = 0; i < nValue_; ++i) {
226 ave = accumulators_[i].average();
227 err = accumulators_[i].blockingError();
228 outputFile_ <<
" " << std::left << std::setw(nameWidth)
230 outputFile_ <<
Dbl(ave) <<
" +- " <<
Dbl(err, 9, 2) <<
"\n";
236 system().fileMaster().openOutputFile(fileName, outputFile_);
239 "---------------------------------------------------------------------";
240 for (
int i = 0; i < nValue_; ++i) {
241 outputFile_ << line << std::endl;
242 outputFile_ << names_[i] <<
" :" << std::endl;
243 accumulators_[i].output(outputFile_);
244 outputFile_ << std::endl;
252 system().fileMaster().openOutputFile(fileName, outputFile_);
253 outputFile_ <<
"Value = " <<
nValue() << std::endl;
254 outputFile_ <<
"iStep ";
255 for (
int i = 0; i < nValue_; ++i) {
256 outputFile_ << names_[i] <<
" ";
258 outputFile_ << std::endl;
virtual void readParameters(std::istream &in)
Read parameters from archive.
const std::string & outputFileName() const
Return outputFileName string.
Analyzer()
Default constructor.
int interval() const
Get interval value.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
AverageListAnalyzer(System< D > &system)
Constructor.
System< D > * systemPtr_
Pointer to the parent system.
virtual ~AverageListAnalyzer()
Destructor.
void setName(int i, std::string name)
Set name of variable.
virtual void readParameters(std::istream &in)
Read interval, outputFileName and (optionally) nSamplePerOutput.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
virtual void setup()
Setup before loop.
void outputAccumulators()
Write results of statistical analysis to files.
System< D > & system()
Return reference to parent system.
void clearAccumulators()
Clear internal state of the accumulator.
virtual void compute()=0
Compute value of sampled quantity.
int nValue() const
Get number of variables.
const std::string & name(int i) const
Get name associated with value.
int nSamplePerOutput() const
Get value of nSamplePerOutput.
void updateAccumulators(long iStep)
Add current value to accumulator, output block average if needed.
void initializeAccumulators(int nValue)
Instantiate Average accumulators and set nSamplePerOutput set nValue.
virtual void sample(long iStep)
Compute a sampled value and update the accumulator.
virtual void clear()
Clear accumulators.
double value(int i) const
Get current value of a specific variable.
virtual void output()
Write final results to file after a simulation.
Main class, representing one complete system.
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.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.