PSCF v1.5.0
McMove.h
1#ifndef RP_MC_MOVE_H
2#define RP_MC_MOVE_H
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 <util/param/ParamComposite.h> // base class
12#include <util/misc/Timer.h> // member
13#include <util/global.h>
14#include <pscf/backend/TmplDeclare.h>
15
16// Forward declarations
17namespace Util {
18 class Random;
19}
20namespace Pscf {
21 namespace Rp {
22 template <int D, class T> class System;
23 template <int D, class T> class Simulator;
24 template <int D, class T> class McSimulator;
25 }
26}
27
28
29namespace Pscf {
30namespace Rp {
31
32 using namespace Util;
33
48 template <int D, class T>
49 class McMove : public ParamComposite
50 {
51
52 public:
53
60
64 ~McMove() = default;
65
71 virtual void readParameters(std::istream &in);
72
79
89 virtual void setup();
90
113 virtual bool move();
114
120 virtual bool needsCc()
121 { return false; }
122
128 virtual bool needsDc()
129 { return false; }
130
136 virtual void outputTimers(std::ostream& out);
137
141 virtual void clearTimers();
142
143 // Accessor Functions
144
148 double probability() const;
149
153 long nAttempt() const;
154
158 long nAccept() const;
159
163 long nFail() const;
164
168 virtual void output();
169
170 protected:
171
176
181
186
192 void outputTimerData(std::ostream& out);
193
198
202 System<D,T> const & system() const;
203
208
213
218
223
227 void readProbability(std::istream& in);
228
239 virtual void attemptMove()
240 {};
241
244 Timer compressorTimer_;
245 Timer componentTimer_;
246 Timer hamiltonianTimer_;
247 Timer decisionTimer_;
248 Timer totalTimer_;
249
250 private:
251
253 McSimulator<D,T>* simulatorPtr_;
254
256 System<D,T>* systemPtr_;
257
259 Random* randomPtr_;
260
262 VecRandom<T>* vecRandomPtr_;
263
265 double probability_;
266
268 long nAttempt_;
269
271 long nAccept_;
272
274 long nFail_;
275
276 };
277
278 // Public inline methods
279
280 /*
281 * Return number of moves that have been attempted.
282 */
283 template <int D, class T> inline
285 { return nAttempt_; }
286
287 /*
288 * Return number of moves that have been accepted.
289 */
290 template <int D, class T> inline
292 { return nAccept_; }
293
294 /*
295 * Return number of moves that fail to converge.
296 */
297 template <int D, class T> inline
299 { return nFail_; }
300
301 // Protected inline methods
302
303 /*
304 * Increment the number of attempted moves.
305 */
306 template <int D, class T>
308 { ++nAttempt_; }
309
310 /*
311 * Increment the number of accepted moves.
312 */
313 template <int D, class T>
315 { ++nAccept_; }
316
317 /*
318 * Increment the number of fail moves.
319 */
320 template <int D, class T>
322 { ++nFail_; }
323
324 /*
325 * Get parent System object (non-const ref).
326 */
327 template <int D, class T> inline
329 { return *systemPtr_; }
330
331 /*
332 * Get parent System object (const ref).
333 */
334 template <int D, class T> inline
336 { return *systemPtr_; }
337
338 /*
339 * Get parent McSimulator object (non-const ref).
340 */
341 template <int D, class T> inline
343 { return *simulatorPtr_; }
344
345 /*
346 * Get parent McSimulator object (const ref).
347 */
348 template <int D, class T> inline
350 { return *simulatorPtr_; }
351
352 /*
353 * Get the scalar andom number generator.
354 */
355 template <int D, class T> inline
357 { return *randomPtr_; }
358
359 /*
360 * Get the vector random number generator.
361 */
362 template <int D, class T> inline
364 { return *vecRandomPtr_; }
365
366 /*
367 * Get the probability.
368 */
369 template <int D, class T> inline
371 { return probability_; }
372
373 /*
374 * Set the probability.
375 */
376 template <int D, class T> inline
378 { probability_ = probability; }
379
380 // Explicit instantiation declarations
381 PSCF_TMPL_DECLARE(McMove)
382
383}
384}
385#endif
Random & random()
Get the scalar random number generator.
Definition McMove.h:356
McSimulator< D, T > & simulator()
Get parent McSimulator object (non-const ref).
Definition McMove.h:342
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
McMove is an abstract base class for Monte Carlo moves.
Definition McMove.h:50
Random & random()
Get the scalar random number generator.
Definition McMove.h:356
virtual void clearTimers()
Clear timers.
Definition McMove.tpp:229
McSimulator< D, T > & simulator()
Get parent McSimulator object (non-const ref).
Definition McMove.h:342
virtual void attemptMove()
Attempt unconstrained move.
Definition McMove.h:239
~McMove()=default
Destructor.
double probability() const
Definition McMove.h:370
void incrementNFail()
Increment the number of failed moves.
Definition McMove.h:321
virtual void outputTimers(std::ostream &out)
Write timing results to a file.
Definition McMove.tpp:180
void setProbability(double probability)
Set the probability for this McMove.
Definition McMove.h:377
void readProbability(std::istream &in)
Read the probability from file.
Definition McMove.tpp:54
void outputTimerData(std::ostream &out)
Definition McMove.tpp:192
VecRandom< T > & vecRandom()
Get the vector random number generator.
Definition McMove.h:363
long nFail() const
Return number of moves that failed to converge.
Definition McMove.h:298
void incrementNAccept()
Increment the number of accepted moves.
Definition McMove.h:314
System< D, T > & system()
Get parent System object (non-const ref).
Definition McMove.h:328
virtual void output()
Definition McMove.tpp:173
virtual bool needsCc()
Decide whether cc fields need to be saved for move.
Definition McMove.h:120
virtual void setup()
Definition McMove.tpp:71
Timer attemptMoveTimer_
Timers for McMove.
Definition McMove.h:243
virtual void readParameters(std::istream &in)
Read required parameters from file.
Definition McMove.tpp:47
long nAttempt() const
Return number of moves that have been attempted.
Definition McMove.h:284
virtual bool move()
Definition McMove.tpp:93
virtual bool needsDc()
Decide whether dc fields need to be saved for move.
Definition McMove.h:128
void incrementNAttempt()
Increment the number of attempted moves.
Definition McMove.h:307
long nAccept() const
Return number of moves that have been accepted.
Definition McMove.h:291
McMove(McSimulator< D, T > &simulator)
Constructor.
Definition McMove.tpp:32
Monte-Carlo simulation coordinator.
Definition McSimulator.h:55
Base class for field theoretic PS-FTS simulator.
Definition Simulator.h:93
Base class template for classes that represent a complete system.
ParamComposite()
Constructor.
Random number generator.
Definition Random.h:47
Wall clock timer.
Definition Timer.h:35
File containing preprocessor macros for error handling.
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.
Utility classes for scientific computation.