PSCF v1.2
rpc/solvers/Solvent.tpp
1#ifndef RPC_SOLVENT_TPP
2#define RPC_SOLVENT_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, 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 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 // Compute mu_ or phi_ and prefactor
79 double prefactor;
80 if (ensemble_ == Species::Closed) {
81 prefactor = phi_/q_;
82 mu_ = log(prefactor);
83 } else {
84 prefactor = exp(mu_);
85 phi_ = prefactor*q_;
86 }
87
88 // Normalize concentration
89 for (int i = 0; i < nx; ++i) {
90 cField_[i] *= prefactor;
91 }
92
93 }
94
95}
96}
97#endif
Description of a regular grid of points in a periodic domain.
Field of real double precision values on an FFT mesh.
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.
void allocate()
Allocate memory for concentrationf field.
Descriptor for a solvent species.
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
PSCF package top-level namespace.
Definition param_pc.dox:1