PSCF v1.3
rpc/fts/montecarlo/RealMove.tpp
1#ifndef RPC_REAL_MOVE_TPP
2#define RPC_REAL_MOVE_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, 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 <rpc/fts/montecarlo/McSimulator.h>
14#include <util/param/ParamComposite.h>
15#include <rpc/system/System.h>
16#include <util/random/Random.h>
17
18namespace Pscf {
19namespace Rpc {
20
21 using namespace Util;
22
23 /*
24 * Constructor.
25 */
26 template <int D>
28 : McMove<D>(simulator),
29 dwc_(),
30 sigma_(0.0),
31 isAllocated_(false)
32 { setClassName("RealMove"); }
33
34 /*
35 * Destructor, empty default implementation.
36 */
37 template <int D>
40
41 /*
42 * ReadParameters, empty default implementation.
43 */
44 template <int D>
45 void RealMove<D>::readParameters(std::istream &in)
46 {
47
48 // Read the probability
50
51 // The standard deviation of the Gaussian distribution
52 read(in, "sigma", sigma_);
53 }
54
55 template <int D>
57 {
59 const int nMonomer = system().mixture().nMonomer();
60 IntVec<D> const & meshDimensions = system().domain().mesh().dimensions();
61 if (!isAllocated_){
62 dwc_.allocate(meshDimensions);
63 w_.allocate(nMonomer);
64 for (int i = 0; i < nMonomer; ++i) {
65 w_[i].allocate(meshDimensions);
66 }
67 isAllocated_ = true;
68 }
69 }
70
71
72
73 /*
74 * Attempt unconstrained move
75 */
76 template <int D>
78 {
79 const int nMonomer = system().mixture().nMonomer();
80 const int meshSize = system().domain().mesh().size();
81
82 // Copy current fields to w_
83 for (int i = 0; i < nMonomer; ++i) {
84 w_[i] = system().w().rgrid(i);
85 }
86
87 // Loop over composition eigenvectors of projected chi matrix
88 for (int j = 0; j < nMonomer - 1; j++){
89
90 // Generate Gaussian distributed random numbers
91 for (int k = 0; k < meshSize; k++){
92 dwc_[k] = sigma_* random().gaussian();
93 }
94
95 // Loop over monomer types
96 double evec;
97 for (int i = 0; i < nMonomer; ++i) {
98 RField<D> & w = w_[i];
99 evec = simulator().chiEvecs(j, i);
100 for (int k = 0; k < meshSize; ++k) {
101 w[k] += evec*dwc_[k];
102 }
103 }
104
105 }
106
107 // Update w-fields in parent system
108 system().w().setRGrid(w_);
109 }
110
111 /*
112 * Trivial default implementation - do nothing
113 */
114 template <int D>
116 {}
117
118 template<int D>
119 void RealMove<D>::outputTimers(std::ostream& out)
120 {
121 out << "\n";
122 out << "RealMove time contributions:\n";
124 }
125
126}
127}
128#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.
Definition cpu/RField.h:29
Random & random()
Get Random number generator of parent System.
McMove(McSimulator< D > &simulator)
Constructor.
System< D > & system()
Get parent System object.
McSimulator< D > & simulator()
Get parent McSimulator object.
virtual void outputTimers(std::ostream &out)
Log output timing results.
void readProbability(std::istream &in)
Read the probability from file.
virtual void setup()
Setup before the beginning of each simulation run.
Monte-Carlo simulation coordinator.
void outputTimers(std::ostream &out)
Return real move times contributions.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
void setClassName(const char *className)
Set class name string.
void readParameters(std::istream &in)
Read required parameters from file.
RealMove(McSimulator< D > &simulator)
Constructor.
void output()
Output statistics for this move (at the end of simulation)
void attemptMove()
Attempt unconstrained move.
void setup()
Setup before the beginning of each simulation run.
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1