CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::Monte::MonteCarlo Class Reference

#include <MonteCarlo.hh>

+ Inheritance diagram for CASM::Monte::MonteCarlo:

Detailed Description

Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically)

MonteCarlo serves as a base for all types of Monte Carlo simulations (e.g. GrandCanonical). The base class holds all the data structures to be sampled for every type of derived Monte Carlo class. The derived class is responsible for adding data and using it to perform a calculation.

Definition at line 44 of file MonteCarlo.hh.

Public Types

typedef Monte::size_type size_type
 
typedef std::map< std::string, double > ScalarPropertyMap
 a map of keyname to property value More...
 
typedef std::map< std::string, Eigen::VectorXd > VectorPropertyMap
 a map of keyname to property value Eigen::VectorXd More...
 
typedef std::map< std::string, notstd::cloneable_ptr< MonteSampler >, SamplerNameCompareSamplerMap
 a map of keyname to MonteSampler More...
 
typedef std::vector< std::pair< size_type, size_type > > SampleTimes
 a vector of std::pair(pass, step) indicating when samples were taken More...
 

Public Member Functions

const MonteSettingssettings () const
 const Access settings used for construction More...
 
const PrimClexprimclex () const
 const Access the PrimClex that *this is based on More...
 
const Supercellsupercell () const
 const Access the Supercell that *this is based on More...
 
void set_nlist ()
 Set a pointer to the SuperNeighborList once it is ready. More...
 
const SuperNeighborListnlist () const
 const Access the SuperNeighborList via pointer stored by 'set_nlist' More...
 
const Configurationconfig () const
 const Access current microstate More...
 
const ConfigDoFconfigdof () const
 const Access current microstate More...
 
void reset (const ConfigDoF &dof)
 Set current microstate and clear samplers. More...
 
const ScalarPropertyMapscalar_properties () const
 const Access scalar properties map More...
 
const double & scalar_property (std::string property_name) const
 const Access a particular scalar property More...
 
const VectorPropertyMapvector_properties () const
 const Access vector properties map More...
 
const Eigen::VectorXd & vector_property (std::string property_name) const
 const Access a particular vector property More...
 
void sample_data (const MonteCounter &counter)
 Samples all requested property data, and stores pass and step number sample was taken at. More...
 
void clear_samples ()
 Clear all data from all samplers. More...
 
bool must_converge () const
 Return true if convergence is requested. More...
 
std::pair< bool, size_typeis_equilibrated () const
 Returns pair(true, equil_samples) if required equilibration has occured for all samplers that must converge. More...
 
bool check_convergence_time () const
 Returns true if a convergence check is due. More...
 
bool is_converged () const
 Check to see if all the properties required to converge have converged. More...
 
const SamplerMapsamplers () const
 const Access sampler map More...
 
const SampleTimessample_times () const
 const Access a vector of std::pair<pass, step> indicating when samples were taken More...
 
const std::vector< ConfigDoF > & trajectory () const
 const Access snapshots of the Monte Carlo calculation More...
 
bool debug () const
 return true if running in debug mode More...
 

Protected Member Functions

template<typename MonteTypeSettings >
 MonteCarlo (const PrimClex &primclex, const MonteTypeSettings &settings, Log &_log)
 Construct with a starting ConfigDoF as specified the given MonteSettings and prepare data samplers. More...
 
const PrimClex_primclex () const
 Access the PrimClex that *this is based on. More...
 
const Supercell_supercell () const
 Access the Supercell that *this is based on. More...
 
Configuration_config () const
 Access current microstate. More...
 
ConfigDoF_configdof () const
 Access current microstate. More...
 
Log_log () const
 
MTRand & _mtrand ()
 
ScalarPropertyMap_scalar_properties ()
 Access scalar properties map. More...
 
double & _scalar_property (std::string property_name)
 Access a particular scalar property. More...
 
VectorPropertyMap_vector_properties ()
 const Access vector properties map More...
 
Eigen::VectorXd & _vector_property (std::string property_name)
 const Access a particular vector property More...
 

Private Member Functions

void _set_check_convergence_time () const
 Set the next time convergence is due to be checked. More...
 

Private Attributes

ScalarPropertyMap m_scalar_property
 a map of keyname to property value More...
 
VectorPropertyMap m_vector_property
 a map of keyname to property value Eigen::VectorXd More...
 
const MonteSettingsm_settings
 Contains all input settings. More...
 
const PrimClexm_primclex
 PrimClex for this system. More...
 
Supercell m_scel
 Supercell for the calculation. More...
 
const SuperNeighborListm_nlist
 Pointer to SuperNeighborList. More...
 
Configuration m_config
 Stores all degrees of freedom of the current microstate. More...
 
ConfigDoFm_configdof
 
MTRand m_twister
 Random number generator. More...
 
