PSCF v1.3.1
rpg/fts/montecarlo/McMove.h
1#ifndef RPG_MC_MOVE_H
2#define RPG_MC_MOVE_H
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/param/ParamComposite.h> // base class
12#include <util/misc/Timer.h> // member
13
14// Forward declarations
15namespace Util {
16 class Random;
17}
18namespace Pscf {
19 class CudaRandom;
20 namespace Rpg {
21 template <int D> class System;
22 template <int D> class McSimulator;
23 }
24}
25
26namespace Pscf {
27namespace Rpg {
28
29 using namespace Util;
30
40 template <int D>
41 class McMove : public ParamComposite
42 {
43
44 public:
45
52
58 virtual ~McMove();
59
65 virtual void readParameters(std::istream &in);
66
72 void setProbability(double probability);
73
83 virtual void setup();
84
107 virtual bool move();
108
113 virtual bool needsCc()
114 { return false; }
115
120 virtual bool needsDc()
121 { return false; }
122
126 virtual void outputTimers(std::ostream& out);
127
131 virtual void clearTimers();
132
133 // Accessor Functions
134
138 double probability() const;
139
143 long nAttempt() const;
144
148 long nAccept() const;
149
153 long nFail() const;
154
158 virtual void output();
159
160 protected:
161
165 void incrementNAttempt();
166
170 void incrementNAccept();
171
175 void incrementNFail();
176
180 System<D>& system();
181
186
190 Random& random();
191
196
200 void readProbability(std::istream& in);
201
212 virtual void attemptMove()
213 {};
214
217 Timer compressorTimer_;
218 Timer componentTimer_;
219 Timer hamiltonianTimer_;
220 Timer decisionTimer_;
221 Timer totalTimer_;
222
223 private:
224
226 McSimulator<D>* simulatorPtr_;
227
229 System<D>* systemPtr_;
230
232 Random *randomPtr_;
233
235 CudaRandom *cudaRandomPtr_;
236
238 double probability_;
239
241 long nAttempt_;
242
244 long nAccept_;
245
247 long nFail_;
248
249 };
250
251 // Public inline methods
252
253 /*
254 * Return number of moves that have been attempted.
255 */
256 template <int D>
257 inline long McMove<D>::nAttempt() const
258 { return nAttempt_; }
259
260 /*
261 * Return number of moves that have been accepted.
262 */
263 template <int D>
264 inline long McMove<D>::nAccept() const
265 { return nAccept_; }
266
267 /*
268 * Return number of moves that fail to converge.
269 */
270 template <int D>
271 inline long McMove<D>::nFail() const
272 { return nFail_; }
273
274 // Protected inline methods
275
276 /*
277 * Increment the number of attempted moves.
278 */
279 template <int D>
281 { ++nAttempt_; }
282
283 /*
284 * Increment the number of accepted moves.
285 */
286 template <int D>
288 { ++nAccept_; }
289
290 /*
291 * Increment the number of fail moves.
292 */
293 template <int D>
295 { ++nFail_; }
296
297 /*
298 * Get parent System object.
299 */
300 template <int D>
302 { return *systemPtr_; }
303
304 /*
305 * Get parent McSimulator object.
306 */
307 template <int D>
309 { return *simulatorPtr_; }
310
311 /*
312 * Get Random number generator.
313 */
314 template <int D>
316 { return *randomPtr_; }
317
318 /*
319 * Get CudaRandom number generator.
320 */
321 template <int D>
323 { return *cudaRandomPtr_; }
324
325 /*
326 * Get the probability.
327 */
328 template <int D>
329 inline double McMove<D>::probability() const
330 { return probability_; }
331
332 /*
333 * Set the probability.
334 */
335 template <int D>
337 { probability_ = probability; }
338
339 // Explicit instantiation declarations
340 extern template class McMove<1>;
341 extern template class McMove<2>;
342 extern template class McMove<3>;
343
344}
345}
346#endif
Random number generator on GPU.
Definition CudaRandom.h:30
McMove is an abstract base class for Monte Carlo moves.
CudaRandom & cudaRandom()
Get cuda random number generator by reference.
long nAttempt() const
Return number of moves that have been attempted.
virtual ~McMove()
Destructor.
void incrementNAttempt()
Increment the number of attempted moves.
Random & random()
Get Random number generator of parent System.
virtual void attemptMove()
Attempt unconstrained move.
double probability() const
Return probability for this McMove.
long nAccept() const
Return number of moves that have been accepted.
void setProbability(double probability)
Set the probability for this McMove.
virtual bool move()
Generate, attempt, and accept or reject a Monte Carlo move.
void readProbability(std::istream &in)
Read the probability from file.
virtual bool needsCc()
Decide whether cc fields need to be saved for move The default implementation is false.
McSimulator< D > & simulator()
Get parent McSimulator object.
virtual void readParameters(std::istream &in)
Read required parameters from file.
System< D > & system()
Get parent System object.
void incrementNAccept()
Increment the number of accepted moves.
void incrementNFail()
Increment the number of failed moves.
virtual void outputTimers(std::ostream &out)
Log output timing results.
virtual void setup()
Setup before the beginning of each simulation run.
McMove(McSimulator< D > &simulator)
Constructor.
long nFail() const
Return number of moves that fail to converge.
Timer attemptMoveTimer_
Timers for McMove.
virtual bool needsDc()
Decide whether dc fields need to be saved for move The default implementation is false.
virtual void clearTimers()
Clear timers.
virtual void output()
Output statistics for this move (at the end of simulation)
Monte-Carlo simulation coordinator.
Main class, representing a complete physical system.
ParamComposite()
Constructor.
Random number generator.
Definition Random.h:47
Wall clock timer.
Definition Timer.h:35
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1
Utility classes for scientific computation.