PSCF v1.4.0
r1d/solvers/Solvent.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Solvent.h"
9#include <r1d/field/Domain.h>
10
11namespace Pscf {
12namespace R1d {
13
14 /*
15 * Constructor.
16 */
19 { setClassName("Solvent"); }
20
21 /*
22 * Destructor.
23 */
26
27 /*
28 * Set association with Domain and allocate concentration field.
29 */
31 {
32 domainPtr_ = &domain;
33 int nx = domain.nx();
34 if (nx > 0) {
35 cField_.allocate(nx);
36 }
37 }
38
39 /*
40 * Compute concentration, q, and phi or mu.
41 */
42 void Solvent::compute(FieldT const & wField)
43 {
44 UTIL_CHECK(cField_.isAllocated());
45
46 // Evaluate unnormalized concentration, Boltzmann weight
47 int nx = domain().nx();
48 double s = size();
49 for (int i = 0; i < nx; ++i) {
50 cField_[i] = exp(-s*wField[i]);
51 }
52
53 // Compute spatial average q
54 double Q = domain().spatialAverage(cField_);
55
56 // Set q and compute mu or phi (depending on ensemble)
58
59 // Normalize concentration
60 double prefactor = phi()/Q;
61 for (int i = 0; i < nx; ++i) {
62 cField_[i] *= prefactor;
63 }
64
65 }
66
67}
68}
One-dimensional spatial domain and discretization grid.
int nx() const
Get number of spatial grid points, including both endpoints.
double spatialAverage(Field const &f) const
Compute spatial average of a field.
void setDiscretization(Domain const &domain)
Set association with Domain and allocate concentration field array.
typename Propagator::FieldT FieldT
Field type.
void compute(FieldT const &wField)
Compute monomer concentration field, q and phi and/or mu.
Domain const & domain() const
Return associated domain by reference.
void setQ(WT q)
Set q and compute phi or mu (depending on the ensemble).
Definition Species.tpp:76
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
SCFT with real 1D fields.
PSCF package top-level namespace.