bool m_write_trajectory = false
 Save trajectory? More...
 
std::vector< ConfigDoFm_trajectory
 Snapshots of the Monte Carlo simulation, taken by sample_data() if m_write_trajectory is true. More...
 
bool m_must_converge
 True if any MonteSampler must converge. More...
 
Logm_log
 Target for messages. More...
 
SamplerMap m_sampler
 a map of pair<keyname, index> to MonteSampler More...
 
SampleTimes m_sample_time
 a vector of std::pair(pass, step) indicating when samples were taken More...
 
std::pair< bool, size_typem_is_equil
 
bool m_is_equil_uptodate = false
 
bool m_is_converged
 
bool m_is_converged_uptodate = false
 
size_type m_next_convergence_check = 100
 
size_type m_convergence_check_period = 100
 
bool m_debug
 

Member Typedef Documentation

◆ SamplerMap

a map of keyname to MonteSampler

  • scalar example: m_sampler["formation_energy"]
  • vector example: m_sampler["corr(12)"]

Definition at line 65 of file MonteCarlo.hh.

◆ SampleTimes

typedef std::vector<std::pair<size_type, size_type> > CASM::Monte::MonteCarlo::SampleTimes

a vector of std::pair(pass, step) indicating when samples were taken

Definition at line 69 of file MonteCarlo.hh.

◆ ScalarPropertyMap

typedef std::map<std::string, double> CASM::Monte::MonteCarlo::ScalarPropertyMap

a map of keyname to property value

  • example: m_scalar_property["formation_energy"]

Definition at line 51 of file MonteCarlo.hh.

◆ size_type

◆ VectorPropertyMap

typedef std::map<std::string, Eigen::VectorXd> CASM::Monte::MonteCarlo::VectorPropertyMap

a map of keyname to property value Eigen::VectorXd

  • example: m_vector_property["corr"]

Definition at line 56 of file MonteCarlo.hh.

Constructor & Destructor Documentation

◆ MonteCarlo()

template<typename MonteTypeSettings >
template CASM::Monte::MonteCarlo::MonteCarlo ( const PrimClex primclex,
const MonteTypeSettings &  settings,
Log _log 
)
protected

Construct with a starting ConfigDoF as specified the given MonteSettings and prepare data samplers.

Construct with a starting ConfigDoF as specified the given Settings and prepare data samplers.

Definition at line 21 of file MonteCarlo_impl.hh.

Member Function Documentation

◆ _config()

Configuration& CASM::Monte::MonteCarlo::_config ( ) const
inlineprotected

Access current microstate.

  • This can be used by a const member if it undoes any changes to the ConfigDoF before returning

Definition at line 181 of file MonteCarlo.hh.

◆ _configdof()

ConfigDoF& CASM::Monte::MonteCarlo::_configdof ( ) const
inlineprotected

Access current microstate.

  • This can be used by a const member if it undoes any changes to the ConfigDoF before returning

Definition at line 187 of file MonteCarlo.hh.

◆ _log()

Log& CASM::Monte::MonteCarlo::_log ( ) const
inlineprotected

Definition at line 189 of file MonteCarlo.hh.

◆ _mtrand()

MTRand& CASM::Monte::MonteCarlo::_mtrand ( )
inlineprotected

Definition at line 191 of file MonteCarlo.hh.

◆ _primclex()

const PrimClex& CASM::Monte::MonteCarlo::_primclex ( ) const
inlineprotected

Access the PrimClex that *this is based on.

Definition at line 172 of file MonteCarlo.hh.

◆ _scalar_properties()

ScalarPropertyMap& CASM::Monte::MonteCarlo::_scalar_properties ( )
inlineprotected

Access scalar properties map.

Definition at line 194 of file MonteCarlo.hh.

◆ _scalar_property()

double& CASM::Monte::MonteCarlo::_scalar_property ( std::string  property_name)
inlineprotected

Access a particular scalar property.

Definition at line 197 of file MonteCarlo.hh.

◆ _set_check_convergence_time()

void CASM::Monte::MonteCarlo::_set_check_convergence_time ( ) const
private

Set the next time convergence is due to be checked.

Currently set to 10 samples from the time this function is called

Definition at line 200 of file MonteCarlo.cc.

◆ _supercell()

const Supercell& CASM::Monte::MonteCarlo::_supercell ( ) const
inlineprotected

Access the Supercell that *this is based on.

Definition at line 175 of file MonteCarlo.hh.

◆ _vector_properties()

VectorPropertyMap& CASM::Monte::MonteCarlo::_vector_properties ( )
inlineprotected

const Access vector properties map

Definition at line 202 of file MonteCarlo.hh.

◆ _vector_property()

Eigen::VectorXd& CASM::Monte::MonteCarlo::_vector_property ( std::string  property_name)
inlineprotected

const Access a particular vector property

