CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SymType.hh
Go to the documentation of this file.
1 #ifndef XTALSYMTYPE_HH
2 #define XTALSYMTYPE_HH
3 
4 #include <algorithm>
5 #include <functional>
6 #include <stdexcept>
7 #include <string>
8 #include <tuple>
9 #include <vector>
10 
11 #include "casm/external/Eigen/Dense"
12 
13 namespace CASM {
14 namespace xtal {
16 typedef Eigen::Vector3d SymOpTranslationType;
17 typedef bool SymOpTimeReversalType;
18 
22 struct SymOp {
25  : matrix(mat),
28 
29  static SymOp identity() {
30  return SymOp(SymOpMatrixType::Identity(), SymOpTranslationType::Zero(),
31  false);
32  }
33 
34  static SymOp time_reversal() {
35  return SymOp(SymOpMatrixType::Identity(), SymOpTranslationType::Zero(),
36  true);
37  }
38 
41  }
42 
43  static SymOp point_operation(const SymOpMatrixType &mat) {
44  return SymOp(mat, SymOpTranslationType::Zero(), false);
45  }
46 
50 };
51 
53 SymOp operator*(const SymOp &LHS, const SymOp &RHS);
54 
58 /* typedef std::tuple<SymOpMatrixType, SymOpTranslationType,
59  * SymOpTimeReversalType> SymOpType; */
60 typedef std::vector<SymOp> SymOpVector;
61 
63 const SymOpMatrixType &get_matrix(const SymOp &op);
69 
70 //*********************************************************************************************************************//
71 
72 // TODO: Sort out how to handle a maximum group size? A bad closure could result
73 // in an infinite group.
88 template <typename SymOpCompareType>
89 void close_group(SymOpVector *partial_group,
90  const SymOpCompareType &symop_binary_comp) {
91  int max_size = 500;
92 
93  bool is_closed = false;
94  while (!is_closed) {
95  is_closed = true;
96  int current_size = partial_group->size();
97  if (current_size > max_size) {
98  throw std::runtime_error("Group closure resulted in over " +
99  std::to_string(max_size) + " operations.");
100  }
101 
102  for (int i = 0; i < current_size; ++i) {
103  for (int j = 0; j < current_size; ++j) {
104  const SymOp &l_op = partial_group->at(i);
105  const SymOp &r_op = partial_group->at(j);
106  SymOp candidate = l_op * r_op;
107  auto equals_candidate = [symop_binary_comp,
108  candidate](const SymOp &group_operation) {
109  return symop_binary_comp(candidate, group_operation);
110  };
111 
112  // If you can't find find the operation then the group wasn't closed.
113  // Add it and make sure to start over to continue closing with the new
114  // operations.
115  if (std::find_if(partial_group->begin(), partial_group->end(),
116  equals_candidate) == partial_group->end()) {
117  partial_group->push_back(candidate);
118  is_closed = false;
119  }
120  }
121  }
122  }
123 
124  return;
125 }
126 
127 template <typename SymOpCompareType, typename... CompareArgs>
128 void close_group(SymOpVector *partial_group, const CompareArgs &... args) {
129  SymOpCompareType symop_binary_comp(args...);
130  return close_group(partial_group, symop_binary_comp);
131 }
132 } // namespace xtal
133 } // namespace CASM
134 
135 #endif
Coordinate operator*(const SymOp &LHS, const Coordinate &RHS)
Definition: Coordinate.cc:329
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
IdentitySymRepBuilder Identity()
Eigen::Vector3d const & get_translation(MappingNode const &_node)
External accessor for translation, to provide xtal::SymOp adaptability.
bool SymOpTimeReversalType
Definition: SymType.hh:17
bool get_time_reversal(MappingNode const &_node)
External accessor for time_reversal, to provide xtal::SymOp adaptability.
Eigen::Matrix3d const & get_matrix(MappingNode const &_node)
External accessor for isometry, to provide xtal::SymOp adaptability.
Eigen::Matrix3d SymOpMatrixType
Definition: SymType.hh:15
Eigen::Vector3d SymOpTranslationType
Definition: SymType.hh:16
void close_group(SymOpVector *partial_group, const SymOpCompareType &symop_binary_comp)
Definition: SymType.hh:89
std::vector< SymOp > SymOpVector
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::Matrix3d Matrix3d
static SymOp identity()
Definition: SymType.hh:29
static SymOp translation_operation(const SymOpTranslationType &translation)
Definition: SymType.hh:39
SymOpMatrixType matrix
Definition: SymType.hh:47
SymOp(const SymOpMatrixType &mat, const SymOpTranslationType &translation, SymOpTimeReversalType time_reversal)
Definition: SymType.hh:23
SymOpTranslationType translation
Definition: SymType.hh:48
SymOpTimeReversalType is_time_reversal_active
Definition: SymType.hh:49
static SymOp point_operation(const SymOpMatrixType &mat)
Definition: SymType.hh:43
static SymOp time_reversal()
Definition: SymType.hh:34