PSCF v1.5.0
FhMixture.h
1#ifndef PSCF_FH_MIXTURE_H
2#define PSCF_FH_MIXTURE_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
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
14#include <pscf/floryHuggins/FhMolecule.h> // member
15#include <util/containers/DArray.h> // member
16#include <util/containers/DMatrix.h> // member
17
18// Forward declarations
19namespace Pscf {
20 class FhInteraction;
21 class LuSolver;
22 template <typename WT> class Composition;
23}
24
25namespace Pscf {
26
27 using namespace Util;
28
35 {
36 public:
37
41 FhMixture();
42
46 ~FhMixture();
47
49
50
56 virtual void readParameters(std::istream& in);
57
71 template <typename WT>
72 void initialize(Composition<WT> const& mixture);
73
81 void setNMolecule(int nMolecule);
82
90 void setNMonomer(int nMonomer);
91
93
95
109 void setComposition(DArray<double> const & phi);
110
120 void computeMu(FhInteraction const & interaction, double xi = 0.0);
121
134 void computePhi(FhInteraction const & interaction,
135 DArray<double> const & mu,
136 DArray<double> const & phi,
137 double& xi);
138
150 void computeFreeEnergy(FhInteraction const & interaction);
151
153
155
161 FhMolecule& molecule(int id);
162
168 double mu(int id) const;
169
175 double phi(int id) const;
176
182 double c(int id) const;
183
187 double fHelmholtz() const;
188
192 double pressure() const;
193
197 int nMolecule() const;
198
202 int nMonomer() const;
203
205
211 void validate() const;
212
213 private:
214
220 DArray<FhMolecule> molecules_;
221
225 DArray<double> mu_;
226
230 DArray<double> phi_;
231
236
241
245 DArray<double> residual_;
246
250 DArray<double> dX_;
251
255 DMatrix<double> dWdC_;
256
260 DMatrix<double> dWdPhi_;
261
265 DMatrix<double> jacobian_;
266
273 DArray<double> lnPhi_;
274
278 DArray<double> lnPhiOld_;
279
283 double fHelmholtz_;
284
288 double pressure_;
289
293 LuSolver* solverPtr_;
294
298 int nMolecule_;
299
303 int nMonomer_;
304
308 bool hasComposition_;
309
313 void computeC();
314
321 void adjustXi(DArray<double> const & mu, double& xi);
322
334 void computeResidual(DArray<double> const & mu, double& error);
335
336 };
337
338 // Inline member functions
339
341 {
342 UTIL_ASSERT(id >= 0);
343 UTIL_ASSERT(id < nMolecule_);
344 return molecules_[id];
345 }
346
347 inline double FhMixture::mu(int id) const
348 {
349 UTIL_ASSERT(id >= 0);
350 UTIL_ASSERT(id < nMolecule_);
351 return mu_[id];
352 }
353
354 inline double FhMixture::phi(int id) const
355 {
356 UTIL_ASSERT(id >= 0);
357 UTIL_ASSERT(id < nMolecule_);
358 return phi_[id];
359 }
360
361 inline double FhMixture::c(int id) const
362 {
363 UTIL_ASSERT(id >= 0);
364 UTIL_ASSERT(id < nMonomer_);
365 return c_[id];
366 }
367
368 inline double FhMixture::fHelmholtz() const
369 { return fHelmholtz_; }
370
371 inline double FhMixture::pressure() const
372 { return pressure_; }
373
374 inline int FhMixture::nMolecule() const
375 { return nMolecule_; }
376
377 inline int FhMixture::nMonomer() const
378 { return nMonomer_; }
379
380 // Explicit instantiation declaration for member function template
381 extern template
383
384} // namespace Pscf
385#endif
Descriptor for a mixture of polymer and solvent species.
Definition Composition.h:68
Flory-Huggins interaction model.
void setComposition(DArray< double > const &phi)
Set system composition.
FhMolecule & molecule(int id)
Get a molecule object (non-const reference).
Definition FhMixture.h:340
FhMixture()
Constructor.
Definition FhMixture.cpp:53
int nMolecule() const
Get number of molecule species (polymer + solvent).
Definition FhMixture.h:374
void validate() const
Validate all data structures.
void computePhi(FhInteraction const &interaction, DArray< double > const &mu, DArray< double > const &phi, double &xi)
Compute composition from chemical potentials.
double mu(int id) const
Return chemical potential for one species.
Definition FhMixture.h:347
double fHelmholtz() const
Return Helmholtz free energy per monomer / kT.
Definition FhMixture.h:368
double pressure() const
Return pressure in units of kT / monomer volume.
Definition FhMixture.h:371
int nMonomer() const
Get number of monomer types.
Definition FhMixture.h:377
void initialize(Composition< WT > const &mixture)
Initialize to properties of a Composition descriptor.
Definition FhMixture.tpp:30
void computeMu(FhInteraction const &interaction, double xi=0.0)
Compute chemical potential from preset composition.
void computeFreeEnergy(FhInteraction const &interaction)
Compute Helmholtz free energy and pressure.
double c(int id) const
Return monomer volume fraction for one monomer type.
Definition FhMixture.h:361
void setNMolecule(int nMolecule)
Set the number of molecular species and allocate memory.
void setNMonomer(int nMonomer)
Set the number of monomer types and allocate memory.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
Definition FhMixture.cpp:88
double phi(int id) const
Return molecular volume fraction for one species.
Definition FhMixture.h:354
Molecular species in a homogeneous Flory-Huggins mixture.
Definition FhMolecule.h:36
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
ParamComposite()
Constructor.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
PSCF package top-level namespace.