CASM  1.1.0
A Clusters Approach to Statistical Mechanics
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 <typename ObjectType, typename SymOpIterator, typename SymOpType,
20  typename SymOpCompare>
21 class EnumEquivalents;
22 
23 template <typename ObjectType, typename SymOpIterator, typename SymOpType,
24  typename SymOpCompare>
25 struct traits<
26  EnumEquivalents<ObjectType, SymOpIterator, SymOpType, SymOpCompare> > {
27  static const std::string name;
28 };
29 
39 template <typename ObjectType, typename SymOpIterator,
40  typename SymOpType =
41  typename std::iterator_traits<SymOpIterator>::value_type,
42  typename SymOpCompare = std::less<SymOpType> >
43 class EnumEquivalents : public InputEnumeratorBase<ObjectType> {
44  // -- Required members -------------------
45 
46  public:
64  template <typename MakeInvariantSubgroup>
65  EnumEquivalents(const ObjectType &generating_obj, SymOpIterator begin,
66  SymOpIterator end,
67  MakeInvariantSubgroup f = MakeInvariantSubgroup(),
68  SymOpCompare compare = SymOpCompare())
69  : m_initial(notstd::clone(generating_obj)),
74  f(generating_obj, begin, end, std::back_inserter(m_invariant_subgroup));
75 
76  this->_initialize(&(*m_current));
77 
78  if (!_check(*m_symop_it)) {
79  increment();
80  }
81 
82  // set step to 0
83  if (this->valid()) {
84  this->_set_step(0);
85  }
86  }
87 
88  public:
89  // -- Unique -------------------
90 
91  const ObjectType &generator() const { return *m_initial; }
92 
93  const SymOpType &sym_op() const { return *m_symop_it; }
94 
95  const std::vector<SymOpType> &invariant_subgroup() const {
96  return m_invariant_subgroup;
97  }
98 
99  private:
100  // -- Required members -------------------
101 
103  void increment() override {
104  while (++m_symop_it != m_symop_end && !_check(*m_symop_it)) {
105  // increment
106  }
107  if (m_symop_it == m_symop_end) {
108  this->_invalidate();
109  } else {
110  // generate equivalent by applying symop
112 
113  // increment
114  this->_increment_step();
115  }
116  }
117 
118  // -- Unique -------------------
119 
122  bool _check(const SymOpType &X) const {
123  return std::none_of(
125  [&](const SymOpType &Bi) { return m_compare(X * Bi, X); });
126  }
127 
130  SymOpIterator m_symop_it;
131  SymOpIterator m_symop_end;
132  std::vector<SymOpType> m_invariant_subgroup;
133  SymOpCompare m_compare;
134 };
135 
136 template <typename ObjectType, typename SymOpIterator, typename SymOpType,
137  typename SymOpCompare>
138 const std::string traits<EnumEquivalents<ObjectType, SymOpIterator, SymOpType,
139  SymOpCompare> >::name =
140  "EnumEquivalents";
141 
142 } // namespace CASM
143 
144 #endif
Enumerate over all equivalents.
Base class for implementing specialized input enumerators.
bool valid() const
Returns false if enumeration is complete.
Definition: Enumerator.hh:118
void _invalidate()
Call if enumeration complete.
Definition: Enumerator.hh:159
void _increment_step()
Increment current step value.
Definition: Enumerator.hh:153
void _set_step(step_type val)
Set current step value.
Definition: Enumerator.hh:150
const SymOpType & sym_op() const
const ObjectType & generator() const
EnumEquivalents(const ObjectType &generating_obj, SymOpIterator begin, SymOpIterator end, MakeInvariantSubgroup f=MakeInvariantSubgroup(), SymOpCompare compare=SymOpCompare())
Constructor.
void increment() override
Implement increment.
bool _check(const SymOpType &X) const
notstd::cloneable_ptr< ObjectType > m_initial
std::vector< SymOpType > m_invariant_subgroup
notstd::cloneable_ptr< ObjectType > m_current
const std::vector< SymOpType > & invariant_subgroup() const
Main CASM namespace.
Definition: APICommand.hh:8
bool compare(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Compare ClusterInvariants.
MappingNode copy_apply(PermuteIterator const &_it, MappingNode const &_node, bool transform_cost_mat=true)
Reorders the permutation and compounds the spatial isometry (rotation.
GenericDatumFormatter< std::string, DataObject > name()
Non-std smart pointer classes and functions.
std::unique_ptr< T > clone(const T &obj)