PSCF v1.3
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
12#include <pscf/iterator/AmIteratorTmpl.h> // base class template
13#include <pscf/iterator/AmbdInteraction.h> // member variable
14#include <util/containers/DArray.h> // base class argument
15#include <util/containers/RingBuffer.h> // method input variable
16
17namespace Pscf {
18namespace Rpg
19{
20
21 template <int D>
22 class System;
23
24 using namespace Util;
25
31 template <int D>
32 class AmIteratorGrid : public AmIteratorTmpl<Iterator<D>, FieldCUDA>
33 {
34
35 public:
36
43
48
54 void readParameters(std::istream& in);
55
61 void outputTimers(std::ostream& out) const;
62
63 // Inherited public member functions
64 using AmIteratorTmpl<Iterator<D>, FieldCUDA>::solve;
66 using Iterator<D>::isFlexible;
67 using Iterator<D>::flexibleParams;
68 using Iterator<D>::setFlexibleParams;
69 using Iterator<D>::nFlexibleParams;
70 using Iterator<D>::stress;
71
72 protected:
73
74 // Inherited protected members
79 using AmIteratorTmpl<Iterator<D>, FieldCUDA>::verbose;
80 using AmIteratorTmpl<Iterator<D>, FieldCUDA>::residual;
81 using Iterator<D>::system;
82 using Iterator<D>::isSymmetric_;
83 using Iterator<D>::isFlexible_;
84 using Iterator<D>::flexibleParams_;
85
91 void setup(bool isContinuation);
92
93 private:
94
96 AmbdInteraction interaction_;
97
99 double scaleStress_;
100
101 // Virtual functions used to implement AM algorithm
102
109 void setEqual(FieldCUDA& a, FieldCUDA const & b);
110
114 double dotProduct(FieldCUDA const & a, FieldCUDA const & b);
115
121 double maxAbs(FieldCUDA const & a);
122
129 void updateBasis(RingBuffer<FieldCUDA> & basis,
130 RingBuffer<FieldCUDA> const & hists);
131
140 void addHistories(FieldCUDA& trial,
141 RingBuffer<FieldCUDA> const & basis,
142 DArray<double> coeffs, int nHist);
143
151 void addPredictedError(FieldCUDA& fieldTrial,
152 FieldCUDA const & resTrial,
153 double lambda);
154
156 bool hasInitialGuess();
157
161 int nElements();
162
168 void getCurrent(FieldCUDA& curr);
169
173 void evaluate();
174
180 void getResidual(FieldCUDA& resid);
181
187 void update(FieldCUDA& newGuess);
188
192 void outputToLog();
193
194 // --- Private member functions specific to this implementation ---
195
201 cudaReal findAverage(FieldCUDA const & field);
202
203 };
204
205 #ifndef RPG_AM_ITERATOR_GRID_TPP
206 // Suppress implicit instantiation
207 extern template class AmIteratorGrid<1>;
208 extern template class AmIteratorGrid<2>;
209 extern template class AmIteratorGrid<3>;
210 #endif
211
212} // namespace Rpg
213} // namespace Pscf
214#endif
Modified interaction to compute residual defn.
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)
Setup iterator just before entering iteration loop.
void outputTimers(std::ostream &out) const
Output timing results to log file.
Base class for iterative solvers for SCF equations.
Main class, representing one complete system.
Dynamically allocatable contiguous array template.
Definition DArray.h:32
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.
Class for storing history of previous values in an array.
Definition RingBuffer.h:27
SCFT and PS-FTS with real periodic fields (GPU)
PSCF package top-level namespace.
Definition param_pc.dox:1