CASM  1.1.0
A Clusters Approach to Statistical Mechanics
LinearIndexConverter.hh
Go to the documentation of this file.
1 #ifndef LINEARINDEXCONVERTER_HH
2 #define LINEARINDEXCONVERTER_HH
3 
4 #include <unordered_map>
5 #include <vector>
6 
9 
10 namespace CASM {
11 namespace xtal {
12 
27  public:
29 
33  UnitCellCoordIndexConverter(const matrix_type &transformation_matrix,
34  int basis_sites_in_prim)
36  impl::OrderedLatticePointGenerator(transformation_matrix),
37  basis_sites_in_prim)),
38  m_basis_sites_in_prim(basis_sites_in_prim),
40  m_bring_within_f(transformation_matrix) {
42 
43  for (Index ix = 0; ix < m_linear_index_to_bijk.size(); ++ix) {
44  const auto &bijk = m_linear_index_to_bijk[ix];
45  m_bijk_to_linear_index[bijk] = ix;
46  }
47 
48  // By default the construction will always allow receiving bijk values that
49  // fall outside of the superlattice
50  this->always_bring_within();
51  }
52 
55  void never_bring_within();
56 
59  void always_bring_within();
60 
63  UnitCellCoord bring_within(const UnitCellCoord &bijk) const;
64 
66  const UnitCellCoord &operator()(Index ix) const;
67 
70  Index operator()(const UnitCellCoord &bijk) const;
71 
73  Index total_sites() const { return m_linear_index_to_bijk.size(); }
74 
75  private:
77  std::vector<UnitCellCoord> m_linear_index_to_bijk;
78 
80  std::unordered_map<UnitCellCoord, Index> m_bijk_to_linear_index;
81 
84  mutable std::unordered_map<UnitCellCoord, Index>
86 
90 
94 
97 
99  void _throw_if_incompatible_index(Index ix) const;
100 
105  void _throw_if_incompatible_bijk(const UnitCellCoord &bijk) const;
106 
110  static std::vector<UnitCellCoord> _make_all_ordered_bijk_values(
111  const impl::OrderedLatticePointGenerator &make_point,
112  int basis_sites_in_prim);
113 
116  static void _throw_if_bad_basis_sites_in_prim(int basis_sites_in_prim);
117 };
118 
132  public:
134  UnitCellIndexConverter(const matrix_type &transformation_matrix)
135  : UnitCellCoordIndexConverter(transformation_matrix, 1) {}
136 
140 
142  UnitCell bring_within(const UnitCell &ijk) const {
144  .unitcell();
145  }
146 
148  const UnitCell &operator()(Index ix) const {
150  }
151 
154  Index operator()(const UnitCell &ijk) const {
156  }
157 
158  private:
159  // TODO:
160  // Secretly cache things to "speed things up" if you're *really* that
161  // concerned about the UnitCellCoord copies slowing you down. Don't implement
162  // this until you've profiled it.
163 };
164 
172 template <typename IntegralCoordinateType>
174 
175 template <>
178 };
179 
180 template <>
183 };
184 
185 template <typename IntegralCoordinateType>
188 
189 } // namespace xtal
190 } // namespace CASM
191 
192 #endif
Unit Cell Coordinates.
const UnitCell & unitcell() const
UnitCellCoord bring_within(const UnitCellCoord &bijk) const
UnitCellCoordIndexConverter(const matrix_type &transformation_matrix, int basis_sites_in_prim)
std::vector< UnitCellCoord > m_linear_index_to_bijk
Convert from linear index to UnitCellCoord.
void _throw_if_incompatible_index(Index ix) const
Throws exception if the specified index is out of the allowed range.
impl::OrderedLatticePointGenerator::matrix_type matrix_type
static void _throw_if_bad_basis_sites_in_prim(int basis_sites_in_prim)
void _throw_if_incompatible_bijk(const UnitCellCoord &bijk) const
std::unordered_map< UnitCellCoord, Index > m_bijk_to_linear_index
Convert from UnitCellCoord to linear index.
std::unordered_map< UnitCellCoord, Index > m_bijk_to_linear_index_outside_of_superlattice
static std::vector< UnitCellCoord > _make_all_ordered_bijk_values(const impl::OrderedLatticePointGenerator &make_point, int basis_sites_in_prim)
Index total_sites() const
Returns the total number of sites within the superlattice.
const UnitCellCoord & operator()(Index ix) const
Given the linear index, retreive the corresponding UnitCellCoord.
IntegralCoordinateWithin_f m_bring_within_f
Functor to bring UnitCellCoord values back into the superlattice.
Unit Cell Indices.
UnitCell bring_within(const UnitCell &ijk) const
Bring the given UnitCell into the superlattice using lattice translations.
UnitCellIndexConverter(const matrix_type &transformation_matrix)
UnitCellCoordIndexConverter::matrix_type matrix_type
const UnitCell & operator()(Index ix) const
Given the linear index, retreive the corresponding UnitCell.
Index operator()(const UnitCell &ijk) const
IntegralCoordinateWithin_f::matrix_type matrix_type
typename _LinearIndexConverter< IntegralCoordinateType >::type LinearIndexConverter
Main CASM namespace.
Definition: APICommand.hh:8
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39