CASM  1.1.0
A Clusters Approach to Statistical Mechanics
MonteCounter.cc
Go to the documentation of this file.
2 
5 
6 namespace CASM {
7 namespace Monte {
8 
9 // ---- MonteCounter Definitions ---------------------------------
10 
13  size_type _steps_per_pass)
14  : m_steps_per_pass(_steps_per_pass) {
15  // --- If not in 'must converge mode' -----
16 
17  if (((int)settings.is_N_step()) + ((int)settings.is_N_pass()) +
18  ((int)settings.is_N_sample()) >
19  1) {
20  throw std::runtime_error(
21  std::string("Error in MonteCounter constructor\n") +
22  " Zero or one of 'N_step', 'N_pass', and 'N_sample' should be given");
23  }
24 
26  if (settings.is_N_step()) {
27  m_is_N_step = settings.is_N_step();
28  m_N_step = settings.N_step();
29  }
30 
32  if (settings.is_N_pass()) {
33  m_is_N_pass = settings.is_N_pass();
34  m_N_pass = settings.N_pass();
35  }
36 
38  if (settings.is_N_sample()) {
39  m_is_N_sample = settings.is_N_sample();
40  m_N_sample = settings.N_sample();
41  }
42 
43  // --- Imposed limits ------------
44 
46  if (settings.is_max_step()) {
47  m_is_max_step = true;
48  m_max_step = settings.max_step();
49  }
50 
52  if (settings.is_min_step()) {
53  m_is_min_step = true;
54  m_min_step = settings.min_step();
55  }
56 
58  if (settings.is_max_pass()) {
59  m_is_max_pass = true;
60  m_max_pass = settings.max_pass();
61  }
62 
64  if (settings.is_min_pass()) {
65  m_is_min_pass = true;
66  m_min_pass = settings.min_pass();
67  }
68 
70  if (settings.is_max_sample()) {
71  m_is_max_sample = true;
72  m_max_sample = settings.max_sample();
73  }
74 
76  if (settings.is_min_sample()) {
77  m_is_min_sample = true;
78  m_min_sample = settings.min_sample();
79  }
80 
81  // --- Periods at which certain things should happen --------
82 
87 
90  m_sample_period = settings.sample_period();
91 }
92 
94 
96 
99  return m_steps_per_pass;
100 }
101 
103 
105  m_samples++;
107 }
108 
110  m_pass = 0;
111  m_step = 0;
112 
113  m_samples = 0;
114 
116 
117  return;
118 }
119 
121 void MonteCounter::set(size_type _pass, size_type _step, size_type _samples) {
122  reset();
123 
124  m_pass = _pass;
125  m_step = _step;
126 
127  m_samples = _samples;
128 }
129 
132  return true;
133  }
134  return false;
135 }
136 
139  ++m_step;
140  if (m_step == m_steps_per_pass) {
141  ++m_pass;
142  m_step = 0;
143 
146  }
147  }
148 
151  }
152 
153  return *this;
154 }
155 
158  MonteCounter init(*this);
159 
160  ++(*this);
161 
162  return init;
163 }
164 
167  if (m_is_N_step && step() >= m_N_step) {
168  return true;
169  }
170  if (m_is_N_pass && pass() >= m_N_pass) {
171  return true;
172  }
173  if (m_is_N_sample && samples() >= m_N_sample) {
174  return true;
175  }
176  return false;
177 }
178 
182  return false;
183  }
184 
185  if (m_is_min_pass && (m_pass < m_min_pass)) {
186  return false;
187  }
188 
190  return false;
191  }
192 
193  return true;
194 }
195 
198  if (m_is_max_sample && (m_samples >= m_max_sample)) {
199  return true;
200  }
201 
202  if (m_is_max_pass && (m_pass >= m_max_pass)) {
203  return true;
204  }
205 
207  return true;
208  }
209 
210  return false;
211 }
212 
213 void MonteCounter::debugprint(std::ostream &sout) const {
214  sout << "pass: " << m_pass << "\n";
215  sout << "step: " << m_step << "\n";
216  sout << "samples: " << m_samples << "\n";
217  sout << "since_last_sample: " << m_since_last_sample << "\n";
218  sout << "is_max_pass: " << m_is_max_pass << "\n";
219  sout << "m_max_pass: " << m_max_pass << "\n\n";
220 
221  sout << "is_min_pass: " << m_is_min_pass << "\n";
222  sout << "m_min_pass: " << m_min_pass << "\n\n";
223 
224  sout << "is_max_step: " << m_is_max_step << "\n";
225  sout << "m_max_step: " << m_max_step << "\n\n";
226 
227  sout << "is_min_step: " << m_is_min_step << "\n";
228  sout << "m_min_step: " << m_min_step << "\n\n";
229 
230  sout << "is_max_sample: " << m_is_max_sample << "\n";
231  sout << "m_max_sample: " << m_max_sample << "\n\n";
232 
233  sout << "is_min_sample: " << m_is_min_sample << "\n" << std::endl;
234  sout << "m_min_sample: " << m_min_sample << "\n\n" << std::endl;
235 }
236 
237 } // namespace Monte
238 } // namespace CASM
size_type min_step() const
Minimum number of steps, default 0 if sample by step.
bool is_max_step() const
Returns true if a maximum number of steps has been specified.
bool sample_by_pass() const
Sample by pass?
bool is_min_step() const
Returns true if a minimum number of steps has been specified.
bool is_N_pass() const
Returns true if the number of passes has been specified.
bool is_max_pass() const
Returns true if a maximum number of passes has been specified.
size_type max_sample() const
Maximum number of steps, default std::numeric_limit<size_type>::max()
size_type sample_period() const
Figure out how often to take samples.
size_type max_step() const
Maximum number of steps, required if sample by step.
bool is_min_pass() const
Returns true if a minimum number of passes has been specified.
size_type N_sample() const
Returns the number of samples requested.
size_type min_sample() const
Minimum number of steps, default 0.
size_type max_pass() const
Maximum number of passes, required if sample by pass.
bool is_N_sample() const
Returns true if the number of samples has been specified.
size_type N_pass() const
Returns the number of passes requested.
bool is_max_sample() const
Returns true if a maximum number of samples has been specified.
size_type min_pass() const
Minimum number of passes, default 0 if sample by pass.
bool is_min_sample() const
Returns true if a minimum number of samples has been specified.
size_type N_step() const
Returns the number of steps requested.
bool is_N_step() const
Returns true if the number of steps has been specified.
Track the number of passes, steps and samples taken in a Monte Carlo calculation.
Definition: MonteCounter.hh:23
bool sample_time() const
Returns true if based on period and current number of steps it is time to take a sample.
bool m_is_max_step
Maximum allowed number of steps.
void reset()
Set all counter variables back to 0.
bool maximums_met() const
Check if maximum number of pass, step, and samples has been met.
size_type m_step
Number of steps taken during the current pass.
Definition: MonteCounter.hh:80
bool m_is_N_step
Requested number of steps.
Definition: MonteCounter.hh:91
size_type samples() const
Number of samples taken.
SAMPLE_MODE m_sample_mode
Whether sampling mode is by SAMPLE_MODE::PASS or SAMPLE_MODE::STEP.
bool m_is_min_pass
Minimum allowed number of passes.
MonteCounter & operator++()
Prefix increment step and updates pass.
bool is_complete() const
Check if requested number of pass, step, or samples has been met.
bool m_is_N_pass
Requested number of passes.
Definition: MonteCounter.hh:95
bool minimums_met() const
Check if minimum number of pass, step, and samples has been met.
size_type m_samples
Number of data samples taken.
Definition: MonteCounter.hh:83
bool m_is_max_sample
Maximum allowed number of samples to take.
size_type steps_per_pass() const
Number of steps per pass.
Definition: MonteCounter.cc:98
size_type step() const
Number of steps into the current pass.
Definition: MonteCounter.cc:95
size_type m_since_last_sample
Number of passes or steps since last sample.
Definition: MonteCounter.hh:86
void increment_samples()
Increments the number of samples taken and resets counter until the next sample should be taken.
void debugprint(std::ostream &sout) const
bool m_is_max_pass
Maximum allowed number of passes.
void set(size_type _pass, size_type _step, size_type _samples)
Set all counter variables for performing a restart.
bool m_is_min_step
Minimum allowed number of steps.
MonteCounter(const EquilibriumMonteSettings &settings, size_type _steps_per_pass)
Construct a MonteCounter and initialize to all counts to zero.
Definition: MonteCounter.cc:12
bool m_is_N_sample
Requested number of samples.
Definition: MonteCounter.hh:99
bool m_is_min_sample
Minimum allowed number of samples to take.
size_type pass() const
Number of complete passes performed.
Definition: MonteCounter.cc:93
Main CASM namespace.
Definition: APICommand.hh:8