PSCF v1.4.0
rp/solvers/Solvent.tpp
1#ifndef RP_SOLVENT_TPP
2#define RP_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 Rp {
16
17 /*
18 * Constructor.
19 */
20 template <int D, class T>
22 : meshPtr_(nullptr)
23 { ParamComposite::setClassName("Solvent"); }
24
25 /*
26 * Destructor.
27 */
28 template <int D, class T>
31
32 /*
33 * Create an association with a mesh.
34 */
35 template <int D, class T>
37 {
38 UTIL_CHECK(!meshPtr_);
39 UTIL_CHECK(mesh.size() > 1);
40 meshPtr_ = &mesh;
41 }
42
43 /*
44 * Allocate memory for the concentration field (cField).
45 */
46 template <int D, class T>
48 {
49 UTIL_CHECK(meshPtr_);
50 cField_.allocate(meshPtr_->dimensions());
51 }
52
53 /*
54 * Compute concentration, q, and phi or mu.
55 */
56 template <int D, class T>
57 void Solvent<D,T>::compute(typename T::RField const & wField,
58 double phiTot)
59 {
60 // Local constants
61 const int nx = meshPtr_->size();
62 const double size = SolventSpeciesT::size();
63
64 // Evaluate unnormalized integral and Q
65 VecOp::expVc(cField_, wField, -1.0*size);
66 double Q = Reduce::sum(cField_);
67 Q = Q / double(nx); // spatial average
68 Q /= phiTot; // correct for partial occupation
69
70 // Note: phiTot = 1.0 except in the case of a mask that confines
71 // material to a fraction of the unit cell.
72
73 // Set q and compute mu or phi
75
76 // Normalize concentration
77 double prefactor = SpeciesT::phi()/Q;
78 VecOp::mulEqS(cField_, prefactor);
79
80 }
81
82}
83}
84#endif
Description of a regular grid of points in a periodic domain.
Definition Mesh.h:61
int size() const
Get total number of grid points.
Definition Mesh.h:229
void compute(typename T::RField const &wField, double phiTot=1.0)
Compute concentration field, q, and phi or mu.
void associate(Mesh< D > const &mesh)
Create an association with a Mesh.
void allocate()
Allocate memory for a concentration field.
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
double sum(Array< double > const &in)
Compute sum of array elements (real).
Definition Reduce.cpp:20
void mulEqS(Array< double > &a, double b)
Vector-scalar in-place multiplication, a[i] *= b (real).
Definition VecOp.cpp:265
void expVc(Array< double > &a, Array< double > const &b, const double c)
Exponentiation a scaled vector, a[i] = exp(b[i]*c) (real).
Definition VecOp.cpp:319
Class templates for real-valued periodic fields.
PSCF package top-level namespace.