PSCF v1.1
pscf/homogeneous/Mixture.h
1#ifndef PSCF_HOMOGENEOUS_MIXTURE_H
2#define PSCF_HOMOGENEOUS_MIXTURE_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/param/ParamComposite.h> // base class
12
13#include <pscf/chem/Monomer.h> // Member template argument
14#include <pscf/homogeneous/Molecule.h> // Member template argument
15#include <util/containers/DArray.h> // Member template
16#include <util/containers/DMatrix.h> // Member template
17
18namespace Pscf {
19 class Interaction;
20 class LuSolver;
21}
22
23namespace Pscf {
24namespace Homogeneous {
25
26 using namespace Util;
27
33 class Mixture : public ParamComposite
34 {
35 public:
36
40 Mixture();
41
45 ~Mixture();
46
48
49
55 virtual void readParameters(std::istream& in);
56
62 void setNMolecule(int nMolecule);
63
69 void setNMonomer(int nMonomer);
70
72
74
80 void setComposition(DArray<double> const & phi);
81
91 void computeMu(Interaction const & interaction, double xi = 0.0);
92
101 void computePhi(Interaction const & interaction,
102 DArray<double> const & mu,
103 DArray<double> const & phi,
104 double& xi);
105
117 void computeFreeEnergy(Interaction const & interaction);
118
120
122
128 Molecule& molecule(int id);
129
135 double mu(int id) const;
136
142 double phi(int id) const;
143
149 double c(int id) const;
150
154 double fHelmholtz() const;
155
159 double pressure() const;
160
164 int nMolecule() const;
165
169 int nMonomer() const;
170
172
178 void validate() const;
179
180 private:
181
187 DArray<Molecule> molecules_;
188
192 DArray<double> mu_;
193
197 DArray<double> phi_;
198
203
208
212 DArray<double> residual_;
213
217 DArray<double> dX_;
218
222 DMatrix<double> dWdC_;
223
227 DMatrix<double> dWdPhi_;
228
232 DMatrix<double> jacobian_;
233
237 DArray<double> phiOld_;
238
242 double fHelmholtz_;
243
247 double pressure_;
248
252 LuSolver* solverPtr_;
253
257 int nMolecule_;
258
262 int nMonomer_;
263
267 bool hasComposition_;
268
272 void computeC();
273
277 void adjustXi(DArray<double> const & mu, double& xi);
278
282 void computeResidual(DArray<double> const & mu,
283 double& error);
284
285 };
286
287 // Inline member functions
288
290 {
291 UTIL_ASSERT(id >= 0);
292 UTIL_ASSERT(id < nMolecule_);
293 return molecules_[id];
294 }
295
296 inline double Mixture::mu(int id) const
297 {
298 UTIL_ASSERT(id >= 0);
299 UTIL_ASSERT(id < nMolecule_);
300 return mu_[id];
301 }
302
303 inline double Mixture::phi(int id) const
304 {
305 UTIL_ASSERT(id >= 0);
306 UTIL_ASSERT(id < nMolecule_);
307 return phi_[id];
308 }
309
310 inline double Mixture::c(int id) const
311 {
312 UTIL_ASSERT(id >= 0);
313 UTIL_ASSERT(id < nMonomer_);
314 return c_[id];
315 }
316
317 inline double Mixture::fHelmholtz() const
318 { return fHelmholtz_; }
319
320 inline double Mixture::pressure() const
321 { return pressure_; }
322
323 inline int Mixture::nMolecule() const
324 { return nMolecule_; }
325
326 inline int Mixture::nMonomer() const
327 { return nMonomer_; }
328
329} // namespace Homogeneous
330} // namespace Pscf
331#endif
A spatially homogeneous mixture.
double c(int id) const
Return monomer volume fraction for one monomer type.
double pressure() const
Return pressure in units of kT / monomer volume.
void validate() const
Validate all data structures.
Molecule & molecule(int id)
Get a molecule object (non-const reference).
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
double phi(int id) const
Return molecular volume fraction for one species.
int nMonomer() const
Get number of monomer types.
void setComposition(DArray< double > const &phi)
Set system composition.
void computePhi(Interaction const &interaction, DArray< double > const &mu, DArray< double > const &phi, double &xi)
Compute composition from chemical potentials.
void computeFreeEnergy(Interaction const &interaction)
Compute Helmholtz free energy and pressure.
int nMolecule() const
Get number of molecule species (polymer + solvent).
double mu(int id) const
Return chemical potential for one species.
void setNMonomer(int nMonomer)
Set the number of monomer types.
void computeMu(Interaction const &interaction, double xi=0.0)
Compute chemical potential from preset composition.
double fHelmholtz() const
Return Helmholtz free energy per monomer / kT.
void setNMolecule(int nMolecule)
Set the number of molecular species and allocate memory.
Descriptor of a molecular species in a homogeneous mixture.
Definition: Molecule.h:39
Flory-Huggins excess free energy model.
Definition: Interaction.h:26
Solve Ax=b by LU decomposition of A.
Definition: LuSolver.h:31
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
Dynamically allocated Matrix.
Definition: DMatrix.h:25
An object that can read multiple parameters from file.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition: global.h:75
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1