CASM  1.1.0
A Clusters Approach to Statistical Mechanics
VectorSymCompare_v2.cc
Go to the documentation of this file.
2 
4 #include "casm/misc/CASM_math.hh"
5 
6 namespace CASM {
7 
8 namespace SymRepTools_v2 {
9 
10 VectorInvariants::VectorInvariants(Eigen::VectorXcd const &vector)
11  : m_cols(vector.cols()), m_norm(vector.norm()) {}
12 
13 double VectorInvariants::cols() const { return m_cols; }
14 
15 double VectorInvariants::norm() const { return m_norm; }
16 
17 } // namespace SymRepTools_v2
18 
20  SymRepTools_v2::VectorInvariants const &B_invariants,
21  double tol) {
22  return A_invariants.cols() == B_invariants.cols() &&
23  almost_equal(A_invariants.norm(), B_invariants.norm(), tol);
24 }
25 
26 bool compare(SymRepTools_v2::VectorInvariants const &A_invariants,
27  SymRepTools_v2::VectorInvariants const &B_invariants, double tol) {
28  if (A_invariants.cols() == B_invariants.cols()) {
29  return CASM::compare(A_invariants.norm(), B_invariants.norm(), tol);
30  }
31  return A_invariants.cols() < B_invariants.cols();
32 }
33 
34 namespace SymRepTools_v2 {
35 
36 VectorSymCompare::VectorSymCompare(MatrixRep const &matrix_rep, double tol)
37  : m_matrix_rep(matrix_rep), m_tol(tol) {}
38 
39 // lexicographical comparison (reversed, uses vector_B < vector_A)
40 bool VectorSymCompare::compare(Eigen::VectorXcd const &vector_A,
41  Eigen::VectorXcd const &vector_B) const {
42  return colmajor_lex_compare(vector_B, vector_A, m_tol);
43 }
44 
45 // return VectorInvariants
47  Eigen::VectorXcd const &vector) const {
48  return VectorInvariants{vector};
49 }
50 
51 // apply matrix rep to vector
52 Eigen::VectorXcd VectorSymCompare::copy_apply(Index const &op_index,
53  Eigen::VectorXcd vector) const {
54  return m_matrix_rep[op_index] * vector;
55 }
56 
57 // no change needed to prepare for comparison
58 Eigen::VectorXcd VectorSymCompare::prepare(Eigen::VectorXcd vector) const {
59  return vector;
60 }
61 
62 // compare orbits by first comparing invariants, then orbit prototypes
64  Eigen::VectorXcd const &A_prototype, VectorInvariants const &A_invariants,
65  Eigen::VectorXcd const &B_prototype,
66  VectorInvariants const &B_invariants) const {
67  // first compare invariants
68  if (CASM::compare(A_invariants, B_invariants, m_tol)) {
69  return true;
70  }
71  if (CASM::compare(B_invariants, A_invariants, m_tol)) {
72  return false;
73  }
74 
75  // next compare A and B
76  return this->compare(A_prototype, B_prototype);
77 }
78 
79 namespace {
80 template <typename Derived>
81 typename Derived::PlainObject vector_space_prepare_impl(
82  Eigen::MatrixBase<Derived> const &obj, double _tol) {
83  typename Derived::PlainObject result =
84  typename Derived::PlainObject(CASM::reduced_column_echelon(obj, _tol)
85  .householderQr()
86  .householderQ())
87  .leftCols(obj.cols());
88  CASM::Index col = 0;
89  for (CASM::Index row = 0; row < result.rows(); ++row) {
90  CASM::Index i = 0;
91  for (i = col; i < result.cols(); ++i) {
92  if (!CASM::almost_zero(result(row, i), _tol)) {
93  result.col(i) *= std::abs(result(row, i)) / result(row, i);
94  ++col;
95  break;
96  }
97  }
98  }
99  return result;
100 }
101 } // namespace
102 
109 Eigen::MatrixXcd vector_space_prepare(Eigen::MatrixXcd const &vector_space,
110  double tol) {
111  return vector_space_prepare_impl(vector_space, tol);
112 }
113 
121  double tol) {
122  return vector_space_prepare_impl(vector_space, tol);
123 }
124 
125 } // namespace SymRepTools_v2
126 
127 } // namespace CASM
Used for generating SimpleOrbit of high symmetry direction vectors.
VectorInvariants(Eigen::VectorXcd const &vector)
T norm(const Tensor< T > &ttens)
Definition: Tensor.hh:932
Eigen::MatrixXcd vector_space_prepare(Eigen::MatrixXcd const &vector_space, double tol)
Vector space preparation for comparison.
std::vector< Eigen::MatrixXd > MatrixRep
Main CASM namespace.
Definition: APICommand.hh:8
bool almost_equal(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Check if ClusterInvariants are equal.
Eigen::MatrixXd MatrixXd
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)
VectorInvariants make_invariants(Eigen::VectorXcd const &vector) const
bool compare(Eigen::VectorXcd const &vector_A, Eigen::VectorXcd const &vector_B) const
bool inter_orbit_compare(Eigen::VectorXcd const &A_prototype, VectorInvariants const &A_invariants, Eigen::VectorXcd const &B_prototype, VectorInvariants const &B_invariants) const
VectorSymCompare(MatrixRep const &matrix_rep, double tol)
Eigen::VectorXcd copy_apply(Index const &op_index, Eigen::VectorXcd vector) const
Eigen::VectorXcd prepare(Eigen::VectorXcd vector) const