1#ifndef RPG_BD_SIMULATOR_TPP
2#define RPG_BD_SIMULATOR_TPP
11#include "BdSimulator.h"
13#include <rpg/fts/brownian/BdStep.h>
14#include <rpg/fts/brownian/BdStepFactory.h>
15#include <rpg/fts/analyzer/AnalyzerFactory.h>
16#include <rpg/fts/trajectory/TrajectoryReader.h>
17#include <rpg/fts/trajectory/TrajectoryReaderFactory.h>
18#include <rpg/fts/perturbation/PerturbationFactory.h>
19#include <rpg/fts/perturbation/Perturbation.h>
20#include <rpg/fts/ramp/RampFactory.h>
21#include <rpg/fts/ramp/Ramp.h>
22#include <rpg/fts/compressor/Compressor.h>
23#include <rpg/system/System.h>
25#include <pscf/cuda/CudaRandom.h>
26#include <util/misc/Timer.h>
40 analyzerManager_(*this,
system),
43 trajectoryReaderFactoryPtr_(0),
48 trajectoryReaderFactoryPtr_
58 if (bdStepFactoryPtr_) {
59 delete bdStepFactoryPtr_;
64 if (trajectoryReaderFactoryPtr_) {
65 delete trajectoryReaderFactoryPtr_;
83 bdStepPtr_ = bdStepFactoryPtr_->readObjectOptional(in, *
this,
103 state_.needsHamiltonian =
false;
121 void BdSimulator<D>::setup(
int nStep)
128 if (hasPerturbation()) {
129 perturbation().setup();
140 if (hasCompressor()) {
141 compressor().compress();
142 compressor().clearTimers();
149 computeHamiltonian();
155 if (analyzerManager_.size() > 0){
156 analyzerManager_.setup();
184 analyzerTimer.
start();
185 analyzerManager_.sample(
iStep_);
186 analyzerTimer.
stop();
202 analyzerTimer.
start();
205 if (analyzerManager_.size() > 0) {
206 analyzerManager_.sample(
iStep_);
210 analyzerTimer.
stop();
219 double time = timer.
time();
220 double analyzerTime = analyzerTimer.
time();
224 analyzerManager_.output();
235 Log::file() <<
"nStep " << nStep << std::endl;
241 <<
" sec" << std::endl;
242 double rStep = double(nStep);
243 Log::file() <<
"time / nStep " << time / rStep
244 <<
" sec" << std::endl;
245 Log::file() <<
"Analyzer run time " << analyzerTime
246 <<
" sec" << std::endl;
261 std::string classname,
262 std::string filename)
273 if (!trajectoryReaderPtr) {
275 message =
"Invalid TrajectoryReader class name " + classname;
280 trajectoryReaderPtr->
open(filename);
281 trajectoryReaderPtr->readHeader();
287 hasFrame = trajectoryReaderPtr->
readFrame();
300 analyzerManager_.sample(
iStep_);
304 hasFrame = trajectoryReaderPtr->
readFrame();
307 Log::file() <<
"end main loop" << std::endl;
308 int nFrames =
iStep_ - min;
309 trajectoryReaderPtr->
close();
310 delete trajectoryReaderPtr;
313 analyzerManager_.output();
317 Log::file() <<
"# of frames " << nFrames << std::endl;
319 <<
" sec" << std::endl;
320 Log::file() <<
"time / frame " << timer.
time()/double(nFrames)
321 <<
" sec" << std::endl;
static long baseInterval
The interval for every Analyzer must be a multiple of baseInterval.
virtual void outputTimers(std::ostream &out) const
Output timing results.
void simulate(int nStep)
Perform a field theoretic Monte-Carlo simulation.
virtual void analyze(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
void setClassName(const char *className)
Set class name string.
Factory< TrajectoryReader< D > > & trajectoryReaderFactory()
Get the trajectory reader factory by reference.
BdStep< D > & stepper()
Get BdStep.
bool hasBdStep() const
Does this BdSimulator have an associated BdStep?
~BdSimulator()
Destructor.
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
BdSimulator(System< D > &system)
Constructor.
virtual void readParameters(std::istream &in)
Read parameters for a MC simulation.
Factory for subclasses of BdStep.
void readRandomSeed(std::istream &in)
Read random seed and initialize random number generators.
System< D > & system()
Get parent system by reference.
void readRamp(std::istream &in, bool &isEnd)
Optionally read an associated ramp.
void clearData()
Clear field eigen-components and hamiltonian components.
SimState< D > state_
State saved during fts simulation.
long iTotalStep_
Simulation step counter.
void allocate()
Allocate required memory.
void readPerturbation(std::istream &in, bool &isEnd)
Optionally read an associated perturbation.
void readCompressor(std::istream &in, bool &isEnd)
Read the compressor block of the parameter file.
Ramp< D > const & ramp() const
Get the associated Ramp by const reference.
bool hasRamp() const
Does this Simulator have a Ramp?
Simulator(System< D > &system)
Constructor.
Compressor< D > & compressor()
Get the compressor by non-const reference.
bool hasCompressor() const
Does this Simulator have a Compressor object?
long iStep_
Simulation step counter.
Main class, representing one complete system.
Factory for subclasses of TrajectoryReader.
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.
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.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.