CASM  1.1.0
A Clusters Approach to Statistical Mechanics
GrandCanonicalConditions.cc
Go to the documentation of this file.
2 
4 #include "casm/clex/PrimClex.hh"
7 
8 namespace CASM {
9 namespace Monte {
10 
19  const PrimClex &_primclex, double _temperature,
20  const Eigen::VectorXd &_param_chem_pot, double _tol)
21  :
22 
23  m_primclex(&_primclex),
24  m_tolerance(_tol) {
25  // -- set T ----
26  set_temperature(_temperature);
27 
28  // -- set param_chem_pot ----
29  set_param_chem_pot(_param_chem_pot);
30 }
31 
32 // ***************************************ACCESSORS**********************************************
33 // //
34 
36  return *m_primclex;
37 }
38 
40 
41 double GrandCanonicalConditions::beta() const { return m_beta; }
42 
44  return m_exchange_chem_pot;
45 }
46 
48  Index index_curr) const {
49  return m_exchange_chem_pot(index_new, index_curr);
50 }
51 
53  return m_param_chem_pot;
54 }
55 
57  return m_param_chem_pot(index);
58 }
59 
61 
62 // ***************************************MUTATORS***********************************************
63 // //
64 
66  m_temperature = in_temp;
67  m_beta = 1.0 / (KB * m_temperature);
68  return;
69 }
70 
72  const Eigen::VectorXd &in_param_chem_pot) {
73  m_param_chem_pot = in_param_chem_pot;
74  m_chem_pot = primclex().composition_axes().dparam_dmol().transpose() *
76 
77  int Ncomp = primclex().composition_axes().components().size();
78  m_exchange_chem_pot = Eigen::MatrixXd(Ncomp, Ncomp);
79  for (int index_new = 0; index_new < Ncomp; ++index_new) {
80  for (int index_curr = 0; index_curr < Ncomp; ++index_curr) {
81  Eigen::VectorXl dn = Eigen::VectorXl::Zero(Ncomp);
82  dn(index_new) += 1;
83  dn(index_curr) -= 1;
84  m_exchange_chem_pot(index_new, index_curr) =
85  m_param_chem_pot.transpose() *
86  primclex().composition_axes().dparam_dmol() * dn.cast<double>();
87  }
88  }
89 
90  return;
91 }
92 
94  double in_param_chem_pot) {
95  m_param_chem_pot(ind) = in_param_chem_pot;
97  return;
98 }
99 
100 // ***************************************OPERATORS**********************************************
101 // //
102 
104  const GrandCanonicalConditions &RHS) {
106  for (int i = 0; i < m_param_chem_pot.size(); i++) {
107  m_param_chem_pot(i) += RHS.m_param_chem_pot(i);
108  }
110  m_beta = 1.0 / (CASM::KB * m_temperature);
111  return *this;
112 }
113 
115  const GrandCanonicalConditions &RHS) const {
116  return GrandCanonicalConditions(*this) += RHS;
117 }
118 
121  const GrandCanonicalConditions &RHS) {
123  for (int i = 0; i < m_param_chem_pot.size(); i++) {
124  m_param_chem_pot(i) -= RHS.m_param_chem_pot(i);
125  }
127  m_beta = 1.0 / (CASM::KB * m_temperature);
128  return *this;
129 }
130 
132  const GrandCanonicalConditions &RHS) const {
133  return GrandCanonicalConditions(*this) -= RHS;
134 }
135 
137  const GrandCanonicalConditions &RHS) const {
139  return false;
140  }
141 
142  for (int i = 0; i < m_param_chem_pot.size(); i++) {
144  m_tolerance)) {
145  return false;
146  }
147  }
148 
149  return true;
150 }
151 
153  const GrandCanonicalConditions &RHS) const {
154  return !(*this == RHS);
155 }
156 
158  const GrandCanonicalConditions &RHS_inc) const {
159  int max_division = 0;
160 
161  if (!almost_zero(RHS_inc.temperature())) {
162  max_division = round(temperature() / RHS_inc.temperature());
163  }
164 
165  for (Index i = 0; i < param_chem_pot().size(); i++) {
166  int temp_division = round(param_chem_pot(i) / RHS_inc.param_chem_pot(i));
167 
168  if (temp_division > max_division &&
169  !almost_zero(RHS_inc.param_chem_pot(i))) {
170  max_division = temp_division;
171  }
172  }
173 
174  return max_division;
175 }
176 
177 std::ostream &operator<<(std::ostream &sout,
178  const GrandCanonicalConditions &cond) {
179  sout << "T: " << cond.temperature() << "\n";
180  for (int i = 0; i < cond.param_chem_pot().size(); i++) {
181  jsonParser json;
182  sout << "param_chem_pot: " << to_json_array(cond.param_chem_pot(), json)
183  << "\n";
184  }
185  return sout;
186 }
187 
188 } // namespace Monte
189 } // namespace CASM
Eigen::MatrixXd dparam_dmol() const
Return the matrix Mij = dx_i/dn_j.
std::vector< std::string > components() const
The order of components in mol composition vectors.
void set_param_chem_pot(const Eigen::VectorXd &in_chem_pot)
GrandCanonicalConditions operator-(const GrandCanonicalConditions &RHS) const
int operator/(const GrandCanonicalConditions &RHS_inc) const
Divide ALL parameters and return the greatest number in absolute value.
Eigen::MatrixXd m_exchange_chem_pot
Matrix(i,j) of chem_pot(i) - chem_pot(j)
GrandCanonicalConditions & operator+=(const GrandCanonicalConditions &RHS)
Add temperature and all chemical potentials to *this.
double m_tolerance
Tolerance for comparison operators == and !=.
Eigen::MatrixXd exchange_chem_pot() const
matrix of exchange chemical potential, M(new, curr) = chem_pot(new)
GrandCanonicalConditions operator+(const GrandCanonicalConditions &RHS) const
GrandCanonicalConditions & operator-=(const GrandCanonicalConditions &RHS)
Subtract temperature and all chemical potentials to *this.
double m_beta
Inverse temperature. Includes Boltzmann term.
bool operator!=(const GrandCanonicalConditions &RHS) const
Compare temperature and all chemical potentials to *this.
Eigen::VectorXd param_chem_pot() const
parametric chemical potential: dg/dcomp_x
bool operator==(const GrandCanonicalConditions &RHS) const
Compare temperature and all chemical potentials to *this.
void set_temperature(double in_temp)
Set the temperature of the current grand canonical condition.
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
Eigen::MatrixXd MatrixXd
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
Matrix< long int, Dynamic, 1 > VectorXl
Definition: eigen.hh:15