1#ifndef PSCF_AM_ITERATOR_TMPL_H
2#define PSCF_AM_ITERATOR_TMPL_H
11#include <util/containers/DArray.h>
12#include <util/containers/DMatrix.h>
13#include <util/containers/RingBuffer.h>
38 template <
typename Iterator,
typename T>
66 int solve(
bool isContinuation =
false);
74 using Iterator::setClassName;
135 virtual double norm(T
const & hist);
151 virtual void clear();
163 virtual void setup(
bool isContinuation);
262 void computeResidCoeff();
306 virtual void setEqual(T& a, T
const & b) = 0;
314 virtual double dotProduct(T
const & a, T
const & b) = 0;
321 virtual double maxAbs(T
const & hist) = 0;
345 void addHistories(T& trial,
358 void addPredictedError(T& fieldTrial, T
const & resTrial,
366 virtual bool hasInitialGuess() = 0;
375 virtual int nElements() = 0;
382 virtual void getCurrent(T& curr) = 0;
391 virtual void evaluate() = 0;
398 virtual void getResidual(T& resid) = 0;
405 virtual void update(T& newGuess) = 0;
410 virtual void outputToLog() = 0;
417 template <
typename Iterator,
typename T>
419 {
return resHists_[0]; }
424 template <
typename Iterator,
typename T>
426 {
return fieldHists_[0]; }
431 template <
typename Iterator,
typename T>
438 template <
typename Iterator,
typename T>
440 {
return isAllocatedAM_; }
443#include "AmIteratorTmpl.tpp"
Template for Anderson mixing iterator algorithm.
virtual void setup(bool isContinuation)
Initialize just before entry to iterative loop.
void setMaxHist(int maxHist)
Set value of maxHist (number of retained previous states)
virtual double computeError(int verbose)
Compute and return error used to test for convergence.
T const & residual() const
Return the current residual vector by const reference.
void allocateAM()
Allocate memory required by AM algorithm, if necessary.
bool isAllocatedAM() const
Have data structures required by the AM algorithm been allocated?
virtual void clear()
Clear information about history.
void setErrorType(std::string errorType)
Set and validate value of errorType string.
int verbose() const
Verbosity level, allowed values 0, 1, or 2.
~AmIteratorTmpl()
Destructor.
void readErrorType(std::istream &in)
Read and validate the optional errorType string parameter.
void setMaxItr(int maxItr)
Set value of maxItr.
AmIteratorTmpl()
Constructor.
virtual bool isValidErrorType()
Checks if a string is a valid error type.
std::string errorType_
Type of error criterion used to test convergence.
void readParameters(std::istream &in)
Read all parameters and initialize.
int solve(bool isContinuation=false)
Iterate to a solution.
T const & field() const
Return the current field or state vector by const reference.
virtual double norm(T const &hist)
Find the L2 norm of a vector.
Dynamically allocatable contiguous array template.
Dynamically allocated Matrix.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
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.
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.