CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CanonicalConditions.cc
Go to the documentation of this file.
2 
4 #include "casm/clex/PrimClex.hh"
8 
9 namespace CASM {
10 namespace Monte {
11 
20  double _temperature,
21  const Eigen::VectorXd &_param_comp,
22  double _tol)
23  :
24 
25  m_primclex(&_primclex),
26  m_tolerance(_tol) {
27  // -- set T ----
28  set_temperature(_temperature);
29 
30  // -- set mol composition per prim ----
31  set_param_composition(_param_comp);
32 }
33 
34 // ***************************************ACCESSORS**********************************************
35 // //
36 
38 
40 
41 double CanonicalConditions::beta() const { return m_beta; }
42 
45  return m_param_composition;
46 }
47 
50  return m_param_composition(index);
51 }
52 
56 }
57 
60  return mol_composition()(index);
61 }
62 
63 double CanonicalConditions::tolerance() const { return m_tolerance; }
64 
65 // ***************************************MUTATORS***********************************************
66 // //
67 
69  m_temperature = in_temp;
70  m_beta = 1.0 / (KB * m_temperature);
71  return;
72 }
73 
76  const Eigen::VectorXd &in_param_comp) {
77  m_param_composition = in_param_comp;
78 }
79 
82  double in_param_comp) {
83  m_param_composition(ind) = in_param_comp;
84 }
85 
86 // ***************************************OPERATORS**********************************************
87 // //
88 
90  const CanonicalConditions &RHS) {
93  m_beta = 1.0 / (CASM::KB * m_temperature);
94  return *this;
95 }
96 
98  const CanonicalConditions &RHS) const {
99  return CanonicalConditions(*this) += RHS;
100 }
101 
104  const CanonicalConditions &RHS) {
107  m_beta = 1.0 / (CASM::KB * m_temperature);
108  return *this;
109 }
110 
112  const CanonicalConditions &RHS) const {
113  return CanonicalConditions(*this) -= RHS;
114 }
115 
118  return false;
119  }
120 
122  m_tolerance)) {
123  return false;
124  }
125 
126  return true;
127 }
128 
130  return !(*this == RHS);
131 }
132 
134  int max_division = 0;
135 
136  if (!almost_zero(RHS_inc.temperature())) {
137  max_division = round(temperature() / RHS_inc.temperature());
138  }
139 
140  for (Index i = 0; i < m_param_composition.size(); i++) {
141  int temp_division =
143 
144  if (temp_division > max_division &&
145  !almost_zero(RHS_inc.m_param_composition(i))) {
146  max_division = temp_division;
147  }
148  }
149 
150  return max_division;
151 }
152 
153 std::ostream &operator<<(std::ostream &sout, const CanonicalConditions &cond) {
154  sout << "T: " << cond.temperature() << "\n";
155  for (int i = 0; i < cond.param_composition().size(); i++) {
156  jsonParser json;
157  sout << "param_composition: "
158  << to_json_array(cond.param_composition(), json) << "\n";
159  }
160  return sout;
161 }
162 
163 } // namespace Monte
164 } // namespace CASM
Eigen::VectorXd mol_composition(const Eigen::VectorXd &x) const
Convert parametric composition, 'x', to number of mol per prim, 'n'.
Eigen::VectorXd param_composition() const
parametric composition: comp_x
void set_temperature(double in_temp)
Set the temperature of the current grand canonical condition.
bool operator!=(const CanonicalConditions &RHS) const
Compare temperature and all chemical potentials to *this.
bool operator==(const CanonicalConditions &RHS) const
Compare temperature and all chemical potentials to *this.
int operator/(const CanonicalConditions &RHS_inc) const
Divide ALL parameters and return the greatest number in absolute value.
void set_param_composition(const Eigen::VectorXd &in_param_comp)
Set parametric composition.
const PrimClex & primclex() const
double m_tolerance
Tolerance for comparison operators == and !=.
Eigen::VectorXd m_param_composition
Vector of the param composition.
CanonicalConditions & operator+=(const CanonicalConditions &RHS)
Add temperature and all chemical potentials to *this.
Eigen::VectorXd mol_composition() const
mol composition: comp_n
CanonicalConditions & operator-=(const CanonicalConditions &RHS)
Subtract temperature and all chemical potentials to *this.
CanonicalConditions operator+(const CanonicalConditions &RHS) const
CanonicalConditions()
Default constructor.
double m_beta
Inverse temperature. Includes Boltzmann term.
CanonicalConditions operator-(const CanonicalConditions &RHS) const
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
Eigen::CwiseUnaryOp< decltype(Local::round_l< typename Derived::Scalar >), const Derived > round(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd.
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
Definition: PrimClex.cc:243
CASM::jsonParser & to_json_array(const Eigen::MatrixBase< Derived > &value, CASM::jsonParser &json)
Write Eigen Matrix with 1 row or 1 column to JSON array.
Definition: json_io.hh:313
std::ostream & operator<<(std::ostream &sout, const CanonicalConditions &cond)
Main CASM namespace.
Definition: APICommand.hh:8
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
Definition: CASM_math.hh:104
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
const double KB
Definition: definitions.hh:33
Eigen::VectorXd VectorXd