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>
14#include <util/accumulators/Average.h>
15#include <util/misc/Timer.h>
46 template <
typename Iterator,
typename T>
74 int solve(
bool isContinuation =
false);
144 bool useLambdaRamp =
true);
172 virtual void setup(
bool isContinuation);
360 bool hasAmTest_{
false};
362 double projectionError_{0};
363 double correctionError_{0};
364 double projectionRatio_{0};
365 double correctionRatio_{0};
380 void updateBasis(RingBuffer<T> & basis,
381 RingBuffer<T>
const & history);
389 void updateU(DMatrix<double> & U,
390 RingBuffer<T>
const & resBasis);
399 void computeV(DArray<double> & v,
400 T
const & resCurrent,
401 RingBuffer<T>
const & resBasis);
410 void computeTrialCoeff();
435 void addEqVectors(T& v,
436 RingBuffer<T>
const & basis,
437 DArray<double> coeffs);
454 void addCorrection(T& stateTrial, T
const & residualTrial);
465 virtual int nElements() = 0;
470 virtual bool hasInitialGuess() = 0;
477 virtual void getCurrent(T& curr) = 0;
486 virtual void evaluate() = 0;
493 virtual void getResidual(T& resid) = 0;
500 virtual void update(T& newGuess) = 0;
505 virtual void outputToLog() = 0;
517 virtual void setEqual(T& a, T
const & b) = 0;
525 virtual double dotProduct(T
const & a, T
const & b) = 0;
535 double norm(T
const & a);
542 virtual double maxAbs(T
const & a) = 0;
551 virtual void subVV(T& a, T
const & b, T
const & c) = 0;
560 virtual void addEqVc(T& a, T
const & b,
double c) = 0;
567 template <
typename Iterator,
typename T>
574 template <
typename Iterator,
typename T>
581 template <
typename Iterator,
typename T>
583 {
return stateHistory_[0]; }
588 template <
typename Iterator,
typename T>
590 {
return residualHistory_[0]; }
595 template <
typename Iterator,
typename T>
597 {
return isAllocatedAM_; }
602 template <
typename Iterator,
typename T>
604 {
return totalItr_; }
609 template <
typename Iterator,
typename T>
611 {
return timerMDE_.time(); }
616 template <
typename Iterator,
typename T>
618 {
return timerAM_.time(); }
623 template <
typename Iterator,
typename T>
625 {
return timerResid_.time(); }
630 template <
typename Iterator,
typename T>
632 {
return timerError_.time(); }
637 template <
typename Iterator,
typename T>
639 {
return timerCoeff_.time(); }
644 template <
typename Iterator,
typename T>
646 {
return timerOmega_.time(); }
651 template <
typename Iterator,
typename T>
653 {
return timerTotal_.time(); }
656#include "AmIteratorTmpl.tpp"
double lambdaRampFactor()
Compute ramped prefactor of mixing parameter lambda.
virtual void setup(bool isContinuation)
Initialize just before entry to iterative loop.
double timerError()
Get time evaluating scalar error.
void readMixingParameters(std::istream &in, bool useLambdaRamp=true)
Read optional parameters used in default correction algorithm.
double computeError(int verbose)
Compute and return error used to test for convergence.
T const & residual() const
Get the current residual vector by const reference.
double timerTotal()
Get total time.
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.
double timerOmega()
Get time spent updating w states.
void outputTimers(std::ostream &out) const
Log output timing results.
std::string errorType() const
void clearTimers()
Clear timers.
int totalItr()
Return the total number of iterations needed to converge.
double timerAM()
Get total time for AM algorithm, excluding MDE solution.
~AmIteratorTmpl()
Destructor.
double timerCoeff()
Get time spent evaluating Anderson mixing coefficients.
void readErrorType(std::istream &in)
Read and validate the optional errorType string parameter.
double timerMDE()
Get time spent solving the modified diffusion equation (MDE).
double timerResid()
Get time spent computing residual.
AmIteratorTmpl()
Constructor.
virtual double computeLambda()
Compute mixing parameter for correction step of Anderson mixing.
virtual bool isValidErrorType()
Checks if a string is a valid error type.
virtual double computeError(T &residTrial, T &stateTrial, std::string errorType, int verbose)
Compute and return error used to test for convergence.
virtual void readParameters(std::istream &in)
Read all parameters and initialize.
T const & state() const
Return the current state vector by const reference.
int solve(bool isContinuation=false)
Iterate to a solution.
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.
PSCF package top-level namespace.