PSCF v1.3
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/domain/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 #if 0
60 double prefactor;
61 if (ensemble() == Species::Closed) {
62 prefactor = phi_/q_;
63 mu_ = log(prefactor);
64 } else {
65 prefactor = exp(mu_);
66 phi_ = prefactor*q_;
67 }
68 #endif
69
70 // Normalize concentration
71 double prefactor = phi()/Q;
72 for (int i = 0; i < nx; ++i) {
73 cField_[i] *= prefactor;
74 }
75
76 }
77
78}
79}
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.
SolventSpecies()
Constructor.
double size() const
Get the size (number of monomers) in this solvent.
double phi() const
Get the overall volume fraction for this species.
Definition Species.h:149
void setQ(double q)
Set q and compute phi or mu (depending on the ensemble).
Definition Species.cpp:63
Ensemble ensemble() const
Get the statistical ensemble for this species (open or closed).
Definition Species.h:167
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.
Definition param_pc.dox:1