1#ifndef RP_SCFT_THERMO_TPP
2#define RP_SCFT_THERMO_TPP
11#include "ScftThermo.h"
13#include <rp/solvers/Mixture.h>
14#include <rp/solvers/Polymer.h>
15#include <rp/solvers/Solvent.h>
16#include <rp/field/Domain.h>
17#include <rp/field/CFields.h>
18#include <rp/field/WFields.h>
19#include <rp/field/Mask.h>
21#include <pscf/crystal/Basis.h>
22#include <pscf/crystal/UnitCell.h>
24#include <pscf/backend/Reduce.h>
25#include <pscf/chem/PolymerSpecies.h>
26#include <pscf/chem/SolventSpecies.h>
27#include <pscf/interaction/Interaction.h>
28#include <pscf/mesh/Mesh.h>
30#include <util/format/Int.h>
31#include <util/format/Dbl.h>
41 template <
int D,
class T>
55 template <
int D,
class T>
79 for (
int i = 0; i < np; ++i) {
80 polymerPtr = &
mixture().polymerSpecies(i);
81 phi = polymerPtr->
phi();
82 mu = polymerPtr->
mu();
84 length = polymerPtr->
length();
86 length = (double) polymerPtr->
nBead();
89 fIdeal_ += phi*( mu - 1.0 ) / length;
99 for (
int i = 0; i < ns; ++i) {
100 solventPtr = &mixture().solventSpecies(i);
101 phi = solventPtr->
phi();
102 mu = solventPtr->
mu();
103 size = solventPtr->
size();
105 fIdeal_ += phi*( mu - 1.0 )/size;
120 const double phiTot = mask().phiTot();
124 if (w().isSymmetric()) {
128 const int nBasis = domain().basis().nBasis();
129 for (
int i = 0; i < nm; ++i) {
130 for (
int k = 0; k < nBasis; ++k) {
131 temp -= w().basis(i)[k] * c().basis(i)[k];
136 const int meshSize = domain().mesh().size();
137 for (
int i = 0; i < nm; ++i) {
140 temp /= double(meshSize);
144 fHelmholtz_ += fIdeal_;
148 if (
w().isSymmetric() &&
h().isSymmetric()) {
152 const int nBasis =
domain().basis().nBasis();
153 for (
int i = 0; i < nm; ++i) {
154 for (
int k = 0; k < nBasis; ++k) {
155 fExt_ +=
h().basis(i)[k] *
c().basis(i)[k];
160 const int meshSize =
domain().mesh().size();
161 for (
int i = 0; i < nm; ++i) {
164 fExt_ /= double(meshSize);
167 fHelmholtz_ += fExt_;
171 if (w().isSymmetric()) {
174 const int nBasis = domain().basis().nBasis();
176 for (
int i = 0; i < nm; ++i) {
177 for (
int j = i; j < nm; ++j) {
178 const double chi = interaction().chi(i,j);
181 for (
int k = 0; k < nBasis; ++k) {
182 temp += c().basis(i)[k] * c().basis(j)[k];
185 fInter_ += 0.5*chi*temp;
194 const int meshSize = domain().mesh().size();
196 for (
int i = 0; i < nm; ++i) {
197 for (
int j = i; j < nm; ++j) {
198 const double chi = interaction().chi(i,j);
202 fInter_ += 0.5*chi*temp;
209 fInter_ /= double(meshSize);
212 fHelmholtz_ += fInter_;
215 pressure_ = -fHelmholtz_;
219 PolymerSpecies<double>
const * polymerPtr;
221 for (
int i = 0; i < np; ++i) {
222 polymerPtr = &mixture().polymerSpecies(i);
223 phi = polymerPtr->phi();
224 mu = polymerPtr->mu();
226 length = polymerPtr->length();
228 length = (double) polymerPtr->nBead();
231 pressure_ += mu * phi / length;
238 SolventSpecies<double>
const * solventPtr;
240 for (
int i = 0; i < ns; ++i) {
241 solventPtr = &mixture().solventSpecies(i);
242 phi = solventPtr->phi();
243 mu = solventPtr->mu();
244 size = solventPtr->size();
246 pressure_ += mu * phi / size;
257 template <
int D,
class T>
259 { hasData_ =
false; }
264 template <
int D,
class T>
272 out <<
"fHelmholtz " <<
Dbl(
fHelmholtz(), 18, 11) << std::endl;
273 out <<
"pressure " <<
Dbl(
pressure(), 18, 11) << std::endl;
275 out <<
"fIdeal " <<
Dbl(fIdeal_, 18, 11) << std::endl;
276 out <<
"fInter " <<
Dbl(fInter_, 18, 11) << std::endl;
278 out <<
"fExt " <<
Dbl(fExt_, 18, 11) << std::endl;
286 out <<
"polymers:" << std::endl;
291 for (
int i = 0; i < np; ++i) {
293 <<
" " <<
Dbl(
mixture().polymer(i).phi(),18, 11)
294 <<
" " <<
Dbl(
mixture().polymer(i).mu(), 18, 11)
301 out <<
"solvents:" << std::endl;
306 for (
int i = 0; i < ns; ++i) {
308 <<
" " <<
Dbl(
mixture().solvent(i).phi(),18, 11)
309 <<
" " <<
Dbl(
mixture().solvent(i).mu(), 18, 11)
315 out <<
"cellParams:" << std::endl;
316 for (
int i = 0; i <
domain().unitCell().nParameter(); ++i) {
319 <<
Dbl(
domain().unitCell().parameter(i), 18, 11)
Descriptor for a linear or acyclic branched block polymer.
int nBead() const
Total number of beads in the polymer (bead model).
double length() const
Sum of the lengths of all blocks in the polymer (thread model).
ScftThermo(System< D, T > const &system)
Constructor.
bool hasData() const
Have free energies and pressure been computed?
void clear()
Clear all thermodynamic data.
void write(std::ostream &out)
Write SCFT thermodynamic properties to a file.
SystemConstRef< D, T > SystemConstRefT
Base class type name alias.
void compute()
Compute SCFT free energy density and pressure for current fields.
System< D, T > const & system() const
Get the associated System.
CFields< D, T > const & c() const
Get the concentration (c) field container.
WFields< D, CPT > const & h() const
double fHelmholtz() const
Get total Helmholtz free energy per monomer / kT.
Mixture< D, T > const & mixture() const
Get the Mixture.
double pressure() const
Get the precomputed pressure times monomer volume / kT.
WFields< D, T > const & w() const
Get the chemical potential (w) field container.
Domain< D, CPT > const & domain() const
Base class template for classes that represent a complete system.
Descriptor for a solvent species.
double size() const
Get the size (number of monomers) in this solvent.
WT mu() const
Get the chemical potential for this species (units kT=1).
WT phi() const
Get the overall volume fraction for this species.
Dbl()
Default constructor.
Int()
Default constructor.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
double innerProduct(Array< double > const &a, Array< double > const &b)
Compute Euclidean inner product of two real arrays .
bool isThread()
Is the thread model in use ?
Code for programs that simulate real-valued periodic fields.
PSCF package top-level namespace.