PSCF v1.3.2
rpg/scft/iterator/AmIteratorGrid.h
1#ifndef RPG_AM_ITERATOR_GRID_H
2#define RPG_AM_ITERATOR_GRID_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 "Iterator.h" // base class argument
12#include <prdc/cuda/types.h> // base class argument
13#include <pscf/cuda/DeviceArray.h> // base class argument
14#include <pscf/iterator/AmIteratorTmpl.h> // base class template
15
16#include <pscf/iterator/AmbdInteraction.h> // member variable
17#include <util/containers/DArray.h> // base class argument
18#include <util/containers/RingBuffer.h> // method input variable
19
20namespace Pscf {
21namespace Rpg {
22
23 template <int D> class System;
24
25 using namespace Util;
26 using namespace Prdc;
27 using namespace Prdc::Cuda;
28
34 template <int D>
36 : public AmIteratorTmpl<Iterator<D>, DeviceArray<cudaReal> >
37 {
38
39 public:
40
41 // Public typename aliases.
42
45
48
49 // Public member functions
50
57
62
68 void readParameters(std::istream& in);
69
75 void outputTimers(std::ostream& out) const;
76
77 // Inherited public member functions
78 using Base::solve;
80 using Iterator<D>::isFlexible;
81 using Iterator<D>::flexibleParams;
82 using Iterator<D>::setFlexibleParams;
83 using Iterator<D>::nFlexibleParams;
84 using Iterator<D>::stress;
85
86 protected:
87
88 // Inherited protected members
89 using Base::verbose;
90 using Base::residual;
91 using Iterator<D>::system;
92 using Iterator<D>::isSymmetric_;
93 using Iterator<D>::isFlexible_;
94 using Iterator<D>::flexibleParams_;
99
105 void setup(bool isContinuation) override;
106
107 private:
108
110 AmbdInteraction interaction_;
111
113 double scaleStress_;
114
115 // Private virtual functions that interact with parent system
116
120 int nElements() override;
121
125 bool hasInitialGuess() override;
126
132 void getCurrent(VectorT& curr) override;
133
137 void evaluate() override;
138
144 void getResidual(VectorT& resid) override;
145
151 void update(VectorT& newGuess) override;
152
156 void outputToLog() override;
157
158 // Private virtual functions for vector math
159
166 void setEqual(VectorT& a, VectorT const & b) override;
167
171 double dotProduct(VectorT const & a,
172 VectorT const & b) override;
173
179 double maxAbs(VectorT const & a) override;
180
188 void subVV(VectorT& a,
189 VectorT const & b,
190 VectorT const & c) override;
191
199 void addEqVc(VectorT& a,
200 VectorT const & b, double c) override;
201
202 // --- Private member function specific to this implementation ---
203
209 cudaReal findAverage(VectorT const & field);
210
211 };
212
213 // Explicit instantiation declarations
214 extern template class AmIteratorGrid<1>;
215 extern template class AmIteratorGrid<2>;
216 extern template class AmIteratorGrid<3>;
217
218} // namespace Rpg
219} // namespace Pscf
220#endif
int solve(bool isContinuation=false)
Modified interaction to compute residual defn.
Dynamic array on the GPU device with aligned data.
Definition DeviceArray.h:43
Rpg implementation of the Anderson Mixing iterator.
AmIteratorGrid(System< D > &system)
Constructor.
void readParameters(std::istream &in)
Read all parameters and initialize.
void setup(bool isContinuation) override
Setup iterator just before entering iteration loop.
DeviceArray< cudaReal > VectorT
Typename for state and residual vectors.
void outputTimers(std::ostream &out) const
Output timing results to log file.
AmIteratorTmpl< Iterator< D >, VectorT > Base
Aliase for base class.
Base class for iterative solvers for SCF equations.
Main class, representing a complete physical system.
FSArrayParam< Type, N > & readOptionalFSArray(std::istream &in, const char *label, FSArray< Type, N > &array, int size)
Add and read an optional FSArray < Type, N > array parameter.
void setClassName(const char *className)
Set class name string.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
void readParamCompositeOptional(std::istream &in, ParamComposite &child, bool next=true)
Add and attempt to read an optional child ParamComposite.
Periodic fields and crystallography.
Definition CField.cpp:11
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.