CASM  1.1.0
A Clusters Approach to Statistical Mechanics
MonteSampler.cc
Go to the documentation of this file.
2 
4 
5 namespace CASM {
6 namespace Monte {
7 
8 // ---- MonteSampler Definitions ---------------------------------
9 
11 MonteSampler::MonteSampler(const std::string &print_name,
12  double data_confidence, 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 
19 MonteSampler::MonteSampler(const std::string &print_name, double data_prec,
20  double data_confidence, size_type data_initsize)
21  : m_must_converge(true),
22  m_prec(data_prec),
23  m_conf(data_confidence),
24  m_data(data_initsize),
25  m_name(print_name) {}
26 
27 // ---- ScalarMonteSampler Definitions ---------------------------------
28 
35 ScalarMonteSampler::ScalarMonteSampler(std::string _property_name,
36  std::string print_name,
37  double data_confidence,
38  size_type data_initsize)
39  : MonteSampler(print_name, data_confidence, data_initsize),
40  m_property_name(_property_name) {}
41 
50 ScalarMonteSampler::ScalarMonteSampler(std::string _property_name,
51  std::string print_name, double data_prec,
52  double data_confidence,
53  size_type data_initsize)
54  : MonteSampler(print_name, data_prec, data_confidence, data_initsize),
55  m_property_name(_property_name) {}
56 
59  const MonteCounter &counter) {
61 }
62 
63 // ---- VectorMonteSampler Definitions ---------------------------------
64 
72 VectorMonteSampler::VectorMonteSampler(std::string _property_name,
73  size_type _index, std::string print_name,
74  double data_confidence,
75  size_type data_initsize)
76  : MonteSampler(print_name, data_confidence, data_initsize),
77  m_property_name(_property_name),
78  m_index(_index) {}
79 
88 VectorMonteSampler::VectorMonteSampler(std::string _property_name,
89  size_type _index, std::string print_name,
90  double data_prec, double data_confidence,
91  size_type data_initsize)
92  : MonteSampler(print_name, data_prec, data_confidence, data_initsize),
93  m_property_name(_property_name),
94  m_index(_index) {}
95 
98  const MonteCounter &counter) {
100 }
101 
102 // ---- QueryMonteSampler Definitions --------------------------------
103 
106  const DataFormatter<Configuration> &formatter)
107  : m_formatter(formatter),
108  m_last_sample(std::numeric_limits<MonteCounter::size_type>::max(),
109  std::numeric_limits<MonteCounter::size_type>::max()) {}
110 
113  const MonteCarlo &mc, const MonteCounter &counter) {
114  auto curr_sample = std::make_pair(counter.pass(), counter.step());
115  if (curr_sample != m_last_sample) {
116  m_value = m_formatter.evaluate_as_matrix(mc.config()).row(0);
117  m_last_sample = curr_sample;
118  }
119  return m_value;
120 }
121 
124  std::shared_ptr<QueryMonteSampler::Formatter> formatter, size_type _index,
125  std::string print_name, double data_confidence, size_type data_initsize)
126  : MonteSampler(print_name, data_confidence, data_initsize),
127  m_index(_index),
128  m_formatter(formatter) {}
129 
132  std::shared_ptr<QueryMonteSampler::Formatter> formatter, size_type _index,
133  std::string print_name, double data_prec, double data_confidence,
134  size_type data_initsize)
135  : MonteSampler(print_name, data_prec, data_confidence, data_initsize),
136  m_index(_index),
137  m_formatter(formatter) {}
138 
141  const MonteCounter &counter) {
142  data().push_back(m_formatter->sample(mc, counter)[m_index]);
143 }
144 
145 // ---- CompMonteSampler Definitions ---------------------------------
146 
155  const CompositionConverter &_comp_converter,
156  std::string print_name,
157  double data_confidence,
158  size_type data_initsize)
159  : MonteSampler(print_name, data_confidence, data_initsize),
160  m_index(_index),
161  m_comp_converter(_comp_converter) {}
162 
173  const CompositionConverter &_comp_converter,
174  std::string print_name, double data_prec,
175  double data_confidence,
176  size_type data_initsize)
177  : MonteSampler(print_name, data_prec, data_confidence, data_initsize),
178  m_index(_index),
179  m_comp_converter(_comp_converter) {}
180 
183  const MonteCounter &counter) {
184  auto comp_n = mc.vector_property("comp_n");
186 
188 }
189 
190 // ---- SiteFracMonteSampler Definitions ---------------------------------
191 
200  size_type _basis_size,
201  std::string print_name,
202  double data_confidence,
203  size_type data_initsize)
204  : MonteSampler(print_name, data_confidence, data_initsize),
205  m_index(_index),
206  m_basis_size(_basis_size) {}
207 
218  size_type _index, size_type _basis_size, std::string print_name,
219  double data_prec, double data_confidence, size_type data_initsize)
220  : MonteSampler(print_name, data_prec, data_confidence, data_initsize),
221  m_index(_index),
222  m_basis_size(_basis_size) {}
223 
226  const MonteCounter &counter) {
228 }
229 
230 // ---- AtomFracMonteSampler Definitions ---------------------------------
231 
240  size_type _vacancy_index,
241  std::string print_name,
242  double data_confidence,
243  size_type data_initsize)
244  : MonteSampler(print_name, data_confidence, data_initsize),
245  m_index(_index),
246  m_vacancy_index(_vacancy_index) {}
247 
258  size_type _index, size_type _vacancy_index, std::string print_name,
259  double data_prec, double data_confidence, size_type data_initsize)
260  : MonteSampler(print_name, data_prec, data_confidence, data_initsize),
261  m_index(_index),
262  m_vacancy_index(_vacancy_index) {}
263 
266  const MonteCounter &counter) {
267  double atom_sum = 0.0;
268  for (size_type i = 0; i < mc.vector_property("comp_n").size(); ++i) {
269  if (i != m_vacancy_index) {
270  atom_sum += mc.vector_property("comp_n")(i);
271  }
272  }
273 
274  data().push_back(mc.vector_property("comp_n")(m_index) / atom_sum);
275 }
276 
277 } // namespace Monte
278 } // namespace CASM
Convert between number of species per unit cell and parametric composition.
Eigen::VectorXd param_composition(const Eigen::VectorXd &n) const
Convert number of mol per prim, 'n' to parametric composition 'x'.
Extract data from objects of 'DataObject' class.
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
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.
CompositionConverter m_comp_converter
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 push_back(double value)
Add an observation.
Definition: MCData.hh:27
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically)
Definition: MonteCarlo.hh:44
const double & scalar_property(std::string property_name) const
const Access a particular scalar property
Definition: MonteCarlo.hh:111
const Configuration & config() const
const Access current microstate
Definition: MonteCarlo.hh:90
const Eigen::VectorXd & vector_property(std::string property_name) const
const Access a particular vector property
Definition: MonteCarlo.hh:121
Track the number of passes, steps and samples taken in a Monte Carlo calculation.
Definition: MonteCounter.hh:23
size_type step() const
Number of steps into the current pass.
Definition: MonteCounter.cc:95
size_type pass() const
Number of complete passes performed.
Definition: MonteCounter.cc:93
An abstract base class for sampling and storing data observations.
Definition: MonteSampler.hh:26
MonteSampler(const std::string &print_name, double data_confidence, size_type data_initsize)
Construct sampler that does not need to converge.
Definition: MonteSampler.cc:11
const MCData & data() const
const Access the raw data observation container
Formatter(const DataFormatter< Configuration > &formatter)
Construct sampler that does not need to converge.
const Eigen::VectorXd & sample(const MonteCarlo &mc, const MonteCounter &counter)
Evaluate datum formatters, if necessary, and return result.
std::shared_ptr< QueryMonteSampler::Formatter > m_formatter
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.
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:35
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
Definition: MonteSampler.cc:58
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.
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
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:72
void sample(const MonteCarlo &mc, const MonteCounter &counter)
Sample data from a MonteCarlo calculation.
Definition: MonteSampler.cc:97
Eigen::VectorXd comp(const Configuration &config)
Returns parametric composition, as calculated using PrimClex::param_comp.
Eigen::VectorXd comp_n(const Configuration &config)
Returns the composition, as number of each species per unit cell.
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::VectorXd VectorXd
T max(const T &A, const T &B)
Definition: CASM_math.hh:95
Definition: stream_io.hh:24