CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
LatticeIsEquivalent.cc
Go to the documentation of this file.
2 
3 #include "casm/symmetry/SymOp.hh"
4 
5 namespace CASM {
6 
8  m_lat(lat), m_tol(_tol) {}
9 
10 
13  Eigen::Matrix3d T = lat_column_mat().inverse() * B.lat_column_mat();
14  return is_unimodular(T, m_tol);
15  }
16 
18  bool LatticeIsEquivalent::operator()(const SymOp &op) const {
19  return (*this)(op.matrix());
20  }
21 
23  bool LatticeIsEquivalent::operator()(const Eigen::Matrix3d &cart_op) const {
24  Eigen::Matrix3d tfrac_op;
25 
26  tfrac_op = lat_column_mat().inverse() * cart_op * lat_column_mat();
27 
28  //Use a soft tolerance of 1% to see if further screening should be performed
29  if(!almost_equal(1.0, std::abs(tfrac_op.determinant()), 0.01) || !is_integer(tfrac_op, 0.01)) {
30  return false;
31  }
32 
33  //make tfrac_op integer.
34  for(int i = 0; i < 3; i++) {
35  for(int j = 0; j < 3; j++) {
36  tfrac_op(i, j) = round(tfrac_op(i, j));
37  }
38  }
39 
40  return _check(tfrac_op);
41  }
42 
44  bool LatticeIsEquivalent::operator()(const Eigen::Matrix3i &tfrac_op) const {
45 
46  //false if determinant is not 1, because it doesn't preserve volume
47  if(std::abs(tfrac_op.determinant()) != 1) {
48  return false;
49  }
50 
51  return _check(tfrac_op.cast<double>());
52  }
53 
55  return m_lat;
56  }
57 
59  return m_map_error;
60  }
61 
63  return m_cart_op;
64  }
65 
67  return SymOp(cart_op(), map_error());
68  }
69 
71  bool LatticeIsEquivalent::_check(const Eigen::Matrix3d &tfrac_op) const {
72 
73  // If symmetry is perfect, then -> cart_op * lat_column_mat() == lat_column_mat() * frac_op by definition
74  // If we assum symmetry is imperfect, then -> cart_op * lat_column_mat() == F * lat_column_mat() * frac_op
75  // where 'F' is the displacement gradient tensor imposed by frac_op
76  m_cart_op = lat_column_mat() * tfrac_op * inv_lat_column_mat();
77 
78  // tMat uses some matrix math to get F.transpose()*F*lat_column_mat();
79  Eigen::Matrix3d tMat = m_cart_op.transpose() * lat_column_mat() * tfrac_op;
80 
81  // Subtract lat_column_mat() from tMat, leaving us with (F.transpose()*F - Identity)*lat_column_mat().
82  // This is 2*E*lat_column_mat(), where E is the green-lagrange strain
83  tMat = (tMat - lat_column_mat()) / 2.0;
84 
85  //... and then multiplying by the transpose...
86  tMat = tMat * tMat.transpose();
87 
88  // The diagonal elements of tMat describe the square of the distance by which the transformed vectors 'miss' the original vectors
89  if(tMat(0, 0) < m_tol * m_tol && tMat(1, 1) < m_tol * m_tol && tMat(2, 2) < m_tol * m_tol) {
90  m_map_error = sqrt(tMat.diagonal().maxCoeff());
91  return true;
92  }
93  return false;
94  }
95 
97  return m_lat.lat_column_mat();
98  }
99 
101  return m_lat.inv_lat_column_mat();
102  }
103 
104 }
105 
SymOp sym_op() const
Return the SymOp, constructed from the map_error and cart_op stored after performing an equivalence c...
bool operator()(const Lattice &B) const
Is this lattice the same, even if they have different lattice vectors.
Main CASM namespace.
Definition: complete.cpp:8
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:104
const matrix_type & matrix() const
Const access of entire cartesian symmetry matrix.
Definition: SymOp.hh:57
const Eigen::Matrix3d & inv_lat_column_mat() const
Inverse of Lattice::lat_column_mat() It is the transformation matrix 'C2F', such that f = C2F * c whe...
Definition: Lattice.hh:113
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
const Lattice & lat() const
const Eigen::Matrix3d & lat_column_mat() const
LatticeIsEquivalent(const Lattice &lat, double _tol=TOL)
bool _check(const Eigen::Matrix3d &tfrac_op) const
Find the effect of applying symmetry to the lattice vectors.
bool is_integer(const Eigen::MatrixBase< Derived > &M, double tol)
Check if Eigen::Matrix is integer.
double map_error() const
Return the mapping error, calculated after performing an equivalence check.
Eigen::Matrix3d Matrix3d
const Eigen::Matrix3d & inv_lat_column_mat() const
Eigen::Matrix3d cart_op() const
Return the cartesian SymOp matrix, stored after performing an equivalence check.
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
int round(double val)
Definition: CASM_math.cc:6
bool is_unimodular(const Eigen::MatrixBase< Derived > &M, double tol)
Check if Eigen::Matrix is unimodular.