PSCF v1.5.0
Pscf::Rp::McSimulator< D, T > Class Template Reference

Monte-Carlo simulation coordinator. More...

#include <McSimulator.h>

Inheritance diagram for Pscf::Rp::McSimulator< D, T >:
Pscf::Rp::Simulator< D, T > Util::ParamComposite Util::ParamComponent Util::Serializable Util::MpiFileIo

Public Member Functions

Construction, destruction and initialization
 McSimulator (System< D, T > &system)
 Constructor.
 ~McSimulator ()
 Destructor.
virtual void readParameters (std::istream &in)
 Read parameter file block.
Primary Actions: Simulation and Analysis
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.
virtual void outputTimers (std::ostream &out) const
 Output timing results.
virtual void clearTimers ()
 Clear timers.
Miscellaneous
McMoveManager< D, T > const & mcMoveManager () const
 Get the McMoveManager (const).
McMoveManager< D, T > & mcMoveManager ()
 Get the McMoveManager (non-const).
AnalyzerManager< D, T > const & analyzerManager () const
 Get the AnalyzerManager (const).
AnalyzerManager< D, T > & analyzerManager ()
 Get the AnalyzerManager (non-const).
Factory< TrajectoryReader< D, T > > & trajectoryReaderFactory ()
 Get the trajectory reader factory by reference.
bool hasMcMoves () const
 Have any MC moves been defined?
bool needsCc ()
 Does the stored state need to include Cc fields?
bool needsDc ()
 Does the stored state need to include Dc fields?
Public Member Functions inherited from Pscf::Rp::Simulator< D, T >
 Simulator (System< D, T > &system)
 Constructor.
 ~Simulator ()
 Destructor.
void allocate ()
 Allocate required memory during initialization.
void clearData ()
 Clear field eigen-components and Hamiltonian components.
void analyzeChi ()
 Perform eigenvalue analysis of projected chi matrix.
DArray< double > const & chiEvals () const
 Get an array of the eigenvalues of the projected chi matrix.
double chiEval (int a) const
 Get a single eigenvalue of the projected chi matrix.
DMatrix< double > const & chiEvecs () const
 Get the matrix of all eigenvectors of the projected chi matrix.
double chiEvecs (int a, int i) const
 Get one element of an eigenvector of the projected chi matrix.
DArray< double > const & sc () const
 Get all components of the vector S.
double sc (int a) const
 Get a single component of the S vector.
void computeHamiltonian ()
 Compute the Hamiltonian used in PS-FTS.
double hamiltonian () const
 Get the Hamiltonian used in PS-FTS.
double idealHamiltonian () const
 Get an ideal contribution to the Hamiltonian.
double fieldHamiltonian () const
 Get the quadratic field contribution to the Hamiltonian.
double perturbationHamiltonian () const
 Get a perturbation to the standard Hamiltonian.
bool hasHamiltonian () const
 Has the Hamiltonian been computed for the current w and c fields?
void computeWc ()
 Compute eigenvector components of the current w fields.
DArray< RField< D, T > > const & wc () const
 Get all eigenvector components of the current w fields.
RField< D, T > const & wc (int a) const
 Get one eigenvector component of the current w fields.
bool hasWc () const
 Are eigen-components of the current w fields valid ?
void computeCc ()
 Compute eigenvector components of the current c fields.
DArray< RField< D, T > > const & cc () const
 Get all eigenvector components of the current c fields.
RField< D, T > const & cc (int a) const
 Get one eigenvector component of the current c fields.
bool hasCc () const
 Are eigen-components of the current c fields valid ?
void computeDc ()
 Compute functional derivatives of the Hamiltonian.
DArray< RField< D, T > > const & dc () const
 Get all of the current d fields.
RField< D, T > const & dc (int i) const
 Get one eigenvector component of the current d fields.
bool hasDc () const
 Are the current d fields valid ?
void saveState ()
 Save a copy of the current system state.
void restoreState ()
 Restore the system to the saved state.
void clearState ()
 Clear the saved copy of the system state.
virtual void outputMdeCounter (std::ostream &out) const
 Output MDE counter.
long iStep ()
 Return the current converged simulation step index.
long iTotalStep ()
 Return the current simulation step index.
