PSCF v1.1
pspc/iterator/Iterator.h
1#ifndef PSPC_ITERATOR_H
2#define PSPC_ITERATOR_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#include <util/containers/FSArray.h>
13#include <util/global.h>
14
15namespace Pscf {
16namespace Pspc
17{
18
19 template <int D>
20 class System;
21
22 using namespace Util;
23
29 template <int D>
30 class Iterator : public ParamComposite
31 {
32
33 public:
34
38 Iterator();
39
46
50 ~Iterator();
51
58 virtual int solve(bool isContinuation) = 0;
59
63 bool isFlexible() const
64 { return (isFlexible_); }
65
73 { return flexibleParams_; }
74
78 int nFlexibleParams() const;
79
80 protected:
81
85 System<D> const & system() const
86 { return *sysPtr_; }
87
92 { return *sysPtr_; }
93
96
102 void setFlexibleParams(FSArray<bool,6> const & flexParams);
103
108
109 private:
110
112 System<D>* sysPtr_;
113
114 };
115
116 // Inline member functions
117
118 // Default constructor
119 template <int D>
121 { setClassName("Iterator"); }
122
123 // Constructor
124 template <int D>
126 : sysPtr_(&system)
127 { setClassName("Iterator"); }
128
129 // Destructor
130 template <int D>
132 {}
133
134 // Get the number of flexible lattice parameters
135 template <int D>
137 {
138 UTIL_CHECK(flexibleParams_.size() == system().unitCell().nParameter());
139 int nFlexParams = 0;
140 for (int i = 0; i < flexibleParams_.size(); i++) {
141 if (flexibleParams_[i]) nFlexParams++;
142 }
143 return nFlexParams;
144 }
145
146 // Set the array indicating which lattice parameters are flexible.
147 template <int D>
149 {
150 flexibleParams_ = flexParams;
151 if (nFlexibleParams() == 0) {
152 isFlexible_ = false;
153 } else {
154 isFlexible_ = true;
155 }
156 }
157
158} // namespace Pspc
159} // namespace Pscf
160#endif
Base class for iterative solvers for SCF equations.
void setFlexibleParams(FSArray< bool, 6 > const &flexParams)
Set the array indicating which lattice parameters are flexible.
bool isFlexible() const
Return true iff unit cell has any flexible lattice parameters.
Iterator()
Default constructor.
virtual int solve(bool isContinuation)=0
Iterate to solution.
bool isFlexible_
Are any lattice parameters flexible during iteration?
FSArray< bool, 6 > flexibleParams_
Array of indices of the lattice parameters that are flexible.
System< D > const & system() const
Get parent system by const reference.
int nFlexibleParams() const
Get the number of flexible lattice parameters.
System< D > & system()
Get parent system by non-const reference.
FSArray< bool, 6 > flexibleParams() const
Get the array indicating which lattice parameters are flexible.
Main class for SCFT simulation of one system.
Definition: pspc/System.h:76
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:38
An object that can read multiple parameters from file.
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
#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