CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigDoF.cc
Go to the documentation of this file.
7 
8 namespace CASM {
9 
11 Index ConfigDoF::size() const { return occupation().size(); }
12 
15 
18 
20 double ConfigDoF::tol() const { return m_tol; }
21 
25  for (auto &local_dof : m_local_dofs) {
26  local_dof.second.setZero();
27  }
28  for (auto &global_dof : m_global_dofs) {
29  global_dof.second.setZero();
30  }
31 }
32 
34 int &ConfigDoF::occ(Index i) { return m_occupation.occ(i); }
35 
37 const int &ConfigDoF::occ(Index i) const { return m_occupation.values()[i]; }
38 
44  Eigen::Ref<const Eigen::VectorXi> const &_occupation) {
45  if (occupation().size() != _occupation.size()) {
46  std::stringstream msg;
47  msg << "Size mismatch in ConfigDoF::set_occupation(): "
48  << "Expected size=" << occupation().size()
49  << ", received size=" << _occupation.size();
50  throw std::runtime_error(msg.str());
51  }
52  m_occupation.set_values(_occupation);
53 }
54 
56 Eigen::VectorXi const &ConfigDoF::occupation() const {
57  return m_occupation.values();
58 }
59 
61  return size() != 0 && occupation().size() == size();
62 }
63 
64 std::map<DoFKey, GlobalContinuousConfigDoFValues> const &
66  return m_global_dofs;
67 }
68 
70  DoFKey const &_key) const {
71  auto it = m_global_dofs.find(_key);
72  if (it == m_global_dofs.end())
73  throw std::runtime_error(
74  "Attempting to access uninitialized ConfigDoF value for '" + _key +
75  "'");
76  return it->second;
77 }
78 
80  auto it = m_global_dofs.find(_key);
81  if (it == m_global_dofs.end())
82  throw std::runtime_error(
83  "Attempting to access uninitialized ConfigDoF value for '" + _key +
84  "'");
85  return it->second;
86 }
87 
88 bool ConfigDoF::has_global_dof(DoFKey const &_key) const {
89  return global_dofs().count(_key);
90 }
91 
100  Eigen::Ref<const Eigen::VectorXd> const &_val) {
101  auto it = m_global_dofs.find(_key);
102  if (it == m_global_dofs.end()) {
103  throw std::runtime_error(
104  "Attempting to assign global ConfigDoF values of type " + _key +
105  " but no such value type has been allocated.\n");
106  }
107  if (it->second.values().size() != _val.size()) {
108  std::stringstream msg;
109  msg << "Size mismatch in ConfigDoF::set_global_dof(): "
110  << "For key=\"" << _key
111  << "\", expected size=" << it->second.values().size()
112  << ", received size=" << _val.size();
113  throw std::runtime_error(msg.str());
114  }
115 
116  it->second.set_values(_val);
117 }
118 
119 std::map<DoFKey, LocalContinuousConfigDoFValues> const &ConfigDoF::local_dofs()
120  const {
121  return m_local_dofs;
122 }
123 
125  DoFKey const &_key) const {
126  auto it = m_local_dofs.find(_key);
127  if (it == m_local_dofs.end())
128  throw std::runtime_error(
129  "Attempting to access uninitialized ConfigDoF value for '" + _key +
130  "'");
131  return it->second;
132 }
133 
135  auto it = m_local_dofs.find(_key);
136  if (it == m_local_dofs.end())
137  throw std::runtime_error(
138  "Attempting to access uninitialized ConfigDoF value for '" + _key +
139  "'");
140  return it->second;
141 }
142 
143 bool ConfigDoF::has_local_dof(DoFKey const &_key) const {
144  return local_dofs().count(_key);
145 }
146 
151 //
155  Eigen::Ref<const Eigen::MatrixXd> const &_val) {
156  auto it = m_local_dofs.find(_key);
157  if (it == m_local_dofs.end()) {
158  throw std::runtime_error(
159  "Attempting to assign local ConfigDoF values of type " + _key +
160  " but no such value type has been allocated.\n");
161  }
162 
163  if (it->second.values().rows() != _val.rows() ||
164  it->second.values().cols() != _val.cols()) {
165  std::stringstream msg;
166  msg << "Size mismatch in ConfigDoF::set_local_dof(): "
167  << "For key=\"" << _key
168  << "\", expected rows=" << it->second.values().rows()
169  << ", received rows=" << _val.rows()
170  << ", expected cols=" << it->second.values().cols()
171  << ", received cols=" << _val.cols();
172  throw std::runtime_error(msg.str());
173  }
174 
175  it->second.set_values(_val);
176 }
177 
183  for (auto &dof : m_global_dofs) {
184  dof.second.set_values(*(it.global_dof_rep(dof.first).MatrixXd()) *
185  dof.second.values());
186  }
187 
188  Permutation tperm(it.combined_permute());
189  if (occupation().size()) {
190  if (it.sym_info().has_aniso_occs()) {
191  Index l = 0;
192  for (Index b = 0; b < n_sublat(); ++b) {
193  for (Index n = 0; n < n_vol(); ++n, ++l) {
194  occ(l) = (*(it.occ_rep(b).permutation()))[occ(l)];
195  }
196  }
197  }
198  set_occupation(tperm * occupation());
199  }
200 
201  for (auto &dof : m_local_dofs) {
202  LocalContinuousConfigDoFValues tmp = dof.second;
203 
204  for (Index b = 0; b < tmp.n_sublat(); ++b) {
205  Index rows = it.local_dof_rep(dof.first, b).MatrixXd()->rows();
206  tmp.sublat(b).topRows(rows) =
207  *(it.local_dof_rep(dof.first, b).MatrixXd()) *
208  dof.second.sublat(b).topRows(rows);
209  }
210  for (Index l = 0; l < size(); ++l) {
211  dof.second.site_value(l) = tmp.site_value(tperm[l]);
212  }
213  }
214 
215  return *this;
216 }
217 
221  for (auto &dof : m_global_dofs) {
222  dof.second.set_values(
223  *(_op.representation(dof.second.info().symrep_ID()).MatrixXd()) *
224  dof.second.values());
225  }
226 
227  if (occupation().size()) {
228  Index l = 0;
229  for (Index b = 0; b < n_sublat(); ++b) {
230  if (!m_occupation.symrep_IDs()[b].is_identity()) {
231  SymPermutation const &permrep(
233  l = b * n_vol();
234  for (Index n = 0; n < n_vol(); ++n, ++l) {
235  occ(l) = (*permrep.permutation())[occ(l)];
236  }
237  }
238  }
239  }
240 
241  for (auto &dof : m_local_dofs) {
242  LocalContinuousConfigDoFValues tmp = dof.second;
243 
244  for (Index b = 0; b < tmp.n_sublat(); ++b)
245  dof.second.sublat(b) =
246  *(_op.representation(dof.second.info()[b].symrep_ID()).MatrixXd()) *
247  dof.second.sublat(b);
248  }
249 
250  return *this;
251 }
252 
257  std::swap(m_tol, RHS.m_tol);
258 }
259 
260 void swap(ConfigDoF &A, ConfigDoF &B) { A.swap(B); }
261 
262 } // namespace CASM
Index size() const
Number of sites in the ConfigDoF.
Definition: ConfigDoF.cc:11
std::map< DoFKey, LocalContinuousConfigDoFValues > const & local_dofs() const
Definition: ConfigDoF.cc:119
void set_global_dof(DoFKey const &_key, Eigen::Ref< const Eigen::VectorXd > const &_val)
Set global continuous DoF values.
Definition: ConfigDoF.cc:99
void swap(ConfigDoF &RHS)
Definition: ConfigDoF.cc:253
Index n_vol() const
Integer volume of ConfigDoF.
Definition: ConfigDoF.cc:14
std::map< DoFKey, GlobalContinuousConfigDoFValues > const & global_dofs() const
Definition: ConfigDoF.cc:65
bool has_local_dof(DoFKey const &_key) const
Definition: ConfigDoF.cc:143
LocalDiscreteConfigDoFValues m_occupation
Definition: ConfigDoF.hh:201
bool has_occupation() const
Definition: ConfigDoF.cc:60
Index n_sublat() const
Number of sublattices in ConfigDoF.
Definition: ConfigDoF.cc:17
ConfigDoF & apply_sym_no_permute(SymOp const &_op)
Definition: ConfigDoF.cc:220
void setZero()
Set all DoF values to zero.
Definition: ConfigDoF.cc:23
void set_local_dof(DoFKey const &_key, Eigen::Ref< const Eigen::MatrixXd > const &_val)
Set local continuous DoF values.
Definition: ConfigDoF.cc:154
bool has_global_dof(DoFKey const &_key) const
Definition: ConfigDoF.cc:88
GlobalContinuousConfigDoFValues const & global_dof(DoFKey const &_key) const
Definition: ConfigDoF.cc:69
Eigen::VectorXi const & occupation() const
Const reference occupation values.
Definition: ConfigDoF.cc:56
ConfigDoF & apply_sym(PermuteIterator const &it)
Definition: ConfigDoF.cc:182
double tol() const
Tolerance for comparison of continuous DoF values.
Definition: ConfigDoF.cc:20
int & occ(Index i)
Reference occupation value on site i.
Definition: ConfigDoF.cc:34
std::map< std::string, LocalContinuousConfigDoFValues > m_local_dofs
Definition: ConfigDoF.hh:205
LocalContinuousConfigDoFValues const & local_dof(DoFKey const &_key) const
Definition: ConfigDoF.cc:124
void set_occupation(Eigen::Ref< const Eigen::VectorXi > const &_occupation)
Set occupation values.
Definition: ConfigDoF.cc:43
std::map< std::string, GlobalContinuousConfigDoFValues > m_global_dofs
Definition: ConfigDoF.hh:203
void setZero()
Set DoF values to zero.
SiteReference site_value(Index l)
Access site DoF value vector.
SublatReference sublat(Index b)
Access matrix block of values for all sites on one sublattice.
void setZero()
Set DoF values to zero.
std::vector< SymGroupRepID > const & symrep_IDs() const
int & occ(Index i)
Reference occupation value on site i.
Eigen::VectorXi const & values() const
void set_values(Eigen::Ref< ValueType const > const &_values)
Set occupation values (values are indices into Site::occupant_dof())
void setZero()
Set occupation values to zero.
SupercellSymInfo const & sym_info() const
Reference the SupercellSymInfo containing the operations being pointed at.
SymOpRepresentation const & global_dof_rep(DoFKey const &_key) const
SymOpRepresentation const & local_dof_rep(DoFKey const &_key, Index b) const
SymOpRepresentation const & occ_rep(Index b) const
Permutation combined_permute() const
bool has_aniso_occs() const
true if any species are anisotropic, such that the occ_symreps are non-trivial
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
SymOpRepresentation const & representation(SymGroupRepID _rep_ID) const
virtual Permutation const * permutation() const
Permutation const * get_permutation_rep(SymGroupRepID _rep_ID) const
get pointer to permutation representation corresponding to _rep_ID
virtual Eigen::MatrixXd const * MatrixXd() const
SymPermutation describes how a symmetry operation permutes a list of 'things' For example,...
Permutation const * permutation() const override
Access the permutation array 'm_permute'.
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:260
std::string DoFKey
Definition: DoFDecl.hh:7
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39