CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
GrandCanonicalConditions.cc
Go to the documentation of this file.
4 
5 #include "casm/clex/PrimClex.hh"
6 
7 namespace CASM {
8 
9 
18  const PrimClex &_primclex,
19  double _temperature,
20  const Eigen::VectorXd &_param_chem_pot,
21  double _tol) :
22 
23  m_primclex(&_primclex),
24  m_tolerance(_tol) {
25 
26  // -- set T ----
27  set_temperature(_temperature);
28 
29 
30  // -- set param_chem_pot ----
31  set_param_chem_pot(_param_chem_pot);
32 
33  }
34 
35  // ***************************************ACCESSORS********************************************** //
36 
38  return *m_primclex;
39  }
40 
42  return m_temperature;
43  }
44 
46  return m_beta;
47  }
48 
50  return m_exchange_chem_pot;
51  }
52 
53  double GrandCanonicalConditions::exchange_chem_pot(Index index_new, Index index_curr) const {
54  return m_exchange_chem_pot(index_new, index_curr);
55  }
56 
58  return m_param_chem_pot;
59  }
60 
62  return m_param_chem_pot(index);
63  }
64 
66  return m_tolerance;
67  }
68 
69 
70  // ***************************************MUTATORS*********************************************** //
71 
73  m_temperature = in_temp;
74  m_beta = 1.0 / (KB * m_temperature);
75  return;
76  }
77 
79  m_param_chem_pot = in_param_chem_pot;
81 
82  int Ncomp = primclex().composition_axes().components().size();
83  m_exchange_chem_pot = Eigen::MatrixXd(Ncomp, Ncomp);
84  for(int index_new = 0; index_new < Ncomp; ++index_new) {
85  for(int index_curr = 0; index_curr < Ncomp; ++index_curr) {
86  Eigen::VectorXl dn = Eigen::VectorXl::Zero(Ncomp);
87  dn(index_new) += 1;
88  dn(index_curr) -= 1;
89  m_exchange_chem_pot(index_new, index_curr) =
90  m_param_chem_pot.transpose() * primclex().composition_axes().dparam_dmol() * dn.cast<double>();
91  }
92  }
93 
94  return;
95  }
96 
97  void GrandCanonicalConditions::set_param_chem_pot(Index ind, double in_param_chem_pot) {
98  m_param_chem_pot(ind) = in_param_chem_pot;
100  return;
101  }
102 
103 
104  // ***************************************OPERATORS********************************************** //
105 
108  for(int i = 0; i < m_param_chem_pot.size(); i++) {
109  m_param_chem_pot(i) += RHS.m_param_chem_pot(i);
110  }
112  m_beta = 1.0 / (CASM::KB * m_temperature);
113  return *this;
114  }
115 
117  return GrandCanonicalConditions(*this) += RHS;
118  }
119 
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  return GrandCanonicalConditions(*this) -= RHS;
133  }
134 
137  return false;
138  }
139 
140  for(int i = 0; i < m_param_chem_pot.size(); i++) {
142  return false;
143  }
144  }
145 
146  return true;
147  }
148 
150  return !(*this == RHS);
151  }
152 
154  int max_division = 0;
155 
156  if(!almost_zero(RHS_inc.temperature())) {
157  max_division = round(temperature() / RHS_inc.temperature());
158  }
159 
160  for(Index i = 0; i < param_chem_pot().size(); i++) {
161  int temp_division = round(param_chem_pot(i) / RHS_inc.param_chem_pot(i));
162 
163  if(temp_division > max_division && !almost_zero(RHS_inc.param_chem_pot(i))) {
164  max_division = temp_division;
165  }
166  }
167 
168  return max_division;
169  }
170 
171  std::ostream &operator<<(std::ostream &sout, const GrandCanonicalConditions &cond) {
172  sout << "T: " << cond.temperature() << "\n";
173  for(int i = 0; i < cond.param_chem_pot().size(); i++) {
174  jsonParser json;
175  sout << "param_chem_pot: " << to_json_array(cond.param_chem_pot(), json) << "\n";
176  }
177  return sout;
178  }
179 
180 
181 }
182 
183 
Eigen::MatrixXd MatrixXd
Eigen::MatrixXd dparam_dmol() const
Return the matrix Mij = dx_i/dn_j.
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
Definition: CASM_math.hh:41
bool operator!=(const GrandCanonicalConditions &RHS) const
Compare temperature and all chemical potentials to *this.
GrandCanonicalConditions & operator+=(const GrandCanonicalConditions &RHS)
Add temperature and all chemical potentials to *this.
Eigen::VectorXd param_chem_pot() const
parametric chemical potential: dg/dcomp_x
Main CASM namespace.
Definition: complete.cpp:8
Eigen::VectorXd m_param_chem_pot
Vector of the parametric chemical potentials conjugate to the parametric compositions.
Eigen::MatrixXd exchange_chem_pot() const
matrix of exchange chemical potential, M(new, curr) = chem_pot(new) - chem_pot(curr) ...
GrandCanonicalConditions operator-(const GrandCanonicalConditions &RHS) const
Subtract temperature and all chemical potentials together and return a new Condition.
double m_beta
Inverse temperature. Includes Boltzmann term.
Eigen::MatrixXd m_exchange_chem_pot
Matrix(i,j) of chem_pot(i) - chem_pot(j)
std::vector< std::string > components() const
The order of components in mol composition vectors.
double m_tolerance
Tolerance for comparison operators == and !=.
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
int operator/(const GrandCanonicalConditions &RHS_inc) const
Divide ALL parameters and return the greatest number in absolute value.
EigenIndex Index
For long integer indexing:
void set_param_chem_pot(const Eigen::VectorXd &in_chem_pot)
Set all the parametric chemical potentials of the current grand canonical condition.
Matrix< long int, Dynamic, 1 > VectorXl
Eigen::VectorXd VectorXd
const double KB
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
const CompositionConverter & composition_axes() const
const Access CompositionConverter object
Definition: PrimClex.cc:237
GrandCanonicalConditions operator+(const GrandCanonicalConditions &RHS) const
Add temperature and all chemical potentials together and return a new Condition.
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: container.hh:191
bool operator==(const GrandCanonicalConditions &RHS) const
Compare temperature and all chemical potentials to *this.
GrandCanonicalConditions()
Default constructor.
void set_temperature(double in_temp)
Set the temperature of the current grand canonical condition.
GrandCanonicalConditions & operator-=(const GrandCanonicalConditions &RHS)
Subtract temperature and all chemical potentials to *this.
Eigen::VectorXd m_chem_pot
Vector of the 'atomic' chemical potentials for each species. Ordered as primclex.get_param_comp().get_components()
int round(double val)
Definition: CASM_math.cc:6