|
| Extrapolation () |
| Leave values uninitialized.
|
|
| Extrapolation (unsigned max, const ContainerType ©able) |
| Set maximum extrapolation order and allocate memory.
|
|
void | set_max (unsigned max, const ContainerType ©able) |
| Set maximum extrapolation order and allocate memory.
|
|
unsigned | get_max () const |
| Current extrapolation count.
|
|
bool | exists (value_type t) const |
| Check if time exists in current points.
|
|
template<class ContainerType0 > |
void | extrapolate (value_type t, ContainerType0 &new_x) const |
| Extrapolate value to given time.
|
|
template<class ContainerType0 > |
void | derive (value_type t, ContainerType0 &dot_x) const |
| Evaluate first derivative of interpolating polynomial
|
|
template<class ContainerType0 > |
void | extrapolate (ContainerType0 &new_x) const |
| Extrapolate value (equidistant version)
|
|
template<class MatrixType0 , class ContainerType0 , class ContainerType1 > |
void | extrapolate_least_squares (MatrixType0 &&A, const ContainerType0 &b, ContainerType0 &new_x, const ContainerType1 &weights) |
| EXPERIMENTAL Perform a least squares extrapolation.
|
|
template<class ContainerType0 > |
void | derive (ContainerType0 &dot_x) const |
| Evaluate first derivative of interpolating polynomial (equidistant version)
|
|
template<class ContainerType0 > |
void | update (value_type t_new, const ContainerType0 &new_entry) |
| insert a new entry, deleting the oldest entry or update existing entry
|
|
template<class ContainerType0 > |
void | update (const ContainerType0 &new_entry) |
| insert a new entry
|
|
const ContainerType & | head () const |
| return the current head (the one most recently inserted)
|
|
ContainerType & | tail () |
| DEPRECATED write access to tail value ( the one that will be deleted in the next update, undefined if max==0)
|
|
const ContainerType & | tail () const |
| DEPRECATED read access to tail value ( the one that will be deleted in the next update, undefined if max==0)
|
|
template<class ContainerType>
struct dg::Extrapolation< ContainerType >
Extrapolate a polynomial passing through up to three points.
This class constructs an interpolating polynomial through up to three given points and evaluates its value or its derivative at a new point. The points can be updated to get a new polynomial.
The intention of this class is to provide an initial guess for iterative solvers based on past solutions:
\[ x_{init} = \alpha_0 x_0 + \alpha_{-1}x_{-1} + \alpha_{-2} x_{-2}\]
where the indices indicate the current (0) and past (negative) solutions. Choose between 1 (constant), 2 (linear) or 3 (parabola) extrapolation. The user can choose to provide a time value t_i
associated with the x_i
, which are then used to compute the coefficients alpha_i
(using Lagrange interpolation). Otherwise an equidistant distribution is assumed.
extra.update( 0.0, y0);
extra.extrapolate( 0.3, guess);
INFO( "Difference 1 is "<<err);
CHECK( err < 1e-14);
extra.update( 0.1, y1);
extra.update( 0.1, y1);
extra.update( 0.2, y2);
extra.extrapolate( 0.3, guess);
INFO( "Difference 2 is "<<err);
CHECK( err < 1e-3);
- Note
- Since extrapolation with higher order polynomials is so prone to oscillations anything higher than linear rarely leads to anything useful. So best stick to constant or linear extrapolation
-
The derivative of the interpolating polynomial at a new point reduces to familiar finite difference formulas
- Template Parameters
-
ContainerType | Any class for which a specialization of TensorTraits exists and which fulfills the requirements of the there defined data and execution policies derived from AnyVectorTag and AnyPolicyTag . Among others
dg::HVec (serial), dg::DVec (cuda / omp), dg::MHVec (mpi + serial) or dg::MDVec (mpi + cuda / omp)
std::vector<dg::DVec> (vector of shared device vectors), std::array<double, 4> (array of 4 doubles) or std::map < std::string, dg::DVec> ( a map of named vectors)
double (scalar) and other primitive types ...
If there are several ContainerTypes in the argument list, then TensorTraits must exist for all of them |
- See also
- See The dg dispatch system for a detailed explanation of our type dispatch system
-
https://en.wikipedia.org/wiki/Extrapolation
template<class ContainerType >
template<class ContainerType0 >
Evaluate first derivative of interpolating polynomial
Equivalent to constructing the interpolating polynomial, deriving it once and then evaluating it at the required point
- Parameters
-
t | time at which derivative of interpolating polynomial is evaluated |
dot_x | (write only) contains derived value on output |
- Note
- If t is chosen as the latest time of update t0, then the result coincides with the backward difference formula of order
max
- Attention
- If max==1, the result is 0 (derivative of a constant)
-
If the update function has not been called enough times to fill all values the result depends: (i) never called => dot_x is zero (ii) called at least once => the interpolating polynomial is constructed with all available values
- Template Parameters
-
template<class ContainerType >
template<class MatrixType0 , class ContainerType0 , class ContainerType1 >
void dg::Extrapolation< ContainerType >::extrapolate_least_squares |
( |
MatrixType0 && | A, |
|
|
const ContainerType0 & | b, |
|
|
ContainerType0 & | new_x, |
|
|
const ContainerType1 & | weights ) |
|
inline |
EXPERIMENTAL Perform a least squares extrapolation.
This algorithm computes \( b_i = A x_i\), then solves the least squares problem \( \min_a || B a - b||_W \) with \( b_i\) the columns of \( B\) to compute \( x_{new} = \sum_i a_i x_i\).
- Note
- This is different from
LeastSquaresExtrapolation
if the matrix \( A\) is time-dependent.
-
So far this was only tested for toefl simulations with default parameters where we get mixed results. Depending on the
max
parameter one can see a slow down or a speed-up. Around 10 we observed a positive effect of about 10% acceleration
- Parameters
-
A | the matrix |
b | the right hand side |
new_x | Contains initial guess based on a least squares extrapolation on output |
weights | The weights/volume in which to minimize |