PSCF v1.1
AmIteratorGrid.h
1#ifndef PSPG_AM_ITERATOR_GRID_H
2#define PSPG_AM_ITERATOR_GRID_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 "Iterator.h" // base class
12#include <pscf/iterator/AmIteratorTmpl.h> // base class template
13#include <pscf/iterator/AmbdInteraction.h> // member variable
14
15namespace Pscf {
16namespace Pspg
17{
18
19 template <int D>
20 class System;
21
22 using namespace Util;
23
29 template <int D>
30 class AmIteratorGrid : public AmIteratorTmpl<Iterator<D>, FieldCUDA>
31 {
32
33 public:
34
41
46
52 void readParameters(std::istream& in);
53
55 using Iterator<D>::isFlexible;
56
57 protected:
58
60 using Iterator<D>::system;
61 using Iterator<D>::isFlexible_;
62
68 void setup(bool isContinuation);
69
70 private:
71
73 AmbdInteraction interaction_;
74
76 double scaleStress_;
77
78 // Virtual functions used to implement AM algorithm
79
86 void setEqual(FieldCUDA& a, FieldCUDA const & b);
87
91 double dotProduct(FieldCUDA const & a, FieldCUDA const & b);
92
98 double maxAbs(FieldCUDA const & a);
99
100 #if 0
106 double norm(FieldCUDA const & a);
107
115 double computeUDotProd(RingBuffer<FieldCUDA> const & resBasis,
116 int m, int n);
117
125 double computeVDotProd(FieldCUDA const & resCurrent,
126 RingBuffer<FieldCUDA> const & resBasis,
127 int m);
128
136 void updateU(DMatrix<double> & U,
137 RingBuffer<FieldCUDA> const & resBasis,
138 int nHist);
139
148 void updateV(DArray<double> & v,
149 FieldCUDA const & resCurrent,
150 RingBuffer<FieldCUDA> const & resBasis,
151 int nHist);
152 #endif
153
160 void updateBasis(RingBuffer<FieldCUDA> & basis,
161 RingBuffer<FieldCUDA> const & hists);
162
171 void addHistories(FieldCUDA& trial,
172 RingBuffer<FieldCUDA> const & basis,
173 DArray<double> coeffs, int nHist);
174
182 void addPredictedError(FieldCUDA& fieldTrial,
183 FieldCUDA const & resTrial,
184 double lambda);
185
187 bool hasInitialGuess();
188
192 int nElements();
193
194 /*
195 * Get the current state of the system.
196 *
197 * \param curr current field vector (output)
198 */
199 void getCurrent(FieldCUDA& curr);
200
204 void evaluate();
205
211 void getResidual(FieldCUDA& resid);
212
218 void update(FieldCUDA& newGuess);
219
223 void outputToLog();
224
225 // --- Private member functions specific to this implementation ---
226
227 cudaReal findAverage(cudaReal const * field, int n);
228
229 };
230
231} // namespace Pspg
232} // namespace Pscf
233#endif
Template for Anderson mixing iterator algorithm.
int solve(bool isContinuation=false)
Iterate to a solution.
FieldCUDA const & field() const
Return the current field or state vector by const reference.
virtual double norm(FieldCUDA const &hist)
Find the L2 norm of a vector.
Modified interaction to compute residual defn.
Pspg implementation of the Anderson Mixing iterator.
void readParameters(std::istream &in)
Read all parameters and initialize.
void setup(bool isContinuation)
Setup iterator just before entering iteration loop.
Base class for iterative solvers for SCF equations.
Main class in SCFT simulation of one system.
Definition: pspg/System.h:71
Dynamically allocatable contiguous array template.
Definition: DArray.h:32
Dynamically allocated Matrix.
Definition: DMatrix.h:25
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.
Class for storing history of previous values in an array.
Definition: RingBuffer.h:27
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1