1#ifndef RPC_BD_SIMULATOR_TPP
2#define RPC_BD_SIMULATOR_TPP
11#include "BdSimulator.h"
13#include <rpc/fts/brownian/BdStep.h>
14#include <rpc/fts/brownian/BdStepFactory.h>
15#include <rpc/fts/compressor/Compressor.h>
16#include <rpc/fts/analyzer/AnalyzerFactory.h>
17#include <rpc/fts/trajectory/TrajectoryReader.h>
18#include <rpc/fts/trajectory/TrajectoryReaderFactory.h>
19#include <rpc/fts/perturbation/PerturbationFactory.h>
20#include <rpc/fts/perturbation/Perturbation.h>
21#include <rpc/fts/ramp/RampFactory.h>
22#include <rpc/fts/ramp/Ramp.h>
23#include <rpc/system/System.h>
25#include <util/random/Random.h>
26#include <util/misc/Timer.h>
40 analyzerManager_(*this,
system),
42 bdStepFactoryPtr_(nullptr),
43 trajectoryReaderFactoryPtr_(nullptr)
47 trajectoryReaderFactoryPtr_
57 if (bdStepFactoryPtr_) {
58 delete bdStepFactoryPtr_;
63 if (trajectoryReaderFactoryPtr_) {
64 delete trajectoryReaderFactoryPtr_;
81 bdStepFactoryPtr_->readObjectOptional(in, *
this,
107 state_.needsHamiltonian =
false;
126 void BdSimulator<D>::setup(
int nStep)
133 if (hasPerturbation()) {
134 perturbation().setup();
145 if (hasCompressor()) {
146 compressor().compress();
147 compressor().clearTimers();
154 computeHamiltonian();
157 if (analyzerManager_.size() > 0){
158 analyzerManager_.setup();
186 analyzerTimer.
start();
187 if (analyzerManager_.size() > 0){
188 analyzerManager_.sample(
iStep_);
190 analyzerTimer.
stop();
196 converged =
bdStep().step();
206 analyzerTimer.
start();
208 if (analyzerManager_.size() > 0) {
210 analyzerManager_.sample(
iStep_);
214 analyzerTimer.
stop();
218 <<
" failed to converge" <<
"\n";
224 double time = timer.
time();
225 double analyzerTime = analyzerTimer.
time();
229 analyzerManager_.output();
240 Log::file() <<
"nStep " << nStep << std::endl;
245 <<
" sec" << std::endl;
246 double rStep = double(nStep);
247 Log::file() <<
"time / nStep " << time / rStep
248 <<
" sec" << std::endl;
249 Log::file() <<
"Analyzer run time " << analyzerTime
250 <<
" sec" << std::endl;
267 std::string classname,
268 std::string filename)
279 if (!trajectoryReaderPtr) {
281 message =
"Invalid TrajectoryReader class name " + classname;
286 trajectoryReaderPtr->
open(filename);
287 trajectoryReaderPtr->readHeader();
293 hasFrame = trajectoryReaderPtr->
readFrame();
307 analyzerManager_.sample(
iStep_);
311 hasFrame = trajectoryReaderPtr->
readFrame();
314 Log::file() <<
"end main loop" << std::endl;
315 int nFrames =
iStep_ - min;
316 trajectoryReaderPtr->
close();
317 delete trajectoryReaderPtr;
320 analyzerManager_.output();
324 Log::file() <<
"# of frames " << nFrames << std::endl;
326 <<
" sec" << std::endl;
327 Log::file() <<
"time / frame " << timer.
time()/double(nFrames)
328 <<
" sec" << std::endl;
static long baseInterval
The interval for an Analyzer must be a multiple of baseInterval.
std::string indent() const
Return indent string for this object (string of spaces).
~BdSimulator()
Destructor.
BdSimulator(System< D > &system)
Constructor.
void setClassName(const char *className)
Set class name string.
Factory< TrajectoryReader< D > > & trajectoryReaderFactory()
Get the trajectory reader factory by reference.
BdStep< D > & bdStep()
Get the BdStep by reference.
virtual void analyze(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
virtual void readParameters(std::istream &in)
Read parameter file block for a Brownian dynamics (BD) simulation.
void simulate(int nStep)
Perform a field theoretic Monte-Carlo simulation.
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
bool hasBdStep() const
Does this BdSimulator have a BdStep object?
Factory for subclasses of BdStep.
Ramp< D > const & ramp() const
Get the associated Ramp by const reference.
void readPerturbation(std::istream &in, bool &isEnd)
Optionally read an associated perturbation.
System< D > & system()
Get parent system by reference.
SimState< D > state_
Previous state saved during at the beginning of a step.
bool hasRamp() const
Does this Simulator have a Ramp?
void clearData()
Clear field eigen-components and hamiltonian components.
Compressor< D > & compressor()
Get the compressor by non-const reference.
void allocate()
Allocate required memory.
long iTotalStep_
Step counter - total number of attempted BD or MC steps.
bool hasCompressor() const
Does this Simulator have a Compressor?
void readRandomSeed(std::istream &in)
Optionally read a random number generator seed.
void readCompressor(std::istream &in, bool &isEnd)
Read the compressor block of the parameter file.
long iStep_
Step counter - attempted steps for which compressor converges.
void readRamp(std::istream &in, bool &isEnd)
Optionally read an associated ramp.
Main class, representing one complete system.
Factory for subclasses of TrajectoryReader.
Trajectory file reader (base class).
virtual bool readFrame()=0
Read a single frame.
virtual void close()=0
Close the trajectory file.
virtual void open(std::string filename)=0
Open trajectory file and read header, if any.
static std::ostream & file()
Get log ostream by reference.
static bool echo()
Get echo parameter.
std::string className() const
Get class name string.
void start(TimePoint begin)
Start timing from an externally supplied time.
double time() const
Return the accumulated time, in seconds.
void stop(TimePoint end)
Stop the clock at an externally supplied time.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Real periodic fields, SCFT and PS-FTS (CPU).
PSCF package top-level namespace.