PSCF v1.2
rpg/solvers/Solvent.tpp
1#ifndef RPG_SOLVENT_TPP
2#define RPG_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 <prdc/cuda/resources.h>
13#include <pscf/mesh/Mesh.h>
14
15namespace Pscf {
16namespace Rpg {
17
18 template <int D>
20 : meshPtr_(nullptr)
21 { setClassName("Solvent"); }
22
23 template <int D>
26
27 /*
28 * Compute concentration, q, phi or mu.
29 */
30 template <int D>
31 void Solvent<D>::compute(RField<D> const & wField, double phiTot)
32 {
33 int nx = meshPtr_->size(); // Number of grid points
34
35 // Evaluate unnormalized integral and q_
36 double s = size();
37 q_ = 0.0;
38
39 // cField_ = exp(-size() * wField)
40 VecOp::expVc(cField_, wField, -1.0*size());
41
42 q_ = Reduce::sum(cField_) / ((double) nx); // spatial average
43 q_ /= phiTot; // correct for partial occupation
44
45 // Note: phiTot = 1.0 except in the case of a mask that confines
46 // material to a fraction of the unit cell.
47
48 // Compute mu_ or phi_ and prefactor
49 double prefactor;
50 if (ensemble_ == Species::Closed) {
51 prefactor = phi_/q_;
52 mu_ = log(prefactor);
53 } else {
54 prefactor = exp(mu_);
55 phi_ = prefactor*q_;
56 }
57
58 // Normalize concentration
59 VecOp::mulEqS(cField_, prefactor);
60 }
61
62}
63}
64#endif
Field of real double precision values on an FFT mesh.
void compute(RField< D > const &wField, double phiTot=1.0)
Compute monomer concentration field, q and phi and/or mu.
void setClassName(const char *className)
Set class name string.
cudaReal sum(DeviceArray< cudaReal > const &in)
Compute sum of array elements (GPU kernel wrapper).
Definition Reduce.cu:480
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, cudaReal const b, const int beginIdA, const int n)
Vector multiplication in-place, a[i] *= b, kernel wrapper (cudaReal).
Definition VecOp.cu:1875
PSCF package top-level namespace.
Definition param_pc.dox:1