PSCF v1.1
pspc/solvers/Solvent.tpp
1#ifndef PSPC_SOLVENT_TPP
2#define PSPC_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 Pspc {
16
17 /*
18 * Constructor
19 */
20 template <int D>
23 { setClassName("Solvent"); }
24
25 /*
26 * Destructor
27 */
28 template <int D>
30 {}
31
32 /*
33 * Create an association with a Mesh & allocate the concentration field.
34 */
35 template <int D>
37 {
38 meshPtr_ = &mesh;
39 cField_.allocate(mesh.dimensions());
40 }
41
42 /*
43 * Compute concentration, q, and phi or mu.
44 */
45 template <int D>
46 void Solvent<D>::compute(RField<D> const & wField, double phiTot)
47 {
48 int nx = meshPtr_->size(); // Number of grid points
49
50 // Initialize cField_ to zero
51 for (int i = 0; i < nx; ++i) {
52 cField_[i] = 0.0;
53 }
54
55 // Evaluate unnormalized integral and q_
56 double s = size();
57 q_ = 0.0;
58 for (int i = 0; i < nx; ++i) {
59 cField_[i] = exp(-s*wField[i]);
60 q_ += cField_[i];
61 }
62 q_ = q_/double(nx); // spatial average
63 q_ = q_/phiTot; // correct for partial occupation
64
65 // Note: phiTot = 1.0 except in the case of a mask that confines
66 // material to a fraction of the unit cell.
67
68 // Compute mu_ or phi_ and prefactor
69 double prefactor;
70 if (ensemble_ == Species::Closed) {
71 prefactor = phi_/q_;
72 mu_ = log(prefactor);
73 } else {
74 prefactor = exp(mu_);
75 phi_ = prefactor*q_;
76 }
77
78 // Normalize concentration
79 for (int i = 0; i < nx; ++i) {
80 cField_[i] *= prefactor;
81 }
82
83 }
84
85}
86}
87#endif
Description of a regular grid of points in a periodic domain.
Definition: Mesh.h:61
IntVec< D > dimensions() const
Get an IntVec<D> of the grid dimensions.
Definition: Mesh.h:217
Field of real double precision values on an FFT mesh.
Definition: RField.h:29
void compute(RField< D > const &wField, double phiTot=1.0)
Compute monomer concentration field, q and phi and/or mu.
void setDiscretization(Mesh< D > const &mesh)
Set association with Mesh and allocate concentration field array.
Descriptor for a solvent species.
void setClassName(const char *className)
Set class name string.
C++ namespace for polymer self-consistent field theory (PSCF).