AlmaBTE  1.3
A solver of the space- and time-dependent Boltzmann transport equation for phonons
symmetry.hpp
Go to the documentation of this file.
1 // Copyright 2015-2018 The ALMA Project Developers
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 // implied. See the License for the specific language governing
13 // permissions and limitations under the License.
14 
15 #pragma once
16 
20 
21 #include <structures.hpp>
22 
23 namespace alma {
28 public:
30  const std::array<std::size_t, 2> pair;
32  const std::size_t operation;
34  const bool exchange;
36  Transformed_pair(std::size_t a,
37  std::size_t b,
38  std::size_t _operation,
39  bool _exchange)
40  : pair({{a, b}}), operation(_operation), exchange(_exchange) {
41  }
42 };
43 
44 
48 public:
50  const double symprec;
56  Symmetry_operations(const Crystal_structure& structure,
57  double _symprec = 1e-5);
59  std::size_t get_nsym() const {
60  return this->translations.size();
61  }
63  int get_spacegroup_number() const {
64  return this->sg_number;
65  }
67  std::string get_spacegroup_symbol() const {
68  return this->sg_symbol;
69  }
70 
71 
73  std::string get_wyckoff() const {
74  return this->wyckoff;
75  }
77  std::vector<int> get_equivalences() const {
78  return this->equivalences;
79  }
80 
81 
90  template <typename T>
91  auto transform_v(const Eigen::MatrixBase<T>& vector,
92  std::size_t index,
93  bool cartesian = false) const
94  -> Eigen::Matrix<typename T::Scalar, Eigen::Dynamic, Eigen::Dynamic> {
95  if (index >= this->translations.size())
96  throw alma::value_error("invalid operation index");
97 
98  if (cartesian)
99  return this->crotations[index] * vector +
100  this->ctranslations[index];
101  else
102  return this->rotations[index] * vector + this->translations[index];
103  }
104 
105 
114  template <typename T>
115  auto rotate_v(const Eigen::MatrixBase<T>& vector,
116  std::size_t index,
117  bool cartesian = false) const
118  -> Eigen::Matrix<typename T::Scalar, Eigen::Dynamic, Eigen::Dynamic> {
119  if (index >= this->translations.size())
120  throw alma::value_error("invalid operation index");
121 
122  if (cartesian)
123  return this->crotations[index] * vector;
124  else
125  return this->rotations[index] * vector;
126  }
127 
128 
137  template <typename T>
138  Eigen::Matrix<T, 3, 3> rotate_m(
139  const Eigen::Ref<const Eigen::Matrix<T, 3, 3>>& matrix,
140  std::size_t index,
141  bool cartesian = false) const {
142  if (index >= this->translations.size())
143  throw alma::value_error("invalid operation index");
144 
145  if (cartesian)
146  return this->crotations[index] * matrix *
147  this->crotations[index].transpose();
148  else
149  return this->rotations[index] * matrix *
150  this->rotations[index].transpose();
151  }
152 
153 
162  template <typename T>
163  Eigen::Matrix<T, 3, 3> unrotate_m(
164  const Eigen::Ref<const Eigen::Matrix<T, 3, 3>>& matrix,
165  std::size_t index,
166  bool cartesian = false) const {
167  if (index >= this->translations.size())
168  throw alma::value_error("invalid operation index");
169 
170  if (cartesian)
171  return this->crotations[index].transpose() * matrix *
172  this->crotations[index];
173  else
174  return this->rotations[index].transpose() * matrix *
175  this->rotations[index];
176  }
177 
178 
185  std::size_t map_atom(std::size_t original, std::size_t index) const {
186  if (original >= this->symmetry_map.size())
187  throw alma::value_error("invalid atom index");
188 
189  if (index >= this->translations.size())
190  throw alma::value_error("invalid operation index");
191  return this->symmetry_map[original][index];
192  }
193 
194 
200  bool is_inversion(std::size_t index) const {
201  return this->determinants[index] < 0.;
202  }
203 
204 
211  template <typename T>
212  auto rotate_q(const Eigen::MatrixBase<T>& vector, std::size_t index) const
213  -> Eigen::Matrix<typename T::Scalar, Eigen::Dynamic, Eigen::Dynamic> {
214  if (index >= this->translations.size())
215  throw alma::value_error("invalid operation index");
216  return this->qrotations[index] * vector;
217  }
218 
225  template <typename T>
226  Eigen::Matrix<T, 3, 3> symmetrize_m(
227  const Eigen::Ref<const Eigen::Matrix<T, 3, 3>>& matrix,
228  bool cartesian = false) const {
229  Eigen::Matrix<T, 3, 3> nruter;
230  nruter.fill(0.);
231  const std::vector<Eigen::MatrixXd>* rots;
232  if (cartesian) {
233  rots = &this->crotations;
234  }
235  else {
236  rots = &this->rotations;
237  }
238  for (const auto& r : *rots) {
239  nruter += r.transpose() * matrix * r;
240  }
241  nruter /= rots->size();
242  return nruter;
243  }
244 
250  std::vector<std::vector<Transformed_pair>> get_pair_classes() const;
251 
252 private:
254  std::vector<Eigen::VectorXd> translations;
256  std::vector<Eigen::VectorXd> ctranslations;
258  std::vector<Eigen::MatrixXd> rotations;
260  std::vector<Eigen::MatrixXd> crotations;
262  std::vector<Eigen::MatrixXd> qrotations;
264  std::vector<double> determinants;
267  std::vector<Eigen::MatrixXd> displacements;
269  int sg_number;
271  std::string sg_symbol;
273  std::string wyckoff;
276  std::vector<int> equivalences;
278  std::vector<std::vector<std::size_t>> symmetry_map;
281  void fill_map(const Crystal_structure& structure);
282 };
283 } // namespace alma
POD class used to hold a pair of atom indices and a symmetry operation.
Definition: symmetry.hpp:27
int get_spacegroup_number() const
Definition: symmetry.hpp:63
Definition: analytic1d.hpp:26
auto rotate_v(const Eigen::MatrixBase< T > &vector, std::size_t index, bool cartesian=false) const -> Eigen::Matrix< typename T::Scalar, Eigen::Dynamic, Eigen::Dynamic >
Rotate (but do not translate) a vector according to one of the symmetry operations.
Definition: symmetry.hpp:115
std::size_t map_atom(std::size_t original, std::size_t index) const
Get the atom index that an atom is mapped to through a symmetry operation.
Definition: symmetry.hpp:185
std::string get_wyckoff() const
Definition: symmetry.hpp:73
Exception related to the parameters passed to a function.
Definition: exceptions.hpp:33
const bool exchange
True if an additional exchange of indices is necessary.
Definition: symmetry.hpp:34
Eigen::Matrix< T, 3, 3 > symmetrize_m(const Eigen::Ref< const Eigen::Matrix< T, 3, 3 >> &matrix, bool cartesian=false) const
Symmetrize a 3x3 matrix using all the operations in the group.
Definition: symmetry.hpp:226
Eigen::Matrix< T, 3, 3 > rotate_m(const Eigen::Ref< const Eigen::Matrix< T, 3, 3 >> &matrix, std::size_t index, bool cartesian=false) const
Rotate a 3 x 3 matrix according to one of the symmetry operations.
Definition: symmetry.hpp:138
Transformed_pair(std::size_t a, std::size_t b, std::size_t _operation, bool _exchange)
Basic constructor.
Definition: symmetry.hpp:36
std::size_t get_nsym() const
Definition: symmetry.hpp:59
bool is_inversion(std::size_t index) const
Find out if a symmetry operation involves an inversion.
Definition: symmetry.hpp:200
Definitions of the basic data-handling classes in ALMA.
Objects of this class hold a subset of the information provided by spg_get_dataset().
Definition: symmetry.hpp:47
const double symprec
Tolerance for the symmetry search.
Definition: symmetry.hpp:50
auto transform_v(const Eigen::MatrixBase< T > &vector, std::size_t index, bool cartesian=false) const -> Eigen::Matrix< typename T::Scalar, Eigen::Dynamic, Eigen::Dynamic >
Transform a vector according to one of the symmetry operations.
Definition: symmetry.hpp:91
Hold information about a crystal structure.
Definition: structures.hpp:51
std::vector< int > get_equivalences() const
Definition: symmetry.hpp:77
Eigen::Matrix< T, 3, 3 > unrotate_m(const Eigen::Ref< const Eigen::Matrix< T, 3, 3 >> &matrix, std::size_t index, bool cartesian=false) const
Rotate a 3 x 3 matrix according to the inverse of one of the symmetry operations. ...
Definition: symmetry.hpp:163
auto rotate_q(const Eigen::MatrixBase< T > &vector, std::size_t index) const -> Eigen::Matrix< typename T::Scalar, Eigen::Dynamic, Eigen::Dynamic >
Rotate a vector expressed in direct reciprocal coordinates according to one of the symmetry operation...
Definition: symmetry.hpp:212
const std::size_t operation
Index of a symmetry operation.
Definition: symmetry.hpp:32
const std::array< std::size_t, 2 > pair
Pair of atom indices.
Definition: symmetry.hpp:30
std::string get_spacegroup_symbol() const
Definition: symmetry.hpp:67