CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SymCompare.hh
Go to the documentation of this file.
1 #ifndef CASM_SymCompare
2 #define CASM_SymCompare
3 
4 #include <memory>
5 #include <utility>
6 
9 
10 namespace CASM {
11 
12 class SymOp;
13 class SymOpRepresentation;
14 
51 template <typename Base>
52 class SymCompare : public Base {
53  public:
54  using MostDerived = typename Base::MostDerived;
55  using Base::derived;
56 
58 
60  Element copy_apply(SymOp const &op, Element obj) const;
61 
64  Element spatial_prepare(Element obj) const;
65 
69 
72  Element prepare(Element obj) const;
73 
75  bool compare(const Element &A, const Element &B) const;
76 
78  bool equal(const Element &A, const Element &B) const;
79 
83 
85  InvariantsType make_invariants(const Element &element) const;
86 
88  bool invariants_compare(const InvariantsType &A,
89  const InvariantsType &B) const;
90 
92  bool invariants_equal(const InvariantsType &A, const InvariantsType &B) const;
93 
95  bool inter_orbit_compare(const Element &A, const InvariantsType &A_invariants,
96  const Element &B,
97  const InvariantsType &B_invariants) const;
98 
100  bool inter_orbit_equal(const Element &A, const InvariantsType &A_invariants,
101  const Element &B,
102  const InvariantsType &B_invariants) const;
103 
106  std::unique_ptr<SymOpRepresentation> canonical_transform(
107  Element const &obj) const;
108 
111  SymOp const &spatial_transform() const;
112 
113  protected:
115  bool inter_orbit_compare_impl(const Element &A,
116  const InvariantsType &A_invariants,
117  const Element &B,
118  const InvariantsType &B_invariants) const;
119 };
120 
122 template <typename Base>
124  SymOp const &op, Element obj) const {
125  return derived().copy_apply_impl(op, obj);
126 }
127 
141 template <typename Base>
143  Element obj) const {
144  return derived().spatial_prepare_impl(obj);
145 }
146 
153 template <typename Base>
155  Element obj) const {
156  return derived().representation_prepare_impl(obj);
157 }
158 
162 template <typename Base>
164  Element obj) const {
165  return spatial_prepare(representation_prepare(obj));
166 }
167 
172 template <typename Base>
173 bool SymCompare<Base>::compare(const Element &A, const Element &B) const {
174  return derived().compare_impl(A, B);
175 }
176 
182 template <typename Base>
183 bool SymCompare<Base>::equal(const Element &A, const Element &B) const {
184  return !compare(A, B) && !compare(B, A);
185 }
186 
188 template <typename Base>
190  const Element &obj) const {
191  return derived().make_invariants_impl(obj);
192 }
193 
200 template <typename Base>
202  const InvariantsType &B) const {
203  return derived().invariants_compare_impl(A, B);
204 }
205 
209 template <typename Base>
211  const InvariantsType &B) const {
212  return !invariants_compare(A, B) && !invariants_compare(B, A);
213 }
214 
221 template <typename Base>
223  const Element &A, const InvariantsType &A_invariants, const Element &B,
224  const InvariantsType &B_invariants) const {
225  return derived().inter_orbit_compare_impl(A, A_invariants, B, B_invariants);
226 }
227 
234 template <typename Base>
236  const Element &A, const InvariantsType &A_invariants, const Element &B,
237  const InvariantsType &B_invariants) const {
238  return !inter_orbit_compare(A, A_invariants, B, B_invariants) &&
239  !inter_orbit_compare(B, B_invariants, A, A_invariants);
240 }
241 
243 template <typename Base>
244 std::unique_ptr<SymOpRepresentation> SymCompare<Base>::canonical_transform(
245  Element const &obj) const {
246  return derived().canonical_transform_impl(obj);
247 }
248 
251 template <typename Base>
253  return derived().spatial_transform_impl();
254 }
255 
264 template <typename Base>
266  const Element &A, const InvariantsType &A_invariants, const Element &B,
267  const InvariantsType &B_invariants) const {
268  // first compare invariants
269  if (this->invariants_compare(A_invariants, B_invariants)) {
270  return true;
271  }
272  if (this->invariants_compare(B_invariants, A_invariants)) {
273  return false;
274  }
275 
276  // next compare A and B
277  return this->compare(A, B);
278 }
279 
280 } // namespace CASM
281 
282 #endif
CRTP base class for implementing element and orbit comparison.
Definition: SymCompare.hh:52
Element spatial_prepare(Element obj) const
Prepare an element for comparison via an isometric affine transformation.
Definition: SymCompare.hh:142
std::unique_ptr< SymOpRepresentation > canonical_transform(Element const &obj) const
Access transform that took cluster from unprepared to prepared state.
Definition: SymCompare.hh:244
SymOp const & spatial_transform() const
Access spatial transform that was used during most recent spatial preparation of an element.
Definition: SymCompare.hh:252
typename traits< MostDerived >::Element Element
Definition: SymCompare.hh:57
bool inter_orbit_compare_impl(const Element &A, const InvariantsType &A_invariants, const Element &B, const InvariantsType &B_invariants) const
Orders orbit prototypes, breaking invariants_compare ties.
Definition: SymCompare.hh:265
typename Base::MostDerived MostDerived
Definition: SymCompare.hh:54
Element representation_prepare(Element obj) const
Prepare an element for comparison via transformation of its internal representation.
Definition: SymCompare.hh:154
Element copy_apply(SymOp const &op, Element obj) const
Applies SymOp to Element.
Definition: SymCompare.hh:123
bool inter_orbit_equal(const Element &A, const InvariantsType &A_invariants, const Element &B, const InvariantsType &B_invariants) const
Check equivalence of prototypes in different orbit.
Definition: SymCompare.hh:235
InvariantsType make_invariants(const Element &element) const
Make orbit invariants from one element in the orbit.
Definition: SymCompare.hh:189
bool invariants_compare(const InvariantsType &A, const InvariantsType &B) const
Defines an order for orbits that have different invariants.
Definition: SymCompare.hh:201
bool compare(const Element &A, const Element &B) const
Orders 'prepared' elements.
Definition: SymCompare.hh:173
bool equal(const Element &A, const Element &B) const
Check equivalence of 'prepared' elements.
Definition: SymCompare.hh:183
typename traits< MostDerived >::InvariantsType InvariantsType
type InvariantsType is used to screen elements for equivalence and sort orbits
Definition: SymCompare.hh:82
Element prepare(Element obj) const
Prepare an element for comparison via representation_prepare(), followed by spatial_prepare()
Definition: SymCompare.hh:163
bool inter_orbit_compare(const Element &A, const InvariantsType &A_invariants, const Element &B, const InvariantsType &B_invariants) const
Orders orbit prototypes, breaking invariants_compare ties.
Definition: SymCompare.hh:222
bool invariants_equal(const InvariantsType &A, const InvariantsType &B) const
Check equivalence of invariants.
Definition: SymCompare.hh:210
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
Main CASM namespace.
Definition: APICommand.hh:8
bool compare(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Compare ClusterInvariants.