CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigEnumRandomOccupations.cc
Go to the documentation of this file.
2 
3 #include "casm/clex/Supercell.hh"
5 
6 namespace CASM {
7 
9  MTRand &_mtrand, Index _n_config)
10  : mtrand(_mtrand), n_config(_n_config) {}
11 
13  ConfigEnumInput const &_in_config,
15  : ConfigEnumRandomOccupations(_in_config, params.n_config, params.mtrand) {}
16 
18  ConfigEnumInput const &_in_config, Index _n_config, MTRand &_mtrand)
19  : m_n_config(_n_config),
20  m_mtrand(_mtrand),
21  m_max_allowed(
22  _in_config.configuration().supercell().max_allowed_occupation()),
23  m_site_selection(_in_config.sites().begin(), _in_config.sites().end()) {
24  if (m_n_config < 0) {
25  throw std::runtime_error(
26  "Error in ConfigEnumRandomOccupations: n_config < 0");
27  }
28  if (m_n_config == 0) {
29  this->_invalidate();
30  return;
31  }
32 
33  m_current = notstd::make_cloneable<Configuration>(_in_config.configuration());
34 
36  this->_initialize(&(*m_current));
37 
38  // Make initial random config
39  this->randomize();
40  _set_step(0);
41  m_current->set_source(this->source(step()));
42 }
43 
44 std::string ConfigEnumRandomOccupations::name() const {
45  return enumerator_name;
46 }
47 
49  "ConfigEnumRandomOccupations";
50 
54  this->_increment_step();
55  if (step() < m_n_config) {
56  this->randomize();
57  m_current->set_source(this->source(step()));
58  } else {
59  this->_invalidate();
60  }
61 }
62 
64  for (Index l : m_site_selection) {
65  m_current->set_occ(l, m_mtrand.randInt(m_max_allowed[l]));
66  }
67 }
68 
69 } // namespace CASM
Enumerate n random occupations in a particular Supercell.
void increment() override
Implements increment.
ConfigEnumRandomOccupations(ConfigEnumInput const &_in_config, ConfigEnumRandomOccupationsParams const &params)
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
notstd::cloneable_ptr< Configuration > m_current
virtual jsonParser source(step_type step) const
Definition: Enumerator.hh:129
void _invalidate()
Call if enumeration complete.
Definition: Enumerator.hh:159
void _increment_step()
Increment current step value.
Definition: Enumerator.hh:153
step_type step() const
Increments with each enumerated object.
Definition: Enumerator.hh:115
void _set_step(step_type val)
Set current step value.
Definition: Enumerator.hh:150
Configuration const & configuration() const
Main CASM namespace.
Definition: APICommand.hh:8
void reset_properties(ConfigType &config)
Definition: Calculable.cc:147
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Parameters controlling ConfigEnumRandomOccupations.
ConfigEnumRandomOccupationsParams(MTRand &_mtrand, Index _n_config)