PSCF v1.1
|
Template for Anderson mixing iterator algorithm. More...
#include <AmIteratorTmpl.h>
Public Member Functions | |
AmIteratorTmpl () | |
Constructor. More... | |
~AmIteratorTmpl () | |
Destructor. More... | |
void | readParameters (std::istream &in) |
Read all parameters and initialize. More... | |
int | solve (bool isContinuation=false) |
Iterate to a solution. More... | |
Protected Member Functions | |
void | setMaxItr (int maxItr) |
Set value of maxItr. More... | |
void | setMaxHist (int maxHist) |
Set value of maxHist (number of retained previous states) More... | |
void | setErrorType (std::string errorType) |
Set and validate value of errorType string. More... | |
void | readErrorType (std::istream &in) |
Read and validate the optional errorType string parameter. More... | |
virtual bool | isValidErrorType () |
Checks if a string is a valid error type. More... | |
virtual double | norm (T const &hist) |
Find the L2 norm of a vector. More... | |
void | allocateAM () |
Allocate memory required by AM algorithm, if necessary. More... | |
virtual void | clear () |
Clear information about history. More... | |
virtual void | setup (bool isContinuation) |
Initialize just before entry to iterative loop. More... | |
virtual double | computeError (int verbose) |
Compute and return error used to test for convergence. More... | |
T const & | residual () const |
Return the current residual vector by const reference. More... | |
T const & | field () const |
Return the current field or state vector by const reference. More... | |
int | verbose () const |
Verbosity level, allowed values 0, 1, or 2. More... | |
bool | isAllocatedAM () const |
Have data structures required by the AM algorithm been allocated? More... | |
template<typename Type > | |
ScalarParam< Type > & | read (std::istream &in, const char *label, Type &value) |
Add and read a new required ScalarParam < Type > object. More... | |
template<typename Type > | |
ScalarParam< Type > & | readOptional (std::istream &in, const char *label, Type &value) |
Add and read a new optional ScalarParam < Type > object. More... | |
Protected Attributes | |
std::string | errorType_ |
Type of error criterion used to test convergence. More... | |
Template for Anderson mixing iterator algorithm.
Anderson mixing is an algorithm for solving a system of N nonlinear equations of the form r_{i}(x) = 0 for i = 0, ..., N-1, where x denotes a vector or array of unknown coordinate values. A vector of array of unknowns is referred here the "field" vector, while a vector or array of values of the errors r_{0},..., r_{N-1} is referred to as the residual vector.
The template parameter Iterator is a base class that must be derived from Util::ParamComposite, and must declare a virtual solve(bool) function with the same interface as that declared here.
The template type parameter T is the type of the data structure used to store both field and residual vectors.
Definition at line 39 of file AmIteratorTmpl.h.
Pscf::AmIteratorTmpl< Iterator, T >::AmIteratorTmpl |
Constructor.
Definition at line 31 of file AmIteratorTmpl.tpp.
Pscf::AmIteratorTmpl< Iterator, T >::~AmIteratorTmpl |
Destructor.
Definition at line 49 of file AmIteratorTmpl.tpp.
void Pscf::AmIteratorTmpl< Iterator, T >::readParameters | ( | std::istream & | in | ) |
Read all parameters and initialize.
in | input filestream |
Definition at line 56 of file AmIteratorTmpl.tpp.
int Pscf::AmIteratorTmpl< Iterator, T >::solve | ( | bool | isContinuation = false | ) |
Iterate to a solution.
isContinuation | true iff continuation within a sweep |
Definition at line 85 of file AmIteratorTmpl.tpp.
|
protected |
Set value of maxItr.
Provided to allow subclasses to set a modified default value before calling readParameters, in which maxItr is optional. Global default, set in constructor, is maxItr = 200.
maxItr | maximum number of iterations attempted |
Definition at line 244 of file AmIteratorTmpl.tpp.
|
protected |
Set value of maxHist (number of retained previous states)
Provided to allow subclasses to set a modified default value before calling readParameters, in which maxItr is optional. Global default, set in constructor, is maxHist = 50.
maxHist | maximum number of retained previous states |
Definition at line 251 of file AmIteratorTmpl.tpp.
|
protected |
Set and validate value of errorType string.
Provided to allow subclasses to set a modified default value before calling readParameters, in which errorType is optional. Global default, set in constructor, is relNormResid = 50.
errorType | error type string |
Definition at line 258 of file AmIteratorTmpl.tpp.
References UTIL_THROW.
|
protected |
Read and validate the optional errorType string parameter.
in | input filestream |
Definition at line 274 of file AmIteratorTmpl.tpp.
References UTIL_THROW.
|
protectedvirtual |
Checks if a string is a valid error type.
Virtual to allow extension of allowed error type string values.
Definition at line 290 of file AmIteratorTmpl.tpp.
|
protectedvirtual |
Find the L2 norm of a vector.
The default implementation calls dotProduct internally. Virtual to allow more optimized versions.
hist | residual vector |
Definition at line 486 of file AmIteratorTmpl.tpp.
|
protected |
Allocate memory required by AM algorithm, if necessary.
If the required memory has been allocated previously, this function does nothing and returns.
Definition at line 313 of file AmIteratorTmpl.tpp.
|
protectedvirtual |
Clear information about history.
This function clears the the history and basis vector ring buffer containers.
Definition at line 341 of file AmIteratorTmpl.tpp.
References Util::Log::file().
|
protectedvirtual |
Initialize just before entry to iterative loop.
This function is called by the solve function before entering the loop over iterations. The default functions calls allocateAM() if isAllocatedAM() is false, and otherwise calls clear() if isContinuation is false.
isContinuation | true iff continuation within a sweep |
Reimplemented in Pscf::Fd1d::AmIterator, Pscf::Pspc::AmIterator< D >, Pscf::Pspg::AmIteratorBasis< D >, and Pscf::Pspg::AmIteratorGrid< D >.
Definition at line 471 of file AmIteratorTmpl.tpp.
|
protectedvirtual |
Compute and return error used to test for convergence.
verbose | verbosity level of output report |
Definition at line 528 of file AmIteratorTmpl.tpp.
References Util::Log::file(), UTIL_CHECK, and UTIL_THROW.
|
protected |
Return the current residual vector by const reference.
Definition at line 418 of file AmIteratorTmpl.h.
|
protected |
Return the current field or state vector by const reference.
Definition at line 425 of file AmIteratorTmpl.h.
|
protected |
Verbosity level, allowed values 0, 1, or 2.
Definition at line 432 of file AmIteratorTmpl.h.
|
protected |
Have data structures required by the AM algorithm been allocated?
Definition at line 439 of file AmIteratorTmpl.h.
|
protected |
Add and read a new required ScalarParam < Type > object.
This is equivalent to ScalarParam<Type>(in, label, value, true).
in | input stream for reading |
label | Label string |
value | reference to new ScalarParam< Type > |
Definition at line 305 of file ParamComposite.h.
Referenced by pscfpp.param.Composite::__init__(), pscfpp.field.Field::__init__(), pscfpp.command.Script::__init__(), pscfpp.output.Thermo::__init__(), pscfpp.param.Matrix::__init__(), and pscfpp.param.Array::__init__().
|
inlineprotected |
Add and read a new optional ScalarParam < Type > object.
This is equivalent to ScalarParam<Type>(in, label, value, false).
in | input stream for reading |
label | Label string |
value | reference to new ScalarParam< Type > |
Definition at line 319 of file ParamComposite.h.
|
protected |
Type of error criterion used to test convergence.
Definition at line 71 of file AmIteratorTmpl.h.