CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
MonteCounter.cc
Go to the documentation of this file.
2 
5 
6 namespace CASM {
7 
8  // ---- MonteCounter Definitions ---------------------------------
9 
12  m_steps_per_pass(_steps_per_pass) {
13 
14  // --- If not in 'must converge mode' -----
15 
16  if(((int) settings.is_N_step()) + ((int) settings.is_N_pass()) + ((int) settings.is_N_sample()) > 1) {
17  throw std::runtime_error(
18  std::string("Error in MonteCounter constructor\n") +
19  " Zero or one of 'N_step', 'N_pass', and 'N_sample' should be given");
20  }
21 
23  if(settings.is_N_step()) {
24  m_is_N_step = settings.is_N_step();
25  m_N_step = settings.N_step();
26  }
27 
29  if(settings.is_N_pass()) {
30  m_is_N_pass = settings.is_N_pass();
31  m_N_pass = settings.N_pass();
32  }
33 
35  if(settings.is_N_sample()) {
36  m_is_N_sample = settings.is_N_sample();
37  m_N_sample = settings.N_sample();
38  }
39 
40 
41  // --- Imposed limits ------------
42 
44  if(settings.is_max_step()) {
45  m_is_max_step = true;
46  m_max_step = settings.max_step();
47  }
48 
50  if(settings.is_min_step()) {
51  m_is_min_step = true;
52  m_min_step = settings.min_step();
53  }
54 
56  if(settings.is_max_pass()) {
57  m_is_max_pass = true;
58  m_max_pass = settings.max_pass();
59  }
60 
62  if(settings.is_min_pass()) {
63  m_is_min_pass = true;
64  m_min_pass = settings.min_pass();
65  }
66 
68  if(settings.is_max_sample()) {
69  m_is_max_sample = true;
70  m_max_sample = settings.max_sample();
71  }
72 
74  if(settings.is_min_sample()) {
75  m_is_min_sample = true;
76  m_min_sample = settings.min_sample();
77  }
78 
79 
80  // --- Periods at which certain things should happen --------
81 
84 
86  m_sample_period = settings.sample_period();
87 
88  }
89 
90 
92  return m_pass;
93  }
94 
96  return m_step;
97  }
98 
99 
102  return m_steps_per_pass;
103  }
104 
105 
107  return m_samples;
108  }
109 
110 
112  m_samples++;
114  }
115 
116 
118  m_pass = 0;
119  m_step = 0;
120 
121  m_samples = 0;
122 
124 
125  return;
126  }
127 
129  void MonteCounter::set(size_type _pass, size_type _step, size_type _samples) {
130 
131  reset();
132 
133  m_pass = _pass;
134  m_step = _step;
135 
136  m_samples = _samples;
137 
138  }
139 
140 
143  return true;
144  }
145  return false;
146  }
147 
150 
151  ++m_step;
152  if(m_step == m_steps_per_pass) {
153  ++m_pass;
154  m_step = 0;
155 
158  }
159  }
160 
163  }
164 
165  return *this;
166  }
167 
170 
171  MonteCounter init(*this);
172 
173  ++(*this);
174 
175  return init;
176  }
177 
178 
181  if(m_is_N_step && step() >= m_N_step) {
182  return true;
183  }
184  if(m_is_N_pass && pass() >= m_N_pass) {
185  return true;
186  }
187  if(m_is_N_sample && samples() >= m_N_sample) {
188  return true;
189  }
190  return false;
191  }
192 
195 
197  return false;
198  }
199 
200  if(m_is_min_pass && (m_pass < m_min_pass)) {
201  return false;
202  }
203 
205  return false;
206  }
207 
208  return true;
209  }
210 
213 
215  return true;
216  }
217 
218  if(m_is_max_pass && (m_pass >= m_max_pass)) {
219  return true;
220  }
221 
223  return true;
224  }
225 
226  return false;
227  }
228 
229  void MonteCounter::debugprint(std::ostream &sout) const {
230  sout << "pass: " << m_pass << "\n";
231  sout << "step: " << m_step << "\n";
232  sout << "samples: " << m_samples << "\n";
233  sout << "since_last_sample: " << m_since_last_sample << "\n";
234  sout << "is_max_pass: " << m_is_max_pass << "\n";
235  sout << "m_max_pass: " << m_max_pass << "\n\n";
236 
237  sout << "is_min_pass: " << m_is_min_pass << "\n";
238  sout << "m_min_pass: " << m_min_pass << "\n\n";
239 
240  sout << "is_max_step: " << m_is_max_step << "\n";
241  sout << "m_max_step: " << m_max_step << "\n\n";
242 
243  sout << "is_min_step: " << m_is_min_step << "\n";
244  sout << "m_min_step: " << m_min_step << "\n\n";
245 
246  sout << "is_max_sample: " << m_is_max_sample << "\n";
247  sout << "m_max_sample: " << m_max_sample << "\n\n";
248 
249  sout << "is_min_sample: " << m_is_min_sample << "\n" << std::endl;
250  sout << "m_min_sample: " << m_min_sample << "\n\n" << std::endl;
251 
252  }
253 
254 
255 }
256 
bool is_N_step() const
Returns true if the number of steps has been specified.
bool minimums_met() const
Check if minimum number of pass, step, and samples has been met.
size_type m_step
Number of steps taken during the current pass.
Definition: MonteCounter.hh:86
bool is_max_step() const
Returns true if a maximum number of steps has been specified.
void increment_samples()
Increments the number of samples taken and resets counter until the next sample should be taken...
MonteCounter & operator++()
Prefix increment step and updates pass.
size_type min_step() const
Minimum number of steps, default 0 if sample by step.
size_type m_min_sample
size_type max_step() const
Maximum number of steps, required if sample by step.
Monte::SAMPLE_MODE m_sample_mode
Whether sampling mode is by Monte::SAMPLE_MODE::PASS or Monte::SAMPLE_MODE::STEP. ...
bool sample_by_pass() const
Sample by pass?
size_type N_step() const
Returns the number of steps requested.
void debugprint(std::ostream &sout) const
bool is_complete() const
Check if requested number of pass, step, or samples has been met.
bool m_is_max_pass
Maximum allowed number of passes.
Main CASM namespace.
Definition: complete.cpp:8
size_type m_since_last_sample
Number of passes or steps since last sample.
Definition: MonteCounter.hh:94
bool m_is_N_step
Requested number of steps.
Definition: MonteCounter.hh:99
size_type sample_period() const
Figure out how often to take samples.
bool m_is_max_sample
Maximum allowed number of samples to take.
bool is_max_pass() const
Returns true if a maximum number of passes has been specified.
size_type min_pass() const
Minimum number of passes, default 0 if sample by pass.
bool m_is_N_sample
Requested number of samples.
Track the number of passes, steps and samples taken in a Monte Carlo calculation. ...
Definition: MonteCounter.hh:20
bool is_N_sample() const
Returns true if the number of samples has been specified.
size_type pass() const
Number of complete passes performed.
Definition: MonteCounter.cc:91
size_type min_sample() const
Minimum number of steps, default 0.
bool maximums_met() const
Check if maximum number of pass, step, and samples has been met.
bool is_min_step() const
Returns true if a minimum number of steps has been specified.
void reset()
Set all counter variables back to 0.
int m_steps_per_pass
Number of steps per pass is equal to the number of sites with variable degrees of freedom in the supe...
bool is_N_pass() const
Returns true if the number of passes has been specified.
bool is_min_pass() const
Returns true if a minimum number of passes has been specified.
bool m_is_min_step
Minimum allowed number of steps.
size_type N_sample() const
Returns the number of samples requested.
size_type m_pass
One pass is equal to the number of sites with variable degrees of freedom in the supercell.
Definition: MonteCounter.hh:83
size_type step() const
Number of steps into the current pass.
Definition: MonteCounter.cc:95
bool sample_time() const
Returns true if based on period and current number of steps it is time to take a sample.
bool is_min_sample() const
Returns true if a minimum number of samples has been specified.
MonteCounter(const EquilibriumMonteSettings &settings, size_type _steps_per_pass)
Construct a MonteCounter and initialize to all counts to zero.
Definition: MonteCounter.cc:11
int m_sample_period
How often to sample data. In terms of m_sample_mode. If == 1 sample every pass/step.
bool m_is_min_sample
Minimum allowed number of samples to take.
bool m_is_min_pass
Minimum allowed number of passes.
size_type samples() const
Number of samples taken.
size_type m_max_sample
bool m_is_N_pass
Requested number of passes.
size_type steps_per_pass() const
Number of steps per pass.
size_type N_pass() const
Returns the number of passes requested.
void set(size_type _pass, size_type _step, size_type _samples)
Set all counter variables for performing a restart.
size_type m_samples
Number of data samples taken.
Definition: MonteCounter.hh:90
size_type max_sample() const
Maximum number of steps, default std::numeric_limit::max()
size_type max_pass() const
Maximum number of passes, required if sample by pass.
bool is_max_sample() const
Returns true if a maximum number of samples has been specified.
bool m_is_max_step
Maximum allowed number of steps.