PSCF v1.1
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Pscf::AmIteratorTmpl< Iterator, T > Class Template Referenceabstract

Template for Anderson mixing iterator algorithm. More...

#include <AmIteratorTmpl.h>

Inheritance diagram for Pscf::AmIteratorTmpl< Iterator, T >:

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...
 

Detailed Description

template<typename Iterator, typename T>
class Pscf::AmIteratorTmpl< Iterator, T >

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.

Constructor & Destructor Documentation

◆ AmIteratorTmpl()

template<typename Iterator , typename T >
Pscf::AmIteratorTmpl< Iterator, T >::AmIteratorTmpl

Constructor.

Definition at line 31 of file AmIteratorTmpl.tpp.

◆ ~AmIteratorTmpl()

template<typename Iterator , typename T >
Pscf::AmIteratorTmpl< Iterator, T >::~AmIteratorTmpl

Destructor.

Definition at line 49 of file AmIteratorTmpl.tpp.

Member Function Documentation

◆ readParameters()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::readParameters ( std::istream &  in)

Read all parameters and initialize.

Parameters
ininput filestream

Definition at line 56 of file AmIteratorTmpl.tpp.

◆ solve()

template<typename Iterator , typename T >
int Pscf::AmIteratorTmpl< Iterator, T >::solve ( bool  isContinuation = false)

Iterate to a solution.

Parameters
isContinuationtrue iff continuation within a sweep
Returns
0 for convergence, 1 for failure

Definition at line 85 of file AmIteratorTmpl.tpp.

◆ setMaxItr()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::setMaxItr ( int  maxItr)
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.

Parameters
maxItrmaximum number of iterations attempted

Definition at line 244 of file AmIteratorTmpl.tpp.

◆ setMaxHist()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::setMaxHist ( int  maxHist)
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.

Parameters
maxHistmaximum number of retained previous states

Definition at line 251 of file AmIteratorTmpl.tpp.

◆ setErrorType()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::setErrorType ( std::string  errorType)
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.

Parameters
errorTypeerror type string

Definition at line 258 of file AmIteratorTmpl.tpp.

References UTIL_THROW.

◆ readErrorType()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::readErrorType ( std::istream &  in)
protected

Read and validate the optional errorType string parameter.

Parameters
ininput filestream

Definition at line 274 of file AmIteratorTmpl.tpp.

References UTIL_THROW.

◆ isValidErrorType()

template<typename Iterator , typename T >
bool Pscf::AmIteratorTmpl< Iterator, T >::isValidErrorType
protectedvirtual

Checks if a string is a valid error type.

Virtual to allow extension of allowed error type string values.

Returns
true if type is valid, false otherwise.

Definition at line 290 of file AmIteratorTmpl.tpp.

◆ norm()

template<typename Iterator , typename T >
double Pscf::AmIteratorTmpl< Iterator, T >::norm ( T const &  hist)
protectedvirtual

Find the L2 norm of a vector.

The default implementation calls dotProduct internally. Virtual to allow more optimized versions.

Parameters
histresidual vector

Definition at line 486 of file AmIteratorTmpl.tpp.

◆ allocateAM()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::allocateAM
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.

◆ clear()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::clear
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().

◆ setup()

template<typename Iterator , typename T >
void Pscf::AmIteratorTmpl< Iterator, T >::setup ( bool  isContinuation)
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.

Parameters
isContinuationtrue 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.

◆ computeError()

template<typename Iterator , typename T >
double Pscf::AmIteratorTmpl< Iterator, T >::computeError ( int  verbose)
protectedvirtual

Compute and return error used to test for convergence.

Parameters
verboseverbosity level of output report
Returns
error measure used to test for convergence.

Definition at line 528 of file AmIteratorTmpl.tpp.

References Util::Log::file(), UTIL_CHECK, and UTIL_THROW.

◆ residual()

template<typename Iterator , typename T >
T const & Pscf::AmIteratorTmpl< Iterator, T >::residual
protected

Return the current residual vector by const reference.

Definition at line 418 of file AmIteratorTmpl.h.

◆ field()

template<typename Iterator , typename T >
T const & Pscf::AmIteratorTmpl< Iterator, T >::field
protected

Return the current field or state vector by const reference.

Definition at line 425 of file AmIteratorTmpl.h.

◆ verbose()

template<typename Iterator , typename T >
int Pscf::AmIteratorTmpl< Iterator, T >::verbose
protected

Verbosity level, allowed values 0, 1, or 2.

Definition at line 432 of file AmIteratorTmpl.h.

◆ isAllocatedAM()

template<typename Iterator , typename T >
bool Pscf::AmIteratorTmpl< Iterator, T >::isAllocatedAM
protected

Have data structures required by the AM algorithm been allocated?

Definition at line 439 of file AmIteratorTmpl.h.

◆ read()

template<typename Iterator , typename T >
template<typename Type >
ScalarParam< Type > & Util::ParamComposite::read ( std::istream &  in,
const char *  label,
Type &  value 
)
protected

Add and read a new required ScalarParam < Type > object.

This is equivalent to ScalarParam<Type>(in, label, value, true).

Parameters
ininput stream for reading
labelLabel string
valuereference 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__().

◆ readOptional()

template<typename Iterator , typename T >
template<typename Type >
ScalarParam< Type > & Util::ParamComposite::readOptional ( std::istream &  in,
const char *  label,
Type &  value 
)
inlineprotected

Add and read a new optional ScalarParam < Type > object.

This is equivalent to ScalarParam<Type>(in, label, value, false).

Parameters
ininput stream for reading
labelLabel string
valuereference to new ScalarParam< Type >

Definition at line 319 of file ParamComposite.h.

Member Data Documentation

◆ errorType_

template<typename Iterator , typename T >
std::string Pscf::AmIteratorTmpl< Iterator, T >::errorType_
protected

Type of error criterion used to test convergence.

Definition at line 71 of file AmIteratorTmpl.h.


The documentation for this class was generated from the following files: