CASM  1.1.0
A Clusters Approach to Statistical Mechanics
DoFSet.hh
Go to the documentation of this file.
1 #ifndef CASM_XTAL_DOFSET
2 #define CASM_XTAL_DOFSET
3 
4 #include <map>
5 #include <unordered_set>
6 #include <vector>
7 
9 #include "casm/external/Eigen/Core"
10 
11 namespace CASM {
12 namespace xtal {
13 struct SymOp;
14 
29 class DoFSet {
30  public:
32 
33  DoFSet(const BasicTraits &init_traits,
34  const std::vector<std::string> &init_component_names,
35  const Eigen::MatrixXd &init_basis)
36  : m_traits(init_traits),
37  m_component_names(init_component_names),
38  m_basis(init_basis) {
39  assert(m_component_names.size() == this->dim());
40  assert(m_basis.cols() == this->dim());
41  assert(m_basis.rows() ==
42  this->traits().dim()); // TODO: This makes sense I think?
43  }
44 
45  DoFSet(const BasicTraits &init_traits)
46  : DoFSet(
47  init_traits, init_traits.standard_var_names(),
48  Eigen::MatrixXd::Identity(init_traits.dim(), init_traits.dim())) {}
49 
52  const std::string &type_name() const { return m_traits.name(); }
53 
55  const std::vector<std::string> &component_names() const {
56  return this->m_component_names;
57  }
58 
60  BasicTraits const &traits() const { return m_traits; }
61 
64  Index dim() const { return this->basis().cols(); }
65 
67  Eigen::MatrixXd const &basis() const { return m_basis; }
68 
69  private:
73 
76  std::vector<std::string> m_component_names;
77 
83 };
84 
87 std::vector<std::string> component_descriptions(DoFSet const &dofset);
88 
95 class SiteDoFSet : public DoFSet {
96  public:
97  SiteDoFSet(const DoFSet &init_dofset,
98  const std::unordered_set<std::string> &init_exclude_occs)
99  : DoFSet(init_dofset), m_excluded_occs(init_exclude_occs) {}
100 
101  SiteDoFSet(const DoFSet &init_dofset) : DoFSet(init_dofset) {}
102 
103  SiteDoFSet(const BasicTraits &init_traits,
104  const std::vector<std::string> &init_component_names,
105  const Eigen::MatrixXd &init_basis,
106  const std::unordered_set<std::string> &init_exclude_occs)
107  : SiteDoFSet(DoFSet(init_traits, init_component_names, init_basis),
108  init_exclude_occs) {}
109 
110  SiteDoFSet(const BasicTraits &init_traits,
111  const std::unordered_set<std::string> &init_exclude_occs = {})
112  : SiteDoFSet(DoFSet(init_traits), init_exclude_occs) {}
113 
116  bool is_excluded_occ(std::string const &_occ_name) const {
117  return m_excluded_occs.count(_occ_name);
118  }
119 
121  const std::unordered_set<std::string> &excluded_occupants() const {
122  return this->m_excluded_occs;
123  }
124 
125  private:
126  std::unordered_set<std::string> m_excluded_occs;
127 };
128 
129 template <typename DoFSetType>
130 std::map<std::string, DoFSetType> make_dofset_map(
131  std::vector<DoFSetType> const &dofset_vec) {
132  std::map<std::string, DoFSetType> dofset_map;
133  for (auto const &dofset : dofset_vec) {
134  dofset_map.emplace(dofset.type_name(), dofset);
135  }
136  return dofset_map;
137 }
138 
150  public:
151  DoFSetIsEquivalent_f(const DoFSet &reference_value, double tol)
152  : m_reference_dofset(reference_value), m_tol(tol) {}
153 
156  bool operator()(const DoFSet &other_value) const;
157 
158  private:
161 
163  double m_tol;
164 
166  bool _traits_match(const DoFSet &other_value) const;
167 
170  bool _basis_spans_same_space(const DoFSet &other_value) const;
171 };
172 
186  SiteDoFSetIsEquivalent_f(const SiteDoFSet &reference_value, double tol)
187  : DoFSetIsEquivalent_f(reference_value, tol),
188  m_reference_excluded_occs(reference_value.excluded_occupants()) {}
189 
192  bool operator()(const SiteDoFSet &other_value) const {
193  return DoFSetIsEquivalent_f::operator()(other_value) &&
194  this->_excluded_occupants_match(other_value);
195  }
196 
197  private:
198  std::unordered_set<std::string> m_reference_excluded_occs;
199 
200  bool _excluded_occupants_match(const SiteDoFSet &other_value) const {
201  return this->m_reference_excluded_occs == other_value.excluded_occupants();
202  }
203 };
204 
207  const Eigen::MatrixXd &to_basis,
208  double tol);
209 
210 } // namespace xtal
211 } // namespace CASM
212 
213 namespace CASM {
214 // This is how it's currently organized for xtal::Lattice, but maybe we want
215 // something else (see SymTools.hh)
216 namespace sym {
218 xtal::DoFSet copy_apply(const xtal::SymOp &op, const xtal::DoFSet &_dof);
219 } // namespace sym
220 } // namespace CASM
221 
222 #endif
Specifies traits of (possibly) anisotropic crystal properties.
std::string const & name() const
Const access of name.
const std::string & type_name() const
Returns type_name of DoFSet, which should be a standardized DoF type (e.g., "disp",...
Definition: DoFSet.hh:52
DoFSet(const BasicTraits &init_traits)
Definition: DoFSet.hh:45
Eigen::MatrixXd const & basis() const
Matrix that relates DoFSet variables to a conventional coordiante system.
Definition: DoFSet.hh:67
Index dim() const
Definition: DoFSet.hh:64
Eigen::MatrixXd m_basis
Definition: DoFSet.hh:82
BasicTraits m_traits
Definition: DoFSet.hh:72
std::vector< std::string > m_component_names
Definition: DoFSet.hh:76
BasicTraits const & traits() const
Returns traits object for the DoF type of this DoFSet.
Definition: DoFSet.hh:60
DoFSet(const BasicTraits &init_traits, const std::vector< std::string > &init_component_names, const Eigen::MatrixXd &init_basis)
Definition: DoFSet.hh:33
const std::vector< std::string > & component_names() const
Returns the names of each of the component axes.
Definition: DoFSet.hh:55
bool is_excluded_occ(std::string const &_occ_name) const
Returns true if DoFSet is inactive (e.g., takes zero values) when specified occupant is present.
Definition: DoFSet.hh:116
const std::unordered_set< std::string > & excluded_occupants() const
Return all occupants that the DoFSet should not be applied to.
Definition: DoFSet.hh:121
std::unordered_set< std::string > m_excluded_occs
Definition: DoFSet.hh:126
SiteDoFSet(const BasicTraits &init_traits, const std::vector< std::string > &init_component_names, const Eigen::MatrixXd &init_basis, const std::unordered_set< std::string > &init_exclude_occs)
Definition: DoFSet.hh:103
SiteDoFSet(const DoFSet &init_dofset)
Definition: DoFSet.hh:101
SiteDoFSet(const DoFSet &init_dofset, const std::unordered_set< std::string > &init_exclude_occs)
Definition: DoFSet.hh:97
SiteDoFSet(const BasicTraits &init_traits, const std::unordered_set< std::string > &init_exclude_occs={})
Definition: DoFSet.hh:110
IdentitySymRepBuilder Identity()
xtal::Coordinate copy_apply(const xtal::SymOp &op, xtal::Coordinate coord)
Copy and apply SymOp to a Coordinate.
Definition: Coordinate.cc:354
std::vector< std::string > component_descriptions(DoFSet const &dofset)
Definition: DoFSet.cc:12
Eigen::MatrixXd dofset_transformation_matrix(const Eigen::MatrixXd &from_basis, const Eigen::MatrixXd &to_basis, double tol)
Create the symmtery representation for going from one basis to another.
Definition: DoFSet.cc:52
std::map< std::string, DoFSetType > make_dofset_map(std::vector< DoFSetType > const &dofset_vec)
Definition: DoFSet.hh:130
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
double m_tol
Tolerance value for making comparisons.
Definition: DoFSet.hh:163
bool _traits_match(const DoFSet &other_value) const
Returns true if the traits match. Only compares the names.
Definition: DoFSet.cc:20
bool operator()(const DoFSet &other_value) const
Definition: DoFSet.cc:47
bool _basis_spans_same_space(const DoFSet &other_value) const
Definition: DoFSet.cc:24
DoFSetIsEquivalent_f(const DoFSet &reference_value, double tol)
Definition: DoFSet.hh:151
DoFSet m_reference_dofset
Values passed to operator() will be compared against this.
Definition: DoFSet.hh:160
SiteDoFSetIsEquivalent_f(const SiteDoFSet &reference_value, double tol)
Definition: DoFSet.hh:186
bool _excluded_occupants_match(const SiteDoFSet &other_value) const
Definition: DoFSet.hh:200
std::unordered_set< std::string > m_reference_excluded_occs
Definition: DoFSet.hh:198
bool operator()(const SiteDoFSet &other_value) const
Definition: DoFSet.hh:192