PSCF v1.4.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 - 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
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 MixtureBase;
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
63 template <typename WT>
64 void initialize(MixtureBase<WT> const& mixture);
65
71 void setNMolecule(int nMolecule);
72
78 void setNMonomer(int nMonomer);
79
81
83
89 void setComposition(DArray<double> const & phi);
90
100 void computeMu(FhInteraction const & interaction, double xi = 0.0);
101
110 void computePhi(FhInteraction const & interaction,
111 DArray<double> const & mu,
112 DArray<double> const & phi,
113 double& xi);
114
126 void computeFreeEnergy(FhInteraction const & interaction);
127
129
131
137 FhMolecule& molecule(int id);
138
144 double mu(int id) const;
145
151 double phi(int id) const;
152
158 double c(int id) const;
159
163 double fHelmholtz() const;
164
168 double pressure() const;
169
173 int nMolecule() const;
174
178 int nMonomer() const;
179
181
187 void validate() const;
188
189 private:
190
196 DArray<FhMolecule> molecules_;
197
201 DArray<double> mu_;
202
206 DArray<double> phi_;
207
212
217
221 DArray<double> residual_;
222
226 DArray<double> dX_;
227
231 DMatrix<double> dWdC_;
232
236 DMatrix<double> dWdPhi_;
237
241 DMatrix<double> jacobian_;
242
246 DArray<double> phiOld_;
247
251 double fHelmholtz_;
252
256 double pressure_;
257
261 LuSolver* solverPtr_;
262
266 int nMolecule_;
267
271 int nMonomer_;
272
276 bool hasComposition_;
277
281 void computeC();
282
286 void adjustXi(DArray<double> const & mu, double& xi);
287
291 void computeResidual(DArray<double> const & mu,
292 double& error);
293
294 };
295
296 // Inline member functions
297
299 {
300 UTIL_ASSERT(id >= 0);
301 UTIL_ASSERT(id < nMolecule_);
302 return molecules_[id];
303 }
304
305 inline double FhMixture::mu(int id) const
306 {
307 UTIL_ASSERT(id >= 0);
308 UTIL_ASSERT(id < nMolecule_);
309 return mu_[id];
310 }
311
312 inline double FhMixture::phi(int id) const
313 {
314 UTIL_ASSERT(id >= 0);
315 UTIL_ASSERT(id < nMolecule_);
316 return phi_[id];
317 }
318
319 inline double FhMixture::c(int id) const
320 {
321 UTIL_ASSERT(id >= 0);
322 UTIL_ASSERT(id < nMonomer_);
323 return c_[id];
324 }
325
326 inline double FhMixture::fHelmholtz() const
327 { return fHelmholtz_; }
328
329 inline double FhMixture::pressure() const
330 { return pressure_; }
331
332 inline int FhMixture::nMolecule() const
333 { return nMolecule_; }
334
335 inline int FhMixture::nMonomer() const
336 { return nMonomer_; }
337
338 // Explicit instantiation declaration for member function template
339 extern template
341
342} // namespace Pscf
343#endif
Flory-Huggins interaction model.
~FhMixture()
Destructor.
Definition FhMixture.cpp:44
void setComposition(DArray< double > const &phi)
Set system composition.
Definition FhMixture.cpp:96
FhMolecule & molecule(int id)
Get a molecule object (non-const reference).
Definition FhMixture.h:298
FhMixture()
Constructor.
Definition FhMixture.cpp:20
void initialize(MixtureBase< WT > const &mixture)
Initialize to properties of a MixtureBase descriptor.
Definition FhMixture.tpp:24
int nMolecule() const
Get number of molecule species (polymer + solvent).
Definition FhMixture.h:332
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:305
double fHelmholtz() const
Return Helmholtz free energy per monomer / kT.
Definition FhMixture.h:326
double pressure() const
Return pressure in units of kT / monomer volume.
Definition FhMixture.h:329
int nMonomer() const
Get number of monomer types.
Definition FhMixture.h:335
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:319
void setNMolecule(int nMolecule)
Set the number of molecular species and allocate memory.
Definition FhMixture.cpp:74
void setNMonomer(int nMonomer)
Set the number of monomer types.
Definition FhMixture.cpp:84
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
Definition FhMixture.cpp:54
double phi(int id) const
Return molecular volume fraction for one species.
Definition FhMixture.h:312
Molecular species in a homogeneous Flory-Huggins mixture.
Definition FhMolecule.h:36
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:58
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.