PSCF v1.3
rpg/fts/montecarlo/McMoveManager.tpp
1#ifndef RPG_MC_MOVE_MANAGER_TPP
2#define RPG_MC_MOVE_MANAGER_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 <util/global.h>
12#include <rpg/fts/montecarlo/McMoveManager.h>
13#include <rpg/fts/montecarlo/McMoveFactory.h>
14#include <rpg/fts/montecarlo/McSimulator.h>
15#include <util/random/Random.h>
16
17namespace Pscf {
18namespace Rpg {
19
20 using namespace Util;
21
22 /*
23 * Constructor.
24 */
25 template <int D>
27 System<D>& system)
28 : Manager< McMove<D> >(),
29 simulatorPtr_(&simulator),
30 systemPtr_(&system),
31 randomPtr_(&simulator.random())
32 { setClassName("McMoveManager"); }
33
34 /*
35 * Destructor.
36 */
37 template <int D>
40
41 /*
42 * Return a pointer to a new McMoveFactory object.
43 */
44 template <int D>
46 { return new McMoveFactory<D>(*simulatorPtr_); }
47
48 /*
49 * Read instructions for creating objects from file.
50 */
51 template <int D>
52 void McMoveManager<D>::readParameters(std::istream &in)
53 {
54 // Read parameters for all McMove<D> objects
56
57 // Allocate and store probabilities
58 probabilities_.allocate(size());
59 double totalProbability = 0.0;
60 int iMove;
61 for (iMove = 0; iMove < size(); ++iMove) {
62 probabilities_[iMove] = (*this)[iMove].probability();
63 totalProbability += probabilities_[iMove];
64 }
65
66 // Allocate and store and normalize probabilities
67 for (iMove = 0; iMove < size(); ++iMove) {
68 probabilities_[iMove] = probabilities_[iMove]/totalProbability;
69 (*this)[iMove].setProbability(probabilities_[iMove]);
70 }
71 }
72
73 /*
74 * Initialize all moves just prior to a run.
75 */
76 template <int D>
78 {
79 for (int iMove = 0; iMove < size(); ++iMove) {
80 (*this)[iMove].setup();
81 }
82 }
83
84 /*
85 * Choose a McMove at random.
86 */
87 template <int D>
89 {
90 int iMove;
91 iMove = randomPtr_->drawFrom(&probabilities_[0], size());
92 return (*this)[iMove];
93 }
94
95 /*
96 * Output statistics for every move.
97 */
98 template <int D>
100 {
101 for (int i=0; i< size(); i++) {
102 (*this)[i].output();
103 }
104 }
105
106 /*
107 * Log output timing results
108 */
109 template <int D>
110 void McMoveManager<D>::outputTimers(std::ostream& out) const
111 {
112 for (int i=0; i< size(); i++) {
113 (*this)[i].outputTimers(out);
114 }
115 }
116
117 /*
118 * Clear timers
119 */
120 template <int D>
122 {
123 for (int i=0; i< size(); i++) {
124 (*this)[i].clearTimers();
125 }
126 }
127
128 /*
129 * Decide whether any move needs to store cc fields.
130 */
131 template <int D>
133 {
134 for (int i=0; i< size(); i++) {
135 if((*this)[i].needsCc()){
136 return true;
137 }
138 }
139 return false;
140 }
141
142 /*
143 * Decide whether any move needs to store dc fields.
144 */
145 template <int D>
147 {
148 for (int i=0; i< size(); i++) {
149 if((*this)[i].needsDc()){
150 return true;
151 }
152 }
153 return false;
154 }
155
156}
157}
158#endif
Factory for subclasses of McMove.
void output() const
Output statistics for all moves.
void setup()
Initialize at beginning of system run.
void outputTimers(std::ostream &out) const
Log output timing results.
virtual void readParameters(std::istream &in)
Read instructions for creating McMove objects.
McMove< D > & chooseMove()
Choose an McMove at random, using specified probabilities.
bool needsDc()
Decide whether any move needs to store dc fields.
McMoveManager(McSimulator< D > &simulator, System< D > &system)
Constructor.
bool needsCc()
Decide whether any move needs to store cc fields.
McMove is an abstract base class for Monte Carlo moves.
Monte-Carlo simulation coordinator.
Main class, representing one complete system.
Factory template.
Definition Factory.h:34
virtual Factory< McMove< D > > * newDefaultFactory() const
Definition Manager.h:541
Manager(bool uniqueNames=false)
Definition Manager.h:232
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1