CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigEnumAllOccupations.cc
Go to the documentation of this file.
2 
3 #include "casm/clex/Supercell.hh"
5 
6 namespace CASM {
7 
8 namespace local_impl {
9 std::vector<int> max_selected_occupation(
10  ConfigEnumInput const &config_enum_input) {
11  auto const &supercell = config_enum_input.configuration().supercell();
12  Eigen::VectorXi max_allowed = supercell.max_allowed_occupation();
13 
14  std::vector<int> max_allowed_on_selected_sites;
15  for (Index i : config_enum_input.sites()) {
16  max_allowed_on_selected_sites.push_back(max_allowed[i]);
17  }
18 
19  return max_allowed_on_selected_sites;
20 }
21 
22 void set_occupation(Configuration &configuration,
23  std::set<Index> const &site_indices,
24  std::vector<int> const &counter) {
25  Index i = 0;
26  for (Index site_index : site_indices) {
27  configuration.set_occ(site_index, counter[i++]);
28  }
29 }
30 } // namespace local_impl
31 
34 template <>
36  ConfigEnumAllOccupations const &enumerator) {
37  return enumerator.canonical_guarantee();
38 }
39 
42  const ConfigEnumInput &config_enum_input)
43  : m_site_index_selection(config_enum_input.sites()),
44  m_counter(std::vector<int>(config_enum_input.sites().size(), 0),
45  local_impl::max_selected_occupation(config_enum_input),
46  std::vector<int>(config_enum_input.sites().size(), 1)),
48  config_enum_input.configuration())),
49  m_enumerate_on_a_subset_of_supercell_sites(
50  m_site_index_selection.size() !=
51  config_enum_input.configuration().size()) {
54  this->_initialize(&(*m_current));
55 
56  // Make sure that current() is a primitive canonical config
58  increment();
59  }
60 
61  // set step to 0
62  if (valid()) {
63  _set_step(0);
64  }
65  m_current->set_source(this->source(step()));
66 }
67 
68 std::string ConfigEnumAllOccupations::name() const { return enumerator_name; }
69 
77 }
78 
80  "ConfigEnumAllOccupations";
81 
84  bool is_valid_config{false};
85 
86  while (!is_valid_config && ++m_counter) {
88  is_valid_config = _current_is_valid_for_output();
89  }
90 
91  // if while loop exited with valid configuration, increment step number
92  if (m_counter.valid()) {
93  this->_increment_step();
94  }
95  // if while loop exited because counter hit end, invalidate this enumerator
96  else {
97  this->_invalidate();
98  }
99  m_current->set_source(this->source(step()));
100 }
101 
105  return current().is_primitive();
106  } else {
107  return current().is_primitive() && current().is_canonical();
108  }
109 }
110 
111 } // namespace CASM
bool valid() const
Definition: BaseCounter.hh:160
void increment() override
Implements increment.
bool _current_is_valid_for_output() const
Returns true if current() is primitive and canonical.
static const std::string enumerator_name
bool m_enumerate_on_a_subset_of_supercell_sites
True if enumerating on a subset of supercell sites.
std::set< Index > m_site_index_selection
Site index to enumerate on.
notstd::cloneable_ptr< Configuration > m_current
The current configuration.
ConfigEnumAllOccupations(ConfigEnumInput const &config_enum_input)
Construct with a Supercell, using all permutations.
Counter< std::vector< int > > m_counter
Counter over allowed occupation indices on sites in m_site_index_selection.
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
const Supercell & supercell() const
Get the Supercell for this Configuration.
void set_occ(Index site_l, int val)
Set occupant variable on site l.
Eigen::VectorXi max_allowed_occupation() const
returns maximum allowed occupation bitstring – used for initializing enumeration counters
Definition: Supercell.cc:213
bool valid() const
Returns false if enumeration is complete.
Definition: Enumerator.hh:118
virtual jsonParser source(step_type step) const
Definition: Enumerator.hh:129
reference current() const
Access the current ObjectType by reference.
Definition: Enumerator.hh:211
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
bool is_guaranteed_for_database_insert(ConfigEnumAllOccupations const &enumerator)
std::set< Index > const & sites() const
Configuration const & configuration() const
void set_occupation(Configuration &configuration, std::set< Index > const &site_indices, std::vector< int > const &counter)
std::vector< int > max_selected_occupation(ConfigEnumInput const &config_enum_input)
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
Non-std smart pointer classes and functions.
cloneable_ptr< T > make_cloneable(Args &&... args)
make a cloneable_ptr<T> via T(Args... args)
Definition: stream_io.hh:24