System< D, T > & system ()
 Get the parent system by reference.
Random & random ()
 Get the scalar random number generator by reference.
VecRandom< T > & vecRandom ()
 Get the vector random number generator by reference.
bool hasCompressor () const
 Does this Simulator have a Compressor?
Compressor< D, T > const & compressor () const
 Get the Compressor by const reference.
Compressor< D, T > & compressor ()
 Get the Compressor by non-const reference.
bool hasPerturbation () const
 Does this Simulator have a Perturbation?
Perturbation< D, T > const & perturbation () const
 Get a Perturbation by const reference.
Perturbation< D, T > & perturbation ()
 Get a Perturbation by non-const reference.
bool hasRamp () const
 Does this Simulator have a Ramp?
Ramp< D, T > const & ramp () const
 Get a Ramp by const reference.
Ramp< D, T > & ramp ()
 Get a Ramp by non-const reference.
Public Member Functions inherited from Util::ParamComposite
 ParamComposite ()
 Constructor.
 ParamComposite (const ParamComposite &other)
 Copy constructor.
 ParamComposite (int capacity)
 Constructor.
virtual ~ParamComposite ()
 Virtual destructor.
void resetParam ()
 Resets ParamComposite to its empty state.
virtual void readParam (std::istream &in)
 Read the parameter file block.
virtual void readParamOptional (std::istream &in)
 Read optional parameter file block.
virtual void writeParam (std::ostream &out) const
 Write all parameters to an output stream.
virtual void load (Serializable::IArchive &ar)
 Load all parameters from an input archive.
virtual void loadOptional (Serializable::IArchive &ar)
 Load an optional ParamComposite.
virtual void loadParameters (Serializable::IArchive &ar)
 Load state from archive, without adding Begin and End lines.
virtual void save (Serializable::OArchive &ar)
 Saves all parameters to an archive.
void saveOptional (Serializable::OArchive &ar)
 Saves isActive flag, and then calls save() iff isActive is true.
void readParamComposite (std::istream &in, ParamComposite &child, bool next=true)
 Add and read a required child ParamComposite.
void readParamCompositeOptional (std::istream &in, ParamComposite &child, bool next=true)
 Add and attempt to read an optional child ParamComposite.
template<typename Type>
ScalarParam< Type > & read (std::istream &in, const char *label, Type &value)
 Add and read a new required ScalarParam < Type > object.
template<typename Type>
ScalarParam< Type > & readOptional (std::istream &in, const char *label, Type &value)
 Add and read a new optional ScalarParam < Type > object.
template<typename Type>
CArrayParam< Type > & readCArray (std::istream &in, const char *label, Type *value, int n)
 Add and read a required C array parameter.
template<typename Type>
CArrayParam< Type > & readOptionalCArray (std::istream &in, const char *label, Type *value, int n)
 Add and read an optional C array parameter.
template<typename Type>
DArrayParam< Type > & readDArray (std::istream &in, const char *label, DArray< Type > &array, int n)
 Add and read a required DArray < Type > parameter.
template<typename Type>
DArrayParam< Type > & readOptionalDArray (std::istream &in, const char *label, DArray< Type > &array, int n)
 Add and read an optional DArray < Type > parameter.
template<typename Type, int N>
FArrayParam< Type, N > & readFArray (std::istream &in, const char *label, FArray< Type, N > &array)
 Add and read a required FArray < Type, N > array parameter.
template<typename Type, int N>
FArrayParam< Type, N > & readOptionalFArray (std::istream &in, const char *label, FArray< Type, N > &array)
 Add and read an optional FArray < Type, N > array parameter.
template<typename Type, int N>
FSArrayParam< Type, N > & readFSArray (std::istream &in, const char *label, FSArray< Type, N > &array, int size)
 Add and read a required FSArray < Type, N > array parameter.
template<typename Type, int N>
FSArrayParam< Type, N > & readOptionalFSArray (std::istream &in, const char *label, FSArray< Type, N > &array, int size)
 Add and read an optional FSArray < Type, N > array parameter.
template<typename Type>
CArray2DParam< Type > & readCArray2D (std::istream &in, const char *label, Type *value, int m, int n, int np)
 Add and read a required CArray2DParam < Type > 2D C-array.
