JDFTx  1.2.0
FluidMixture.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman, Kendra Letchworth Weaver
3 
4 This file is part of JDFTx.
5 
6 JDFTx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 JDFTx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
18 -------------------------------------------------------------------*/
19 
20 #ifndef JDFTX_FLUID_FLUIDMIXTURE_H
21 #define JDFTX_FLUID_FLUIDMIXTURE_H
22 
23 #include <fluid/FluidComponent.h>
24 #include <fluid/Fmix.h>
25 #include <core/Units.h>
26 #include <core/Minimize.h>
27 #include <core/EnergyComponents.h>
28 
32 class FluidMixture : public Minimizable<ScalarFieldArray>
33 {
34 public:
35  const GridInfo& gInfo;
36  const double T;
37  bool verboseLog;
39 
40  FluidMixture(const GridInfo& gInfo, const double T=298*Kelvin);
41  virtual ~FluidMixture();
42 
48  void initialize(double P=1.01325*Bar, double epsBulkOverride=0., double epsInfOverride=0.);
49 
52  double getBoilingPressure(double NliqGuess, double NvapGuess, std::vector<double>* Nvap=0) const;
53 
54  unsigned get_nIndep() const { return nIndepIdgas + (polarizable ? 3 : 0); }
55  unsigned get_nDensities() const { return nDensities; }
56 
57  const std::vector<const FluidComponent*>& getComponents() const;
58  ScalarFieldArray state;
59 
64  bool useMFKernel;
65  double Qtol;
66 
71  void initState(double scale = 0.0, double Elo=-DBL_MAX, double Ehi=+DBL_MAX);
72 
74  void loadState(const char* filename);
75 
77  void saveState(const char* filename) const;
78 
80  struct Outputs
81  {
87 
89  Outputs( ScalarFieldArray* N=0, vector3<>* electricP=0,
90  ScalarFieldTilde* Phi_rhoExternal=0, ScalarFieldArray* psiEff=0, EnergyComponents* Phi=0);
91  };
92 
99  double operator()(const ScalarFieldArray& indep, ScalarFieldArray& Phi_indep, Outputs outputs=Outputs()) const;
100 
104  double getFreeEnergy(Outputs outputs=Outputs()) const;
105 
107  void step(const ScalarFieldArray& dir, double alpha);
108 
110  double compute(ScalarFieldArray* grad, ScalarFieldArray* Kgrad);
111 
112  double sync(double x) const;
113 
114 private:
115  unsigned nIndepIdgas;
116  unsigned nDensities;
117  bool polarizable;
118  double p;
119  double Crot, Cpol;
120 
121  std::vector<const FluidComponent*> component;
122  std::vector<const Fmix*> fmixArr;
123 
124  std::vector<double> Kindep;
125  double Keps;
126 
127  void addComponent(FluidComponent*);
128  friend struct FluidComponent;
129 
130  void addFmix(const Fmix* fmix);
131  friend class Fmix;
132 
134  double computeUniformEx(const std::vector< double >& Nmol, std::vector< double >& Phi_Nmol) const;
135 
137  double compute_p(double Ntot) const;
138 
139  friend struct BoilingPressureSolver;
140  static ScalarFieldTilde coulomb(const ScalarFieldTilde& rho) { return (-4*M_PI) * Linv(O(rho)); }
141 };
142 
143 #endif // JDFTX_FLUID_FLUIDMIXTURE_H
std::vector< ScalarField > ScalarFieldArray
dynamic size collection of real space scalar fields
Definition: ScalarFieldArray.h:32
Simulation grid descriptor.
Definition: GridInfo.h:45
double operator()(const ScalarFieldArray &indep, ScalarFieldArray &Phi_indep, Outputs outputs=Outputs()) const
Free energy and gradient evaluation.
ScalarFieldTilde * Phi_rhoExternal
derivative of free energy w.r.t rhoExternal
Definition: FluidMixture.h:84
double compute(ScalarFieldArray *grad, ScalarFieldArray *Kgrad)
Return energy at current state, and optionally the gradient (interface for minimize()) ...
Mixture of fluids that provides the total free energy functional for minimization Constructing Fex an...
Definition: FluidMixture.h:32
unsigned get_nDensities() const
get the total number of site densities
Definition: FluidMixture.h:55
double sync(double x) const
All processes minimize together; make sure scalars are in sync to round-off error.
void initState(double scale=0.0, double Elo=-DBL_MAX, double Ehi=+DBL_MAX)
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:45
vector3 Eexternal
External uniform electric field.
Definition: FluidMixture.h:38
void initialize(double P=1.01325 *Bar, double epsBulkOverride=0., double epsInfOverride=0.)
ScalarFieldTilde Linv(const ScalarFieldTilde &)
Inverse Laplacian.
void loadState(const char *filename)
Load the state from a single binary file.
ScalarFieldTilde rhoExternal
Definition: FluidMixture.h:63
Abstract base class for mixing functionals: interactions between fluids (beyond hard sphere and scale...
Definition: Fmix.h:29
void step(const ScalarFieldArray &dir, double alpha)
Advance step along direction dir by scale alpha (interface for minimize())
const double Kelvin
Definition: Units.h:33
EnergyComponents * Phi
retrieve fluid energy components
Definition: FluidMixture.h:86
ScalarFieldTilde O(const ScalarFieldTilde &)
Inner product operator (diagonal in PW basis)
const double T
Temperature.
Definition: FluidMixture.h:36
const std::vector< const FluidComponent * > & getComponents() const
access component list
Commonly used measurement units in terms of atomic units.
Named fluid components for which bulk properties / geometries / excess functionals are available...
Definition: FluidComponent.h:27
double getFreeEnergy(Outputs outputs=Outputs()) const
Get the free energy, densities and moments for the current state.
ScalarFieldArray * N
site densities
Definition: FluidMixture.h:82
Nonlinear minimization templates.
bool verboseLog
print energy components etc. if enabled (off by default)
Definition: FluidMixture.h:37
Definition: EnergyComponents.h:36
double Qtol
If true, use the mean field kernel for external coulomb interactions as well.
Definition: FluidMixture.h:65
Outputs(ScalarFieldArray *N=0, vector3<> *electricP=0, ScalarFieldTilde *Phi_rhoExternal=0, ScalarFieldArray *psiEff=0, EnergyComponents *Phi=0)
initialize all the above to null
double getBoilingPressure(double NliqGuess, double NvapGuess, std::vector< double > *Nvap=0) const
const double Bar
Definition: Units.h:52
void saveState(const char *filename) const
Save the state to a single binary file.
vector3 * electricP
total electric dipole moment in cell (useful only with multipole-based IdealGas&#39;s) ...
Definition: FluidMixture.h:83
Optional outputs for operator() and getFreeEnergy(), retrieve results for all non-null pointers...
Definition: FluidMixture.h:80
Definition: Minimize.h:46
Represent components of the (free) energy.
ScalarFieldArray * psiEff
Estimate ideal gas effective potentials (useful only when no electric field or potential on non-indep...
Definition: FluidMixture.h:85
unsigned get_nIndep() const
get the number of scalar fields used as independent variables
Definition: FluidMixture.h:54