CASM  1.1.0
A Clusters Approach to Statistical Mechanics
SubClusterGenerator.hh
Go to the documentation of this file.
1 #ifndef CASM_SubClusterGenerator
2 #define CASM_SubClusterGenerator
3 
4 #include <boost/iterator/iterator_facade.hpp>
5 
8 
9 namespace CASM {
10 
16 template <typename ClusterType>
18  : public boost::iterator_facade<SubClusterGenerator<ClusterType>,
19  ClusterType, boost::forward_traversal_tag> {
20  public:
23 
25  explicit SubClusterGenerator(const ClusterType &clust)
26  : m_cluster(notstd::make_unique<ClusterType>(clust)),
27  m_current_valid(false),
28  m_current(notstd::make_unique<ClusterType>(clust)),
29  m_site_counter(std::vector<int>(m_cluster->size(), 0),
30  std::vector<int>(m_cluster->size(), 1),
31  std::vector<int>(m_cluster->size(), 1)) {}
32 
33  private:
35 
36  void increment() {
38  m_current_valid = false;
39  }
40 
41  bool equal(const SubClusterGenerator &other) const {
42  if (valid() && other.valid()) {
43  return std::equal(m_site_counter.value_begin(),
45  other.m_site_counter.value_begin());
46  }
47  if (!valid() && !other.valid()) {
48  return true;
49  }
50  return false;
51  }
52 
53  ClusterType &dereference() const {
54  // lazy construction of 'm_current'
55  if (!m_current_valid) {
56  m_current->elements().clear();
57  for (Index i = 0; i < m_site_counter.size(); ++i) {
58  if (m_site_counter()[i]) {
59  m_current->elements().push_back(m_cluster->element(i));
60  }
61  }
62  }
63  return *m_current;
64  }
65 
66  bool valid() const {
67  if (!m_cluster || !m_site_counter.valid()) {
68  return false;
69  }
70  return m_site_counter.valid();
71  }
72 
73  private:
76 
79 
82 
85 };
86 } // namespace CASM
87 
88 #endif
size_type size() const
Definition: BaseCounter.hh:178
bool valid() const
Definition: BaseCounter.hh:160
const_value_iterator value_begin() const
Definition: BaseCounter.hh:180
const_value_iterator value_end() const
Definition: BaseCounter.hh:184
A Counter allows looping over many incrementing variables in one loop.
Definition: Counter.hh:109
Generates subclusters of a cluster with an iterator-like interface.
notstd::cloneable_ptr< ClusterType > m_current
The current subcluster.
ClusterType & dereference() const
bool m_current_valid
for lazy construction of m_current
bool equal(const SubClusterGenerator &other) const
Counter< std::vector< int > > m_site_counter
Indicates which sites to include (1) or not include (0) in the subcluster.
SubClusterGenerator(const ClusterType &clust)
Construt with the cluster to find subclusters of.
notstd::cloneable_ptr< ClusterType > m_cluster
the cluster we're finding subclusters of
friend class boost::iterator_core_access
SubClusterGenerator()
Default construtor.
Main CASM namespace.
Definition: APICommand.hh:8
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Non-std smart pointer classes and functions.
std::unique_ptr< T > make_unique(Args &&... args)
c++17 does not include 'make_unique'
Definition: stream_io.hh:24