template<typename Type>
CArray2DParam< Type > & readOptionalCArray2D (std::istream &in, const char *label, Type *value, int m, int n, int np)
 Add and read an optional CArray2DParam < Type > 2D C-array parameter.
template<typename Type>
DMatrixParam< Type > & readDMatrix (std::istream &in, const char *label, DMatrix< Type > &matrix, int m, int n)
 Add and read a required DMatrix < Type > matrix parameter.
template<typename Type>
DMatrixParam< Type > & readOptionalDMatrix (std::istream &in, const char *label, DMatrix< Type > &matrix, int m, int n)
 Add and read an optional DMatrix < Type > matrix parameter.
template<typename Type>
DSymmMatrixParam< Type > & readDSymmMatrix (std::istream &in, const char *label, DMatrix< Type > &matrix, int n)
 Add and read a required symmetrix DMatrix.
template<typename Type>
DSymmMatrixParam< Type > & readOptionalDSymmMatrix (std::istream &in, const char *label, DMatrix< Type > &matrix, int n)
 Add and read an optional DMatrix matrix parameter.
Begin & readBegin (std::istream &in, const char *label, bool isRequired=true)
 Add and read a class label and opening bracket.
End & readEnd (std::istream &in)
 Add and read the closing bracket.
Blank & readBlank (std::istream &in)
 Add and read a new Blank object, representing a blank line.
void loadParamComposite (Serializable::IArchive &ar, ParamComposite &child, bool next=true)
 Add and load a required child ParamComposite.
void loadParamCompositeOptional (Serializable::IArchive &ar, ParamComposite &child, bool next=true)
 Add and load an optional child ParamComposite if isActive.
template<typename Type>
ScalarParam< Type > & loadParameter (Serializable::IArchive &ar, const char *label, Type &value, bool isRequired)
 Add and load a new ScalarParam < Type > object.
template<typename Type>
ScalarParam< Type > & loadParameter (Serializable::IArchive &ar, const char *label, Type &value)
 Add and load new required ScalarParam < Type > object.
template<typename Type>
CArrayParam< Type > & loadCArray (Serializable::IArchive &ar, const char *label, Type *value, int n, bool isRequired)
 Add a C array parameter and load its elements.
template<typename Type>
CArrayParam< Type > & loadCArray (Serializable::IArchive &ar, const char *label, Type *value, int n)
 Add and load a required CArrayParam< Type > array parameter.
template<typename Type>
DArrayParam< Type > & loadDArray (Serializable::IArchive &ar, const char *label, DArray< Type > &array, int n, bool isRequired)
 Add an load a DArray < Type > array parameter.
template<typename Type>
DArrayParam< Type > & loadDArray (Serializable::IArchive &ar, const char *label, DArray< Type > &array, int n)
 Add and load a required DArray< Type > array parameter.
template<typename Type, int N>
FArrayParam< Type, N > & loadFArray (Serializable::IArchive &ar, const char *label, FArray< Type, N > &array, bool isRequired)
 Add and load an FArray < Type, N > fixed-size array parameter.
template<typename Type, int N>
FArrayParam< Type, N > & loadFArray (Serializable::IArchive &ar, const char *label, FArray< Type, N > &array)
 Add and load a required FArray < Type > array parameter.
template<typename Type, int N>
FSArrayParam< Type, N > & loadFSArray (Serializable::IArchive &ar, const char *label, FSArray< Type, N > &array, int size, bool isRequired)
 Add and load an FSArray < Type, N > array parameter.
template<typename Type, int N>
FSArrayParam< Type, N > & loadFSArray (Serializable::IArchive &ar, const char *label, FSArray< Type, N > &array, int size)
 Add and load a required FSArray < Type > array parameter.
template<typename Type>
CArray2DParam< Type > & loadCArray2D (Serializable::IArchive &ar, const char *label, Type *value, int m, int n, int np, bool isRequired)
 Add and load a CArray2DParam < Type > C 2D array parameter.
template<typename Type>
CArray2DParam< Type > & loadCArray2D (Serializable::IArchive &ar, const char *label, Type *value, int m, int n, int np)
 Add and load a required < Type > matrix parameter.
