PSCF v1.3
rpc/scft/iterator/Iterator.h
1#ifndef RPC_ITERATOR_H
2#define RPC_ITERATOR_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 <rpc/scft/sweep/Sweep.h>
12#include <prdc/environment/Environment.h>
13#include <util/param/ParamComposite.h> // base class
14#include <util/containers/FSArray.h>
15#include <util/global.h>
16
17namespace Pscf {
18namespace Rpc
19{
20
21 template <int D>
22 class System;
23
24 using namespace Util;
25
31 template <int D>
32 class Iterator : public ParamComposite
33 {
34
35 public:
36
40 Iterator();
41
48
52 ~Iterator();
53
60 virtual int solve(bool isContinuation) = 0;
61
65 virtual void outputTimers(std::ostream& out) const = 0;
66
70 virtual void clearTimers() = 0;
71
75 bool isSymmetric() const
76 { return (isSymmetric_); }
77
81 bool isFlexible() const
82 { return (isFlexible_); }
83
92
96 int nFlexibleParams() const;
97
103 void setFlexibleParams(FSArray<bool,6> const & flexParams);
104
113 virtual double stress(int paramId) const;
114
115 protected:
116
121
126
131
135 System<D> const & system() const
136 {
137 UTIL_CHECK(sysPtr_);
138 return *sysPtr_;
139 }
140
145 {
146 UTIL_CHECK(sysPtr_);
147 return *sysPtr_;
148 }
149
150 private:
151
153 System<D>* sysPtr_;
154
155 };
156
157 // Inline member functions
158
159 // Default constructor
160 template <int D>
162 : isSymmetric_(false),
163 isFlexible_(false),
164 sysPtr_(nullptr)
165 { setClassName("Iterator"); }
166
167 // Constructor
168 template <int D>
170 : isSymmetric_(false),
171 isFlexible_(false),
172 sysPtr_(&system)
173 { setClassName("Iterator"); }
174
175 // Destructor
176 template <int D>
179
180 // Get the number of flexible lattice parameters
181 template <int D>
183 {
184 UTIL_CHECK(flexibleParams_.size() ==
185 system().domain().unitCell().nParameter());
186 int nFlexParams = 0;
187 for (int i = 0; i < flexibleParams_.size(); i++) {
188 if (flexibleParams_[i]) nFlexParams++;
189 }
190 return nFlexParams;
191 }
192
193 // Set the array indicating which lattice parameters are flexible.
194 template <int D>
196 {
197 flexibleParams_ = flexParams;
198 if (nFlexibleParams() == 0) {
199 isFlexible_ = false;
200 } else {
201 isFlexible_ = true;
202 }
203 }
204
205 // Return the stress used by this Iterator, for one lattice parameter.
206 template <int D>
207 double Iterator<D>::stress(int paramId) const
208 {
209 // Parameter must be flexible to access the stress
210 UTIL_CHECK(flexibleParams_[paramId]);
211
212 if (system().hasEnvironment()) {
213 return system().environment().stress(paramId);
214 } else {
215 return system().mixture().stress(paramId);
216 }
217 }
218
219} // namespace Rpc
220} // namespace Pscf
221#endif
virtual void outputTimers(std::ostream &out) const =0
Log output timing results.
bool isSymmetric_
Does this iterator use a symmetry-adapted basis?
void setFlexibleParams(FSArray< bool, 6 > const &flexParams)
Set the array indicating which lattice parameters are flexible.
virtual int solve(bool isContinuation)=0
Iterate to solution.
Iterator()
Default constructor.
System< D > & system()
Get parent system by non-const reference.
int nFlexibleParams() const
Get the number of flexible lattice parameters.
bool isFlexible_
Are any lattice parameters flexible during iteration?
virtual double stress(int paramId) const
Return the stress used by this Iterator, for one lattice parameter.
bool isSymmetric() const
Does this iterator use a symmetry-adapted Fourier basis?
bool isFlexible() const
Return true iff unit cell has any flexible lattice parameters.
FSArray< bool, 6 > flexibleParams_
Array of indices of the lattice parameters that are flexible.
virtual void clearTimers()=0
Clear timers.
System< D > const & system() const
Get parent system by const reference.
FSArray< bool, 6 > flexibleParams() const
Get the array indicating which lattice parameters are flexible.
Main class, representing one complete system.
A fixed capacity (static) contiguous array with a variable logical size.
Definition FSArray.h:38
void setClassName(const char *className)
Set class name string.
ParamComposite()
Constructor.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1