PSCF v1.5.0
Solvent.tpp
1#ifndef RP_SOLVENT_TPP
2#define RP_SOLVENT_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Solvent.h"
12#include <pscf/field/RField.h>
13#include <pscf/backend/Reduce.h>
14#include <pscf/backend/VecOp.h>
15#include <pscf/mesh/Mesh.h>
16
17namespace Pscf {
18namespace Rp {
19
20 /*
21 * Constructor.
22 */
23 template <int D, class T>
25 : meshPtr_(nullptr)
26 { ParamComposite::setClassName("Solvent"); }
27
28 /*
29 * Destructor.
30 */
31 template <int D, class T>
34
35 /*
36 * Create an association with a mesh.
37 */
38 template <int D, class T>
40 {
41 UTIL_CHECK(!meshPtr_);
42 UTIL_CHECK(mesh.size() > 1);
43 meshPtr_ = &mesh;
44 }
45
46 /*
47 * Allocate memory for the concentration field (cField).
48 */
49 template <int D, class T>
51 {
52 UTIL_CHECK(meshPtr_);
53 cField_.allocate(meshPtr_->dimensions());
54 }
55
56 /*
57 * Compute concentration, q, and phi or mu.
58 */
59 template <int D, class T>
60 void Solvent<D,T>::compute(RField<D,T> const & wField,
61 double phiTot)
62 {
63 // Local constants
64 const int nx = meshPtr_->size();
65 const double size = SolventSpeciesT::size();
66
67 // Evaluate unnormalized integral and Q
68 VecOp::expVc(cField_, wField, -1.0*size);
69 double Q = Reduce::sum(cField_);
70 Q = Q / double(nx); // spatial average
71 Q /= phiTot; // correct for partial occupation
72
73 // Note: phiTot = 1.0 except in the case of a mask that confines
74 // material to a fraction of the unit cell.
75
76 // Set q and compute mu or phi
78
79 // Normalize concentration
80 double prefactor = SpeciesT::phi()/Q;
81 VecOp::mulEqS(cField_, prefactor);
82
83 }
84
85}
86}
87#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
~Solvent()
Destructor.
Definition Solvent.tpp:32
Solvent()
Constructor.
Definition Solvent.tpp:24
void compute(RField< D, T > const &wField, double phiTot=1.0)
Compute concentration field, q, and phi or mu.
Definition Solvent.tpp:60
void associate(Mesh< D > const &mesh)
Create an association with a Mesh.
Definition Solvent.tpp:39
void allocate()
Allocate memory for a concentration field.
Definition Solvent.tpp:50
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:19
void mulEqS(Array< double > &a, double b)
Vector-scalar in-place multiplication, a[i] *= b (real).
Definition VecOp.cpp:270
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:324
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.