template<typename Type>
DMatrixParam< Type > & loadDMatrix (Serializable::IArchive &ar, const char *label, DMatrix< Type > &matrix, int m, int n, bool isRequired)
 Add and load a DMatrixParam < Type > matrix parameter.
template<typename Type>
DMatrixParam< Type > & loadDMatrix (Serializable::IArchive &ar, const char *label, DMatrix< Type > &matrix, int m, int n)
 Add and load a required DMatrixParam < Type > matrix parameter.
template<typename Type>
DSymmMatrixParam< Type > & loadDSymmMatrix (Serializable::IArchive &ar, const char *label, DMatrix< Type > &matrix, int n, bool isRequired)
 Add and load a symmetric DSymmMatrixParam < Type > matrix parameter.
template<typename Type>
DSymmMatrixParam< Type > & loadDSymmMatrix (Serializable::IArchive &ar, const char *label, DMatrix< Type > &matrix, int n)
 Add and load a required DSymmMatrixParam < Type > matrix parameter.
void addParamComposite (ParamComposite &child, bool next=true)
 Add a child ParamComposite object to the format array.
Begin & addBegin (const char *label)
 Add a Begin object representing a class name and bracket.
End & addEnd ()
 Add a closing bracket.
Blank & addBlank ()
 Create and add a new Blank object, representing a blank line.
std::string className () const
 Get class name string.
bool isRequired () const
 Is this ParamComposite required in the input file?
bool isActive () const
 Is this parameter active?
Public Member Functions inherited from Util::ParamComponent
virtual ~ParamComponent ()
 Destructor.
void setIndent (const ParamComponent &parent, bool next=true)
 Set indent level.
std::string indent () const
 Return indent string for this object (string of spaces).
template<class Archive>
void serialize (Archive &ar, const unsigned int version)
 Serialize this ParamComponent as a string.
Public Member Functions inherited from Util::Serializable
virtual ~Serializable ()
 Destructor.
Public Member Functions inherited from Util::MpiFileIo
 MpiFileIo ()
 Constructor.
 MpiFileIo (const MpiFileIo &other)
 Copy constructor.
bool isIoProcessor () const
 Can this processor do file I/O ?

Additional Inherited Members

Public Types inherited from Pscf::Rp::Simulator< D, T >
using RFieldT = RField<D,T>
 Container for a real-valued periodic field.
Public Types inherited from Util::Serializable
typedef BinaryFileOArchive OArchive
 Type of output archive used by save method.
typedef BinaryFileIArchive IArchive
 Type of input archive used by load method.
Static Public Member Functions inherited from Util::ParamComponent
static void initStatic ()
 Initialize static echo member to false.
static void setEcho (bool echo=true)
 Enable or disable echoing for all subclasses of ParamComponent.
static bool echo ()
 Get echo parameter.
Protected Member Functions inherited from Pscf::Rp::Simulator< D, T >
void readRandomSeed (std::istream &in)
 Optionally read a random seed and initialize RNGs.
CompressorFactory< D, T > & compressorFactory ()
 Get the Compressor factory by reference.
void readCompressor (std::istream &in, bool &isEnd)
 Optionally read a Compressor parameter file block.
PerturbationFactory< D, T > & perturbationFactory ()
 Get the Perturbation factory by reference.
void readPerturbation (std::istream &in, bool &isEnd)
 Optionally read a Perturbation parameter file block.
void setPerturbation (Perturbation< D, T > *ptr)
 Set the associated Perturbation.
RampFactory< D, T > & rampFactory ()
 Get the Ramp factory by reference.
void readRamp (std::istream &in, bool &isEnd)
 Optionally read a Ramp parameter file block.
void setRamp (Ramp< D, T > *ptr)
 Set the associated Ramp.
SimState< D, T > & state ()
 Get the SimState stored internal state by reference.
void setClassName (const char *className)
 Set class name string.
void setIsRequired (bool isRequired)
 Set or unset the isActive flag.
void setIsActive (bool isActive)
 Set or unset the isActive flag.
void setParent (ParamComponent &param, bool next=true)
 Set this to the parent of a child component.
void addComponent (ParamComponent &param, bool isLeaf=true)
 Add a new ParamComponent object to the format array.
