CASM  1.1.0
A Clusters Approach to Statistical Mechanics
IntegralCoordinateWithin.cc
Go to the documentation of this file.
2 
3 #include <exception>
4 #include <stdexcept>
5 #include <string>
6 #include <vector>
7 
10 #include "casm/external/Eigen/Core"
11 #include "casm/global/eigen.hh"
12 
13 namespace CASM {
14 namespace xtal {
15 
17  const matrix_type &transformation_matrix) {
18  if (transformation_matrix.determinant() == 0) {
19  throw std::runtime_error(
20  "The transformation matrix that converts the tiling unit to the "
21  "superlattice is singular, and therefore not valid.");
22  }
23  return;
24 }
25 
27  const vector_type &ijk) const {
29  long vol = this->m_transformation_matrix
30  .determinant(); // this volume is signed, could be negative,
31  // that's fine.
32  vec2[0] = ((vec2[0] % vol) + std::abs(vol)) % vol;
33  vec2[1] = ((vec2[1] % vol) + std::abs(vol)) % vol;
34  vec2[2] = ((vec2[2] % vol) + std::abs(vol)) % vol;
35  return (this->m_transformation_matrix * vec2) / vol;
36 }
37 
39  const UnitCellCoord &bijk) const {
40  return UnitCellCoord(bijk.sublattice(), this->operator()(bijk.unitcell()));
41 }
42 
43 //********************************************************************************************************************************//
44 
45 namespace impl {
47  const matrix_type &transformation_matrix)
48  : m_bring_within_f(transformation_matrix),
49  m_total_lattice_points(std::abs(transformation_matrix.determinant())) {
50  smith_normal_form(transformation_matrix, this->m_smith_normal_U,
51  this->m_smith_normal_S, this->m_smith_normal_V);
52 
53  vector_type S_diagonal = this->m_smith_normal_S.diagonal();
54 
55  m_stride[0] = S_diagonal[0];
56  m_stride[1] = S_diagonal[0] * S_diagonal[1];
57 
58  assert(transformation_matrix ==
60 }
61 
64  const vector_type &mnp) const {
65  vector_type ijk = m_smith_normal_U * mnp;
66  return m_bring_within_f(ijk);
67 }
68 
71  Index ix) const {
72  vector_type mnp((ix % m_stride[1]) % m_stride[0],
73  (ix % m_stride[1]) / m_stride[0], ix / m_stride[1]);
74  return mnp;
75 }
76 
79  if (ix < 0 || ix >= this->m_total_lattice_points) {
80  throw std::runtime_error(
81  "Lattice point index out of range! Specified index " +
82  std::to_string(ix) + " when there are " +
83  std::to_string(m_total_lattice_points) + " lattice sites.");
84  }
85 
86  auto mnp = this->_make_smith_normal_form_lattice_point(ix);
87  return this->_normalize_lattice_point(mnp);
88 }
89 
90 std::vector<UnitCell> make_lattice_points(
91  const OrderedLatticePointGenerator::matrix_type &transformation_matrix) {
92  std::vector<UnitCell> all_lattice_points;
93  OrderedLatticePointGenerator generate_point(transformation_matrix);
94 
95  auto total_lattice_points = generate_point.size();
96 
97  for (int i = 0; i < total_lattice_points; ++i) {
98  all_lattice_points.emplace_back(generate_point(i));
99  }
100 
101  return all_lattice_points;
102 }
103 
104 } // namespace impl
105 
106 //********************************************************************************************************************************//
107 
108 std::vector<UnitCell> make_lattice_points(
109  const Eigen::Matrix3l &transformation_matrix) {
110  return impl::make_lattice_points(transformation_matrix);
111 }
112 
113 std::vector<UnitCell> make_lattice_points(const Lattice &tiling_unit,
114  const Lattice &superlattice,
115  double tol) {
116  Eigen::Matrix3l transformation_matrix =
117  make_transformation_matrix_to_super(tiling_unit, superlattice, tol);
118  return make_lattice_points(transformation_matrix);
119 }
120 
121 } // namespace xtal
122 } // namespace CASM
vector_type operator()(const vector_type &ijk) const
Brings the given lattice point within the superlattice.
static void _throw_if_bad_transformation_matrix(const matrix_type &transformation_matrix)
Throws exception if the transformation matrix has determinant 0.
Unit Cell Coordinates.
const UnitCell & unitcell() const
IntegralCoordinateWithin_f::vector_type vector_type
vector_type _make_smith_normal_form_lattice_point(Index ix) const
vector_type _normalize_lattice_point(const vector_type &mnp) const
IntegralCoordinateWithin_f::matrix_type matrix_type
OrderedLatticePointGenerator(const matrix_type &transformation_matrix)
long int size() const
Returns the total number of unique lattice points that can be generated.
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
void smith_normal_form(const Eigen::MatrixBase< DerivedIn > &M, Eigen::MatrixBase< DerivedOut > &U, Eigen::MatrixBase< DerivedOut > &S, Eigen::MatrixBase< DerivedOut > &V)
Return the smith normal form, M == U*S*V.
std::vector< UnitCell > make_lattice_points(const OrderedLatticePointGenerator::matrix_type &transformation_matrix)
std::vector< UnitCell > make_lattice_points(const Eigen::Matrix3l &transformation_matrix)
Eigen::Matrix3l make_transformation_matrix_to_super(const Lattice &tiling_unit, const Lattice &superlattice, double tol)
Definition: Lattice.cc:848
Main CASM namespace.
Definition: APICommand.hh:8
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Matrix< long int, 3, 3 > Matrix3l
Definition: eigen.hh:12
Definition: stream_io.hh:24