PSCF v1.4.0
SweepTmpl.h
1#ifndef PSCF_SWEEP_TMPL_H
2#define PSCF_SWEEP_TMPL_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/containers/DArray.h>
13#include <util/containers/GArray.h>
14#include <pscf/sweep/ParameterModifier.h>
15#include <pscf/sweep/ParameterType.h>
16
17namespace Pscf {
18
19 using namespace Util;
20
26 template <typename State>
28 {
29
30 public:
31
32 // Constructor and destructor are protected (see below).
33
39 virtual void readParameters(std::istream& in);
40
44 virtual void sweep();
45
57 void addParameterType(std::string name, int nId,
58 ParameterModifier& modifier);
59
69
79
80 protected:
81
94
99
107 State& state(int i)
108 {
109 UTIL_CHECK(i < historySize_);
110 return *stateHistory_[i];
111 }
112
122 double s(int i) const
123 {
124 UTIL_CHECK(i < historySize_);
125 return sHistory_[i];
126 }
127
147 double c(int i) const
148 {
149 UTIL_CHECK(i >= 0);
150 UTIL_CHECK(i < historySize_);
151 return c_[i];
152 }
153
157 int historySize() const
158 { return historySize_; }
159
168 int historyCapacity() const
169 { return historyCapacity_; }
170
178 int nAccept() const
179 { return nAccept_; }
180
187
197 virtual void checkAllocation(State & state) = 0;
198
204 virtual void setup() = 0;
205
220 virtual void setParameters(double sNew) = 0;
221
247 virtual void extrapolate(double sNew) = 0;
248
256 void setCoefficients(double sNew);
257
263 virtual int solve(bool isContinuation) = 0;
264
271 virtual void reset() = 0;
272
282 virtual void getSolution() = 0;
283
289 virtual void cleanup();
290
291 // Protected member variables
292
294 int ns_;
295
297 std::string baseFileName_;
298
312
313 private:
314
316 DArray<State> states_;
317
319 DArray<double> sHistory_;
320
322 DArray<State*> stateHistory_;
323
326
328 int historyCapacity_;
329
331 int historySize_;
332
334 int nAccept_;
335
337 bool reuseState_;
338
349 void accept(double s);
350
354 SweepTmpl();
355
356 };
357
358} // namespace Pscf
359#include "SweepTmpl.tpp"
360#endif
Base class allowing subclasses to define sweepable parameters.
int historySize() const
Get the current number of stored previous states.
Definition SweepTmpl.h:157
virtual void getSolution()=0
Update state(0) and output data after successful solution.
void addParameterTypes(GArray< ParameterType > paramTypes)
Declare an array of specialized sweep parameter types.
virtual void extrapolate(double sNew)=0
Create initial guess for the next state by extrapolation.
~SweepTmpl()
Destructor.
Definition SweepTmpl.tpp:35
virtual void checkAllocation(State &state)=0
Check allocation of one state, allocate if necessary.
State & state(int i)
Get reference to a stored state, with i=0 being most recent.
Definition SweepTmpl.h:107
double c(int i) const
Get a coefficient of a previous state in a continuation.
Definition SweepTmpl.h:147
virtual void cleanup()
Clean up operation at the end of a sweep.
void initialize()
Initialize variables that track history of solutions.
virtual void setup()=0
Setup operation at the beginning of a sweep.
SweepTmpl(int historyCapacity)
Constructor (protected).
Definition SweepTmpl.tpp:22
int nAccept() const
Get the number of converged solutions accepted thus far.
Definition SweepTmpl.h:178
void setCoefficients(double sNew)
Compute coefficients of previous states for continuation.
void addParameterType(std::string name, int nId, ParameterModifier &modifier)
Declare a specialized parameter type.
virtual void sweep()
Iterate to solution.
Definition SweepTmpl.tpp:62
virtual void setParameters(double sNew)=0
Set non-adjustable system parameters to new values.
virtual int solve(bool isContinuation)=0
Call current iterator to solve SCFT problem.
virtual void readParameters(std::istream &in)
Read ns and baseFileName parameters.
Definition SweepTmpl.tpp:42
GArray< ParameterType > parameterTypes_
Definition SweepTmpl.h:311
double s(int i) const
Get the value of s for a stored solution, with i = 0 most recent.
Definition SweepTmpl.h:122
virtual void reset()=0
Reset system to previous solution after iterature failure.
void addParameterType(ParameterType paramType)
Declare a single specialized sweep parameter type.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
An automatically growable array, analogous to a std::vector.
Definition GArray.h:34
ParamComposite()
Constructor.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.
Declaration of a specialized sweep parameter type.