PSCF v1.3
rpg/scft/iterator/Iterator.h
1#ifndef RPG_ITERATOR_H
2#define RPG_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 <rpg/scft/sweep/Sweep.h>
12#include <prdc/environment/Environment.h>
13#include <pscf/cuda/DeviceArray.h>
14#include <util/param/ParamComposite.h> // base class
15#include <util/containers/FSArray.h>
16#include <util/global.h>
17
18namespace Pscf {
19namespace Rpg
20{
21
22 template <int D>
23 class System;
24
25 using namespace Util;
26
27 typedef Prdc::Cuda::DeviceArray<Prdc::Cuda::cudaReal> FieldCUDA;
28
34 template <int D>
35 class Iterator : public ParamComposite
36 {
37
38 public:
39
43 Iterator();
44
51
55 ~Iterator();
56
63 virtual int solve(bool isContinuation) = 0;
64
68 virtual void outputTimers(std::ostream& out) const = 0;
69
73 virtual void clearTimers() = 0;
74
78 bool isSymmetric() const;
79
83 bool isFlexible() const;
84
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>& system();
136
140 System<D> const & system() const;
141
142 private:
143
145 System<D>* sysPtr_;
146
147 };
148
149 // Default constructor
150 template<int D>
152 : isSymmetric_(false),
153 isFlexible_(false),
154 sysPtr_(nullptr)
155 { setClassName("Iterator"); }
156
157 // Constructor
158 template<int D>
160 : isSymmetric_(false),
161 isFlexible_(false),
162 sysPtr_(&system)
163 { setClassName("Iterator"); }
164
165 // Destructor
166 template<int D>
168 {}
169
170 // Does this iterator use a symmetry-adapted Fourier basis?
171 template<int D>
172 inline bool Iterator<D>::isSymmetric() const
173 { return isSymmetric_; }
174
175
176 // Is the unit cell flexible (true) or rigid (false) ?
177 template<int D>
178 inline bool Iterator<D>::isFlexible() const
179 { return isFlexible_; }
180
181 // Get the array indicating which lattice parameters are flexible.
182 template<int D>
185
186 // Get the number of flexible lattice parameters
187 template <int D>
189 {
190 UTIL_CHECK(flexibleParams_.size() ==
191 system().domain().unitCell().nParameter());
192 int nFlexParams = 0;
193 for (int i = 0; i < flexibleParams_.size(); i++) {
194 if (flexibleParams_[i]) nFlexParams++;
195 }
196 return nFlexParams;
197 }
198
199 // Set the array indicating which lattice parameters are flexible.
200 template <int D>
202 {
203 flexibleParams_ = flexParams;
204 if (nFlexibleParams() == 0) {
205 isFlexible_ = false;
206 } else {
207 isFlexible_ = true;
208 }
209 }
210
211 // Return the stress used by this Iterator, for one lattice parameter.
212 template <int D>
213 double Iterator<D>::stress(int paramId) const
214 {
215 // Parameter must be flexible to access the stress
216 UTIL_CHECK(flexibleParams_[paramId]);
217
218 if (system().hasEnvironment()) {
219 return system().environment().stress(paramId);
220 } else {
221 return system().mixture().stress(paramId);
222 }
223 }
224
225 // Return reference to parent system.
226 template<int D>
228 { return *sysPtr_; }
229
230 // Return const reference to parent system.
231 template<int D>
232 inline System<D> const & Iterator<D>::system() const
233 { return *sysPtr_; }
234
235} // namespace Rpg
236} // namespace Pscf
237#endif
System< D > & system()
Return reference to parent system.
void setFlexibleParams(FSArray< bool, 6 > const &flexParams)
Set the array indicating which lattice parameters are flexible.
Iterator()
Default constructor.
virtual int solve(bool isContinuation)=0
Iterate to solution.
virtual void clearTimers()=0
Clear timers.
bool isFlexible() const
Is the unit cell flexible (true) or rigid (false).
int nFlexibleParams() const
Get the number of flexible lattice parameters.
bool isSymmetric() const
Does this iterator use a symmetry-adapted Fourier basis?
bool isFlexible_
Is the unit cell flexible during iteration?
virtual double stress(int paramId) const
Return the stress used by this Iterator, for one lattice parameter.
FSArray< bool, 6 > flexibleParams() const
Get the array indicating which lattice parameters are flexible.
bool isSymmetric_
Does this iterator use a symmetry-adapted basis?
virtual void outputTimers(std::ostream &out) const =0
Log output timing results.
FSArray< bool, 6 > flexibleParams_
Array of indices of the lattice parameters that 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
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1