CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
MonteSampler.cc
Go to the documentation of this file.
2 
4 
5 namespace CASM {
6 
7  // ---- MonteSampler Definitions ---------------------------------
8 
10  MonteSampler::MonteSampler(const std::string &print_name,
11  double data_confidence,
12  size_type data_initsize):
13  m_must_converge(false),
14  m_conf(data_confidence),
15  m_data(data_initsize),
16  m_name(print_name) {
17 
18  }
19 
21  MonteSampler::MonteSampler(const std::string &print_name,
22  double data_prec,
23  double data_confidence,
24  size_type data_initsize):
25  m_must_converge(true),
26  m_prec(data_prec),
27  m_conf(data_confidence),
28  m_data(data_initsize),
29  m_name(print_name) {
30 
31  }
32 
33 
34  // ---- ScalarMonteSampler Definitions ---------------------------------
35 
42  ScalarMonteSampler::ScalarMonteSampler(std::string _property_name,
43  std::string print_name,
44  double data_confidence,
45  size_type data_initsize) :
46  MonteSampler(print_name, data_confidence, data_initsize),
47  m_property_name(_property_name) {}
48 
57  ScalarMonteSampler::ScalarMonteSampler(std::string _property_name,
58  std::string print_name,
59  double data_prec,
60  double data_confidence,
61  size_type data_initsize) :
62  MonteSampler(print_name, data_prec, data_confidence, data_initsize),
63  m_property_name(_property_name) {}
64 
65 
67  void ScalarMonteSampler::sample(const MonteCarlo &mc, const MonteCounter &counter) {
69  }
70 
71 
72 
73  // ---- VectorMonteSampler Definitions ---------------------------------
74 
82  VectorMonteSampler::VectorMonteSampler(std::string _property_name,
83  size_type _index,
84  std::string print_name,
85  double data_confidence,
86  size_type data_initsize) :
87  MonteSampler(print_name, data_confidence, data_initsize),
88  m_property_name(_property_name),
89  m_index(_index) {}
90 
100  VectorMonteSampler::VectorMonteSampler(std::string _property_name,
101  size_type _index,
102  std::string print_name,
103  double data_prec,
104  double data_confidence,
105  size_type data_initsize) :
106  MonteSampler(print_name, data_prec, data_confidence, data_initsize),
107  m_property_name(_property_name),
108  m_index(_index) {}
109 
110 
112  void VectorMonteSampler::sample(const MonteCarlo &mc, const MonteCounter &counter) {
114  }
115 
116 
117  // ---- QueryMonteSampler Definitions --------------------------------
118 
121  m_formatter(formatter),
122  m_last_sample(
123  std::numeric_limits<MonteCounter::size_type>::max(),
124  std::numeric_limits<MonteCounter::size_type>::max()) {}
125 
128  auto curr_sample = std::make_pair(counter.pass(), counter.step());
129  if(curr_sample != m_last_sample) {
130  m_value = m_formatter.evaluate_as_matrix(mc.config()).row(0);
131  m_last_sample = curr_sample;
132  }
133  return m_value;
134  }
135 
138  std::shared_ptr<QueryMonteSampler::Formatter> formatter,
139  size_type _index,
140  std::string print_name,
141  double data_confidence,
142  size_type data_initsize) :
143  MonteSampler(print_name, data_confidence, data_initsize),
144  m_index(_index),
145  m_formatter(formatter) {}
146 
149  std::shared_ptr<QueryMonteSampler::Formatter> formatter,
150  size_type _index,
151  std::string print_name,
152  double data_prec,
153  double data_confidence,
154  size_type data_initsize) :
155  MonteSampler(print_name, data_prec, data_confidence, data_initsize),
156  m_index(_index),
157  m_formatter(formatter) {}
158 
159 
161  void QueryMonteSampler::sample(const MonteCarlo &mc, const MonteCounter &counter) {
162  data().push_back(m_formatter->sample(mc, counter)[m_index]);
163  }
164 
165 
166  // ---- CompMonteSampler Definitions ---------------------------------
167 
176  const CompositionConverter &_comp_converter,
177  std::string print_name,
178  double data_confidence,
179  size_type data_initsize) :
180  MonteSampler(print_name, data_confidence, data_initsize),
181  m_index(_index),
182  m_comp_converter(_comp_converter) {}
183 
194  const CompositionConverter &_comp_converter,
195  std::string print_name,
196  double data_prec,
197  double data_confidence,
198  size_type data_initsize) :
199  MonteSampler(print_name, data_prec, data_confidence, data_initsize),
200  m_index(_index),
201  m_comp_converter(_comp_converter) {}
202 
203 
205  void CompMonteSampler::sample(const MonteCarlo &mc, const MonteCounter &counter) {
206 
207  auto comp_n = mc.vector_property("comp_n");
209 
211 
212  }
213 
214 
215  // ---- SiteFracMonteSampler Definitions ---------------------------------
216 
225  size_type _basis_size,
226  std::string print_name,
227  double data_confidence,
228  size_type data_initsize) :
229  MonteSampler(print_name, data_confidence, data_initsize),
230  m_index(_index),
231  m_basis_size(_basis_size) {}
232 
243  size_type _basis_size,
244  std::string print_name,
245  double data_prec,
246  double data_confidence,
247  size_type data_initsize) :
248  MonteSampler(print_name, data_prec, data_confidence, data_initsize),
249  m_index(_index),
250  m_basis_size(_basis_size) {}
251 
252 
254  void SiteFracMonteSampler::sample(const MonteCarlo &mc, const MonteCounter &counter) {
256  }
257 
258 
259  // ---- AtomFracMonteSampler Definitions ---------------------------------
260 
269  size_type _vacancy_index,
270  std::string print_name,
271  double data_confidence,
272  size_type data_initsize) :
273  MonteSampler(print_name, data_confidence, data_initsize),
274  m_index(_index),
275  m_vacancy_index(_vacancy_index) {}
276 
287  size_type _vacancy_index,
288  std::string print_name,
289  double data_prec,
290  double data_confidence,
291  size_type data_initsize) :
292  MonteSampler(print_name, data_prec, data_confidence, data_initsize),
293  m_index(_index),
294  m_vacancy_index(_vacancy_index) {}
295 
296 
298  void AtomFracMonteSampler::sample(const MonteCarlo &mc, const MonteCounter &counter) {
299 
300  double atom_sum = 0.0;
301  for(size_type i = 0; i < mc.vector_property("comp_n").size(); ++i) {
302  if(i != m_vacancy_index) {
303  atom_sum += mc.vector_property("comp_n")(i);
304  }
305  }
306 
307  data().push_back(mc.vector_property("comp_n")(m_index) / atom_sum);
308  }
309 
310 }
311 
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
Definition: MonteSampler.cc:67
SiteFracMonteSampler(size_type _index, size_type _basis_size, std::string print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
Formatter(const DataFormatter< Configuration > &formatter)
Construct sampler that does not need to converge.
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
void push_back(double value)
Add an observation.
Definition: MCData.hh:30
Eigen::VectorXd param_composition(const Eigen::VectorXd &n) const
Convert number of mol per prim, 'n' to parametric composition 'x'.
MonteSampler(const std::string &print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
Definition: MonteSampler.cc:10
const double & scalar_property(std::string property_name) const
const Access a particular scalar property
Definition: MonteCarlo.hh:115
const Configuration & config() const
const Access current microstate
Definition: MonteCarlo.hh:88
An abstract base class for sampling and storing data observations.
Definition: MonteSampler.hh:22
Main CASM namespace.
Definition: complete.cpp:8
Eigen::VectorXd comp(const Configuration &config)
Returns parametric composition, as calculated using PrimClex::param_comp.
std::shared_ptr< QueryMonteSampler::Formatter > m_formatter
Track the number of passes, steps and samples taken in a Monte Carlo calculation. ...
Definition: MonteCounter.hh:20
size_type pass() const
Number of complete passes performed.
Definition: MonteCounter.cc:91
Eigen::VectorXd comp_n(const ConfigDoF &configdof, const Supercell &scel)
Returns comp_n, the number of each molecule per primitive cell, ordered as Structure::get_struc_molec...
Definition: ConfigDoF.cc:312
QueryMonteSampler(std::shared_ptr< QueryMonteSampler::Formatter > formatter, size_type _index, std::string print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
AtomFracMonteSampler(size_type _index, size_type _vacancy_index, std::string print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
CompMonteSampler(size_type _index, const CompositionConverter &_comp_converter, std::string print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
ScalarMonteSampler(std::string _property_name, std::string print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
Definition: MonteSampler.cc:42
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
size_type step() const
Number of steps into the current pass.
Definition: MonteCounter.cc:95
const MCData & data() const
const Access the raw data observation container
Eigen::VectorXd VectorXd
T max(const T &A, const T &B)
Definition: CASM_math.hh:32
MCData::size_type size_type
Definition: MonteSampler.hh:26
const Eigen::VectorXd & vector_property(std::string property_name) const
const Access a particular vector property
Definition: MonteCarlo.hh:125
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically) ...
Definition: MonteCarlo.hh:32
Convert between number of species per unit cell and parametric composition.
Extract data from objects of 'DataObject' class.
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
CompositionConverter m_comp_converter
const Eigen::VectorXd & sample(const MonteCarlo &mc, const MonteCounter &counter)
Evaluate datum formatters, if necessary, and return result.
VectorMonteSampler(std::string _property_name, size_type _index, std::string print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
Definition: MonteSampler.cc:82