Definition at line 205 of file MonteCarlo.hh.

◆ check_convergence_time()

bool CASM::Monte::MonteCarlo::check_convergence_time ( ) const

Returns true if a convergence check is due.

Currently set to every 10 samples

Definition at line 190 of file MonteCarlo.cc.

◆ clear_samples()

void CASM::Monte::MonteCarlo::clear_samples ( )

Clear all data from all samplers.

Definition at line 50 of file MonteCarlo.cc.

◆ config()

const Configuration& CASM::Monte::MonteCarlo::config ( ) const
inline

const Access current microstate

Definition at line 90 of file MonteCarlo.hh.

◆ configdof()

const ConfigDoF& CASM::Monte::MonteCarlo::configdof ( ) const
inline

const Access current microstate

Definition at line 93 of file MonteCarlo.hh.

◆ debug()

bool CASM::Monte::MonteCarlo::debug ( ) const
inline

return true if running in debug mode

Definition at line 162 of file MonteCarlo.hh.

◆ is_converged()

bool CASM::Monte::MonteCarlo::is_converged ( ) const

Check to see if all the properties required to converge have converged.

  • Calls is_equilibrated() to check if required equilibration has occured
  • If equilibrated, checks if the required convergence has occured for all sampler that must converge
  • Convergence is checked only for the range of observations that were taken after all samplers that must converge have equilibrated

Definition at line 126 of file MonteCarlo.cc.

◆ is_equilibrated()

std::pair< bool, Monte::size_type > CASM::Monte::MonteCarlo::is_equilibrated ( ) const

Returns pair(true, equil_samples) if required equilibration has occured for all samplers that must converge.

  • equil_samples is the number of samples required for all samplers that must equilibrate to equilibrate
  • If must_converge() == false, always returns false

Definition at line 69 of file MonteCarlo.cc.

◆ must_converge()

bool CASM::Monte::MonteCarlo::must_converge ( ) const
inline

Return true if convergence is requested.

Definition at line 135 of file MonteCarlo.hh.

◆ nlist()

const SuperNeighborList& CASM::Monte::MonteCarlo::nlist ( ) const
inline

const Access the SuperNeighborList via pointer stored by 'set_nlist'

Definition at line 87 of file MonteCarlo.hh.

◆ primclex()

const PrimClex& CASM::Monte::MonteCarlo::primclex ( ) const
inline

const Access the PrimClex that *this is based on

Definition at line 77 of file MonteCarlo.hh.

◆ reset()

void CASM::Monte::MonteCarlo::reset ( const ConfigDoF dof)
inline

Set current microstate and clear samplers.

Definition at line 98 of file MonteCarlo.hh.

◆ sample_data()

void CASM::Monte::MonteCarlo::sample_data ( const MonteCounter counter)

Samples all requested property data, and stores pass and step number sample was taken at.

Definition at line 34 of file MonteCarlo.cc.

◆ sample_times()

const SampleTimes& CASM::Monte::MonteCarlo::sample_times ( ) const
inline

const Access a vector of std::pair<pass, step> indicating when samples were taken

Definition at line 153 of file MonteCarlo.hh.

◆ samplers()

const SamplerMap& CASM::Monte::MonteCarlo::samplers ( ) const
inline

const Access sampler map

Definition at line 149 of file MonteCarlo.hh.

◆ scalar_properties()

const ScalarPropertyMap& CASM::Monte::MonteCarlo::scalar_properties ( ) const
inline

const Access scalar properties map

Definition at line 106 of file MonteCarlo.hh.

◆ scalar_property()

const double& CASM::Monte::MonteCarlo::scalar_property ( std::string  property_name) const
inline

const Access a particular scalar property

Definition at line 111 of file MonteCarlo.hh.

◆ set_nlist()

void CASM::Monte::MonteCarlo::set_nlist ( )
inline

Set a pointer to the SuperNeighborList once it is ready.

Definition at line 83 of file MonteCarlo.hh.

◆ settings()

const MonteSettings& CASM::Monte::MonteCarlo::settings ( ) const
inline

const Access settings used for construction

Definition at line 74 of file MonteCarlo.hh.

◆ supercell()

const Supercell& CASM::Monte::MonteCarlo::supercell ( ) const
inline

const Access the Supercell that *this is based on

Definition at line 80 of file MonteCarlo.hh.

◆ trajectory()

const std::vector<ConfigDoF>& CASM::Monte::MonteCarlo::trajectory ( ) const
inline

const Access snapshots of the Monte Carlo calculation

If requested, snapshots are taken at the same time as samples. So examine sample_times for pass and step information.

Definition at line 159 of file MonteCarlo.hh.

◆ vector_properties()

const VectorPropertyMap& CASM::Monte::MonteCarlo::vector_properties ( ) const
inline

const Access vector properties map

