CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SuperConfigEnum.cc
Go to the documentation of this file.
2 
7 #include "casm/clex/PrimClex.hh"
14 
15 namespace CASM {
16 
17 std::string SuperConfigEnum::name() const { return enumerator_name; }
18 
19 const std::string SuperConfigEnum::enumerator_name = "SuperConfigEnum";
20 
22  // check that all sub-config have same supercell
23  for (auto it = sub_config().begin(); it != sub_config().end(); ++it) {
24  if (&it->supercell() != &(sub_config().begin()->supercell())) {
25  throw std::runtime_error(
26  "Error constructing SuperConfigEnum: "
27  "Sub-Configurations with different Supercells");
28  }
29  }
30  m_sub_scel = &(m_sub_config.begin()->supercell());
31 
32  // tiling of sub-config supercell lattice into super-config supercell lattice
34  notstd::make_cloneable<xtal::UnitCellIndexConverter>(
37  _target_supercell().lattice().tol()));
38 
39  // initialize 'm_counter' to count over all possible sub-config on
40  // each lattice point
41  Index total_sites = this->_unitcell_index_converter().total_sites();
42  m_counter =
43  Counter<Array<int> >(Array<int>(total_sites, 0),
44  Array<int>(total_sites, sub_config().size() - 1),
45  Array<int>(total_sites, 1));
46 
47  // save indices for mapping sub-config dof values to super config dof values
48  //
49  // for occupation:
50  // m_current->occ(m_index_map[i][j]) = m_sub_scel[m_counter()[i]].occ(j)
51  //
52  // and similar for all other site DoF:
53  // m_current->local_dofs()[dof_key].values().col(m_index_map[i][j]) =
54  // m_sub_scel[m_counter()[i]].local_dofs()[dof_key].values().col(j)
55  //
56  m_index_map.resize(total_sites);
57  for (int i = 0; i < total_sites; ++i) {
59  this->_unitcell_index_converter()(i);
60  for (int j = 0; j < _sub_supercell().num_sites(); ++j) {
61  UnitCellCoord uccord = _sub_supercell().uccoord(j) + ref;
62  Index linear_index = _target_supercell().linear_index(uccord);
63  m_index_map[i].push_back(linear_index);
64  }
65  }
66 
67  m_current = notstd::make_cloneable<Configuration>(_target_supercell());
68 
70  _fill(counter(), *m_current);
71 
72  // Make sure that current() satisfies requested conditions
73  if (!_check_current()) {
74  increment();
75  }
76 
77  // set step to 0
78  if (valid()) {
79  _set_step(0);
80  }
81  m_current->set_source(source(step()));
82 }
83 
84 // **** Mutators ****
85 // increment m_current and return a reference to it
87  bool is_valid_config{false};
88 
89  while (!is_valid_config && ++m_counter) {
90  _fill(counter(), *m_current);
91  is_valid_config = _check_current();
92  }
93 
94  if (m_counter.valid()) {
96  } else {
97  _invalidate();
98  }
99 }
100 
102 bool SuperConfigEnum::_check_current() const { return true; }
103 
109 void SuperConfigEnum::_fill(Array<int> const &counter_val,
110  Configuration &super_config) {
111  double xtal_tol = super_config.supercell().prim().lattice().tol();
112  super_config.configdof() = make_configdof(super_config.supercell(), xtal_tol);
113 
114  for (Index i = 0; i < this->_unitcell_index_converter().total_sites(); ++i) {
115  Configuration const &sub_config_i = _sub_config()[counter_val[i]];
116  for (Index j = 0; j < _sub_supercell().num_sites(); ++j) {
117  // copy site DoF
118  super_config.set_occ(m_index_map[i][j], sub_config_i.occ(j));
119 
120  for (auto &pair : super_config.configdof().local_dofs()) {
121  auto const &dof_key = pair.first;
122 
123  auto &local_dof = super_config.configdof().local_dof(dof_key);
124 
125  local_dof.site_value(m_index_map[i][j]) =
126  sub_config_i.configdof().local_dof(dof_key).site_value(j);
127  }
128  }
129  }
130 }
131 
132 } // namespace CASM
Basic std::vector like container (deprecated)
Definition: Array.hh:45
std::map< DoFKey, LocalContinuousConfigDoFValues > const & local_dofs() const
Definition: ConfigDoF.cc:119
LocalContinuousConfigDoFValues const & local_dof(DoFKey const &_key) const
Definition: ConfigDoF.cc:124
const ConfigDoF & configdof() const
const Access the DoF
const int & occ(Index site_l) const
Occupant variable on site l.
const Supercell & supercell() const
Get the Supercell for this Configuration.
void set_occ(Index site_l, int val)
Set occupant variable on site l.
A Counter allows looping over many incrementing variables in one loop.
Definition: Counter.hh:109
SiteReference site_value(Index l)
Access site DoF value vector.
const Lattice & lattice() const
Definition: Structure.hh:100
xtal::UnitCellIndexConverter & _unitcell_index_converter()
Access the UnitCellIndexConverter.
Supercell const & _sub_supercell() const
Access the sub-config supercell.
Array< int > const & counter() const
Access the current value of the counter.
Counter< Array< int > > m_counter
void increment() override
Implement increment.
Supercell const & _target_supercell()
Access the super-config supercell.
std::string name() const override
Derived enumerators must implement name, via ENUM_MEMBERS.
notstd::cloneable_ptr< xtal::UnitCellIndexConverter > m_unitcell_index_converter
std::vector< Configuration > & _sub_config()
Access the sub-configurations.
void _fill(Array< int > const &counter_val, Configuration &config)
Supercell const * m_sub_scel
notstd::cloneable_ptr< Configuration > m_current
The 'current' Configuration.
bool _check_current() const
Returns true if current() satisifies requested conditions.
std::vector< std::vector< Index > > m_index_map
m_current->occ(m_index_map[i][j]) = m_sub_scel[i].occ(j)
void _init()
Used by constructor.
std::vector< Configuration > const & sub_config() const
Access the sub-configurations.
std::vector< Configuration > m_sub_config
A vector containing each possible sub_config.
static const std::string enumerator_name
Index linear_index(const Coordinate &coord, double tol=TOL) const
Given a Coordinate and tolerance, return linear index into Configuration.
Definition: Supercell.cc:183
UnitCellCoord uccoord(Index linear_index) const
Return the integral coordinates corresponding to a linear index.
Definition: Supercell.cc:209
Eigen::Matrix3l transf_mat() const
Definition: Supercell.cc:235
Index num_sites() const
Definition: Supercell.cc:233
const Structure & prim() const
Definition: Supercell.cc:113
bool valid() const
Returns false if enumeration is complete.
Definition: Enumerator.hh:118
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
double tol() const
Definition: Lattice.hh:195
Unit Cell Coordinates.
Unit Cell Indices.
Index total_sites() const
Returns the total number of sites within the superlattice.
GenericVectorXdScelFormatter lattice()
Definition: SupercellIO.cc:266
Eigen::Matrix3l make_transformation_matrix_to_super(const Lattice &tiling_unit, const Lattice &superlattice, double tol)
Definition: Lattice.cc:848
Main CASM namespace.
Definition: APICommand.hh:8
ConfigDoF make_configdof(Structure const &prim, Index volume)
Construct zero-valued ConfigDoF.
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
pair_type ref
Definition: settings.cc:144