1#ifndef RP_FORCE_BIAS_MOVE_BASE_TPP
2#define RP_FORCE_BIAS_MOVE_BASE_TPP
11#include "ForceBiasMoveBase.h"
13#include <rp/fts/montecarlo/McSimulator.h>
14#include <rp/fts/simulator/Simulator.h>
15#include <rp/fts/compressor/Compressor.h>
16#include <rp/system/System.h>
17#include <rp/solvers/Mixture.h>
18#include <rp/field/Domain.h>
19#include <rp/field/CFields.h>
20#include <rp/field/WFields.h>
22#include <pscf/backend/VecRandom.h>
23#include <pscf/backend/Reduce.h>
24#include <pscf/backend/VecOp.h>
25#include <pscf/mesh/Mesh.h>
26#include <pscf/math/IntVec.h>
28#include <util/param/ParamComposite.h>
29#include <util/random/Random.h>
39 template <
int D,
class T>
50 template <
int D,
class T>
57 int nMonomer =
system().mixture().nMonomer();
59 w_.allocate(nMonomer);
60 for (
int i=0; i < nMonomer; ++i) {
61 w_[i].allocate(meshDimensions);
63 dc_.allocate(nMonomer-1);
64 dwc_.allocate(nMonomer-1);
65 for (
int i=0; i < nMonomer - 1; ++i) {
66 dc_[i].allocate(meshDimensions);
67 dwc_[i].allocate(meshDimensions);
69 biasField_.allocate(meshDimensions);
70 eta_.allocate(meshDimensions);
76 template <
int D,
class T>
80 int meshSize =
system().domain().mesh().size();
81 int nMonomer =
system().mixture().nMonomer();
83 for (
int i=0; i < nMonomer; ++i) {
88 for (
int i = 0; i < nMonomer - 1; ++i) {
99 template <
int D,
class T>
102 McMove<D,T>::totalTimer_.start();
111 const int nMonomer =
system().mixture().nMonomer();
112 const int meshSize =
system().domain().mesh().size();
116 double oldHamiltonian =
simulator().hamiltonian();
127 for (i = 0; i < nMonomer; ++i) {
132 for (i = 0; i < nMonomer - 1; ++i) {
137 const double vSystem =
system().domain().unitCell().volume();
138 const double vNode = vSystem/double(meshSize);
139 const double a = -1.0*mobility_;
140 const double b = sqrt(2.0*mobility_/vNode);
141 const double stddev = 1.0;
142 const double mean = 0.0;
146 for (j = 0; j < nMonomer - 1; ++j) {
155 for (i = 0; i < nMonomer; ++i) {
163 system().w().setRGrid(w_);
169 McMove<D,T>::compressorTimer_.start();
170 int compress =
simulator().compressor().compress();
172 McMove<D,T>::compressorTimer_.stop();
174 bool isConverged =
false;
182 McMove<D,T>::componentTimer_.start();
187 McMove<D,T>::componentTimer_.stop();
190 McMove<D,T>::hamiltonianTimer_.start();
192 double newHamiltonian =
simulator().hamiltonian();
193 double dH = newHamiltonian - oldHamiltonian;
197 for (j = 0; j < nMonomer - 1; ++j) {
200 computeForceBias(biasField_, di, df, dwc_[j], mobility_);
204 McMove<D,T>::hamiltonianTimer_.stop();
207 McMove<D,T>::decisionTimer_.start();
209 double weight = exp(bias - dH);
217 McMove<D,T>::decisionTimer_.stop();
219 McMove<D,T>::totalTimer_.stop();
227 template <
int D,
class T>
An IntVec<D, T> is a D-component vector of elements of integer type T.
void setup() override
Setup before the beginning of each simulation run.
ForceBiasMoveBase(McSimulator< D, T > &simulator)
Constructor.
void output() override
Output statistics for this move (at the end of simulation).
bool move() override
Attempt and accept or reject a force bias Monte-Carlo move.
void readParameters(std::istream &in) override
Read body of parameter file block and allocate memory.
Random & random()
Get the scalar random number generator.
McSimulator< D, T > & simulator()
Get parent McSimulator object (non-const ref).
void incrementNFail()
Increment the number of failed moves.
void readProbability(std::istream &in)
Read the probability from file.
VecRandom< T > & vecRandom()
Get the vector random number generator.
void incrementNAccept()
Increment the number of accepted moves.
System< D, CPT > & system()
virtual void setup()
Setup before the beginning of each simulation run.
Timer attemptMoveTimer_
Timers for McMove.
void incrementNAttempt()
Increment the number of attempted moves.
McMove(McSimulator< D, T > &simulator)
Constructor.
Monte-Carlo simulation coordinator.
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.
bool metropolis(double ratio)
Metropolis algorithm for whether to accept a MC move.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
double sum(Array< double > const &in)
Compute sum of array elements (real).
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).
void addEqVc(Array< double > &a, Array< double > const &b, const double c)
Add scaled vector in-place, a[i] += b[i]*c (real).
Code for programs that simulate real-valued periodic fields.
void addVcVc(Array< double > &a, Array< double > const &b1, const double c1, Array< double > const &b2, const double c2)
Add two scaled vectors, a[i] = b1[i]*c1 + b2[2]*c2 (real).
PSCF package top-level namespace.