KASKADE 7 development version
extrapolation.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2011 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef EXTRAPOLATION_HH
14#define EXTRAPOLATION_HH
15
16#include <vector>
17
18namespace Kaskade
19{
27 template <class T>
29 {
30 public:
31 typedef T value_type;
32
33 explicit ExtrapolationTableau(double hTarget_): hTarget(hTarget_) {}
34
35
39 void clear() { data.clear(); }
40
46 T const& back() const { return data.back(); }
47
52 T const& operator[](int i) const {
53 assert(0<=i && i<data.size());
54 return data[i];
55 }
56
62 int size() const { return data.size(); }
63
64
68 void push_back(T t, double hnew)
69 {
70 T tmp(t);
71
72 for (int i=0; i<data.size(); ++i) {
73 // at loop start: t = t(n+1,i), data[i] = t(n,i)
74
75 // compute coefficients, see Deuflhard/Hohmann 7.1.2
76 int n = data.size()-1;
77 double a = - (hTarget-hnew)/(hnew-h[n-i]);
78 double b = (hTarget-h[n-i])/(hnew-h[n-i]);
79 // compute tmp = t(n+1,i+1) = a*t(n,i)+b*t(n+1,i)
80 tmp = t; tmp *= b;
81 data[i] *= a; tmp += data[i];
82 // store data[i] = t(n+1,i)
83 data[i] = t;
84 // maintain loop invariant: t = t(n+1,i+1)
85 t = tmp;
86 }
87 // store new t(n+1,n+1)
88 data.push_back(t);
89 h.push_back(hnew);
90 }
91
92
93
94 private:
95 // The array data always contains a complete row of the extrapolation tableau.
96 std::vector<T> data;
97 std::vector<double> h;
98 double hTarget;
99 };
100} // namespace Kaskade
101
102#endif
Polynomial extrapolation following Aitken-Neville.
void push_back(T t, double hnew)
T const & operator[](int i) const
ExtrapolationTableau(double hTarget_)