PSCF v1.1
pspg/solvers/Solvent.tpp
1#ifndef PSPC_SOLVENT_TPP
2#define PSPC_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 <pscf/mesh/Mesh.h>
13
14namespace Pscf {
15namespace Pspg {
16
17 template <int D>
19 { setClassName("Solvent"); }
20
21 template <int D>
23 {}
24
25 /*
26 * Create an association with a Mesh & allocate the concentration field.
27 */
28 template <int D>
30 {
31 meshPtr_ = &mesh;
32 concField_.allocate(mesh.dimensions());
33 }
34
35 /*
36 * Compute concentration, q, phi or mu.
37 */
38 template <int D>
39 void Solvent<D>::compute(RDField<D> const & wField)
40 {
41 int nx = meshPtr_->size(); // Number of grid points
42
43 // GPU Resources
44 int nBlocks, nThreads;
45 ThreadGrid::setThreadsLogical(nx, nBlocks, nThreads);
46
47 // Initialize concField_ to zero
48 assignUniformReal<<<nBlocks, nThreads>>>(concField_.cDField(), 0, nx);
49
50 // Evaluate unnormalized integral and q_
51 double s = size();
52 q_ = 0.0;
53 assignExp<<<nBlocks, nThreads>>>(concField_.cDField(), wField.cDField(), s, nx);
54 q_ = (double)gpuSum(concField_.cDField(),nx);
55 q_ = q_/double(nx);
56
57 // Compute mu_ or phi_ and prefactor
58 double prefactor;
59 if (ensemble_ == Species::Closed) {
60 prefactor = phi_/q_;
61 mu_ = log(prefactor);
62 } else {
63 prefactor = exp(mu_);
64 phi_ = prefactor*q_;
65 }
66
67 // Normalize concentration
68 scaleReal<<<nBlocks, nThreads>>>(concField_.cDField(), prefactor, nx);
69
70 }
71
72}
73}
74#endif
Description of a regular grid of points in a periodic domain.
Definition: Mesh.h:61
IntVec< D > dimensions() const
Get an IntVec<D> of the grid dimensions.
Definition: Mesh.h:217
Data * cDField()
Return pointer to underlying C array.
Definition: DField.h:119
Field of real single precision values on an FFT mesh on a device.
Definition: RDField.h:34
void compute(RDField< D > const &wField)
Compute monomer concentration field and phi and/or mu.
void setDiscretization(Mesh< D > const &mesh)
Set association with Mesh, allocate memory.
void setThreadsLogical(int nThreadsLogical)
Set the total number of threads required for execution.
Definition: ThreadGrid.cu:80
C++ namespace for polymer self-consistent field theory (PSCF).