CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SuperlatticeEnumerator.hh
Go to the documentation of this file.
1 #ifndef SuperlatticeEnumerator_HH
2 #define SuperlatticeEnumerator_HH
3 
7 #include "casm/external/Eigen/Dense"
9 
10 // Including this file allows passing arbitrary
11 // symmetry types from the outside without requiring
12 // conversion.
14 
15 namespace CASM {
16 namespace xtal {
17 
30  public:
31  typedef long size_type;
32 
48  std::string dirs = "abc",
49  Eigen::Matrix3i generating_matrix = Eigen::Matrix3i::Identity())
52  m_dims(dirs.size()),
53  m_dirs(dirs) {
54  if (begin_volume < 1) {
55  std::string msg = "Error constructing ScelEnumProps: begin_volume < 1";
56  throw std::invalid_argument(msg);
57  }
58 
59  for (int i = 0; i < m_dirs.size(); i++) {
60  if (m_dirs[i] != 'a' && m_dirs[i] != 'b' && m_dirs[i] != 'c') {
61  std::string msg =
62  "Error constructing ScelEnumProps: an element of dirs != 'a', 'b', "
63  "or 'c'";
64  throw std::invalid_argument(msg);
65  }
66  }
67 
68  // add missing directions to 'dirs',
69  // then permute 'G' so that the specified 'dirs' are first
70  while (m_dirs.size() != 3) {
71  if (std::find(m_dirs.begin(), m_dirs.end(), 'a') == m_dirs.end()) {
72  m_dirs.push_back('a');
73  }
74  if (std::find(m_dirs.begin(), m_dirs.end(), 'b') == m_dirs.end()) {
75  m_dirs.push_back('b');
76  }
77  if (std::find(m_dirs.begin(), m_dirs.end(), 'c') == m_dirs.end()) {
78  m_dirs.push_back('c');
79  }
80  }
81  Eigen::Matrix3i P = Eigen::Matrix3i::Zero();
82  P(m_dirs[0] - 'a', 0) = 1;
83  P(m_dirs[1] - 'a', 1) = 1;
84  P(m_dirs[2] - 'a', 2) = 1;
85 
87  }
88 
90 
91  size_type end_volume() const { return m_end_volume; }
92 
93  int dims() const { return m_dims; }
94 
95  std::string dirs() const { return m_dirs; }
96 
97  Eigen::Matrix3i generating_matrix() const { return m_gen_mat; }
98 
99  private:
102  int m_dims;
103  std::string m_dirs;
104  Eigen::Matrix3i m_gen_mat;
105 };
106 
107 //******************************************************************************************************************//
108 
110 
115 
117  public:
119  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
120 
121  typedef std::forward_iterator_tag iterator_category;
122  typedef int difference_type;
124  typedef const Lattice &reference;
125  typedef const Lattice *pointer;
126 
128 
130  int dims);
131 
132  // required for all iterators
133  // SuperlatticeIterator<UnitType>(const SuperlatticeIterator<UnitType> &B);
134 
135  // required for all iterators?
137 
139  bool operator==(const SuperlatticeIterator &B) const;
140 
142  bool operator!=(const SuperlatticeIterator &B) const;
143 
145  reference operator*() const;
146 
148  pointer operator->() const;
149 
151  Eigen::Matrix3i matrix() const;
152 
155 
158  const SuperlatticeEnumerator &enumerator() const;
159 
162 
164  // SuperlatticeIterator<UnitType> operator++(int); TODO
165 
166  private:
168  void _increment();
169 
172  // bool _is_canonical() const;
173 
177 
180 
183  mutable bool m_super_updated;
184 
188 
191 
194  mutable Lattice m_super;
195 
197  std::vector<Eigen::Matrix3i> m_canon_hist;
198 };
199 
203 
205  public:
206  typedef long int size_type;
207 
209 
220  SuperlatticeEnumerator(const Lattice &unit, const SymOpVector &point_grp,
221  const ScelEnumProps &enum_props);
222 
227  template <typename ExternSymGroupTypeIt>
228  SuperlatticeEnumerator(ExternSymGroupTypeIt begin, ExternSymGroupTypeIt end,
229  const Lattice &unit, const ScelEnumProps &enum_props)
231  unit,
232  adapter::Adapter<SymOpVector, ExternSymGroupTypeIt>()(begin, end),
233  enum_props) {}
234 
236  const Lattice &unit() const;
237 
239  const SymOpVector &point_group() const;
240 
242  void begin_volume(size_type _begin_volume);
243 
245  size_type begin_volume() const;
246 
248  void end_volume(size_type _end_volume);
249 
251  size_type end_volume() const;
252 
255  const Eigen::Matrix3i &gen_mat() const;
256 
258  int dimension() const;
259 
262  const_iterator begin() const;
263 
265  const_iterator end() const;
266 
268  const_iterator cbegin() const;
269 
271  const_iterator cend() const;
272 
275 
276  private:
279 
281  /* Lattice m_lat; */
282 
285 
287  const int m_begin_volume;
288 
291  const int m_end_volume;
292 
296  const Eigen::Matrix3i m_gen_mat;
297 
299  const int m_dims;
300 };
301 
302 //********************************************************************************************************//
303 
321 Eigen::Matrix3i enforce_min_volume(const Lattice &unit,
322  const Eigen::Matrix3i &T,
323  const SymOpVector &point_grp, Index volume,
324  bool fix_shape = false);
325 
326 template <typename ExternSymGroupTypeIt>
327 Eigen::Matrix3i enforce_min_volume(ExternSymGroupTypeIt begin,
328  ExternSymGroupTypeIt end,
329  const Lattice &unit,
330  const Eigen::Matrix3i &T, Index volume,
331  bool fix_shape = false) {
332  return enforce_min_volume(
333  unit, T,
335  fix_shape);
336 }
337 
352 // that has a lattice ref_lat (not to be confused with the point group
353 // of ref_lat itself).
379 Eigen::Matrix3i canonical_hnf(const Eigen::Matrix3i &T,
380  const SymOpVector &effective_pg,
381  const Lattice &ref_lattice);
382 template <typename ExternSymGroupTypeIt>
383 Eigen::Matrix3i canonical_hnf(ExternSymGroupTypeIt begin,
384  ExternSymGroupTypeIt end,
385  const Eigen::Matrix3i &T,
386  const Lattice &ref_lattice) {
387  return canonical_hnf(
389  ref_lattice);
390 }
391 
392 } // namespace xtal
393 } // namespace CASM
394 
395 #endif
Eigen::VectorXi::Scalar value_type
Data structure for holding supercell enumeration properties.
A fake container of supercell matrices.
Iterators used with SuperlatticeEnumerator.
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
SuperlatticeEnumerator(ExternSymGroupTypeIt begin, ExternSymGroupTypeIt end, const Lattice &unit, const ScelEnumProps &enum_props)
bool operator!=(const SuperlatticeIterator &B) const
Iterator comparison.
const_iterator end() const
A const iterator to the past-the-last volume.
const_iterator cend() const
A const iterator to the past-the-last volume.
Lattice m_super
A supercell, stored here so that iterator dereferencing will be OK. Only used when requested.
const Eigen::Matrix3i & gen_mat() const
Get the transformation matrix that's being applied to the unit vectors.
SuperlatticeIterator & operator=(const SuperlatticeIterator &B)
const SuperlatticeEnumerator & enumerator() const
const reference to the SuperlatticeEnumerator this is iterating with
void end_volume(size_type _end_volume)
Set the end volume.
Eigen::Matrix3i matrix() const
constructed supercell matrix
const Lattice m_unit
The unit cell of the supercells.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::forward_iterator_tag iterator_category
fixes alignment of m_deformation
Eigen::Matrix3i generating_matrix() const
int dimension() const
Get the dimensions of the enumerator (1D, 2D or 3D)
const int m_dims
The number of lattice directions the enumeration is being done in.
bool operator==(const SuperlatticeIterator &B) const
Iterator comparison.
size_type begin_volume() const
Get the beginning volume.
Eigen::Matrix3i canonical_hnf(const Eigen::Matrix3i &T, const SymOpVector &effective_pg, const Lattice &ref_lattice)
Return canonical hermite normal form of the supercell matrix.
void _update_super()
Update m_super when required.
HermiteCounter::value_type volume() const
current volume
const Eigen::Matrix3i m_gen_mat
This matrix (G) specifies new lattice vectors to enumerate over column-wise, such that the resulting ...
std::vector< Eigen::Matrix3i > m_canon_hist
Keep track of the HNF matrices for the current determinant value.
pointer operator->() const
Access the supercell.
Eigen::Matrix3i enforce_min_volume(const Lattice &unit, const Eigen::Matrix3i &T, const SymOpVector &point_grp, Index volume, bool fix_shape=false)
Return a transformation matrix that ensures a supercell of at least some volume.
const int m_end_volume
The past-the-last volume supercells to be iterated over (what cend uses)
const_iterator citerator(size_type volume) const
A const iterator to a specified volume.
const Lattice & unit() const
Access the unit the is being made into superlattices.
const_iterator cbegin() const
A const iterator to the beginning volume.
void _try_increment()
Check if the current supercell matrix hermite normal form is in a canonical form.
SuperlatticeIterator & operator++()
Prefix increment operator. Increment to next unique supercell.
bool m_super_updated
Indicates if m_super reflects the current m_current supercell matrix.
SuperlatticeEnumerator(const Lattice &unit, const SymOpVector &point_grp, const ScelEnumProps &enum_props)
Construct a SuperlatticeEnumerator using custom point group operations.
const_iterator begin() const
A const iterator to the beginning volume, specify here how the iterator should jump through the enume...
reference operator*() const
Access the supercell.
size_type end_volume() const
Get the end volume.
const int m_begin_volume
The first volume supercells to be iterated over (what cbegin uses)
notstd::cloneable_ptr< HermiteCounter > m_current
Current supercell matrix in HermitCounter form.
void begin_volume(size_type _begin_volume)
Set the beginning volume.
const SuperlatticeEnumerator * m_enum
Pointer to SuperlatticeEnumerator which holds the unit cell and point group.
SymOpVector m_point_group
The lattice of the unit cell.
ScelEnumProps(size_type begin_volume, size_type end_volume, std::string dirs="abc", Eigen::Matrix3i generating_matrix=Eigen::Matrix3i::Identity())
Constructor.
const SymOpVector & point_group() const
Access the unit point group.
void _increment()
Postfix increment operator. Increment to next unique supercell.
double volume(const Lattice &lat)
Returns the volume of a Lattice.
Definition: Lattice.hh:281
IdentitySymRepBuilder Identity()
std::vector< SymOp > SymOpVector
Main CASM namespace.
Definition: APICommand.hh:8
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
Definition: algorithm.hh:16
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39