CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
OccCandidate.hh
Go to the documentation of this file.
1 #ifndef CASM_OccCandidate_HH
2 #define CASM_OccCandidate_HH
3 
4 #include <vector>
5 #include <tuple>
6 #include <utility>
9 
10 namespace CASM {
11 
12  class jsonParser;
13  template<typename T> struct jsonConstructor;
14 
15  namespace Monte {
16 
17  class Conversions;
18 
19  struct OccCandidate : public Comparisons<OccCandidate> {
20 
21  OccCandidate(Index _asym, Index _species_index) :
22  asym(_asym),
23  species_index(_species_index) {}
24 
27 
28  bool operator<(OccCandidate B) const {
29  if(asym != B.asym) {
30  return asym < B.asym;
31  }
32  return species_index < B.species_index;
33  }
34  };
35 
36  jsonParser &to_json(const OccCandidate &cand, const Conversions &convert, jsonParser &json);
37 
38  }
39 
40  template<>
41  struct jsonConstructor<Monte::OccCandidate> {
42  static Monte::OccCandidate from_json(const jsonParser &json, const Monte::Conversions &convert);
43  };
44 
45  namespace Monte {
46 
47  std::ostream &operator<<(std::ostream &sout, std::pair<const OccCandidate &, const Conversions &> value);
48 
49 
51  class OccSwap : public Comparisons<OccSwap> {
52 
53  public:
54 
55  OccSwap(const OccCandidate &_cand_a, const OccCandidate &_cand_b) :
56  cand_a(_cand_a),
57  cand_b(_cand_b) {}
58 
61 
62  void reverse() {
63  using std::swap;
64  std::swap(cand_a, cand_b);
65  }
66 
68  OccSwap B(*this);
69  B.reverse();
70 
71  if(B._lt(*this)) {
72  *this = B;
73  }
74  return *this;
75  }
76 
77  OccSwap sorted() const {
78  OccSwap res(*this);
79  res.sort();
80  return res;
81  }
82 
83  bool operator<(const OccSwap &B) const {
84  return this->sorted()._lt(B.sorted());
85  }
86 
87 
88  private:
89 
90  bool _lt(const OccSwap &B) const {
91  return this->tuple() < B.tuple();
92  }
93 
94  typedef std::tuple<OccCandidate, OccCandidate> tuple_type;
95 
96  tuple_type tuple() const {
97  return std::make_tuple(cand_a, cand_b);
98  }
99 
100  };
101 
102  jsonParser &to_json(const OccSwap &swap, const Conversions &convert, jsonParser &json);
103  }
104 
105  template<>
106  struct jsonConstructor<Monte::OccSwap> {
107  static Monte::OccSwap from_json(const jsonParser &json, const Monte::Conversions &convert);
108  };
109 
110  namespace Monte {
111 
112  std::ostream &operator<<(std::ostream &sout, std::pair<const OccSwap &, const Conversions &> value);
113 
114 
117 
118  public:
119 
120  typedef std::vector<OccCandidate>::const_iterator const_iterator;
121 
123 
124  OccCandidateList(const Conversions &convert);
125 
127  Index index(const OccCandidate &cand) const {
128  return m_species_to_cand_index[cand.asym][cand.species_index];
129  }
130 
132  Index index(Index asym, Index species_index) const {
133  return m_species_to_cand_index[asym][species_index];
134  }
135 
136  const OccCandidate &operator[](Index candidate_index) const {
137  return m_candidate[candidate_index];
138  }
139 
140  const_iterator begin() const {
141  return m_candidate.begin();
142  }
143 
144  const_iterator end() const {
145  return m_candidate.end();
146  }
147 
148  Index size() const {
149  return m_end;
150  }
151 
152  const std::vector<OccSwap> &canonical_swap() const {
153  return m_canonical_swap;
154  }
155 
156  const std::vector<OccSwap> &grand_canonical_swap() const {
157  return m_grand_canonical_swap;
158  }
159 
160  private:
161 
163  void _make_possible_swaps(const Conversions &convert);
164 
166  std::vector<std::vector<Index> > m_species_to_cand_index;
167 
168  std::vector<OccCandidate> m_candidate;
169 
172 
174  std::vector<OccSwap> m_canonical_swap;
175 
177  std::vector<OccSwap> m_grand_canonical_swap;
178 
179  };
180 
181  jsonParser &to_json(const OccCandidateList &list, const Conversions &convert, jsonParser &json);
182 
183  std::ostream &operator<<(std::ostream &sout, std::pair<const OccCandidateList &, const Conversions &> value);
184  }
185 }
186 
187 #endif
std::vector< OccSwap > m_grand_canonical_swap
vector of allowed grand canonical swaps
const_iterator begin() const
Index index(Index asym, Index species_index) const
Return index into std::vector, or _candidate.size() if not allowed. ...
OccSwap(const OccCandidate &_cand_a, const OccCandidate &_cand_b)
Definition: OccCandidate.hh:55
Implements other comparisons in terms of '<'.
Definition: Comparisons.hh:23
void _make_possible_swaps(const Conversions &convert)
Construct m_canonical_swaps, m_grand_canonical_swaps.
Definition: OccCandidate.cc:95
bool operator<(const OccSwap &B) const
Definition: OccCandidate.hh:83
const std::vector< OccSwap > & canonical_swap() const
std::vector< OccSwap > m_canonical_swap
vector of allowed canonical swaps
OccCandidate cand_b
Definition: OccCandidate.hh:60
jsonParser & to_json(const CanonicalConditions &conditions, jsonParser &json)
Store CanonicalConditions in JSON format.
Definition: CanonicalIO.cc:102
Main CASM namespace.
Definition: complete.cpp:8
OccCandidate cand_a
Definition: OccCandidate.hh:59
std::vector< OccCandidate > m_candidate
const_iterator end() const
std::tuple< OccCandidate, OccCandidate > tuple_type
Definition: OccCandidate.hh:94
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:195
EigenIndex Index
For long integer indexing:
Store swap type, mutating sites, and info for keeping OccLocation up-to-date.
Definition: OccCandidate.hh:51
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.
Definition: jsonParser.hh:489
bool operator<(OccCandidate B) const
Definition: OccCandidate.hh:28
List of asym / species_index pairs indicating allowed variable occupation dof.
Index m_end
Number of allowed candidates, what is returned if a candidate is not allowed.
OccCandidate(Index _asym, Index _species_index)
Definition: OccCandidate.hh:21
bool _lt(const OccSwap &B) const
Definition: OccCandidate.hh:90
Helper struct for constructing objects that need additional data.
Definition: jsonParser.hh:486
tuple_type tuple() const
Definition: OccCandidate.hh:96
const OccCandidate & operator[](Index candidate_index) const
Index index(const OccCandidate &cand) const
Return index into std::vector, or _candidate.size() if not allowed. ...
OccSwap sorted() const
Definition: OccCandidate.hh:77
std::vector< std::vector< Index > > m_species_to_cand_index
m_converter[asym][species_index] -> candidate_index
const std::vector< OccSwap > & grand_canonical_swap() const
std::vector< OccCandidate >::const_iterator const_iterator