PSCF v1.1
fd1d/solvers/Solvent.cpp
1#ifndef FD1D_SOLVENT_TPP
2#define FD1D_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 <fd1d/domain/Domain.h>
13
14namespace Pscf {
15namespace Fd1d {
16
19 { setClassName("Solvent"); }
20
22 {}
23
24 /*
25 * Set association with Domain and allocate concentration field.
26 */
28 {
29 domainPtr_ = &domain;
30 int nx = domain.nx();
31 if (nx > 0) {
32 cField_.allocate(nx);
33 }
34 }
35
36 /*
37 * Compute concentration, q, phi or mu.
38 */
39 void Solvent::compute(WField const & wField)
40 {
41 UTIL_CHECK(cField_.isAllocated());
42
43 // Evaluate unnormalized concentration, Boltzmann weight
44 int nx = domain().nx();
45 double s = size();
46 for (int i = 0; i < nx; ++i) {
47 cField_[i] = exp(-s*wField[i]);
48 }
49
50 // Compute spatial average q_
51 q_ = domain().spatialAverage(cField_);
52
53 // Compute mu_ or phi_ and prefactor
54 double prefactor;
55 if (ensemble_ == Species::Closed) {
56 prefactor = phi_/q_;
57 mu_ = log(prefactor);
58 } else {
59 prefactor = exp(mu_);
60 phi_ = prefactor*q_;
61 }
62
63 // Normalize concentration
64 for (int i = 0; i < nx; ++i) {
65 cField_[i] *= prefactor;
66 }
67
68 }
69
70}
71}
72#endif
One-dimensional spatial domain and discretization grid.
double spatialAverage(Field const &f) const
Compute spatial average of a field.
int nx() const
Get number of spatial grid points, including both endpoints.
void compute(WField const &wField)
Compute monomer concentration field, q and phi and/or mu.
Domain const & domain() const
Return associated domain by reference.
void setDiscretization(Domain const &domain)
Set association with Domain and allocate concentration field array.
Descriptor for a solvent species.
double size() const
Get the size (number of monomers) in this solvent.
Ensemble ensemble_
Statistical ensemble for this species (open or closed).
Definition: Species.h:83
double phi_
Volume fraction, set by either setPhi or compute function.
Definition: Species.h:68
double mu_
Chemical potential, set by either setPhi or compute function.
Definition: Species.h:73
double q_
Partition function, set by compute function.
Definition: Species.h:78
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:199
bool isAllocated() const
Return true if this DArray has been allocated, false otherwise.
Definition: DArray.h:247
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
C++ namespace for polymer self-consistent field theory (PSCF).