PSCF v1.4.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 - 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 <pscf/math/IntVec.h>
13
14namespace Pscf {
15namespace Rp {
16
17 using namespace Util;
18
19 /*
20 * Constructor.
21 */
22 template <int D, class T>
23 RealMove<D,T>::RealMove(typename T::McSimulator& simulator)
24 : McMoveT(simulator),
25 w_(),
26 dwc_(),
27 sigma_(0.0),
28 isAllocated_(false)
29 { ParamComposite::setClassName("RealMove"); }
30
31 /*
32 * Read body of parameter file block.
33 */
34 template <int D, class T>
35 void RealMove<D,T>::readParameters(std::istream &in)
36 {
37 McMoveT::readProbability(in);
38
39 // Standard deviation of field changes
40 ParamComposite::read(in, "sigma", sigma_);
41 }
42
43 /*
44 * Setup before simulation loop.
45 */
46 template <int D, class T>
48 {
49 McMoveT::setup();
51 if (!isAllocated_){
52 const 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 isAllocated_ = true;
60 }
61 }
62
63 /*
64 * Attempt unconstrained move.
65 */
66 template <int D, class T>
68 {
69 // Copy current W fields to w_
70 const int nMonomer = system().mixture().nMonomer();
71 for (int i = 0; i < nMonomer; ++i) {
72 VecOp::eqV(w_[i], system().w().rgrid(i));
73 }
74
75 // Loop over composition eigenvectors of projected chi matrix
76 double evec, mean;
77 mean = 0.0;
78 for (int j = 0; j < nMonomer - 1; ++j) {
79
80 // Generate random field changes
81 vecRandom().normal(dwc_, sigma_, mean);
82
83 // Add changes to w_ field components
84 for (int i = 0; i < nMonomer; ++i) {
85 evec = simulator().chiEvecs(j, i);
86 VecOp::addEqVc(w_[i], dwc_, evec);
87 }
88 }
89
90 // Update w-fields of parent system
91 system().w().setRGrid(w_);
92 }
93
94}
95}
96#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition IntVec.h:27
RealMove(typename T::McSimulator &simulator)
Constructor.
Definition RealMove.tpp:23
void readParameters(std::istream &in) override
Read body of parameter file block.
Definition RealMove.tpp:35
void attemptMove() override
Attempt unconstrained move.
Definition RealMove.tpp:67
void setup() override
Setup before the simulation loop.
Definition RealMove.tpp:47
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:21
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:395
Class templates for real-valued periodic fields.
PSCF package top-level namespace.