PSCF v1.2
rpg/fts/montecarlo/RealMove.tpp
1#ifndef RPG_REAL_MOVE_TPP
2#define RPG_REAL_MOVE_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 "RealMove.h"
12#include "McMove.h"
13#include <rpg/fts/montecarlo/McSimulator.h>
14#include <rpg/fts/VecOpFts.h>
15#include <prdc/cuda/VecOp.h>
16#include <pscf/math/IntVec.h>
17#include <util/param/ParamComposite.h>
18#include <rpg/System.h>
19#include <pscf/cuda/CudaRandom.h>
20
21namespace Pscf {
22namespace Rpg {
23
24 using namespace Util;
25
26 /*
27 * Constructor.
28 */
29 template <int D>
31 : McMove<D>(simulator),
32 w_(),
33 dwc_(),
34 sigma_(0.0),
35 isAllocated_(false)
36 { setClassName("RealMove"); }
37
38 /*
39 * Destructor, empty default implementation.
40 */
41 template <int D>
44
45 /*
46 * ReadParameters, empty default implementation.
47 */
48 template <int D>
49 void RealMove<D>::readParameters(std::istream &in)
50 {
51 // Read the probability
52 readProbability(in);
53
54 // The standard deviation of the Gaussian distribution
55 read(in, "sigma", sigma_);
56
57 }
58
59
60 template <int D>
62 {
64 const int nMonomer = system().mixture().nMonomer();
65 IntVec<D> meshDimensions = system().domain().mesh().dimensions();
66
67 if (!isAllocated_){
68 w_.allocate(nMonomer);
69 for (int i=0; i < nMonomer; ++i) {
70 w_[i].allocate(meshDimensions);
71 }
72 dwc_.allocate(meshDimensions);
73 gaussianField_.allocate(meshDimensions);
74 isAllocated_ = true;
75 }
76 }
77
78 /*
79 * Attempt unconstrained move
80 */
81 template <int D>
83 {
84 const int nMonomer = system().mixture().nMonomer();
85 const int meshSize = system().domain().mesh().size();
86 int i, j;
87
88 // Copy current W fields from parent system into w_
89 for (i = 0; i < nMonomer; ++i) {
90 VecOp::eqV(w_[i], system().w().rgrid(i));
91 }
92
93 double evec;
94 double mean = 0.0;
95
96 // Loop over composition eigenvectors of projected chi matrix
97 for (j = 0; j < nMonomer - 1; ++j) {
98
99 // Generate Gaussian distributed random numbers
100 cudaRandom().normal(gaussianField_, sigma_, mean);
101 VecOp::eqV(dwc_, gaussianField_);
102
103 // Loop over monomer types
104 for (i = 0; i < nMonomer; ++i) {
105 RField<D> & w = w_[i];
106 evec = simulator().chiEvecs(j,i);
107 VecOp::addEqVc(w, dwc_, evec);
108 }
109
110 }
111
112 // Set w-fields of parent System
113 system().setWRGrid(w_);
114
115 }
116
117
118 /*
119 * Trivial default implementation - do nothing
120 */
121 template <int D>
123 {}
124
125 template<int D>
126 void RealMove<D>::outputTimers(std::ostream& out)
127 {
128 out << "\n";
129 out << "RealMove time contributions:\n";
131 }
132
133}
134}
135#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.
McMove is an abstract base class for Monte Carlo moves.
virtual void outputTimers(std::ostream &out)
Log output timing results.
virtual void setup()
Setup before the beginning of each simulation run.
Monte-Carlo simulation coordinator.
void readParameters(std::istream &in)
Read required parameters from file.
void setClassName(const char *className)
Set class name string.
void attemptMove()
Attempt unconstrained move.
RealMove(McSimulator< D > &simulator)
Constructor.
void setup()
Setup before the beginning of each simulation run.
void outputTimers(std::ostream &out)
Return real move times contributions.
void output()
Output statistics for this move (at the end of simulation)
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 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
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.