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_;
84 = bdStepFactoryPtr_->readObjectOptional(in, *
this,
111 state_.needsHamiltonian =
false;
129 void BdSimulator<D>::setup(
int nStep)
136 if (hasPerturbation()) {
137 perturbation().setup();
148 if (hasCompressor()) {
149 compressor().compress();
150 compressor().clearTimers();
157 computeHamiltonian();
163 if (analyzerManager_.size() > 0){
164 analyzerManager_.setup();
192 analyzerTimer.
start();
193 analyzerManager_.sample(
iStep_);
194 analyzerTimer.
stop();
210 analyzerTimer.
start();
213 if (analyzerManager_.size() > 0) {
214 analyzerManager_.sample(
iStep_);
218 analyzerTimer.
stop();
227 double time = timer.
time();
228 double analyzerTime = analyzerTimer.
time();
232 analyzerManager_.output();
243 Log::file() <<
"nStep " << nStep << std::endl;
249 <<
" sec" << std::endl;
250 double rStep = double(nStep);
251 Log::file() <<
"time / nStep " << time / rStep
252 <<
" sec" << std::endl;
253 Log::file() <<
"Analyzer run time " << analyzerTime
254 <<
" sec" << std::endl;
269 std::string classname,
270 std::string filename)
281 if (!trajectoryReaderPtr) {
283 message =
"Invalid TrajectoryReader class name " + classname;
288 trajectoryReaderPtr->
open(filename);
289 trajectoryReaderPtr->readHeader();
295 hasFrame = trajectoryReaderPtr->
readFrame();
308 analyzerManager_.sample(
iStep_);
312 hasFrame = trajectoryReaderPtr->
readFrame();
315 Log::file() <<
"end main loop" << std::endl;
316 int nFrames =
iStep_ - min;
317 trajectoryReaderPtr->
close();
318 delete trajectoryReaderPtr;
321 analyzerManager_.output();
325 Log::file() <<
"# of frames " << nFrames << std::endl;
327 <<
" sec" << std::endl;
328 Log::file() <<
"time / frame " << timer.
time()/double(nFrames)
329 <<
" 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 a Ramp parameter file block.
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 a Perturbation parameter file block.
void readCompressor(std::istream &in, bool &isEnd)
Optionally read a Compressor parameter file block.
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 a complete physical 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.