CASM  1.1.0
A Clusters Approach to Statistical Mechanics
DoFSet.cc
Go to the documentation of this file.
2 
7 
8 namespace CASM {
9 
10 DoFSet::DoFSet(AnisoValTraits const &_type, std::vector<std::string> components,
11  DoFSetInfo _info,
12  std::unordered_set<std::string> _excluded_occupants)
13  : m_traits(_type),
14  m_info(_info),
15  m_excluded_occs(std::move(_excluded_occupants)) {
16  if (components.empty()) {
17  components = traits().standard_var_names();
19  }
20 
21  if (m_info.basis().rows() != traits().dim()) {
22  throw std::runtime_error("Cannot construct DoFSet of type " + type_name() +
23  ", number of rows in basis matrix is " +
24  std::to_string(m_info.basis().rows()) +
25  " but must be " + std::to_string(traits().dim()));
26  }
27  if (m_info.basis().cols() != components.size()) {
28  throw std::runtime_error("Cannot construct DoFSet of type " + type_name() +
29  ", number of columns in basis matrix is " +
30  std::to_string(m_info.basis().cols()) +
31  " but number of variable names is " +
32  std::to_string(components.size()) +
33  ". These numbers must be equal.");
34  }
35 
36  for (std::string const &name : components)
37  m_components.push_back(ContinuousDoF{traits(), name, -1});
38 }
39 
40 //********************************************************************
41 
42 bool DoFSet::identical(DoFSet const &rhs) const {
43  if (!std::equal(begin(), end(), rhs.begin(), compare_no_value)) {
44  return false;
45  }
46 
47  return almost_equal(basis(), rhs.basis());
48 }
49 
50 //********************************************************************
51 
53  Eigen::Ref<const Eigen::MatrixXd> const &trans_mat) {
54  m_info.set_basis(trans_mat * basis());
56 }
57 
58 //********************************************************************
59 
61  for (ContinuousDoF &dof : this->m_components) {
62  dof.lock_ID();
63  }
64  return;
65 }
66 
68  for (int i = 0; i < this->m_components.size(); ++i) {
69  m_components[i].set_ID(i);
70  }
71  return;
72 }
73 
74 bool DoFSet::update_IDs(const std::vector<Index> &before_IDs,
75  const std::vector<Index> &after_IDs) {
76  Index ID_ind;
77  bool is_updated(false);
78  for (Index i = 0; i < m_components.size(); i++) {
79  // IMPORTANT: Do before_IDs.find(), NOT m_components().find() (if such a
80  // thing existed)
81  ID_ind = find_index(before_IDs, m_components[i].ID());
82  // Only set ID if DoF doesn't have an ID lock
83  if (ID_ind < after_IDs.size() && !m_components[i].is_locked()) {
84  m_components[i].set_ID(after_IDs[ID_ind]);
85  // The new ID only changes the formula if the corresponding coeff is
86  // nonzero if(!almost_zero(m_coeffs[i]))
87  is_updated = true;
88  }
89  }
90  return is_updated;
91 }
92 
94  DoFSet result(
95  _type, _type.standard_var_names(),
96  {SymGroupRepID(), Eigen::MatrixXd::Identity(_type.dim(), _type.dim())});
97 
98  if (_type.global()) {
99  Index i = 0;
100  for (auto &dof : result.m_components) {
101  dof.set_ID(i++);
102  dof.lock_ID();
103  }
104  }
105  return result;
106 }
107 //********************************************************************
108 
109 } // namespace CASM
Specifies traits of (possibly) anisotropic crystal properties.
std::vector< std::string > const & standard_var_names() const
Return standard coordinate axes for continuous variable space.
bool global() const
Returns true if type is global.
void set_sequential_IDs()
Definition: DoFSet.cc:67
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
bool update_IDs(const std::vector< Index > &before_IDs, const std::vector< Index > &after_IDs)
Definition: DoFSet.cc:74
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
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
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.
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
IdentitySymRepBuilder Identity()
Main CASM namespace.
Definition: APICommand.hh:8
bool almost_equal(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Check if ClusterInvariants are equal.
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
Definition: algorithm.hh:24
GenericDatumFormatter< std::string, DataObject > name()
bool compare_no_value(ContinuousDoF const &A, ContinuousDoF const &B)
Definition: DoF.hh:412
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Definition: stream_io.hh:24
Eigen::MatrixXd set_basis(Eigen::Ref< const Eigen::MatrixXd > const &_basis)
Definition: DoFSet.hh:88
void set_symrep_ID(SymGroupRepID _id)
Sets SymGroupRepID.
Definition: DoFSet.hh:58
Eigen::MatrixXd const & basis() const
Definition: DoFSet.hh:72