PSCF v1.3
pscf/floryHuggins/Mixture.h
1#ifndef PSCF_FLORY_HUGGINS_MIXTURE_H
2#define PSCF_FLORY_HUGGINS_MIXTURE_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, 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/floryHuggins/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 class MixtureBase;
22}
23
24namespace Pscf {
25namespace FloryHuggins {
26
27 using namespace Util;
28
34 class Mixture : public ParamComposite
35 {
36 public:
37
41 Mixture();
42
46 ~Mixture();
47
49
50
56 virtual void readParameters(std::istream& in);
57
63 void initialize(MixtureBase const& mixture);
64
70 void setNMolecule(int nMolecule);
71
77 void setNMonomer(int nMonomer);
78
80
82
88 void setComposition(DArray<double> const & phi);
89
99 void computeMu(Interaction const & interaction, double xi = 0.0);
100
109 void computePhi(Interaction const & interaction,
110 DArray<double> const & mu,
111 DArray<double> const & phi,
112 double& xi);
113
125 void computeFreeEnergy(Interaction const & interaction);
126
128
130
136 Molecule& molecule(int id);
137
143 double mu(int id) const;
144
150 double phi(int id) const;
151
157 double c(int id) const;
158
162 double fHelmholtz() const;
163
167 double pressure() const;
168
172 int nMolecule() const;
173
177 int nMonomer() const;
178
180
186 void validate() const;
187
188 private:
189
195 DArray<Molecule> molecules_;
196
200 DArray<double> mu_;
201
205 DArray<double> phi_;
206
211
216
220 DArray<double> residual_;
221
225 DArray<double> dX_;
226
230 DMatrix<double> dWdC_;
231
235 DMatrix<double> dWdPhi_;
236
240 DMatrix<double> jacobian_;
241
245 DArray<double> phiOld_;
246
250 double fHelmholtz_;
251
255 double pressure_;
256
260 LuSolver* solverPtr_;
261
265 int nMolecule_;
266
270 int nMonomer_;
271
275 bool hasComposition_;
276
280 void computeC();
281
285 void adjustXi(DArray<double> const & mu, double& xi);
286
290 void computeResidual(DArray<double> const & mu,
291 double& error);
292
293 };
294
295 // Inline member functions
296
298 {
299 UTIL_ASSERT(id >= 0);
300 UTIL_ASSERT(id < nMolecule_);
301 return molecules_[id];
302 }
303
304 inline double Mixture::mu(int id) const
305 {
306 UTIL_ASSERT(id >= 0);
307 UTIL_ASSERT(id < nMolecule_);
308 return mu_[id];
309 }
310
311 inline double Mixture::phi(int id) const
312 {
313 UTIL_ASSERT(id >= 0);
314 UTIL_ASSERT(id < nMolecule_);
315 return phi_[id];
316 }
317
318 inline double Mixture::c(int id) const
319 {
320 UTIL_ASSERT(id >= 0);
321 UTIL_ASSERT(id < nMonomer_);
322 return c_[id];
323 }
324
325 inline double Mixture::fHelmholtz() const
326 { return fHelmholtz_; }
327
328 inline double Mixture::pressure() const
329 { return pressure_; }
330
331 inline int Mixture::nMolecule() const
332 { return nMolecule_; }
333
334 inline int Mixture::nMonomer() const
335 { return nMonomer_; }
336
337} // namespace FloryHuggins
338} // namespace Pscf
339#endif
int nMonomer() const
Get number of monomer types.
double phi(int id) const
Return molecular volume fraction for one species.
double c(int id) const
Return monomer volume fraction for one monomer type.
void setComposition(DArray< double > const &phi)
Set system composition.
void setNMolecule(int nMolecule)
Set the number of molecular species and allocate memory.
double fHelmholtz() const
Return Helmholtz free energy per monomer / kT.
void computeMu(Interaction const &interaction, double xi=0.0)
Compute chemical potential from preset composition.
int nMolecule() const
Get number of molecule species (polymer + solvent).
void setNMonomer(int nMonomer)
Set the number of monomer types.
double mu(int id) const
Return chemical potential for one species.
Molecule & molecule(int id)
Get a molecule object (non-const reference).
void computeFreeEnergy(Interaction const &interaction)
Compute Helmholtz free energy and pressure.
void computePhi(Interaction const &interaction, DArray< double > const &mu, DArray< double > const &phi, double &xi)
Compute composition from chemical potentials.
double pressure() const
Return pressure in units of kT / monomer volume.
void validate() const
Validate all data structures.
void initialize(MixtureBase const &mixture)
Initialize to properties of a MixtureBase Mixture descriptor.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
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
Abstract descriptor for a mixture of polymer and solvent species.
Definition MixtureBase.h:57
Dynamically allocatable contiguous array template.
Definition DArray.h:32
Dynamically allocated Matrix.
Definition DMatrix.h:25
ParamComposite()
Constructor.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Flory-Huggins theory of spatially homogeneous mixtures.
Definition Clump.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1