CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
PermuteIterator.cc
Go to the documentation of this file.
2 
4 
5 namespace CASM {
6 
8 
10  m_fg_permute_rep(iter.m_fg_permute_rep),
11  m_prim_grid(iter.m_prim_grid),
12  m_trans_permute(&(m_prim_grid->translation_permutations())),
13  m_factor_group_index(iter.m_factor_group_index),
14  m_translation_index(iter.m_translation_index) {
15 
16  }
17 
19  const PrimGrid &_prim_grid,
20  Index _factor_group_index,
21  Index _translation_index) :
22  m_fg_permute_rep(_fg_permute_rep),
23  m_prim_grid(&_prim_grid),
24  m_trans_permute(&(m_prim_grid->translation_permutations())),
25  m_factor_group_index(_factor_group_index),
26  m_translation_index(_translation_index) {
27  }
28 
30  swap(*this, iter);
31  return *this;
32  }
33 
36  return *this;
37  }
38 
42  }
43 
45  template<typename T>
46  ReturnArray<T> PermuteIterator::permute(const Array<T> &before_array) const {
47  assert(before_array.size() == factor_group_permute().size() && "WARNING: You're trying to permute an Array with an incompatible permutation!");
48 
49  Array<T> after_array;
50  after_array.reserve(before_array.size());
51 
52  for(int i = 0; i < before_array.size(); i++) {
53  after_array.push_back(permute_by_bit(i, before_array));
54  }
55  return after_array;
56  }
57 
60  return m_factor_group_index;
61  }
62 
65  return m_translation_index;
66  }
67 
71  }
72 
76  }
77 
79  return (*m_prim_grid).sym_op(m_translation_index) * m_fg_permute_rep.sym_op(m_factor_group_index);
80  }
81 
84  }
85 
87  template<typename T>
88  const T &PermuteIterator::permute_by_bit(Index i, const Array<T> &before_array) const {
89  return before_array[ factor_group_permute()[ translation_permute()[i] ] ];
90  }
91 
92  bool PermuteIterator::operator<(const PermuteIterator &iter) const {
93  if(this->factor_group_index() == iter.factor_group_index()) {
94  return this->translation_index() < iter.translation_index();
95  }
96  return this->factor_group_index() < iter.factor_group_index();
97  }
98 
99  bool PermuteIterator::_eq(const PermuteIterator &iter) const {
100  if(m_fg_permute_rep == iter.m_fg_permute_rep &&
101  m_prim_grid == iter.m_prim_grid &&
104  return true;
105  return false;
106  }
107 
108  // prefix ++PermuteIterator
111  if(m_translation_index == m_trans_permute->size()) {
114  }
115  return *this;
116  }
117 
118  // postfix PermuteIterator++
120  PermuteIterator cp(*this);
121  ++cp;
122  return cp;
123  }
124 
125  // prefix --PermuteIterator
127  if(m_translation_index == 0) {
130  }
132  return *this;
133  }
134 
135  // postfix PermuteIterator--
137  PermuteIterator cp(*this);
138  --cp;
139  return cp;
140  }
141 
143  PermuteIterator it(*this);
144  it.m_translation_index = 0;
146  return it;
147  }
148 
149  // Might be able to do this in a faster way, but would be much harder to understand
151  PermuteIterator it(*this);
152  // Finding the inverse factor_group operation is straightforward
154 
155  // Easiest way to get the new translation is just to compare the tau of the
156  // inverse of the 'total' sym_op (described by *this), to the inverse of the
157  // untranslated symop (described by m_fg_permute_rep.sym_op(it.m_factor_group_index))
158  // Result is the portion of the inverse sym_op that needs to be described by a prim_grid translation
161 
162  return it;
163  }
164 
166  PermuteIterator it(*this);
167  // Finding the inverse factor_group operation is straightforward
169 
170  // Easiest way to get the new translation is just to compare the tau of the
171  // 'total' sym_op (described by (*this).sym_op()*RHS.sym_op()), to the
172  // untranslated symop product (described by m_fg_permute_rep.sym_op(it.factor_group_index()))
173  // Result is the portion of the product sym_op that needs to be described by a prim_grid translation
175  m_prim_grid->find_cart((sym_op() * RHS.sym_op()).tau() - m_fg_permute_rep.sym_op(it.factor_group_index()).tau());
176 
177  return it;
178  }
179 
181  json.put_obj();
182  json["factgrp"] = m_factor_group_index;
183  json["trans"] = m_translation_index;
184  return json;
185  }
186 
188  CASM::from_json(m_factor_group_index, json["factgrp"]);
189  CASM::from_json(m_translation_index, json["trans"]);
190  }
191 
198  }
199 
201  return it.to_json(json);
202  }
203 
204  void from_json(PermuteIterator &it, const jsonParser &json) {
205  it.from_json(json);
206  }
207 
208 }
PrimGrid const * m_prim_grid
m_prim_grid holds permutation representation of lattice translations acting on sites of the supercell...
bool operator<(const PermuteIterator &iter) const
Index ind_prod(Index i, Index j) const
Definition: SymGroupRep.hh:253
void from_json(ClexDescription &desc, const jsonParser &json)
Index size() const
Definition: Array.hh:145
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
bool _eq(const PermuteIterator &iter) const
PermuteIterator & operator++()
void from_json(const jsonParser &json)
PermuteIterator & operator--()
Index permute_ind(Index i) const
PermuteIterator inverse() const
Main CASM namespace.
Definition: complete.cpp:8
const SymOp & sym_op(Index i) const
Definition: SymGroupRep.hh:245
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:195
const Permutation & factor_group_permute() const
Return the factor group permutation being pointed at.
void swap(PermuteIterator &a, PermuteIterator &b)
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
EigenIndex Index
For long integer indexing:
Index ind_inverse(Index i) const
Definition: SymGroupRep.hh:249
const T & permute_by_bit(Index i, const Array< T > &before_array) const
Return after_array[i], given i and before_array.
ReturnArray< T > permute(const Array< T > &before_array) const
Apply the combined factor_group permutation and translation permutation being pointed at...
const Permutation & translation_permute() const
Return the translation permutation being pointed at.
PermuteIterator begin_next_fg_op() const
const PermuteIterator & operator*() const
Returns the combination of factor_group permutation and translation permutation.
Index size() const
Definition: Permutation.hh:53
PermuteIterator & operator=(PermuteIterator iter)
Array< Permutation > const * m_trans_permute
m_trans_permute points to the Array of translation permutations inside of m_prim_grid (t...
Permutation const * get_permutation(Index i) const
Definition: SymGroupRep.cc:265
jsonParser & put_obj()
Puts new empty JSON object.
Definition: jsonParser.hh:276
void reserve(Index new_max)
Definition: Array.hh:491
Index translation_index() const
Return the index into m_prim_grid of the translation being pointed at.
friend void swap(PermuteIterator &a, PermuteIterator &b)
jsonParser & to_json(jsonParser &json) const
Index factor_group_index() const
Return the index into m_factor_group_permute of the factor group op being pointed at...
Index find_cart(const Eigen::Ref< const Eigen::Vector3d > &_cart_coord) const
Definition: PrimGrid.cc:171
Basic std::vector like container (deprecated)
Permutation combined_permute() const
Returns the combination of factor_group permutation and translation permutation.
SymGroupRep::RemoteHandle m_fg_permute_rep
permutation representation of factor group acting on sites of the supercell