PSCF v1.3.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/solvers/Mixture.h>
14#include <rpc/field/Domain.h>
15#include <rpc/fts/montecarlo/McSimulator.h>
16#include <util/param/ParamComposite.h>
17#include <rpc/system/System.h>
18#include <util/random/Random.h>
19
20namespace Pscf {
21namespace Rpc {
22
23 using namespace Util;
24
25 /*
26 * Constructor.
27 */
28 template <int D>
30 : McMove<D>(simulator),
31 dwc_(),
32 sigma_(0.0),
33 isAllocated_(false)
34 { setClassName("RealMove"); }
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 RealMove<D>::readParameters(std::istream &in)
48 {
49
50 // Read the probability
52
53 // The standard deviation of the Gaussian distribution
54 read(in, "sigma", sigma_);
55 }
56
57 template <int D>
59 {
61 const int nMonomer = system().mixture().nMonomer();
62 IntVec<D> const & meshDimensions = system().domain().mesh().dimensions();
63 if (!isAllocated_){
64 dwc_.allocate(meshDimensions);
65 w_.allocate(nMonomer);
66 for (int i = 0; i < nMonomer; ++i) {
67 w_[i].allocate(meshDimensions);
68 }
69 isAllocated_ = true;
70 }
71 }
72
73
74
75 /*
76 * Attempt unconstrained move
77 */
78 template <int D>
80 {
81 const int nMonomer = system().mixture().nMonomer();
82 const int meshSize = system().domain().mesh().size();
83
84 // Copy current fields to w_
85 for (int i = 0; i < nMonomer; ++i) {
86 w_[i] = system().w().rgrid(i);
87 }
88
89 // Loop over composition eigenvectors of projected chi matrix
90 for (int j = 0; j < nMonomer - 1; j++){
91
92 // Generate Gaussian distributed random numbers
93 for (int k = 0; k < meshSize; k++){
94 dwc_[k] = sigma_* random().gaussian();
95 }
96
97 // Loop over monomer types
98 double evec;
99 for (int i = 0; i < nMonomer; ++i) {
100 RField<D> & w = w_[i];
101 evec = simulator().chiEvecs(j, i);
102 for (int k = 0; k < meshSize; ++k) {
103 w[k] += evec*dwc_[k];
104 }
105 }
106
107 }
108
109 // Update w-fields in parent system
110 system().w().setRGrid(w_);
111 }
112
113 /*
114 * Trivial default implementation - do nothing
115 */
116 template <int D>
118 {}
119
120 template<int D>
121 void RealMove<D>::outputTimers(std::ostream& out)
122 {
123 out << "\n";
124 out << "RealMove time contributions:\n";
126 }
127
128}
129}
130#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.