PSCF v1.5.0
RealMove.tpp
1#ifndef RP_REAL_MOVE_TPP
2#define RP_REAL_MOVE_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "RealMove.h"
12#include <rp/fts/montecarlo/McSimulator.h>
13#include <rp/fts/simulator/Simulator.h>
14#include <rp/system/System.h>
15#include <rp/solvers/Mixture.h>
16#include <rp/field/Domain.h>
17#include <rp/field/WFields.h>
18
19#include <pscf/backend/VecRandom.h>
20#include <pscf/backend/VecOp.h>
21#include <pscf/math/IntVec.h>
22
23namespace Pscf {
24namespace Rp {
25
26 using namespace Util;
27
28 /*
29 * Constructor.
30 */
31 template <int D, class T>
33 : McMoveT(simulator),
34 w_(),
35 dwc_(),
36 sigma_(0.0),
37 isAllocated_(false)
38 { ParamComposite::setClassName("RealMove"); }
39
40 /*
41 * Read body of parameter file block.
42 */
43 template <int D, class T>
44 void RealMove<D,T>::readParameters(std::istream &in)
45 {
47
48 // Standard deviation of field changes
49 ParamComposite::read(in, "sigma", sigma_);
50 }
51
52 /*
53 * Setup before simulation loop.
54 */
55 template <int D, class T>
57 {
59
60 if (!isAllocated_){
61 const int nMonomer = system().mixture().nMonomer();
62 IntVec<D> meshDimensions = system().domain().mesh().dimensions();
63 w_.allocate(nMonomer);
64 for (int i = 0; i < nMonomer; ++i) {
65 w_[i].allocate(meshDimensions);
66 }
67 dwc_.allocate(meshDimensions);
68 isAllocated_ = true;
69 }
70 }
71
72 /*
73 * Attempt unconstrained move.
74 */
75 template <int D, class T>
77 {
78 // Copy current W fields to w_
79 const int nMonomer = system().mixture().nMonomer();
80 for (int i = 0; i < nMonomer; ++i) {
81 VecOp::eqV(w_[i], system().w().rgrid(i));
82 }
83
84 // Loop over composition eigenvectors of projected chi matrix
85 double evec, mean;
86 mean = 0.0;
87 for (int j = 0; j < nMonomer - 1; ++j) {
88
89 // Generate random field changes
90 vecRandom().normal(dwc_, sigma_, mean);
91
92 // Add changes to w_ field components
93 for (int i = 0; i < nMonomer; ++i) {
94 evec = simulator().chiEvecs(j, i);
95 VecOp::addEqVc(w_[i], dwc_, evec);
96 }
97 }
98
99 // Update w-fields of parent system
100 system().w().setRGrid(w_);
101 }
102
103}
104}
105#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
McSimulator< D, T > & simulator()
Get parent McSimulator object (non-const ref).
Definition McMove.h:342
void readProbability(std::istream &in)
Read the probability from file.
Definition McMove.tpp:54
VecRandom< T > & vecRandom()
Get the vector random number generator.
Definition McMove.h:363
System< D, T > & system()
Get parent System object (non-const ref).
Definition McMove.h:328
virtual void setup()
Setup before the beginning of each simulation run.
Definition McMove.tpp:71
Monte-Carlo simulation coordinator.
Definition McSimulator.h:55
RealMove(McSimulator< D, T > &simulator)
Constructor.
Definition RealMove.tpp:32
void readParameters(std::istream &in) override
Read body of parameter file block.
Definition RealMove.tpp:44
void attemptMove() override
Attempt unconstrained move.
Definition RealMove.tpp:76
void setup() override
Setup before the simulation loop.
Definition RealMove.tpp:56
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 eqV(Array< double > &a, Array< double > const &b, const int beginIdA, const int beginIdB, const int n)
Vector assignment, a[i] = b[i] (real, slice).
Definition VecOp.cpp:26
void addEqVc(Array< double > &a, Array< double > const &b, const double c)
Add scaled vector in-place, a[i] += b[i]*c (real).
Definition VecOp.cpp:400
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.