PSCF v1.4.0
fts/montecarlo/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 - 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#include <util/global.h>
14
15// Forward declaration
16namespace Util { class Random; }
17
18namespace Pscf {
19namespace Rp {
20
21 using namespace Util;
22
42 template <int D, class T>
43 class McMove : public ParamComposite
44 {
45
46 public:
47
53 virtual void readParameters(std::istream &in);
54
61
71 virtual void setup();
72
95 virtual bool move();
96
102 virtual bool needsCc()
103 { return false; }
104
110 virtual bool needsDc()
111 { return false; }
112
118 virtual void outputTimers(std::ostream& out);
119
123 virtual void clearTimers();
124
125 // Accessor Functions
126
130 double probability() const;
131
135 long nAttempt() const;
136
140 long nAccept() const;
141
145 long nFail() const;
146
150 virtual void output();
151
152 protected:
153
159 McMove(typename T::McSimulator& simulator);
160
164 ~McMove() = default;
165
170
175
180
186 void outputTimerData(std::ostream& out);
187
191 typename T::System& system();
192
196 typename T::System const & system() const;
197
201 typename T::McSimulator& simulator();
202
206 typename T::McSimulator const & simulator() const;
207
212
216 typename T::VecRandom& vecRandom();
217
221 void readProbability(std::istream& in);
222
233 virtual void attemptMove()
234 {};
235
238 Timer compressorTimer_;
239 Timer componentTimer_;
240 Timer hamiltonianTimer_;
241 Timer decisionTimer_;
242 Timer totalTimer_;
243
244 private:
245
247 typename T::McSimulator* simulatorPtr_;
248
250 typename T::System* systemPtr_;
251
253 Random* randomPtr_;
254
256 typename T::VecRandom* vecRandomPtr_;
257
259 double probability_;
260
262 long nAttempt_;
263
265 long nAccept_;
266
268 long nFail_;
269
270 };
271
272 // Public inline methods
273
274 /*
275 * Return number of moves that have been attempted.
276 */
277 template <int D, class T> inline
279 { return nAttempt_; }
280
281 /*
282 * Return number of moves that have been accepted.
283 */
284 template <int D, class T> inline
286 { return nAccept_; }
287
288 /*
289 * Return number of moves that fail to converge.
290 */
291 template <int D, class T> inline
293 { return nFail_; }
294
295 // Protected inline methods
296
297 /*
298 * Increment the number of attempted moves.
299 */
300 template <int D, class T>
302 { ++nAttempt_; }
303
304 /*
305 * Increment the number of accepted moves.
306 */
307 template <int D, class T>
309 { ++nAccept_; }
310
311 /*
312 * Increment the number of fail moves.
313 */
314 template <int D, class T>
316 { ++nFail_; }
317
318 /*
319 * Get parent System object (non-const ref).
320 */
321 template <int D, class T> inline
322 typename T::System& McMove<D,T>::system()
323 { return *systemPtr_; }
324
325 /*
326 * Get parent System object (const ref).
327 */
328 template <int D, class T> inline
329 typename T::System const & McMove<D,T>::system() const
330 { return *systemPtr_; }
331
332 /*
333 * Get parent McSimulator object (non-const ref).
334 */
335 template <int D, class T> inline
336 typename T::McSimulator& McMove<D,T>::simulator()
337 { return *simulatorPtr_; }
338
339 /*
340 * Get parent McSimulator object (const ref).
341 */
342 template <int D, class T> inline
343 typename T::McSimulator const & McMove<D,T>::simulator() const
344 { return *simulatorPtr_; }
345
346 /*
347 * Get the scalar andom number generator.
348 */
349 template <int D, class T> inline
351 { return *randomPtr_; }
352
353 /*
354 * Get the vector random number generator.
355 */
356 template <int D, class T> inline
357 typename T::VecRandom& McMove<D,T>::vecRandom()
358 { return *vecRandomPtr_; }
359
360 /*
361 * Get the probability.
362 */
363 template <int D, class T> inline
365 { return probability_; }
366
367 /*
368 * Set the probability.
369 */
370 template <int D, class T> inline
372 { probability_ = probability; }
373
374}
375}
376#endif
Random & random()
Get the scalar random number generator.
virtual void clearTimers()
Clear timers.
Definition McMove.tpp:215
virtual void attemptMove()
Attempt unconstrained move.
~McMove()=default
Destructor.
Types< D >::McSimulator & simulator()
void incrementNFail()
Increment the number of failed moves.
virtual void outputTimers(std::ostream &out)
Write timing results to a file.
Definition McMove.tpp:166
void setProbability(double probability)
Set the probability for this McMove.
void readProbability(std::istream &in)
Read the probability from file.
Definition McMove.tpp:47
T::VecRandom & vecRandom()
Get the vector random number generator.
void outputTimerData(std::ostream &out)
Write timing data to a file, without a class label.
Definition McMove.tpp:178
McMove(typename T::McSimulator &simulator)
Constructor.
Definition McMove.tpp:25
long nFail() const
Return number of moves that failed to converge.
void incrementNAccept()
Increment the number of accepted moves.
T::System & system()
Get parent System object (non-const ref).
virtual void output()
Output statistics for this move (at the end of simulation)
Definition McMove.tpp:159
virtual bool needsCc()
Decide whether cc fields need to be saved for move.
virtual void setup()
Setup before the beginning of each simulation run.
Definition McMove.tpp:56
Timer attemptMoveTimer_
Timers for McMove.
virtual void readParameters(std::istream &in)
Read required parameters from file.
Definition McMove.tpp:40
long nAttempt() const
Return number of moves that have been attempted.
virtual bool move()
Generate, attempt, and accept or reject a Monte Carlo move.
Definition McMove.tpp:78
virtual bool needsDc()
Decide whether dc fields need to be saved for move.
void incrementNAttempt()
Increment the number of attempted moves.
long nAccept() const
Return number of moves that have been accepted.
ParamComposite()
Constructor.
Random number generator.
Definition Random.h:47
Wall clock timer.
Definition Timer.h:35
File containing preprocessor macros for error handling.
Class templates for real-valued periodic fields.
PSCF package top-level namespace.
Utility classes for scientific computation.