CASM  1.1.0
A Clusters Approach to Statistical Mechanics
DoFSet.hh
Go to the documentation of this file.
1 #ifndef CASM_DoFSet
2 #define CASM_DoFSet
3 
4 #include <string>
5 #include <unordered_set>
6 #include <vector>
7 
8 #include "casm/basis_set/DoF.hh"
9 
10 namespace CASM {
11 
12 class AnisoValTraits;
13 class DoFSet;
14 
21 struct DoFSetInfo {
44  DoFSetInfo(SymGroupRepID _id, Eigen::Ref<const Eigen::MatrixXd> const &_basis)
45  : m_symrep_ID(_id), m_basis(_basis) {
46  if (basis().cols() > 0 && basis().rows() > 0)
47  m_inv_basis = basis()
48  .transpose()
49  .colPivHouseholderQr()
50  .solve(Eigen::MatrixXd::Identity(dim(), dim()))
51  .transpose();
52  }
53 
55  SymGroupRepID const &symrep_ID() const { return m_symrep_ID; }
56 
59 
72  Eigen::MatrixXd const &basis() const { return m_basis; }
73 
88  Eigen::MatrixXd set_basis(Eigen::Ref<const Eigen::MatrixXd> const &_basis) {
89  m_basis = _basis;
90  if (basis().cols() > 0 && basis().rows() > 0)
91  m_inv_basis = basis()
92  .transpose()
93  .colPivHouseholderQr()
94  .solve(Eigen::MatrixXd::Identity(dim(), dim()))
95  .transpose();
96  return m_basis;
97  }
98 
107  Eigen::MatrixXd const &inv_basis() const { return m_inv_basis; }
108 
110  Index dim() const { return basis().cols(); }
111 
112  private:
116 };
117 
118 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119 
156 class DoFSet {
157  public:
159 
160  using TypeFunc = std::function<notstd::cloneable_ptr<AnisoValTraits>()>;
161 
162  using Container = std::vector<ContinuousDoF>;
163 
164  using const_iterator = std::vector<ContinuousDoF>::const_iterator;
165 
173  static DoFSet make_default(AnisoValTraits const &_type);
174 
186  DoFSet(AnisoValTraits const &_type, std::vector<std::string> components,
187  DoFSetInfo _info,
188  std::unordered_set<std::string> excluded_occupants = {});
189 
191  Index size() const { return m_components.size(); }
192 
197  std::string const &type_name() const { return m_traits.name(); }
198 
200  AnisoValTraits const &traits() const { return m_traits; }
201 
213  void set_ID(Index _ID) {
214  for (auto &c : m_components) c.set_ID(_ID);
215  }
216 
218  void lock_IDs();
219 
223  void set_sequential_IDs();
224 
227  DoFSetInfo const &info() const { return m_info; }
228 
233  ContinuousDoF const &operator[](Index i) const { return m_components[i]; }
234 
236  const_iterator begin() const { return m_components.cbegin(); }
237 
239  const_iterator end() const { return m_components.cend(); }
240 
242  const_iterator cbegin() const { return m_components.cbegin(); }
243 
245  const_iterator cend() const { return m_components.cend(); }
246 
249  bool is_excluded_occ(std::string const &_occ_name) const {
250  return m_excluded_occs.count(_occ_name);
251  }
252 
254  Index dim() const { return m_info.dim(); }
255 
268  Eigen::MatrixXd const &basis() const { return m_info.basis(); }
269 
276  SymGroupRepID const &symrep_ID() const { return m_info.symrep_ID(); }
277 
279  bool identical(DoFSet const &rhs) const;
280 
282  void transform_basis(Eigen::Ref<const Eigen::MatrixXd> const &trans_mat);
283 
293  bool update_IDs(const std::vector<Index> &before_IDs,
294  const std::vector<Index> &after_IDs);
295 
296  private:
300 
302  std::vector<ContinuousDoF> m_components;
303 
307 
309  std::unordered_set<std::string> m_excluded_occs;
310 };
311 
312 //********************************************************************
313 
314 inline bool operator==(DoFSet const &A, DoFSet const &B) {
315  return A.identical(B);
316 }
317 
318 //********************************************************************
319 
320 inline bool operator!=(DoFSet const &A, DoFSet const &B) {
321  return !A.identical(B);
322 }
323 
324 } // namespace CASM
325 
326 #endif
Specifies traits of (possibly) anisotropic crystal properties.
std::string const & name() const
Const access of name.
void set_sequential_IDs()
Definition: DoFSet.cc:67
std::vector< ContinuousDoF >::const_iterator const_iterator
Definition: DoFSet.hh:164
std::vector< ContinuousDoF > m_components
ContinuousDoF components, one for each column in m_info->basis()
Definition: DoFSet.hh:302
AnisoValTraits const & traits() const
Returns the AnisoValTraits object for the DoF type of this DoFSet.
Definition: DoFSet.hh:200
static DoFSet make_default(AnisoValTraits const &_type)
Definition: DoFSet.cc:93
void lock_IDs()
Locks IDs of components in this DoFSet so they can no longer be updated.
Definition: DoFSet.cc:60
Index dim() const
Dimension of the DoFSet, equivalent to basis().cols()
Definition: DoFSet.hh:254
std::function< notstd::cloneable_ptr< AnisoValTraits >()> TypeFunc
Definition: DoFSet.hh:160
bool update_IDs(const std::vector< Index > &before_IDs, const std::vector< Index > &after_IDs)
Definition: DoFSet.cc:74
SymGroupRepID const & symrep_ID() const
Definition: DoFSet.hh:276
const_iterator cbegin() const
Const iterator to first ContinuousDoF component.
Definition: DoFSet.hh:242
std::vector< ContinuousDoF > Container
Definition: DoFSet.hh:162
void set_ID(Index _ID)
Definition: DoFSet.hh:213
bool is_excluded_occ(std::string const &_occ_name) const
Definition: DoFSet.hh:249
Index size() const
Returns the number of components in this DoFSet.
Definition: DoFSet.hh:191
ContinuousDoF const & operator[](Index i) const
Definition: DoFSet.hh:233
void transform_basis(Eigen::Ref< const Eigen::MatrixXd > const &trans_mat)
Equivalent to m_basis=trans_mat*m_basis. Invalidates SymGroupRepID.
Definition: DoFSet.cc:52
DoFSet(AnisoValTraits const &_type, std::vector< std::string > components, DoFSetInfo _info, std::unordered_set< std::string > excluded_occupants={})
Definition: DoFSet.cc:10
const_iterator cend() const
Const iterator pointing one past last ContinuousDoF component.
Definition: DoFSet.hh:245
Eigen::MatrixXd const & basis() const
Definition: DoFSet.hh:268
bool identical(DoFSet const &rhs) const
Returns true if "rhs" has identical components and basis to this DoFSet.
Definition: DoFSet.cc:42
BasicTraits m_traits
Definition: DoFSet.hh:299
std::unordered_set< std::string > m_excluded_occs
A list of site occupants for which the DoF does not apply.
Definition: DoFSet.hh:309
DoFSetInfo const & info() const
Definition: DoFSet.hh:227
const_iterator end() const
Iterator pointing one past last ContinuousDoF component.
Definition: DoFSet.hh:239
DoFSetInfo m_info
Definition: DoFSet.hh:306
std::string const & type_name() const
Definition: DoFSet.hh:197
const_iterator begin() const
Iterator pointing to the first ContinuousDoF component.
Definition: DoFSet.hh:236
Type-safe ID object for communicating and accessing Symmetry representation info.
IdentitySymRepBuilder Identity()
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd
bool operator!=(DoFSet const &A, DoFSet const &B)
Definition: DoFSet.hh:320
bool operator==(DoFSet const &A, DoFSet const &B)
Definition: DoFSet.hh:314
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
SymGroupRepID m_symrep_ID
Definition: DoFSet.hh:113
Eigen::MatrixXd m_basis
Definition: DoFSet.hh:114
Index dim() const
Dimension of the DoFSet, equivalent to basis().cols()
Definition: DoFSet.hh:110
Eigen::MatrixXd const & inv_basis() const
Definition: DoFSet.hh:107
SymGroupRepID const & symrep_ID() const
Returns SymGroupRepID of associated DoFSet.
Definition: DoFSet.hh:55
DoFSetInfo(SymGroupRepID _id, Eigen::Ref< const Eigen::MatrixXd > const &_basis)
Definition: DoFSet.hh:44
Eigen::MatrixXd set_basis(Eigen::Ref< const Eigen::MatrixXd > const &_basis)
Definition: DoFSet.hh:88
Eigen::MatrixXd m_inv_basis
Definition: DoFSet.hh:115
void set_symrep_ID(SymGroupRepID _id)
Sets SymGroupRepID.
Definition: DoFSet.hh:58
Eigen::MatrixXd const & basis() const
Definition: DoFSet.hh:72