PSCF v1.5.0
McSimulator.h
1#ifndef RP_MC_SIMULATOR_H
2#define RP_MC_SIMULATOR_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 <rp/fts/simulator/Simulator.h> // base class
12
13#include <pscf/backend/TmplDeclare.h>
14#include <util/global.h>
15#include <iostream>
16#include <string>
17
18// Forward declarations
19namespace Util {
20 template <class T> class Factory;
21}
22namespace Pscf {
23 namespace Rp {
24 template <int D, class T> class System;
25 template <int D, class T> class McMoveManager;
26 template <int D, class T> class AnalyzerManager;
27 template <int D, class T> class TrajectoryReader;
28 }
29}
30
31
32namespace Pscf {
33namespace Rp {
34
35 using namespace Util;
36
53 template <int D, class T>
54 class McSimulator : public Simulator<D,T>
55 {
56
57 public:
58
61
68
73
74 // Prohibit copying and assignment.
75 McSimulator(McSimulator<D,T> const &) = delete;
76 McSimulator<D,T>& operator = (McSimulator<D,T> const &) = delete;
77
83 virtual void readParameters(std::istream &in);
84
88
97 void simulate(int nStep);
98
111 virtual void analyze(int min, int max,
112 std::string classname,
113 std::string filename);
114
118 virtual void outputTimers(std::ostream& out) const;
119
123 virtual void clearTimers();
124
128
133
138
143
148
153
159 bool hasMcMoves() const;
160
168 bool needsCc();
169
178 bool needsDc();
179
181
182 protected:
183
184 // Inherited protected member function (selected).
185 using Simulator<D,T>::state;
186
187 // Inherited protected data members (selected).
188 using Simulator<D,T>::iStep_;
189 using Simulator<D,T>::iTotalStep_;
190
191 private:
192
196 McMoveManager<D,T>* mcMoveManagerPtr_;
197
201 AnalyzerManager<D,T>* analyzerManagerPtr_;
202
206 Factory<TrajectoryReader<D,T> >* trajectoryReaderFactoryPtr_;
207
208 // Private member function
209
220 void setup(int nStep, bool isSimulation);
221
222 };
223
224 // Inline member function definitions
225
226 // Get the Monte-Carlo move manager (const)
227 template <int D, class T> inline
229 {
230 UTIL_ASSERT(mcMoveManagerPtr_);
231 return *mcMoveManagerPtr_;
232 }
233
234 // Get the Monte-Carlo move manager (non-const).
235 template <int D, class T> inline
237 {
238 UTIL_ASSERT(mcMoveManagerPtr_);
239 return *mcMoveManagerPtr_;
240 }
241
242 // Get the Analyzer manager (const).
243 template <int D, class T> inline
245 const
246 {
247 UTIL_ASSERT(analyzerManagerPtr_);
248 return *analyzerManagerPtr_;
249 }
250
251 // Get the Analyzer manager.
252 template <int D, class T> inline
254 {
255 UTIL_ASSERT(analyzerManagerPtr_);
256 return *analyzerManagerPtr_;
257 }
258
259 // Get the TrajectoryReader factory.
260 template <int D, class T> inline
263 {
264 UTIL_ASSERT(trajectoryReaderFactoryPtr_);
265 return *trajectoryReaderFactoryPtr_;
266 }
267
268 // Have any MC moves been defined?
269 template <int D, class T> inline
271 { return (bool)(mcMoveManager().size() > 0); }
272
273 // Does the stored state need to include Cc fields?
274 template <int D, class T> inline
276 { return state().needsCc; }
277
278 // Does the stored state need to include Dc fields?
279 template <int D, class T> inline
281 { return state().needsDc; }
282
283 // Explicit instantiation declarations
284 PSCF_TMPL_DECLARE(McSimulator)
285
286}
287}
288#endif
Manager for a list of Analyzer objects.
Manager for a set of McMove objects.
Monte-Carlo simulation coordinator.
Definition McSimulator.h:55
AnalyzerManager< D, T > const & analyzerManager() const
Get the AnalyzerManager (const).
virtual void clearTimers()
Clear timers.
virtual void readParameters(std::istream &in)
Read parameter file block.
McMoveManager< D, T > const & mcMoveManager() const
Get the McMoveManager (const).
virtual void analyze(int min, int max, std::string classname, std::string filename)
Read and analyze a trajectory file.
bool hasMcMoves() const
Have any MC moves been defined?
bool needsCc()
Does the stored state need to include Cc fields?
bool needsDc()
Does the stored state need to include Dc fields?
virtual void outputTimers(std::ostream &out) const
Output timing results.
void simulate(int nStep)
Perform a field theoretic Monte-Carlo simulation.
Factory< TrajectoryReader< D, T > > & trajectoryReaderFactory()
Get the trajectory reader factory by reference.
McSimulator(System< D, T > &system)
Constructor.
Simulator(System< D, T > &system)
Constructor.
Definition Simulator.tpp:53
System< D, T > & system()
Get the parent system by reference.
Definition Simulator.h:944
SimState< D, CPT > & state()
Definition Simulator.h:1031
Base class template for classes that represent a complete system.
Trajectory file reader (abstract base class).
Factory template.
Definition Factory.h:34
File containing preprocessor macros for error handling.
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
Code for programs that simulate real-valued periodic fields.
Definition param_pc.dox:2
PSCF package top-level namespace.
Utility classes for scientific computation.