1#ifndef RPC_AVERAGE_ANALYZER_TPP
2#define RPC_AVERAGE_ANALYZER_TPP
11#include "AverageAnalyzer.h"
13#include <rpc/System.h>
14#include <rpc/fts/simulator/Simulator.h>
16#include <util/format/Int.h>
17#include <util/format/Dbl.h>
18#include <util/misc/FileMaster.h>
19#include <util/misc/ioUtil.h>
33 simulatorPtr_(&simulator),
55 nSamplePerOutput_ = 1;
56 readOptional(in,
"nSamplePerOutput", nSamplePerOutput_);
57 if (nSamplePerOutput_ > 0) {
58 std::string fileName = outputFileName(
".dat");
59 system().fileMaster().openOutputFile(fileName, outputFile_);
64 accumulator_.setNSamplePerBlock(nSamplePerOutput_);
72 { accumulator_.clear(); }
80 if (!isAtInterval(iStep))
return;
82 double value = compute();
83 accumulator_.sample(value);
86 if (nSamplePerOutput_ > 0) {
87 if (accumulator_.isBlockComplete()) {
88 int beginStep = iStep - (nSamplePerOutput_ - 1)*interval();
89 value = accumulator_.blockAverage();
90 outputValue(beginStep, value);
103 outputFile_ <<
Int(step);
104 outputFile_ <<
Dbl(value);
115 if (outputFile_.is_open()) {
118 std::string fileName;
122 fileName = outputFileName(
".prm");
123 system().fileMaster().openOutputFile(fileName, outputFile_);
129 fileName = outputFileName(
".ave");
130 system().fileMaster().openOutputFile(fileName, outputFile_);
131 double ave = accumulator_.average();
132 outputFile_ <<
"Average = ";
133 outputFile_ <<
Dbl(ave);
134 if (!simulator().hasRamp()) {
135 double err = accumulator_.blockingError();
136 outputFile_ <<
" +- " <<
Dbl(err, 10, 3);
141 if (!simulator().hasRamp()) {
145 "-------------------------------------------------------------------";
146 outputFile_ << line << std::endl;
147 accumulator_.output(outputFile_);
148 outputFile_ << std::endl;
Abstract base for periodic output and/or analysis actions.
virtual void readParameters(std::istream &in)
Read parameters from archive.
virtual ~AverageAnalyzer()
Destructor.
AverageAnalyzer(Simulator< D > &simulator, System< D > &system)
Constructor.
virtual void setup()
Setup before loop.
virtual void sample(long iStep)
Compute a sampled value and update the accumulator.
virtual void outputValue(int step, double value)
Output a sampled or block average value.
virtual void output()
Write final results to file after a simulation.
virtual void readParameters(std::istream &in)
Read interval, outputFileName and (optionally) nSamplePerOutput.
Field theoretic simulator (base class).
Main class for SCFT or PS-FTS simulation of one 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.
PSCF package top-level namespace.
Utility classes for scientific computation.