template<typename Type>
ScalarParam< Type > & add (std::istream &in, const char *label, Type &value, bool isRequired=true)
 Add a new required ScalarParam < Type > object.
template<typename Type>
CArrayParam< Type > & addCArray (std::istream &in, const char *label, Type *value, int n, bool isRequired=true)
 Add (but do not read) a required C array parameter.
template<typename Type>
DArrayParam< Type > & addDArray (std::istream &in, const char *label, DArray< Type > &array, int n, bool isRequired=true)
 Add (but do not read) a DArray < Type > parameter.
template<typename Type, int N>
FArrayParam< Type, N > & addFArray (std::istream &in, const char *label, FArray< Type, N > &array, bool isRequired=true)
 Add (but do not read) a FArray < Type, N > array parameter.
template<typename Type, int N>
FSArrayParam< Type, N > & addFSArray (std::istream &in, const char *label, FSArray< Type, N > &array, int size, bool isRequired=true)
 Add (but do not read) a FSArray < Type, N > array parameter.
template<typename Type>
CArray2DParam< Type > & addCArray2D (std::istream &in, const char *label, Type *value, int m, int n, int np, bool isRequired=true)
 Add (but do not read) a CArray2DParam < Type > 2D C-array.
template<typename Type>
DMatrixParam< Type > & addDMatrix (std::istream &in, const char *label, DMatrix< Type > &matrix, int m, int n, bool isRequired=true)
 Add and read a required DMatrix < Type > matrix parameter.
Protected Member Functions inherited from Util::ParamComponent
 ParamComponent ()
 Constructor.
 ParamComponent (const ParamComponent &other)
 Copy constructor.
Protected Attributes inherited from Pscf::Rp::Simulator< D, T >
DArray< RField< D, T > > wc_
 Eigenvector components of w fields on a real space grid.
DArray< RField< D, T > > cc_
 Eigenvector components of c fields on a real space grid.
DArray< RField< D, T > > dc_
 Components of d fields on a real space grid.
SimState< D, T > state_
 Previous state saved at the beginning of a step.
double hamiltonian_
 Total field theoretic Hamiltonian H[W] (extensive value).
double idealHamiltonian_
 Ideal gas contribution (-lnQ) to Hamiltonian.
double fieldHamiltonian_
 Quadratic field contribution to Hamiltonian.
double perturbationHamiltonian_
 Perturbation contribution to the Hamiltonian.
long iStep_
 Step counter - number of steps for which the compressor converged.
long iTotalStep_
 Step counter - total number of attempted BD or MC steps.
long seed_
 Random number generator seed (input value).
bool hasHamiltonian_
 Has the Hamiltonian been computed for the current w and c fields?
bool hasWc_
 Have eigen-components of the current w fields been computed ?
bool hasCc_
 Have eigen-components of the current c fields been computed ?
bool hasDc_
 Have functional derivatives of H[W] been computed ?

Detailed Description

template<int D, class T>
class Pscf::Rp::McSimulator< D, T >

Monte-Carlo simulation coordinator.

An McSimulator provides tools that are specific to MC simulation. An McSimulator has an McMoveManager and an AnalyzerManager, in addition to member functions and variables inherited from the Simulator base class.

Template parameters:

  • D : dimension
  • T : backend identifier class (CPT or CUT)
See also
Manual Page

Definition at line 54 of file McSimulator.h.

Constructor & Destructor Documentation

◆ McSimulator()

◆ ~McSimulator()

template<int D, class T>
Pscf::Rp::McSimulator< D, T >::~McSimulator ( )

Destructor.

Definition at line 70 of file McSimulator.tpp.

Member Function Documentation

◆ readParameters()

template<int D, class T>
void Pscf::Rp::McSimulator< D, T >::readParameters ( std::istream & in)
virtual

◆ simulate()

template<int D, class T>
void Pscf::Rp::McSimulator< D, T >::simulate ( int nStep)
virtual

◆ analyze()

template<int D, class T>
void Pscf::Rp::McSimulator< D, T >::analyze ( int min,
int max,
std::string classname,
std::string filename )
virtual

Read and analyze a trajectory file.

This function uses an instance of the TrajectoryReader subclass specified by the "classname" argument to read a trajectory file.

