PSCF v1.1
SweepTmpl.h
1#ifndef PSCF_SWEEP_TMPL_H
2#define PSCF_SWEEP_TMPL_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, 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
13namespace Pscf {
14
15 using namespace Util;
16
22 template <typename State>
24 {
25
26 public:
27
28 // Constructor is protected (see below).
29
33 ~SweepTmpl();
34
40 virtual void readParameters(std::istream& in);
41
45 virtual void sweep();
46
47 protected:
48
50 int ns_;
51
53 std::string baseFileName_;
54
67
75 State& state(int i)
76 {
77 UTIL_CHECK(i < historySize_);
78 return *stateHistory_[i];
79 }
80
90 double s(int i) const
91 {
92 UTIL_CHECK(i < historySize_);
93 return sHistory_[i];
94 }
95
115 double c(int i) const
116 {
117 UTIL_CHECK(i >= 0);
118 UTIL_CHECK(i < historySize_);
119 return c_[i];
120 }
121
125 int historySize() const
126 { return historySize_; }
127
136 int historyCapacity() const
137 { return historyCapacity_; }
138
146 int nAccept() const
147 { return nAccept_; }
148
154 void initialize();
155
165 virtual void checkAllocation(State & state) = 0;
166
172 virtual void setup() = 0;
173
188 virtual void setParameters(double sNew) = 0;
189
215 virtual void extrapolate(double sNew) = 0;
216
224 void setCoefficients(double sNew);
225
231 virtual int solve(bool isContinuation) = 0;
232
239 virtual void reset() = 0;
240
250 virtual void getSolution() = 0;
251
257 virtual void cleanup();
258
259 private:
260
262 DArray<State> states_;
263
265 DArray<double> sHistory_;
266
268 DArray<State*> stateHistory_;
269
272
274 int historyCapacity_;
275
277 int historySize_;
278
280 int nAccept_;
281
283 bool reuseState_;
284
295 void accept(double s);
296
300 SweepTmpl();
301
302 };
303
304} // namespace Pscf
305#include "SweepTmpl.tpp"
306#endif
Solve a sequence of problems along a path through parameter space.
Definition: SweepTmpl.h:24
int historySize() const
Get the current number of stored previous states.
Definition: SweepTmpl.h:125
virtual void getSolution()=0
Update state(0) and output data after successful solution.
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:75
std::string baseFileName_
Base name for output files.
Definition: SweepTmpl.h:53
double c(int i) const
Get a coefficient of a previous state in a continuation.
Definition: SweepTmpl.h:115
virtual void cleanup()
Clean up operation at the end of a sweep.
Definition: SweepTmpl.tpp:241
void initialize()
Initialize variables that track history of solutions.
Definition: SweepTmpl.tpp:153
virtual void setup()=0
Setup operation at the beginning of a sweep.
int nAccept() const
Get the number of converged solutions accepted thus far.
Definition: SweepTmpl.h:146
void setCoefficients(double sNew)
Compute coefficients of previous states for continuation.
Definition: SweepTmpl.tpp:206
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.
int ns_
Number of steps.
Definition: SweepTmpl.h:50
virtual void readParameters(std::istream &in)
Read ns and baseFileName parameters.
Definition: SweepTmpl.tpp:42
double s(int i) const
Get the value of s for a stored solution, with i = 0 most recent.
Definition: SweepTmpl.h:90
virtual void reset()=0
Reset system to previous solution after iterature failure.
int historyCapacity() const
Get the maximum number of stored previous states.
Definition: SweepTmpl.h:136
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
An object that can read multiple parameters from file.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1