CASM  1.1.0
A Clusters Approach to Statistical Mechanics
OccCandidate.hh
Go to the documentation of this file.
1 #ifndef CASM_OccCandidate_HH
2 #define CASM_OccCandidate_HH
3 
4 #include <tuple>
5 #include <utility>
6 #include <vector>
7 
10 
11 namespace CASM {
12 
13 class jsonParser;
14 template <typename T>
15 struct jsonConstructor;
16 
17 } // namespace CASM
18 
19 namespace CASM {
20 namespace Monte {
21 
22 class Conversions;
23 struct OccCandidate;
24 class OccSwap;
25 
26 } // namespace Monte
27 } // namespace CASM
28 
29 namespace CASM {
30 
31 template <>
32 struct jsonConstructor<Monte::OccCandidate> {
33  static Monte::OccCandidate from_json(const jsonParser &json,
34  const Monte::Conversions &convert);
35 };
36 
37 template <>
38 struct jsonConstructor<Monte::OccSwap> {
39  static Monte::OccSwap from_json(const jsonParser &json,
40  const Monte::Conversions &convert);
41 };
42 } // namespace CASM
43 
44 namespace CASM {
45 namespace Monte {
46 
47 struct OccCandidate : public Comparisons<CRTPBase<OccCandidate>> {
48  OccCandidate(Index _asym, Index _species_index)
49  : asym(_asym), species_index(_species_index) {}
50 
53 
54  bool operator<(OccCandidate B) const {
55  if (asym != B.asym) {
56  return asym < B.asym;
57  }
58  return species_index < B.species_index;
59  }
60 };
61 
62 jsonParser &to_json(const OccCandidate &cand, const Conversions &convert,
63  jsonParser &json);
64 
65 std::ostream &operator<<(
66  std::ostream &sout,
67  std::pair<const OccCandidate &, const Conversions &> value);
68 
71 class OccSwap : public Comparisons<CRTPBase<OccSwap>> {
72  public:
73  OccSwap(const OccCandidate &_cand_a, const OccCandidate &_cand_b)
74  : cand_a(_cand_a), cand_b(_cand_b) {}
75 
78 
79  void reverse() {
80  using std::swap;
82  }
83 
85  OccSwap B(*this);
86  B.reverse();
87 
88  if (B._lt(*this)) {
89  *this = B;
90  }
91  return *this;
92  }
93 
94  OccSwap sorted() const {
95  OccSwap res(*this);
96  res.sort();
97  return res;
98  }
99 
100  bool operator<(const OccSwap &B) const {
101  return this->sorted()._lt(B.sorted());
102  }
103 
104  private:
105  bool _lt(const OccSwap &B) const { return this->tuple() < B.tuple(); }
106 
107  typedef std::tuple<OccCandidate, OccCandidate> tuple_type;
108 
109  tuple_type tuple() const { return std::make_tuple(cand_a, cand_b); }
110 };
111 
112 jsonParser &to_json(const OccSwap &swap, const Conversions &convert,
113  jsonParser &json);
114 
115 std::ostream &operator<<(std::ostream &sout,
116  std::pair<const OccSwap &, const Conversions &> value);
117 
121  public:
122  typedef std::vector<OccCandidate>::const_iterator const_iterator;
123 
125 
126  OccCandidateList(const Conversions &convert);
127 
130  Index index(const OccCandidate &cand) const {
131  return m_species_to_cand_index[cand.asym][cand.species_index];
132  }
133 
136  Index index(Index asym, Index species_index) const {
137  return m_species_to_cand_index[asym][species_index];
138  }
139 
140  const OccCandidate &operator[](Index candidate_index) const {
141  return m_candidate[candidate_index];
142  }
143 
144  const_iterator begin() const { return m_candidate.begin(); }
145 
146  const_iterator end() const { return m_candidate.end(); }
147 
148  Index size() const { return m_end; }
149 
150  const std::vector<OccSwap> &canonical_swap() const {
151  return m_canonical_swap;
152  }
153 
154  const std::vector<OccSwap> &grand_canonical_swap() const {
155  return m_grand_canonical_swap;
156  }
157 
158  private:
160  void _make_possible_swaps(const Conversions &convert);
161 
163  std::vector<std::vector<Index>> m_species_to_cand_index;
164 
165  std::vector<OccCandidate> m_candidate;
166 
170 
172  std::vector<OccSwap> m_canonical_swap;
173 
175  std::vector<OccSwap> m_grand_canonical_swap;
176 };
177 
178 jsonParser &to_json(const OccCandidateList &list, const Conversions &convert,
179  jsonParser &json);
180 
181 std::ostream &operator<<(
182  std::ostream &sout,
183  std::pair<const OccCandidateList &, const Conversions &> value);
184 
185 } // namespace Monte
186 } // namespace CASM
187 
188 #endif
void _make_possible_swaps(const Conversions &convert)
Construct m_canonical_swaps, m_grand_canonical_swaps.
std::vector< OccCandidate >::const_iterator const_iterator
const OccCandidate & operator[](Index candidate_index) const
std::vector< std::vector< Index > > m_species_to_cand_index
m_converter[asym][species_index] -> candidate_index
Index index(const OccCandidate &cand) const
const std::vector< OccSwap > & canonical_swap() const
const_iterator begin() const
std::vector< OccSwap > m_canonical_swap
vector of allowed canonical swaps
const std::vector< OccSwap > & grand_canonical_swap() const
Index index(Index asym, Index species_index) const
std::vector< OccSwap > m_grand_canonical_swap
vector of allowed grand canonical swaps
const_iterator end() const
std::vector< OccCandidate > m_candidate
Store swap type, mutating sites, and info for keeping OccLocation up-to-date.
Definition: OccCandidate.hh:71
bool _lt(const OccSwap &B) const
OccCandidate cand_a
Definition: OccCandidate.hh:76
OccCandidate cand_b
Definition: OccCandidate.hh:77
std::tuple< OccCandidate, OccCandidate > tuple_type
tuple_type tuple() const
OccSwap sorted() const
Definition: OccCandidate.hh:94
OccSwap(const OccCandidate &_cand_a, const OccCandidate &_cand_b)
Definition: OccCandidate.hh:73
bool operator<(const OccSwap &B) const
jsonParser & to_json(const CanonicalConditions &conditions, jsonParser &json)
Store CanonicalConditions in JSON format.
Definition: CanonicalIO.cc:102
std::ostream & operator<<(std::ostream &sout, const CanonicalConditions &cond)
Main CASM namespace.
Definition: APICommand.hh:8
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:260
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
OccCandidate(Index _asym, Index _species_index)
Definition: OccCandidate.hh:48
bool operator<(OccCandidate B) const
Definition: OccCandidate.hh:54
Helper struct for constructing objects that need additional data.
Definition: jsonParser.hh:548
static ReturnType from_json(const jsonParser &json)
Default from_json is equivalent to.
Definition: jsonParser.hh:551
Implements other comparisons in terms of '<'.
Definition: Comparisons.hh:25