PSCF v1.4.0

McMove is an abstract base class for Monte Carlo moves. More...

#include <McMove.h>

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

Public Member Functions

virtual void readParameters (std::istream &in)
 Read required parameters from file.
void setProbability (double probability)
 Set the probability for this McMove.
virtual void setup ()
 Setup before the beginning of each simulation run.
virtual bool move ()
 Generate, attempt, and accept or reject a Monte Carlo move.
virtual bool needsCc ()
 Decide whether cc fields need to be saved for move.
virtual bool needsDc ()
 Decide whether dc fields need to be saved for move.
virtual void outputTimers (std::ostream &out)
 Write timing results to a file.
virtual void clearTimers ()
 Clear timers.
double probability () const
 Return the probability of choosing this McMove.
long nAttempt () const
 Return number of moves that have been attempted.
long nAccept () const
 Return number of moves that have been accepted.
long nFail () const
 Return number of moves that failed to converge.
virtual void output ()
 Output statistics for this move (at the end of simulation)
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.
BeginreadBegin (std::istream &in, const char *label, bool isRequired=true)
 Add and read a class label and opening bracket.
EndreadEnd (std::istream &in)
 Add and read the closing bracket.
BlankreadBlank (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.
BeginaddBegin (const char *label)
 Add a Begin object representing a class name and bracket.
EndaddEnd ()
 Add a closing bracket.
BlankaddBlank ()
 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 ?

Protected Member Functions

 McMove (typename T::McSimulator &simulator)
 Constructor.
 ~McMove ()=default
 Destructor.
void incrementNAttempt ()
 Increment the number of attempted moves.
void incrementNAccept ()
 Increment the number of accepted moves.
void incrementNFail ()
 Increment the number of failed moves.
void outputTimerData (std::ostream &out)
 Write timing data to a file, without a class label.
T::System & system ()
 Get parent System object (non-const ref).
T::System const & system () const
 Get parent System object (const ref)
T::McSimulator & simulator ()
 Get parent McSimulator object (non-const ref).
T::McSimulator const & simulator () const
 Get parent McSimulator object (const ref)
Randomrandom ()
 Get the scalar random number generator.
T::VecRandom & vecRandom ()
 Get the vector random number generator.
void readProbability (std::istream &in)
 Read the probability from file.
virtual void attemptMove ()
 Attempt unconstrained move.
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

Timer attemptMoveTimer_
 Timers for McMove.

Additional Inherited Members

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.

Detailed Description

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

McMove is an abstract base class for Monte Carlo moves.

The virtual move() function must generate a trial move, decide whether to accept or reject it, and update the associated System fields if the move is accepted.

Specializations of this class template are used as base classes for two closely analogous class templates, both also named McMove, that are defined in Rpc and Rpg namespaces and used in the pscf_rpc and pscf_rpg programs, respectively.

Template parameters:

Definition at line 43 of file fts/montecarlo/McMove.h.

Constructor & Destructor Documentation

◆ McMove()

template<int D, class T>
Pscf::Rp::McMove< D, T >::McMove ( typename T::McSimulator & simulator)
protected

Constructor.

Parameters
simulatorparent McSimulator object

Definition at line 25 of file McMove.tpp.

References random(), simulator(), system(), and vecRandom().

◆ ~McMove()

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

Destructor.

Member Function Documentation

◆ readParameters()

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

Read required parameters from file.

Empty default implementation.

Reimplemented from Util::ParamComposite.

Definition at line 40 of file McMove.tpp.

◆ setProbability()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::setProbability ( double probability)
inline

Set the probability for this McMove.

Parameters
probabilityProbability of this move being chosen.

Definition at line 371 of file fts/montecarlo/McMove.h.

References probability().

◆ setup()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::setup ( )
virtual

Setup before the beginning of each simulation run.

This method zeros the statistical accumulators nAttempt, nAccept, and nFail. Derived class re-implementations should call this default version and then complete any other initialization that is required at the beginning of each simulation run within a possible sequence of several such runs.

Definition at line 56 of file McMove.tpp.

References clearTimers(), needsCc(), needsDc(), simulator(), and system().

◆ move()

template<int D, class T>
bool Pscf::Rp::McMove< D, T >::move ( )
virtual

Generate, attempt, and accept or reject a Monte Carlo move.

Implementations of this by subclasses should:

  • Generate a proposed move
  • Decide to accept or reject (using Random::metropolis)
  • Restore the old system state if rejected, or update the system state if accepted.

The default implementation provides a skeleton that calls the virtual attemptMove() function, calls the compressor after attemptMove(), and uses a Metropolis test based on the change of Hamiltonian for acceptance or rejection. MC moves for which this skeleton is appropriate can be implemented by redefining the attemptMove() function and using it in this default implementation of move(). MC moves for which this skeleton is inappropriate or inadequate can be implemented by redefining the move function.

Returns
true if converged, false if failed to converge.

Definition at line 78 of file McMove.tpp.

References attemptMoveTimer_, incrementNAttempt(), and simulator().

◆ needsCc()

template<int D, class T>
virtual bool Pscf::Rp::McMove< D, T >::needsCc ( )
inlinevirtual

Decide whether cc fields need to be saved for move.

The default implementation returns false.

Definition at line 102 of file fts/montecarlo/McMove.h.

Referenced by setup().

◆ needsDc()

template<int D, class T>
virtual bool Pscf::Rp::McMove< D, T >::needsDc ( )
inlinevirtual

Decide whether dc fields need to be saved for move.

The default implementation returns false.

Definition at line 110 of file fts/montecarlo/McMove.h.

Referenced by setup().

◆ outputTimers()

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

Write timing results to a file.

Parameters
outoutput stream

Definition at line 166 of file McMove.tpp.

References Util::ParamComposite::className(), and outputTimerData().

◆ clearTimers()

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

Clear timers.

Definition at line 215 of file McMove.tpp.

References attemptMoveTimer_.

Referenced by setup().

◆ probability()

template<int D, class T>
double Pscf::Rp::McMove< D, T >::probability ( ) const
inline

Return the probability of choosing this McMove.

Definition at line 364 of file fts/montecarlo/McMove.h.

Referenced by setProbability().

◆ nAttempt()

template<int D, class T>
long Pscf::Rp::McMove< D, T >::nAttempt ( ) const
inline

Return number of moves that have been attempted.

Definition at line 278 of file fts/montecarlo/McMove.h.

◆ nAccept()

template<int D, class T>
long Pscf::Rp::McMove< D, T >::nAccept ( ) const
inline

Return number of moves that have been accepted.

Definition at line 285 of file fts/montecarlo/McMove.h.

◆ nFail()

template<int D, class T>
long Pscf::Rp::McMove< D, T >::nFail ( ) const
inline

Return number of moves that failed to converge.

Definition at line 292 of file fts/montecarlo/McMove.h.

◆ output()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::output ( )
virtual

Output statistics for this move (at the end of simulation)

Definition at line 159 of file McMove.tpp.

◆ incrementNAttempt()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::incrementNAttempt ( )
inlineprotected

Increment the number of attempted moves.

Definition at line 301 of file fts/montecarlo/McMove.h.

Referenced by move().

◆ incrementNAccept()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::incrementNAccept ( )
inlineprotected

Increment the number of accepted moves.

Definition at line 308 of file fts/montecarlo/McMove.h.

◆ incrementNFail()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::incrementNFail ( )
inlineprotected

Increment the number of failed moves.

Definition at line 315 of file fts/montecarlo/McMove.h.

◆ outputTimerData()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::outputTimerData ( std::ostream & out)
protected

Write timing data to a file, without a class label.

Parameters
outoutput stream

Definition at line 178 of file McMove.tpp.

Referenced by outputTimers().

◆ system() [1/2]

template<int D, class T>
T::System & Pscf::Rp::McMove< D, T >::system ( )
inlineprotected

Get parent System object (non-const ref).

Definition at line 322 of file fts/montecarlo/McMove.h.

Referenced by McMove(), and setup().

◆ system() [2/2]

template<int D, class T>
T::System const & Pscf::Rp::McMove< D, T >::system ( ) const
inlineprotected

Get parent System object (const ref)

Definition at line 329 of file fts/montecarlo/McMove.h.

◆ simulator() [1/2]

template<int D, class T>
T::McSimulator & Pscf::Rp::McMove< D, T >::simulator ( )
inlineprotected

Get parent McSimulator object (non-const ref).

Definition at line 336 of file fts/montecarlo/McMove.h.

Referenced by McMove(), move(), and setup().

◆ simulator() [2/2]

template<int D, class T>
T::McSimulator const & Pscf::Rp::McMove< D, T >::simulator ( ) const
inlineprotected

Get parent McSimulator object (const ref)

Definition at line 343 of file fts/montecarlo/McMove.h.

◆ random()

template<int D, class T>
Random & Pscf::Rp::McMove< D, T >::random ( )
inlineprotected

Get the scalar random number generator.

Definition at line 350 of file fts/montecarlo/McMove.h.

Referenced by McMove().

◆ vecRandom()

template<int D, class T>
T::VecRandom & Pscf::Rp::McMove< D, T >::vecRandom ( )
inlineprotected

Get the vector random number generator.

Definition at line 357 of file fts/montecarlo/McMove.h.

Referenced by McMove().

◆ readProbability()

template<int D, class T>
void Pscf::Rp::McMove< D, T >::readProbability ( std::istream & in)
protected

Read the probability from file.

Definition at line 47 of file McMove.tpp.

References Util::ParamComposite::read().

◆ attemptMove()

template<int D, class T>
virtual void Pscf::Rp::McMove< D, T >::attemptMove ( )
inlineprotectedvirtual

Attempt unconstrained move.

This function should modify the system w fields in r-grid format, as returned by system().w().rgrid(), in order apply an unconstrained attempted move. The compressor will then be applied in order to restore the density constraint.

The default implementation is empty.

Definition at line 233 of file fts/montecarlo/McMove.h.

Member Data Documentation

◆ attemptMoveTimer_

template<int D, class T>
Timer Pscf::Rp::McMove< D, T >::attemptMoveTimer_
protected

Timers for McMove.

Definition at line 237 of file fts/montecarlo/McMove.h.

Referenced by clearTimers(), and move().


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