1#ifndef RP_BD_SIMULATOR_TPP
2#define RP_BD_SIMULATOR_TPP
11#include <rp/fts/brownian/BdSimulator.h>
13#include <rp/fts/brownian/BdStep.h>
14#include <rp/fts/brownian/BdStepFactory.h>
16#include <rp/fts/simulator/Simulator.h>
17#include <rp/fts/analyzer/AnalyzerManager.h>
18#include <rp/fts/analyzer/AnalyzerFactory.h>
19#include <rp/fts/trajectory/TrajectoryReader.h>
20#include <rp/fts/trajectory/TrajectoryReaderFactory.h>
21#include <rp/fts/perturbation/Perturbation.h>
22#include <rp/fts/ramp/Ramp.h>
23#include <rp/fts/compressor/Compressor.h>
24#include <rp/system/System.h>
25#include <rp/solvers/Mixture.h>
26#include <rp/field/Domain.h>
27#include <rp/field/CFields.h>
28#include <rp/field/WFields.h>
30#include <pscf/field/RField.h>
32#include <util/param/Factory.h>
33#include <util/param/ParamComposite.h>
34#include <util/random/Random.h>
35#include <util/misc/Timer.h>
45 template <
int D,
class T>
48 analyzerManagerPtr_(nullptr),
50 bdStepFactoryPtr_(nullptr),
51 trajectoryReaderFactoryPtr_(nullptr)
57 trajectoryReaderFactoryPtr_
65 template <
int D,
class T>
69 if (analyzerManagerPtr_) {
70 delete analyzerManagerPtr_;
72 if (bdStepFactoryPtr_) {
73 delete bdStepFactoryPtr_;
75 if (trajectoryReaderFactoryPtr_) {
76 delete trajectoryReaderFactoryPtr_;
92 template <
int D,
class T>
104 bdStepFactoryPtr_->readObjectOptional(in, *
this,
108 <<
" BdStep{ [absent] }\n";
133 state().needsCc =
false;
134 state().needsDc =
false;
135 state().needsHamiltonian =
false;
138 state().needsCc =
true;
141 state().needsDc =
true;
152 template <
int D,
class T>
153 void BdSimulator<D,T>::setup(
int nStep,
bool isSimulation)
188 if (isSimulation && hasBdStep()) {
192 if (analyzerManager().size() > 0){
193 analyzerManager().setup();
201 template <
int D,
class T>
222 analyzerTimer.
start();
223 if (analyzerBaseInterval != 0) {
228 analyzerTimer.
stop();
235 converged =
bdStep().step();
246 analyzerTimer.
start();
247 if (analyzerBaseInterval != 0) {
249 if (
iStep_ % analyzerBaseInterval == 0) {
254 analyzerTimer.
stop();
258 <<
" failed to converge" <<
"\n";
271 double time = timer.
time();
272 double analyzerTime = analyzerTimer.
time();
275 if (analyzerBaseInterval != 0){
287 Log::file() <<
"nStep " << nStep << std::endl;
293 <<
" sec" << std::endl;
294 double rStep = double(nStep);
295 Log::file() <<
"time / nStep " << time / rStep
296 <<
" sec" << std::endl;
297 Log::file() <<
"Analyzer run time " << analyzerTime
298 <<
" sec" << std::endl;
311 template <
int D,
class T>
314 std::string classname,
315 std::string filename)
326 if (!trajectoryReaderPtr) {
328 message =
"Invalid TrajectoryReader class name " + classname;
333 trajectoryReaderPtr->
open(filename);
342 while (iStep_ <= max && trajectoryReaderPtr->readFrame()) {
359 Log::file() <<
"end main loop" << std::endl;
360 int nFrame =
iStep_ - min;
361 trajectoryReaderPtr->
close();
362 delete trajectoryReaderPtr;
370 Log::file() <<
"# of frames " << nFrame << std::endl;
372 <<
" sec" << std::endl;
373 Log::file() <<
"time / frame " << timer.
time()/double(nFrame)
374 <<
" sec" << std::endl;
382 template <
int D,
class T>
387 return *trajectoryReaderFactoryPtr_;
AnalyzerManager(Simulator< D, T > &simulator, System< D, T > &system)
Constructor.
static void initStatic()
Define and initialize baseInterval (initialized to 1).
static long baseInterval
The interval for every Analyzer must be a multiple of baseInterval.
virtual void readParameters(std::istream &in)
Read parameter file block.
AnalyzerManager< D, T > & analyzerManager()
Get the AnalyzerManager (const).
BdStep< D, T > & bdStep()
Get the BdStep by non-const reference.
~BdSimulator()
Destructor.
virtual void analyze(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
BdSimulator(System< D, T > &system)
Constructor.
bool hasBdStep() const
Does this BdSimulator have a BdStep object?
void simulate(int nStep)
Perform a field theoretic Brownian dynamics (BD) simulation.
Factory< TrajectoryReader< D, T > > & trajectoryReaderFactory()
Get the trajectory reader factory by reference.
BdStepFactory(BdSimulator< D, T > &simulator)
Constructor.
Simulator(System< D, T > &system)
Constructor.
void computeHamiltonian()
Compute the Hamiltonian used in PS-FTS.
void readRamp(std::istream &in, bool &isEnd)
Optionally read a Ramp parameter file block.
void clearData()
Clear field eigen-components and Hamiltonian components.
void readPerturbation(std::istream &in, bool &isEnd)
Optionally read a Perturbation parameter file block.
void computeWc()
Compute eigenvector components of the current w fields.
void readCompressor(std::istream &in, bool &isEnd)
Optionally read a Compressor parameter file block.
void computeCc()
Compute eigenvector components of the current c fields.
System< D, T > & system()
Get the parent system by reference.
void allocate()
Allocate required memory during initialization.
void readRandomSeed(std::istream &in)
Optionally read a random seed and initialize RNGs.
Perturbation< D, T > const & perturbation() const
Get a Perturbation by const reference.
void computeDc()
Compute functional derivatives of the Hamiltonian.
long iTotalStep_
Step counter - total number of attempted BD or MC steps.
bool hasPerturbation() const
Does this Simulator have a Perturbation?
bool hasRamp() const
Does this Simulator have a Ramp?
SimState< D, T > & state()
Get the SimState stored internal state by reference.
bool hasCompressor() const
Does this Simulator have a Compressor?
Compressor< D, T > const & compressor() const
Get the Compressor by const reference.
long iStep_
Step counter - number of steps for which the compressor converged.
void analyzeChi()
Perform eigenvalue analysis of projected chi matrix.
Ramp< D, T > const & ramp() const
Get a Ramp by const reference.
Base class template for classes that represent a complete system.
Factory for subclasses of TrajectoryReader.
Trajectory file reader (abstract base class).
virtual void open(std::string filename)=0
Open trajectory file and allocate memory if necessary.
virtual void readHeader()
Read header of trajectory file (if any).
virtual void close()=0
Close the trajectory file.
static std::ostream & file()
Get log ostream by reference.
std::string indent() const
Return indent string for this object (string of spaces).
static bool echo()
Get echo parameter.
void setClassName(const char *className)
Set class name string.
std::string className() const
Get class name string.
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
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.
#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.
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.