Loading [MathJax]/extensions/TeX/AMSmath.js
PSCF v1.2
rpc/fts/brownian/ExplicitBdStep.tpp
1#ifndef RPC_EXPLICIT_BD_STEP_TPP
2#define RPC_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 <rpc/fts/brownian/BdSimulator.h>
14#include <rpc/fts/compressor/Compressor.h>
15#include <rpc/System.h>
16#include <pscf/math/IntVec.h>
17#include <util/random/Random.h>
18
19namespace Pscf {
20namespace Rpc {
21
22 using namespace Util;
23 using namespace Prdc::Cpu;
24
25 /*
26 * Constructor.
27 */
28 template <int D>
30 : BdStep<D>(simulator),
31 w_(),
32 dwc_(),
33 mobility_(0.0)
34 {}
35
36 /*
37 * Destructor, empty default implementation.
38 */
39 template <int D>
42
43 /*
44 * ReadParameters, empty default implementation.
45 */
46 template <int D>
47 void ExplicitBdStep<D>::readParameters(std::istream &in)
48 {
49 read(in, "mobility", mobility_);
50
51 // Allocate memory for private containers
52 int nMonomer = system().mixture().nMonomer();
53 IntVec<D> meshDimensions = system().domain().mesh().dimensions();
54 w_.allocate(nMonomer);
55 for (int i=0; i < nMonomer; ++i) {
56 w_[i].allocate(meshDimensions);
57 }
58 dwc_.allocate(meshDimensions);
59
60 }
61
62 template <int D>
64 {
65 // Check array capacities
66 int meshSize = system().domain().mesh().size();
67 int nMonomer = system().mixture().nMonomer();
68 UTIL_CHECK(w_.capacity() == nMonomer);
69 for (int i=0; i < nMonomer; ++i) {
70 UTIL_CHECK(w_[i].capacity() == meshSize);
71 }
72 UTIL_CHECK(dwc_.capacity() == meshSize);
73 }
74
75 template <int D>
77 {
78 // Array sizes and indices
79 const int nMonomer = system().mixture().nMonomer();
80 const int meshSize = system().domain().mesh().size();
81 int i, j, k;
82
83 // Save current state
84 simulator().saveState();
85
86 // Copy current W fields from parent system into w_
87 for (i = 0; i < nMonomer; ++i) {
88 w_[i] = system().w().rgrid(i);
89 }
90
91 // Constants for dynamics
92 const double vSystem = system().domain().unitCell().volume();
93 const double a = -1.0*mobility_;
94 const double b = sqrt(2.0*mobility_*double(meshSize)/vSystem);
95
96 // Modify local field copy wc_
97 // Loop over eigenvectors of projected chi matrix
98 double dwd, dwr, evec;
99 for (j = 0; j < nMonomer - 1; ++j) {
100 RField<D> const & dc = simulator().dc(j);
101 for (k = 0; k < meshSize; ++k) {
102 dwd = a*dc[k];
103 dwr = b*random().gaussian();
104 dwc_[k] = dwd + dwr;
105 }
106 // Loop over monomer types
107 for (i = 0; i < nMonomer; ++i) {
108 RField<D> & w = w_[i];
109 evec = simulator().chiEvecs(j,i);
110 for (k = 0; k < meshSize; ++k) {
111 w[k] += evec*dwc_[k];
112 }
113 }
114 }
115
116 // Set modified fields in parent system
117 system().setWRGrid(w_);
118 simulator().clearData();
119
120 // Enforce incompressibility (also solves MDE repeatedly)
121 bool isConverged = false;
122 int compress = simulator().compressor().compress();
123 if (compress != 0){
124 simulator().restoreState();
125 } else {
126 isConverged = true;
127 UTIL_CHECK(system().hasCFields());
128
129 // Evaluate component properties in new state
130 simulator().clearState();
131 simulator().computeWc();
132 simulator().computeCc();
133 simulator().computeDc();
134 }
135
136 return isConverged;
137 }
138
139}
140}
141#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 for PS-FTS.
BdStep is an abstract base class for Brownian dynamics steps.
ExplicitBdStep(BdSimulator< D > &simulator)
Constructor.
virtual void setup()
Setup before simulation.
virtual void readParameters(std::istream &in)
Read required parameters from file.
virtual bool step()
Take a single Brownian dynamics step.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.