PSCF v1.3
rpc/solvers/Solvent.tpp
1#ifndef RPC_SOLVENT_TPP
2#define RPC_SOLVENT_TPP
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 "Solvent.h"
12#include <pscf/mesh/Mesh.h>
13
14namespace Pscf {
15namespace Rpc {
16
17 /*
18 * Constructor
19 */
20 template <int D>
23 meshPtr_(nullptr)
24 { setClassName("Solvent"); }
25
26 /*
27 * Destructor
28 */
29 template <int D>
32
33 /*
34 * Create an association with a Mesh & allocate the concentration field.
35 */
36 template <int D>
37 void Solvent<D>::associate(Mesh<D> const & mesh)
38 {
39 meshPtr_ = &mesh;
40 }
41
42 /*
43 * Allocate the concentration field (cField).
44 */
45 template <int D>
47 {
48 UTIL_CHECK(meshPtr_);
49 cField_.allocate(meshPtr_->dimensions());
50 }
51
52 /*
53 * Compute concentration, q, and phi or mu.
54 */
55 template <int D>
56 void Solvent<D>::compute(RField<D> const & wField, double phiTot)
57 {
58 int nx = meshPtr_->size(); // Number of grid points
59
60 // Initialize cField_ to zero
61 for (int i = 0; i < nx; ++i) {
62 cField_[i] = 0.0;
63 }
64
65 // Evaluate unnormalized integral and Q
66 double s = size();
67 double Q = 0.0;
68 for (int i = 0; i < nx; ++i) {
69 cField_[i] = exp(-s*wField[i]);
70 Q += cField_[i];
71 }
72 Q = Q/double(nx); // spatial average
73 Q = Q/phiTot; // correct for partial occupation
74
75 // Note: phiTot = 1.0 except in the case of a mask that confines
76 // material to a fraction of the unit cell.
77
78 // Set q and compute mu or phi
80
81 #if 0
82 q_ = Q;
83 double prefactor;
84 if (ensemble() == Species::Closed) {
85 prefactor = phi_/q_;
86 mu_ = log(prefactor);
87 } else {
88 prefactor = exp(mu_);
89 phi_ = prefactor*q_;
90 }
91 #endif
92
93 // Normalize concentration
94 double prefactor = phi()/Q;
95 for (int i = 0; i < nx; ++i) {
96 cField_[i] *= prefactor;
97 }
98
99 }
100
101}
102}
103#endif
Description of a regular grid of points in a periodic domain.
Definition Mesh.h:61
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
double phi() const
Get the overall volume fraction for this species.
Definition Species.h:149
void associate(Mesh< D > const &mesh)
Create an association with the mesh.
void compute(RField< D > const &wField, double phiTot=1.0)
Compute monomer concentration field, q and phi and/or mu.
Ensemble ensemble() const
Get the statistical ensemble for this species (open or closed).
Definition Species.h:167
void allocate()
Allocate memory for concentrationf field.
double size() const
Get the size (number of monomers) in this solvent.
SolventSpecies()
Constructor.
void setQ(double q)
Set q and compute phi or mu (depending on the ensemble).
Definition Species.cpp:63
void setClassName(const char *className)
Set class name string.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1