CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
EnumEquivalents.hh
Go to the documentation of this file.
1 #ifndef CASM_EnumEquivalents
2 #define CASM_EnumEquivalents
3 
6 
7 namespace CASM {
8 
19  template <
20  typename ObjectType,
21  typename SymOpIterator,
22  typename SymOpType,
23  typename SymOpCompare >
25 
26  namespace CASM_TMP {
27 
28  template <
29  typename ObjectType,
30  typename SymOpIterator,
31  typename SymOpType,
32  typename SymOpCompare >
33  struct traits<EnumEquivalents<ObjectType, SymOpIterator, SymOpType, SymOpCompare> > {
34  static const std::string name;
35  };
36 
37  }
38 
48  template <
49  typename ObjectType,
50  typename SymOpIterator,
51  typename SymOpType = typename std::iterator_traits<SymOpIterator>::value_type,
52  typename SymOpCompare = std::less<SymOpType> >
53  class EnumEquivalents : public InputEnumeratorBase<ObjectType> {
54 
55  // -- Required members -------------------
56 
57  public:
58 
76  template<typename MakeInvariantSubgroup>
77  EnumEquivalents(const ObjectType &generating_obj,
78  SymOpIterator begin,
79  SymOpIterator end,
80  MakeInvariantSubgroup f = MakeInvariantSubgroup(),
81  SymOpCompare compare = SymOpCompare()) :
82  m_initial(notstd::clone(generating_obj)),
84  m_symop_it(begin),
85  m_symop_end(end),
87 
88  f(generating_obj, begin, end, std::back_inserter(m_invariant_subgroup));
89 
90  this->_initialize(&(*m_current));
91 
92  if(!_check(*m_symop_it)) {
93  increment();
94  }
95 
96  // set step to 0
97  if(this->valid()) {
98  this->_set_step(0);
99  }
100  }
101 
102 
103  public:
104 
105  // -- Unique -------------------
106 
107  const ObjectType &generator() const {
108  return *m_initial;
109  }
110 
111  const SymOpType &sym_op() const {
112  return *m_symop_it;
113  }
114 
115  const std::vector<SymOpType> &invariant_subgroup() const {
116  return m_invariant_subgroup;
117  }
118 
119  private:
120 
121  // -- Required members -------------------
122 
124  void increment() override {
125 
126  while(++m_symop_it != m_symop_end && !_check(*m_symop_it)) {
127  // increment
128  }
129  if(m_symop_it == m_symop_end) {
130  this->_invalidate();
131  }
132  else {
133 
134  // generate equivalent by applying symop
136 
137  // increment
138  this->_increment_step();
139  }
140  }
141 
142  // -- Unique -------------------
143 
146  bool _check(const SymOpType &X) const {
147  return std::none_of(
150  [&](const SymOpType & Bi) {
151  return m_compare(X * Bi, X);
152  });
153  }
154 
157  SymOpIterator m_symop_it;
158  SymOpIterator m_symop_end;
159  std::vector<SymOpType> m_invariant_subgroup;
160  SymOpCompare m_compare;
161  };
162 
163  namespace CASM_TMP {
164 
165  template <
166  typename ObjectType,
167  typename SymOpIterator,
168  typename SymOpType,
169  typename SymOpCompare >
170  const std::string traits<EnumEquivalents<ObjectType, SymOpIterator, SymOpType, SymOpCompare> >::name = "EnumEquivalents";
171 
172  }
173 
174 }
175 
176 #endif
bool compare(const T &A, const T &B, double tol)
Floating point comparison with tol, return A < B.
Definition: CASM_math.hh:89
Object copy_apply(const Transform &f, Object obj, Args &&...args)
void increment() override
Implement increment.
EnumEquivalents(const ObjectType &generating_obj, SymOpIterator begin, SymOpIterator end, MakeInvariantSubgroup f=MakeInvariantSubgroup(), SymOpCompare compare=SymOpCompare())
Constructor.
const ObjectType & generator() const
Base class for implementing specialized input enumerators.
Main CASM namespace.
Definition: complete.cpp:8
std::vector< SymOpType > m_invariant_subgroup
notstd::cloneable_ptr< ObjectType > m_initial
void _invalidate()
Call if enumeration complete.
Definition: Enumerator.hh:169
std::unique_ptr< T > clone(const T &obj, typename std::enable_if< has_clone< T >::value, T >::type *=nullptr)
const std::vector< SymOpType > & invariant_subgroup() const
bool valid() const
Returns false if enumeration is complete.
Definition: Enumerator.hh:118
Non-std smart pointer classes and functions.
const SymOpType & sym_op() const
void _set_step(step_type val)
Set current step value.
Definition: Enumerator.hh:154
Enumerate over all equivalents.
void _increment_step()
Increment current step value.
Definition: Enumerator.hh:159
bool _check(const SymOpType &X) const
notstd::cloneable_ptr< ObjectType > m_current