PSCF v1.4.0
Species.tpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Species.h"
9#include <pscf/math/arithmetic.h>
10#include <cmath>
11
12namespace Pscf {
13
14 using namespace Util;
15
16 /*
17 * Default constructor.
18 */
19 template <typename WT>
21 : phiMu_(0.0),
22 ensemble_(Ensemble::Closed)
23 {
24 assign(phi_, 0.0);
25 assign(mu_, 0.0);
26 assign(q_, 0.0);
27 setClassName("Species");
28 }
29
30 /*
31 * Read phi or mu (but not both) and set ensemble.
32 */
33 template <typename WT>
34 void Species<WT>::readParameters(std::istream& in)
35 {
36 // Read phi or mu (but not both)
37 bool hasPhi = readOptional(in, "phi", phiMu_).isActive();
38 if (hasPhi) {
39 ensemble_ = Ensemble::Closed;
40 assign(phi_, phiMu_);
41 } else {
42 ensemble_ = Ensemble::Open;
43 read(in, "mu", phiMu_);
44 assign(mu_, phiMu_);
45 }
46 }
47
48 /*
49 * Set volume fraction (if ensemble is closed).
50 */
51 template <typename WT>
53 {
54 UTIL_CHECK(ensemble() == Ensemble::Closed);
55 UTIL_CHECK(phi >= 0.0);
56 UTIL_CHECK(phi <= 1.0);
57 assign(phiMu_, phi);
58 assign(phi_, phi);
59 }
60
61 /*
62 * Set chemical potential (if ensemble is open).
63 */
64 template <typename WT>
66 {
67 UTIL_CHECK(ensemble() == Ensemble::Open);
68 assign(phiMu_, mu);
69 assign(mu_, mu);
70 }
71
72 /*
73 * Set q and compute mu or phi (depending on ensemble).
74 */
75 template <typename WT>
77 {
78 assign(q_, q);
79 if (ensemble() == Ensemble::Closed) {
80 WT ratio;
81 div(ratio, phi_, q_);
82 assignLog(mu_, ratio);
83 //mu_ = std::log(phi_/q_);
84 } else
85 if (ensemble() == Ensemble::Open) {
86 WT lambda;
87 assignExp(lambda, mu_);
88 mul(phi_, lambda, q_);
89 //phi_ = std::exp(mu_)*q_;
90 }
91 }
93} // namespace Pscf
WT q() const
Get the molecular partition function for this species.
Definition Species.h:173
void setMu(double mu)
Set value of mu (chemical potential), if ensemble is closed.
Definition Species.tpp:65
Ensemble ensemble() const
Get the statistical ensemble for this species (open or closed).
Definition Species.h:180
Species()
Constructor.
Definition Species.tpp:20
virtual void readParameters(std::istream &in)
Read phi or mu (but not both) and set ensemble accordingly.
Definition Species.tpp:34
WT mu() const
Get the chemical potential for this species (units kT=1).
Definition Species.h:166
void setQ(WT q)
Set q and compute phi or mu (depending on the ensemble).
Definition Species.tpp:76
WT phi() const
Get the overall volume fraction for this species.
Definition Species.h:159
void setPhi(double phi)
Set value of phi (volume fraction), if ensemble is closed.
Definition Species.tpp:52
void setClassName(const char *className)
Set class name string.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Ensemble
Statistical ensemble type for the number of molecules of one species.
Definition Ensemble.h:23
void div(fftw_complex &z, fftw_complex const &a, fftw_complex const &b)
Division of fftw_complex numbers, z = a / b .
void assignExp(fftw_complex &z, fftw_complex const &a)
Exponentation of a ffts_complex variable, z = exp(a).
void assign(fftw_complex &z, double const &a, double const &b)
Create an fftw_complex from real and imaginary parts, z = a + ib.
void mul(fftw_complex &z, fftw_complex const &a, fftw_complex const &b)
Multiplication of fftw_complex numbers, z = a * b.
void assignLog(fftw_complex &z, fftw_complex const &a)
Logarithm of an fftw_complex variable, z = log(a).
PSCF package top-level namespace.