PSCF v1.3
rpg/solvers/Solvent.tpp
1#ifndef RPG_SOLVENT_TPP
2#define RPG_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 <prdc/cuda/resources.h>
13#include <pscf/mesh/Mesh.h>
14
15namespace Pscf {
16namespace Rpg {
17
18 /*
19 * Constructor.
20 */
21 template <int D>
23 : meshPtr_(nullptr)
24 { setClassName("Solvent"); }
25
26 /*
27 * Destructor.
28 */
29 template <int D>
32
33 /*
34 * Compute concentration, q, phi or mu.
35 */
36 template <int D>
37 void Solvent<D>::compute(RField<D> const & wField, double phiTot)
38 {
39 int nx = meshPtr_->size(); // Number of grid points
40
41 // Evaluate unnormalized integral and Q
42 double s = size();
43 double Q = 0.0;
44
45 // cField_ = exp(-size() * wField)
46 VecOp::expVc(cField_, wField, -1.0*size());
47
48 Q = Reduce::sum(cField_) / ((double) nx); // spatial average
49 Q /= phiTot; // correct for partial occupation
50
51 // Note: phiTot = 1.0 except in the case of a mask that confines
52 // material to a fraction of the unit cell.
53
54 // Set q and compute mu or phi (depending on ensemble)
56
57 // Normalize concentration
58 double prefactor = phi()/Q;
59 VecOp::mulEqS(cField_, prefactor);
60 }
61
62}
63}
64#endif
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
double phi() const
Get the overall volume fraction for this species.
Definition Species.h:149
void compute(RField< D > const &wField, double phiTot=1.0)
Compute monomer concentration field, q and phi and/or mu.
double size() const
Get the size (number of monomers) in this solvent.
void setQ(double q)
Set q and compute phi or mu (depending on the ensemble).
Definition Species.cpp:63
void setClassName(const char *className)
Set class name string.
void expVc(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, cudaReal const c)
Vector exponentiation w/ coefficient, a[i] = exp(b[i]*c), kernel wrapper.
Definition VecOpMisc.cu:393
void mulEqS(DeviceArray< cudaReal > &a, const cudaReal b, const int beginIdA, const int n)
Vector multiplication in-place, a[i] *= b, kernel wrapper (cudaReal).
Definition VecOp.cu:1918
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1