Parameters
minstart at this frame number
maxend at this frame number
classnamename of the TrajectoryReader subclass to use
filenamename of the trajectory file

Reimplemented from Pscf::Rp::Simulator< D, T >.

Definition at line 320 of file McSimulator.tpp.

References analyzerManager(), Pscf::Rp::Analyzer< D, T >::baseInterval, Pscf::Rp::Simulator< D, T >::clearData(), Pscf::Rp::TrajectoryReader< D, T >::close(), Util::Log::file(), Pscf::Rp::Simulator< D, T >::iStep_, Pscf::Rp::TrajectoryReader< D, T >::open(), Pscf::Rp::TrajectoryReader< D, T >::readHeader(), Util::Timer::start(), Util::Timer::stop(), Util::Timer::time(), trajectoryReaderFactory(), UTIL_CHECK, and UTIL_THROW.

◆ outputTimers()

template<int D, class T>
void Pscf::Rp::McSimulator< D, T >::outputTimers ( std::ostream & out) const
virtual

◆ clearTimers()

template<int D, class T>
void Pscf::Rp::McSimulator< D, T >::clearTimers ( )
virtual

Clear timers.

Reimplemented from Pscf::Rp::Simulator< D, T >.

Definition at line 404 of file McSimulator.tpp.

References mcMoveManager().

◆ mcMoveManager() [1/2]

template<int D, class T>
McMoveManager< D, T > const & Pscf::Rp::McSimulator< D, T >::mcMoveManager ( ) const
inline

Get the McMoveManager (const).

Definition at line 228 of file McSimulator.h.

References UTIL_ASSERT.

Referenced by clearTimers(), hasMcMoves(), outputTimers(), readParameters(), and simulate().

◆ mcMoveManager() [2/2]

template<int D, class T>
McMoveManager< D, T > & Pscf::Rp::McSimulator< D, T >::mcMoveManager ( )
inline

Get the McMoveManager (non-const).

Definition at line 236 of file McSimulator.h.

References UTIL_ASSERT.

◆ analyzerManager() [1/2]

template<int D, class T>
AnalyzerManager< D, T > const & Pscf::Rp::McSimulator< D, T >::analyzerManager ( ) const
inline

Get the AnalyzerManager (const).

Definition at line 244 of file McSimulator.h.

References UTIL_ASSERT.

Referenced by analyze(), and simulate().

◆ analyzerManager() [2/2]

template<int D, class T>
AnalyzerManager< D, T > & Pscf::Rp::McSimulator< D, T >::analyzerManager ( )
inline

Get the AnalyzerManager (non-const).

Definition at line 253 of file McSimulator.h.

References UTIL_ASSERT.

◆ trajectoryReaderFactory()

template<int D, class T>
Factory< TrajectoryReader< D, T > > & Pscf::Rp::McSimulator< D, T >::trajectoryReaderFactory ( )
inline

Get the trajectory reader factory by reference.

Definition at line 262 of file McSimulator.h.

References UTIL_ASSERT.

Referenced by analyze().

◆ hasMcMoves()

template<int D, class T>
bool Pscf::Rp::McSimulator< D, T >::hasMcMoves ( ) const
inline

Have any MC moves been defined?

Equivalent to a test for mcMoveManager().size() > 0.

Definition at line 270 of file McSimulator.h.

References mcMoveManager().

Referenced by readParameters(), and simulate().

◆ needsCc()

template<int D, class T>
bool Pscf::Rp::McSimulator< D, T >::needsCc ( )
inline

Does the stored state need to include Cc fields?

This returns if McMove::needsCc returns true for one or more MC moves ih the McMoveManager. Most MC moves require storage of components of the c fields.

Definition at line 275 of file McSimulator.h.

References Pscf::Rp::Simulator< D, T >::state().

◆ needsDc()

template<int D, class T>
bool Pscf::Rp::McSimulator< D, T >::needsDc ( )
inline

Does the stored state need to include Dc fields?

This returns if McMove::needsDc returns true for one or more MC moves in the McMoveManager. Only moves that uses forces to generate a proposed change in the fields, such as a "smart" MC force bias move, will require storage of these fields.

Definition at line 280 of file McSimulator.h.

References Pscf::Rp::Simulator< D, T >::state().


The documentation for this class was generated from the following files: