Loading [MathJax]/extensions/TeX/AMSsymbols.js
PSCF v1.2
rpg/fts/brownian/ExplicitBdStep.tpp
1#ifndef RPG_EXPLICIT_BD_STEP_TPP
2#define RPG_EXPLICIT_BD_STEP_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 "ExplicitBdStep.h"
12
13#include <rpg/fts/brownian/BdSimulator.h>
14#include <rpg/fts/compressor/Compressor.h>
15#include <rpg/System.h>
16#include <prdc/cuda/VecOp.h>
17#include <pscf/math/IntVec.h>
18
19namespace Pscf {
20namespace Rpg {
21
22 using namespace Util;
23 using namespace Pscf::Prdc;
24 using namespace Pscf::Prdc::Cuda;
25
26 /*
27 * Constructor.
28 */
29 template <int D>
31 : BdStep<D>(simulator),
32 w_(),
33 dwc_(),
34 mobility_(0.0)
35 {}
36
37 /*
38 * Destructor, empty default implementation.
39 */
40 template <int D>
43
44 /*
45 * ReadParameters, empty default implementation.
46 */
47 template <int D>
48 void ExplicitBdStep<D>::readParameters(std::istream &in)
49 {
50 read(in, "mobility", mobility_);
51
52 // Allocate memory for private containers
53 int nMonomer = system().mixture().nMonomer();
54 IntVec<D> meshDimensions = system().domain().mesh().dimensions();
55 w_.allocate(nMonomer);
56 for (int i=0; i < nMonomer; ++i) {
57 w_[i].allocate(meshDimensions);
58 }
59 dwc_.allocate(meshDimensions);
60
61 }
62
63 template <int D>
65 {
66 // Check array capacities
67 int meshSize = system().domain().mesh().size();
68 IntVec<D> dimensions = system().domain().mesh().dimensions();
69 int nMonomer = system().mixture().nMonomer();
70 UTIL_CHECK(w_.capacity() == nMonomer);
71 for (int i=0; i < nMonomer; ++i) {
72 UTIL_CHECK(w_[i].capacity() == meshSize);
73 }
74 UTIL_CHECK(dwc_.capacity() == meshSize);
75 gaussianField_.allocate(dimensions);
76 }
77
78 template <int D>
80 {
81 // Array sizes and indices
82 const int nMonomer = system().mixture().nMonomer();
83 const int meshSize = system().domain().mesh().size();
84 int i, j;
85
86 // Save current state
87 simulator().saveState();
88
89 // Copy current W fields from parent system into w_
90 for (i = 0; i < nMonomer; ++i) {
91 VecOp::eqV(w_[i], system().w().rgrid(i));
92 }
93
94 // Constants for dynamics
95 const double vSystem = system().domain().unitCell().volume();
96 double a = -1.0*mobility_;
97 double b = sqrt(2.0*mobility_*double(meshSize)/vSystem);
98
99 // Constants for normal distribution
100 double stddev = 1.0;
101 double mean = 0;
102
103 // Modify local field copy wc_
104 // Loop over eigenvectors of projected chi matrix
105 double evec;
106 for (j = 0; j < nMonomer - 1; ++j) {
107 RField<D> const & dc = simulator().dc(j);
108
109 // Generate normal distributed random floating point numbers
110 cudaRandom().normal(gaussianField_, stddev, mean);
111
112 // dwc
113 VecOp::addVcVc(dwc_, dc, a, gaussianField_, b);
114
115 // Loop over monomer types
116 for (i = 0; i < nMonomer; ++i) {
117 RField<D> & w = w_[i];
118 evec = simulator().chiEvecs(j,i);
119 VecOp::addEqVc(w, dwc_, evec);
120 }
121
122 }
123
124 // Set modified fields in parent system
125 system().setWRGrid(w_);
126 simulator().clearData();
127
128 // Enforce incompressibility (also solves MDE repeatedly)
129 bool isConverged = false;
130 int compress = simulator().compressor().compress();
131 if (compress != 0){
132 simulator().restoreState();
133 } else {
134 isConverged = true;
135 UTIL_CHECK(system().hasCFields());
136
137 // Evaluate component properties in new state
138 simulator().clearState();
139 simulator().computeWc();
140 simulator().computeCc();
141 simulator().computeDc();
142
143 }
144
145 return isConverged;
146 }
147
148}
149}
150#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
Field of real double precision values on an FFT mesh.
Brownian dynamics simulator.
BdStep is an abstract base class for Brownian dynamics steps.
virtual bool step()
Take a single Brownian dynamics step.
virtual void readParameters(std::istream &in)
Read required parameters from file.
ExplicitBdStep(BdSimulator< D > &simulator)
Constructor.
virtual void setup()
Setup before simulation.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
void eqV(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, const int beginIdA, const int beginIdB, const int n)
Vector assignment, a[i] = b[i], kernel wrapper (cudaReal).
Definition VecOp.cu:1020
void addVcVc(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, cudaReal const c, DeviceArray< cudaReal > const &d, cudaReal const e)
Vector addition w/ coefficient, a[i] = (b[i]*c) + (d[i]*e), kernel wrapper.
Definition VecOpMisc.cu:304
void addEqVc(DeviceArray< cudaReal > &a, DeviceArray< cudaReal > const &b, cudaReal const c)
Vector addition in-place w/ coefficient, a[i] += b[i] * c, kernel wrapper.
Definition VecOpMisc.cu:343
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition CField.cu:12
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.