Definition at line 116 of file MonteCarlo.hh.

◆ vector_property()

const Eigen::VectorXd& CASM::Monte::MonteCarlo::vector_property ( std::string  property_name) const
inline

const Access a particular vector property

Definition at line 121 of file MonteCarlo.hh.

Member Data Documentation

◆ m_config

Configuration CASM::Monte::MonteCarlo::m_config
mutableprivate

Stores all degrees of freedom of the current microstate.

'mutable' is used for case where the DoF are modified to calculate event property values and then reverted within a const function

Definition at line 236 of file MonteCarlo.hh.

◆ m_configdof

ConfigDoF& CASM::Monte::MonteCarlo::m_configdof
private

Reference to m_config.configdof(), to avoid invalidating id every time used

Definition at line 240 of file MonteCarlo.hh.

◆ m_convergence_check_period

size_type CASM::Monte::MonteCarlo::m_convergence_check_period = 100
private

Definition at line 281 of file MonteCarlo.hh.

◆ m_debug

bool CASM::Monte::MonteCarlo::m_debug
private

Definition at line 284 of file MonteCarlo.hh.

◆ m_is_converged

bool CASM::Monte::MonteCarlo::m_is_converged
mutableprivate

Definition at line 276 of file MonteCarlo.hh.

◆ m_is_converged_uptodate

bool CASM::Monte::MonteCarlo::m_is_converged_uptodate = false
mutableprivate

Definition at line 277 of file MonteCarlo.hh.

◆ m_is_equil

std::pair<bool, size_type> CASM::Monte::MonteCarlo::m_is_equil
mutableprivate

Definition at line 274 of file MonteCarlo.hh.

◆ m_is_equil_uptodate

bool CASM::Monte::MonteCarlo::m_is_equil_uptodate = false
mutableprivate

Definition at line 275 of file MonteCarlo.hh.

◆ m_log

Log& CASM::Monte::MonteCarlo::m_log
private

Target for messages.

Definition at line 256 of file MonteCarlo.hh.

◆ m_must_converge

bool CASM::Monte::MonteCarlo::m_must_converge
private

True if any MonteSampler must converge.

Definition at line 253 of file MonteCarlo.hh.

◆ m_next_convergence_check

size_type CASM::Monte::MonteCarlo::m_next_convergence_check = 100
mutableprivate

Definition at line 280 of file MonteCarlo.hh.

◆ m_nlist

const SuperNeighborList* CASM::Monte::MonteCarlo::m_nlist
private

Pointer to SuperNeighborList.

Definition at line 230 of file MonteCarlo.hh.

◆ m_primclex

const PrimClex& CASM::Monte::MonteCarlo::m_primclex
private

PrimClex for this system.

Definition at line 224 of file MonteCarlo.hh.

◆ m_sample_time

SampleTimes CASM::Monte::MonteCarlo::m_sample_time
private

a vector of std::pair(pass, step) indicating when samples were taken

Definition at line 270 of file MonteCarlo.hh.

◆ m_sampler

SamplerMap CASM::Monte::MonteCarlo::m_sampler
private

a map of pair<keyname, index> to MonteSampler

  • scalar example: m_sampler[std::make_pair("formation_energy", 0)]
  • vector example: m_sampler[std::make_pair("corr", 12)]

Definition at line 266 of file MonteCarlo.hh.

◆ m_scalar_property

ScalarPropertyMap CASM::Monte::MonteCarlo::m_scalar_property
private

a map of keyname to property value

  • example: m_scalar_property["formation_energy"]

Definition at line 213 of file MonteCarlo.hh.

◆ m_scel

Supercell CASM::Monte::MonteCarlo::m_scel
private

Supercell for the calculation.

Definition at line 227 of file MonteCarlo.hh.

◆ m_settings

const MonteSettings& CASM::Monte::MonteCarlo::m_settings
private

Contains all input settings.

Definition at line 221 of file MonteCarlo.hh.

◆ m_trajectory

std::vector<ConfigDoF> CASM::Monte::MonteCarlo::m_trajectory
private

Snapshots of the Monte Carlo simulation, taken by sample_data() if m_write_trajectory is true.

Definition at line 250 of file MonteCarlo.hh.

◆ m_twister

MTRand CASM::Monte::MonteCarlo::m_twister
private

Random number generator.

Definition at line 243 of file MonteCarlo.hh.

◆ m_vector_property

VectorPropertyMap CASM::Monte::MonteCarlo::m_vector_property
private

a map of keyname to property value Eigen::VectorXd

  • example: m_vector_property["corr"]

Definition at line 218 of file MonteCarlo.hh.

◆ m_write_trajectory

bool CASM::Monte::MonteCarlo::m_write_trajectory = false
private

Save trajectory?

Definition at line 246 of file MonteCarlo.hh.


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