![]() |
OGS
|
|
Anderson acceleration of the damped Picard fixpoint iteration.
Owns a sliding window of the last depth damped steps and the Gram matrix of that window, and mixes them into an accelerated iterate. History vectors are taken from the global vector provider on demand and returned in the destructor (RAII), so no manual release is required at the call site.
The window and its Gram matrix are only ever mutated together; keeping them in one object makes "history and Gram stay in sync" a class invariant instead of a convention spread across the solver loop.
A depth below min_mixing_depth admits no mixing (the sum-to-one constraint forces unit weight on the single stored step), so such an instance is an inert no-op: it takes no vector from the global vector provider and leaves the iterate untouched. This is the plain-Picard case.
Definition at line 30 of file AndersonAcceleration.h.
#include <AndersonAcceleration.h>
Classes | |
| struct | HistoryEntry |
Public Member Functions | |
| AndersonAcceleration (int depth) | |
| ~AndersonAcceleration () | |
| AndersonAcceleration (AndersonAcceleration const &)=delete | |
| AndersonAcceleration & | operator= (AndersonAcceleration const &)=delete |
| void | accelerate (GlobalVector const &x_old, GlobalVector &x_new) |
| void | dropLastStep () |
Static Public Attributes | |
| static constexpr int | min_mixing_depth = 2 |
Static Private Member Functions | |
| static void | releaseHistoryEntry (HistoryEntry const &entry) |
Returns entry's vectors to the global vector provider. | |
Private Attributes | |
| int const | _depth |
| std::vector< HistoryEntry > | _history |
| Circular buffer of history entries, oldest first (size <= _depth). | |
| Eigen::MatrixXd | _gram |
|
explicit |
| depth | number of previous iterates retained for mixing; a value below min_mixing_depth makes the instance an inert no-op (plain Picard). |
Definition at line 150 of file AndersonAcceleration.cpp.
References _depth, _gram, _history, and min_mixing_depth.
Referenced by AndersonAcceleration(), and operator=().
| NumLib::AndersonAcceleration::~AndersonAcceleration | ( | ) |
Definition at line 159 of file AndersonAcceleration.cpp.
References _history, and releaseHistoryEntry().
|
delete |
References AndersonAcceleration().
| void NumLib::AndersonAcceleration::accelerate | ( | GlobalVector const & | x_old, |
| GlobalVector & | x_new ) |
Records the newest damped step \( x_{\rm old} \to x_{\rm new} \) and overwrites x_new in place with the Anderson-mixed iterate.
While fewer than two steps are stored, or when the mixture is rejected as untrustworthy (see detail::computeAndersonWeights), x_new is left unchanged. For a no-op instance (depth < min_mixing_depth) this does nothing.
| x_old | the iterate entering this step. |
| x_new | in: the damped Picard step \( f = \beta(g(x_{\rm old}) -
x_{\rm old}) \) added to x_old; out: the mixed iterate. |
Definition at line 173 of file AndersonAcceleration.cpp.
References _depth, _gram, _history, MathLib::LinAlg::axpy(), NumLib::detail::computeAndersonWeights(), MathLib::LinAlg::copy(), DBUG(), MathLib::LinAlg::dot(), min_mixing_depth, NumLib::GlobalVectorProvider::provider, and MathLib::EigenVector::setZero().
Referenced by NumLib::NonlinearSolver< NonlinearSolverTag::Picard >::solve().
| void NumLib::AndersonAcceleration::dropLastStep | ( | ) |
Discards the step recorded by the most recent accelerate() call, used when the current iteration is repeated. The Gram shift performed while recording is deliberately not undone (see implementation).
Definition at line 278 of file AndersonAcceleration.cpp.
References _history, and releaseHistoryEntry().
Referenced by NumLib::NonlinearSolver< NonlinearSolverTag::Picard >::solve().
|
delete |
References AndersonAcceleration().
|
staticprivate |
Returns entry's vectors to the global vector provider.
Definition at line 167 of file AndersonAcceleration.cpp.
References NumLib::AndersonAcceleration::HistoryEntry::f, NumLib::GlobalVectorProvider::provider, and NumLib::AndersonAcceleration::HistoryEntry::x.
Referenced by ~AndersonAcceleration(), and dropLastStep().
|
private |
Maximum window size; mixing is active only for values >= min_mixing_depth.
Definition at line 81 of file AndersonAcceleration.h.
Referenced by AndersonAcceleration(), and accelerate().
|
private |
Gram matrix G = F^T F of the stored steps, maintained incrementally across iterations (only the newest step's row/column is recomputed). Sized once to the maximum window (_depth x _depth) so the incremental update never reallocates; only the leading history_size x history_size block is live while the window fills.
Definition at line 91 of file AndersonAcceleration.h.
Referenced by AndersonAcceleration(), and accelerate().
|
private |
Circular buffer of history entries, oldest first (size <= _depth).
Definition at line 84 of file AndersonAcceleration.h.
Referenced by AndersonAcceleration(), ~AndersonAcceleration(), accelerate(), and dropLastStep().
|
staticconstexpr |
Smallest depth that admits mixing: below it the sum-to-one constraint forces unit weight on the single stored step, i.e. plain Picard.
Definition at line 35 of file AndersonAcceleration.h.
Referenced by AndersonAcceleration(), accelerate(), NumLib::createNonlinearSolver(), and NumLib::NonlinearSolver< NonlinearSolverTag::Picard >::solve().