CASM  1.1.0
A Clusters Approach to Statistical Mechanics
VectorSymCompare_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_VectorSymCompare_impl
2 #define CASM_VectorSymCompare_impl
3 
5 #include "casm/misc/CASM_math.hh"
8 
9 namespace Eigen {
16 template <typename Derived>
17 typename Derived::PlainObject representation_prepare_impl(
18  Eigen::MatrixBase<Derived> const &obj, double _tol) {
19  typename Derived::PlainObject result =
20  typename Derived::PlainObject(CASM::reduced_column_echelon(obj, _tol)
21  .householderQr()
22  .householderQ())
23  .leftCols(obj.cols());
24  CASM::Index col = 0;
25  for (CASM::Index row = 0; row < result.rows(); ++row) {
26  CASM::Index i = 0;
27  for (i = col; i < result.cols(); ++i) {
28  if (!CASM::almost_zero(result(row, i), _tol)) {
29  result.col(i) *= std::abs(result(row, i)) / result(row, i);
30  ++col;
31  break;
32  }
33  }
34  }
35  return result;
36 }
37 } // namespace Eigen
38 
39 namespace CASM {
40 
42 template <typename Base>
44  return m_tol;
45 }
46 
48 template <typename Base>
51  return InvariantsType{obj};
52 }
53 
62 template <typename Base>
64  InvariantsType const &A_invariants,
65  InvariantsType const &B_invariants) const {
66  return CASM::compare(A_invariants, B_invariants, tol());
67 }
68 
74 template <typename Base>
76  const Element &B) const {
77  // std::cout << "Comparing \n " << A.transpose() << "\n " << B.transpose()
78  // << "\n\n";
79  bool result = colmajor_lex_compare(B, A, tol());
80  // std::cout << "RESULT: " << result << "\n\n";
81  return result;
82 }
83 
85 template <typename Base>
88  return obj;
89 }
90 
92 template <typename Base>
94  return m_spatial_transform;
95 }
96 
102 template <typename Base>
103 std::unique_ptr<SymOpRepresentation>
105  return std::unique_ptr<SymOpRepresentation>(
106  new SymMatrixXd(obj.colPivHouseholderQr().solve(
107  derived().representation_prepare_impl(obj))));
108 }
109 
116 template <typename Element, typename SymApply>
118  Element obj) const {
119  return representation_prepare_impl(obj, this->tol());
120 }
121 
122 } // namespace CASM
123 
124 #endif
CRTP Base class for Vector comparisons.
double tol() const
Return tolerance.
InvariantsType make_invariants_impl(Element const &obj) const
Make orbit invariants from one element in the orbit.
typename traits< MostDerived >::Element Element
bool invariants_compare_impl(InvariantsType const &A_invariants, InvariantsType const &B_invariants) const
Orders 'prepared' elements in the same orbit.
bool compare_impl(const Element &A, const Element &B) const
Compares 'prepared' elements.
std::unique_ptr< SymOpRepresentation > canonical_transform_impl(Element const &obj) const
Returns transformation that takes 'obj' to its prepared (canonical) form.
SymOp const & spatial_transform_impl() const
Spatial prepare does not apply – transform is always identity.
Element spatial_prepare_impl(Element obj) const
Spatial prepare does not apply – element is returned unchanged.
Element representation_prepare_impl(Element obj) const
Prepare an element for comparison by rotating, sorting, and changing sign of column vectors.
typename traits< MostDerived >::Element Element
Definition: SymCompare.hh:57
Generalized symmetry matrix representation for arbitrary dimension Can be used to describe applicatio...
Definition: SymMatrixXd.hh:26
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.
bool colmajor_lex_compare(const Eigen::MatrixBase< Derived > &A, const Eigen::MatrixBase< Derived > &B, double tol)
Floating point lexicographical comparison with tol.
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
Definition: CASM_math.hh:104
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Derived::PlainObject reduced_column_echelon(Eigen::MatrixBase< Derived > const &M, double _tol)
Derived::PlainObject representation_prepare_impl(Eigen::MatrixBase< Derived > const &obj, double _tol)
Prepare an element for comparison.