Flow123d  jenkins-Flow123d-windows32-release-multijob-51
interpolant.hh
Go to the documentation of this file.
1 #ifndef INTERPOLATION_H
2 #define INTERPOLATION_H
3 
4 #include "functors.hh"
5 
6 /** This pair contains both the function and the first derivative values and is used
7  * to as return value for functions of interpolation objects.
8  * The reason is that the FADBAD++ library computes both function value and derivative value
9  * at the same time. So when we use FADBAD++ in interpolant classes to compute
10  * derivates, we also return both values and we stick to it in interpolation evaluation also.
11  * We use the form \verbatim pair<function_value, derivative_value> \endverbatim.
12  */
13 typedef std::pair<double,double> DiffValue;
14 
15 
16 /** Enumerates possible kinds of extrapolation.
17  */
19  {
20  typedef enum {constant, ///< means that the values at the boundary points will be used outside the interval_miss_a
21  linear, ///< means that the linear approximation on the first and last subintervals will be used outside the interval
22  functor ///< means that the original functor will be called outside interpolation interval
23  } Type;
24  };
25 
26 /** Enumerates possible norms in which the interpolation error can be computed.
27  */
28  struct ErrorNorm
29  {
30  typedef enum {l2, ///< L2 norm
31  lp, ///< Lp norm
32  w21, ///< W21 norm
33  wp1, ///< Wp1 norm
34  max ///< Maximum norm
35  } Type;
36  };
37 
38 /** Enumerates types of variable fixation in implicit interpolant.
39  */
40  struct IFixVariable
41  {
42  typedef enum { fix_x, ///< x variable will be fixed with given value
43  fix_y, ///< y variable will be fixed with given value
44  no_fix ///< no variable is fixed (used when InterpolantImplicit is created)
45  } Type;
46  };
47 
48 ///Base class for interpolation.
49 /** This class serves as the common interface for interpolation classes.
50  * It provides functions for setting the common parameters of an interpolation
51  * such as interval, size of the table and extrapolation.
52  *
53  * @see Interpolant
54  * @see InterpolantImplicit
55  */
57 {
58 public:
59  ///Default constructor.
61 
62  ///Destructor.
63  virtual ~InterpolantBase();
64 
65  ///@name Interpolation.
66  //@{
67  ///Returns error of the interpolation.
68  /**It is equal to the chosen norm of the difference divided by the lenght of interval.
69  * Returns -1.0 if the interpolation has not been computed yet.
70  */
71  double error();
72 
73  //Gettters
74  double bound_a() const; ///< Returns left boundary of the interval.
75  double bound_b() const; ///< Returns right boundary of the interval.
76  unsigned int size() const; ///< Returns the size of the interpolation table.
77 
78  ///Sets the interpolation interval boundaries.
79  /** @param bound_a is the left boundary of the interval
80  * @param bound_b is the right boundary of the interval
81  */
82  void set_interval(double bound_a,double bound_b);
83 
84  ///Sets size of the interpolation table. It is also equal to the number of intervals.
85  /** @param size is the new size of the interpolation table
86  */
87  void set_size(unsigned int size);
88 
89  ///Sets the type of norm used for computing estimate of the error of the interpolation.
90  /** @param norm_type is the type of norm in which the error of interpolation is computed
91  * @param p is the exponent used in norms \f$ L_p \f$ and \f$ W_p^1 \f$
92  */
94 
95  /// Sets automatic choice of the size of the table.
96  /** When @p interpolate is called than the size is increased (by smaller interval dividing)
97  * until the given tolerance or the maximum size of the interpolation table is reached.
98  * @param user_tol is the tolerance which should the interpolation meet
99  * @param init_size is the initial choice of table size
100  * @param max_size is maximal size of the table that user allows
101  */
102  void set_size_automatic(double user_tol, unsigned int init_size, unsigned int max_size=default_max_size);
103 
104  ///Sets the type of extrapolation. Functor type is default.
105  /** @param extrapolation is the type of extrapolation (defined by enumeration @p ExtrapolationType)
106  */
108 
109  ///Creates piecewise polynomial interpolation.
110  /** @return
111  * - 0 if interpolation has been created
112  * - 1 if the tolerance has not been satisfied (in case of automatic choice of size)
113  */
114  virtual int interpolate() = 0;
115  //@}
116 
117  /** @name Evaluation statistics.
118  * These members are used recording the statistics of the evaluation.
119  */
120  //@{
121  ///Structure that keeps statistics of evaluation.
122  typedef struct {
123  unsigned int interval_miss_a, ///< counts left misses of the interval
124  interval_miss_b, ///< counts right misses of the interval
125  total_calls; ///< counts total calls of evaluation
126 
127  double min, ///< minimal x for which the evaluation was called outside the interval (initially is equal the left boundary)
128  max; ///< maximal x for which the evaluation was called outside the interval ((initially is equal the right boundary)
129  } EvalStatistics;
130 
131  EvalStatistics statistics() const; ///< Returns structure with evaluation statistics.
132 
133  ///Resets all measured statistics.
134  void reset_stat();
135 
136  ///Can be called to check automatically the evaluation statistics and possibly reinterpolate.
137  /** The function computes ratio of evaluations outside the interpolation interval - on each side of the interval.
138  * Then it compares the results with given percentage and accordingly changes (only streches) the interval and reinterpolate.
139  * @param percentage is the percentage of evaluations outside the interval (on one side)
140  */
141  void check_stats_and_reinterpolate(double percentage=0.3);
142  //@}
143 
144 protected:
145  double bound_a_, ///< Left interval boundary.
146  bound_b_, ///< Right interval boundary.
147  step, ///< Chosen interpolation step.
148  a_div_step; ///< bound_ divided by step - precomputed value for evaluation
149 
150  unsigned int size_, ///< Number of dividing intervals.
151  n_nodes; ///< Number of nodes in the interval \f$(a,b)\f$.
152 
153  double user_tol; ///< User set tolerance which is used during automatic step choice.
154  unsigned int max_size;///< Maximal size of the interpolation table.
155  bool automatic_size; ///< Is true if step/size should be chosen automatically.
156  ErrorNorm::Type norm_type; ///< Type of norm used to compute error of the interpolation.
157  double p; ///< Exponent used in norms \f$ L_p \f$ and \f$ W_p^1 \f$ when computing error.
158 
159  double error_; ///< Error of the interpolation.
160 
161  /** Extrapolation type - 'what' is evaluated outside the interpolation interval.
162  * Default value after interpolant construction is InterpolantBase::functor.
163  */
165 
166 
167  const static unsigned int n_derivatives; ///< Defines how many derivatives we allow to be returned from Taylor's coeficients.
168  const static unsigned int default_max_size; ///< Default maximal size of the interpolation table.
169  const static double simpson_tolerance; ///< Tolerance in Adaptive Simpson intergration. @see AdaptiveSimpson
170 
171  ///Recursive factorial function (used in Taylor row expansion in n-th derivative computation).
172  long fact (long x);
173 
174 
175  ///@name Internal check system.
176  /// This is internal check system which checks the values of parameters before making interpolation.
177  //@{
178  struct Check{
179  ///Enumerates parameters that must be set before creation of the interpolant.
180  enum {functor, bound_a, bound_b, size
181  } Type;
182  };
183  ///Vector of boolean values telling us which parameters are set or not.
185  ///Checks that the parameters are set before interpolation.
186  void check_all();
187  //@}
188 
189 
190  //currently not used
191  //bool use_statistics; ///< Is true if statistics is checked (it must be switched of during error computation)
192  EvalStatistics stats; ///< Structure which keeps evaluation statistics. See \ref InterpolantBase::eval_statistics.
193 
194 };
195 
196 
197 /// The main class for interpolation of functors.
198 /** This class is a wrapper of a functor (defined by class \ref FunctorBase) which provides
199  * computation of derivates and interpolation of the functor. We will describe the functionality
200  * in the following paragrahphs.
201  *
202  * ## Evaluation of a functor and its derivatives
203  *
204  * Beside the interpolation, the class provides calling of the functor itself.
205  * All functions evaluating directly the functor starts with '`f_`', e.g. function \ref f_val computes the functor value.
206  *
207  * We use the FADBAD++ library ([website](http://www.fadbad.com)) to compute derivatives of the functor. First derivatives
208  * can be obtained by function \ref f_diff which uses backward automatic differentiation. Higher order derivatives can be
209  * obtained via \ref f_diffn which uses Taylor expansion method.
210  *
211  * ## Interpolation
212  *
213  * Sofar we provide only a piecewise linear interpolation. Both the function and its derivative can be
214  * interpolated. User has to provide the functor object to the constructor or later to the function \ref set_functor.
215  * Then one must set at least the interval \f$ [a,b]\f$ by \ref set_interval and the size of the interpolation table
216  * by \ref set_size before calling \ref interpolate. Otherwise assert will crash the program in debug build.
217  *
218  * When user wants the size to be chosen automatically then \ref set_size_automatic must be called at first.
219  * An initial guess of size of the interpolation table and a tolerance which is assumed to be the maximum relative difference
220  * between the function and the interpolant (sum of value and derivative difference) must be provided.
221  * Futher user can set the maximum size of the interpolation (default 1000) table which will not be exceeded and the type of norm
222  * in which the estimate of the error of interpolation will be computed (enumerated in \ref ErrorNorm, default maximal norm).
223  * See one of the following paragraphs to learn how we deal with the error of the interpolation.
224  *
225  * Outside the given interval the interpolation is extrapolated. User can choose among several types of extrapolation
226  * which are enumerated in \ref Extrapolation. Constant and linear extrapolation use the first and last interpolating polynomials
227  * to compute the value. Functor type means that the functor itself will be evaluated outside the interval. Type of extrapolation
228  * can be changed by \ref set_extrapolation function. Calling functor is the default type of extrapolation.
229  *
230  *
231  * ### Error of the interpolation
232  *
233  * We are interested in the maximum difference between the function value and its interpolation.
234  * When interpolating also the derivative, we need to compute the difference between derivative and
235  * its interpolation too.
236  * Therefore we would like to compute something like the L-infinity norm, relative to function value and its derivative.
237  * Let \f$ f(x), f'(x) \f$ be the function and its derivative and \f$ g(x), g'(x)\f$ interpolation of the function and interpolation
238  * of the derivative on the interval \f$ I \f$. We suggest an approximation of the infinity norm:
239  * \f[
240  * \|f-g\|_\infty = \sup_{x\in I} F(x) = \sup_{x\in I} \left( \frac{|f(x)-g(x)|}{|f(x)| + tol} + \frac{|f'(x)-g'(x)|}{|f'(x)| + tol} \right)
241  * \approx \max_{x\in J} \left( \frac{|f(x)-g(x)|}{|f(x)| + tol} + \frac{|f'(x)-g'(x)|}{|f'(x)| + tol} \right)
242  * \f]
243  * where \f$ J \f$ is set of points that lies in the middle of two neighboring nodes. \f$ tol \f$ is a given tolerance for zero (avoids zero division).
244  * When computing the size of the interpolation table automatically, we compare the user tolerance \f$ TOL \f$ given by \ref set_size_automatic funtion
245  * directly with the estimated value of the supremum norm.
246  *
247  * This approach is fast and when computing the size automatically, we use the computed values (middle points, function and derivative values) in next
248  * interpolation. On the other hand this does not work good around zero points of the function where the value is small and the fraction becomes large or does
249  * not converge when dividing the intervals (\f$ x^2 \f$ is a good example).
250  *
251  * Therefore we provide also error estimation with \f$ L_p \f$ and \f$ W_p^1 \f$ norm. Then the user given tolerance is compared
252  * as it is stated in the following inequation:
253  * \f[
254  * \left( \frac{\int \limits_I F^p(x) \,\rm{d} x}{|I|} \right)^{\frac{1}{p}} \leq TOL.
255  * \f]
256  * This approach is much more expensive but can give better results.
257  *
258  * TODO: Improve error computation. Suggest more robust method.
259  *
260  * ### Evaluation statistics
261  *
262  * We collect some statistics during the evaluation of the interpolant in the struct \ref InterpolantBase::EvalStatistics -- total number of calls, number of evaluations
263  * inside the interpolation interval and number of evaluation outside the interval. One can use these statistics to decide whether it is necessary
264  * to widen the interval and recompute the interpolation. Function \ref check_stats_and_reinterpolate is provided to do this automatically
265  * according to the given percentage of evaluation outside the interval.
266  *
267  */
268 
270 {
271 public:
272  ///Default constructor.
273  Interpolant();
274 
275  ///Constructor with functor setting.
276  /**
277  * @param func is the pointer to functor
278  * @param interpolate_derivative is true when derivate is also interpolated
279  * @tparam Func is the functor type
280  * @tparam Type is the template type of the functor (e.g. double)
281  */
282  template<template<class> class Func, class Type >
283  Interpolant(Func<Type>* func, bool interpolate_derivative=false);
284 
285  ///Destructor.
286  virtual ~Interpolant(void);
287 
288  ///@name Evaluation.
289  //@{
290  ///Returns interpolated value.
291  /** @param x is the point at which we evaluate the interpolation
292  */
293  double val(double x);
294 
295  ///Do NOT use, only for testing purpose.
296  /** TODO: After testing it can be removed and
297  * \ref val_p1 can be made private again.
298  */
299  double val_test(double x);
300 
301  ///Do NOT use, unless you are 100% sure.
302  /** This function evaluates the P1 interpolant at x.
303  * It does not check the interval, does not provide extrapolation
304  * and does not collect statistics.
305  *
306  * Can be used to POSSIBLY speed the evaluation just a little bit,
307  * if you are absolutely sure that you evaluate the interpolant
308  * only on the given interval and do not want to collect statistics.
309  *
310  * Same can be done with \ref diff_p1 if it is made public.
311  *
312  * Used in unit_test benchmark to compare with val function.
313  */
314  double val_p1(double x);
315 
316  ///Returns interpolated value of the derivation.
317  /** @param x is the point at which we evaluate the interpolation
318  */
319  DiffValue diff(double x);
320 
321  ///Returns value of the original functor.
322  /** @param x is the point at which we evaluate the original functor
323  */
324  double f_val(double x);
325 
326  ///Returns 1st derivative of original functor using FADBAD.
327  /** @param x is the point at which we evaluate the original functor
328  */
329  DiffValue f_diff (double x);
330 
331  /** Returns n-th derivative of original functor using FADBAD.
332  * Uses coeficients in Taylor's row.
333  * @param x is the point at which we evaluate the original functor
334  * @param n is the order of the derivative we want
335  */
336  double f_diffn(double x, unsigned int n);
337  //@}
338 
339 
340  ///@name Interpolation.
341  //@{
342  ///Creates piecewise interpolation with polynomials of selected degree.
343  virtual int interpolate();
344 
345  ///Sets the functor.
346  /** Can be used when the functor is not set in the constructor.
347  * @param func is the pointer to functor
348  * @param interpolate_derivative is true when derivate is also interpolated
349  * @tparam Func is the functor type
350  * @tparam Type is the template type of the functor (e.g. double)
351  */
352  template<template<class> class Func, class Type >
353  void set_functor(Func<Type>* func, bool interpolate_derivative=false);
354  //@}
355 
356 protected:
357  class FuncError_lp;
359 
360  FunctorBase<double>* func; ///< Pointer to original functor with double type.
361  FunctorBase<B<double> >* func_diff; ///< Pointer to original functor with FADBAD B type.
362  FunctorBase<T<double> >* func_diffn; ///< Pointer to original functor with FADBAD T type.
363 
364  bool interpolate_derivative; ///< Is true if we want to interpolate the derivative too.
365 
366  //std::vector<double> x_vec; ///< Vector of nodes.
367  std::vector<double> f_vec; ///< Vector of function values at nodes.
368  std::vector<double> df_vec; ///< Vector of function derivatives values at nodes.
369  //std::vector<double> p1_vec; ///< Vector of linear coeficients of P1 interpolation.
370  //std::vector<double> p1d_vec; ///< Vector of linear coeficients of P1 interpolation.
371 
372  //Creates piecewise constant interpolation.
373  //void interpolate_p0();
374 
375  ///Creates piecewise linear interpolation.
376  //void interpolate_p1();
377 
378  ///Computes estimate of interpolation error in maximum norm.
379  void compute_error(double tol, std::vector<double>& f, std::vector<double>& df);
380 
381  ///Computes estimate of interpolation error with given norm.
382  void compute_error(double tol, double p, ErrorNorm::Type norm_type);
383 
385 
386  ///Creates table of nodes and function values.
387  /** Creates vector of nodes according to the table size
388  * and computes function and derivative values at the nodes.
389  */
390  void compute_values();
391 
392  ///Finds interval on which @p x lies.
393  //unsigned int find_interval(double x);
394 
395 
396  ///Function that evaluates the derivative of P1 interpolant at @p x.
397  DiffValue diff_p1(double x);
398 };
399 
400 
401 
402 
403 
405 {
406 public:
407 
408  ///@name Construction.
409  //@{
410  ///constructor
412 
413  ///Constructor with functor setting.
414  /**
415  * @param func is the pointer to functor
416  * @param interpolate_derivative is true when derivate is also interpolated
417  * @tparam Func is the functor type
418  * @tparam Type is the template type of the functor (e.g. double)
419  */
420  template<template<class> class Func, class Type >
421  InterpolantImplicit(Func<Type>* func, bool interpolate_derivative=false);
422 
423  ///destructor
424  virtual ~InterpolantImplicit(void);
425 
426  ///Sets the implicit functor.
427  /**
428  * @param func is the pointer to implicit functor.
429  * @tparam Func is the functor class.
430  * @tparam Type is the template type of the functor (e.g. double)
431  */
432  template<template<class> class Func, class Type >
433  void set_functor(Func<Type>* func, bool interpolate_derivative=false);
434 
435  //@}
436 
437  ///@name Evaluation.
438  //@{
439 
440  /** Fixes the chosen variable and sets its fixed value.
441  * @param fix is the chosen variable (no_fix, fix_x or fix_y)
442  * @param value is the fixed value
443  */
444  void fix_variable(IFixVariable::Type fix, double value);
445 
446  ///Returns interpolated value.
447  /** @param u is the point at which we evaluate the interpolation
448  */
449  double val(double u);
450 
451  ///Returns interpolated value of the derivation.
452  /** @param u is the point at which we evaluate the interpolation
453  */
454  DiffValue diff(double u);
455 
456  ///Returns interpolated value of the derivation.
457  /** @param x is the point at which we evaluate the interpolation
458  */
459  //double diffn(const double& x, const unsigned int& n);
460 
461  ///Returns value of the original functor.
462  /** @param x is function variable.
463  * @param y is function variable.
464  */
465  double f_val(double x, double y);
466 
467  ///Returns value of the original functor when one of the variables is fixed.
468  /** @param u is function variable (the one not fixed).
469  */
470  double f_val(double u);
471 
472  ///Returns 1st derivative of original functor using FADBAD.
473  /** @param x is function variable.
474  * @param y is function variable.
475  */
476  DiffValue f_diff (double x, double y);
477 
478  /** Returns n-th derivative of original functor using FADBAD.
479  * Uses coeficients in Taylor's row.
480  * @param u is the point at which we evaluate the original functor
481  * @param n is the order of the derivative we want
482  */
483  double f_diffn(double u, unsigned int n);
484  //@}
485 
486 
487  ///@name Interpolation.
488  //@{
489 
490  ///Creates piecewise interpolation with polynomials of selected degree.
491  virtual int interpolate();
492 
493 
494  //@}
495 
496 
497 protected:
498 
499  template<class Type=double>
501 
506 
507  bool interpolate_derivative; ///< Is true if we want to interpolate the derivative too.
508 
510 
512  double fix_val;
513 
514  ///@name Interpolation.
515  //@{
516 
517  ///Creates piecewise linear interpolation.
518  void interpolate_p1();
519 
520  //@}
521 
522 };
523 
524 #endif
FunctorBase< B< double > > * func_diff
Pointer to original functor with FADBAD B type.
Definition: interpolant.hh:361
enum InterpolantBase::Check::@0 Type
Enumerates parameters that must be set before creation of the interpolant.
bool automatic_size
Is true if step/size should be chosen automatically.
Definition: interpolant.hh:155
ErrorNorm::Type norm_type
Type of norm used to compute error of the interpolation.
Definition: interpolant.hh:156
DiffValue f_diff(double x, double y)
Returns 1st derivative of original functor using FADBAD.
double bound_b() const
Returns right boundary of the interval.
void compute_values()
Creates table of nodes and function values.
Definition: interpolant.cc:322
double a_div_step
bound_ divided by step - precomputed value for evaluation
Definition: interpolant.hh:145
Lp norm.
Definition: interpolant.hh:31
double f_diffn(double x, unsigned int n)
Definition: interpolant.cc:158
static const double simpson_tolerance
Tolerance in Adaptive Simpson intergration.
Definition: interpolant.hh:169
bool interpolate_derivative
Is true if we want to interpolate the derivative too.
Definition: interpolant.hh:507
unsigned int n_nodes
Number of nodes in the interval .
Definition: interpolant.hh:150
static const unsigned int default_max_size
Default maximal size of the interpolation table.
Definition: interpolant.hh:168
InterpolantImplicit()
constructor
Definition: interpolant.cc:530
void check_stats_and_reinterpolate(double percentage=0.3)
Can be called to check automatically the evaluation statistics and possibly reinterpolate.
Definition: interpolant.cc:97
void set_interval(double bound_a, double bound_b)
Sets the interpolation interval boundaries.
Definition: interpolant.cc:34
virtual ~InterpolantBase()
Destructor.
Definition: interpolant.cc:30
void fix_variable(IFixVariable::Type fix, double value)
Definition: interpolant.cc:550
void set_functor(Func< Type > *func, bool interpolate_derivative=false)
Sets the implicit functor.
unsigned int total_calls
counts total calls of evaluation
Definition: interpolant.hh:123
double user_tol
User set tolerance which is used during automatic step choice.
Definition: interpolant.hh:153
no variable is fixed (used when InterpolantImplicit is created)
Definition: interpolant.hh:44
InterpolantBase()
Default constructor.
Definition: interpolant.cc:16
double error()
Returns error of the interpolation.
double val_test(double x)
Do NOT use, only for testing purpose.
std::vector< double > df_vec
Vector of function derivatives values at nodes.
Definition: interpolant.hh:368
FunctorBase< T< double > > * func_diffn
Pointer to original functor with FADBAD T type.
Definition: interpolant.hh:362
std::pair< double, double > DiffValue
Definition: interpolant.hh:13
void compute_error(double tol, std::vector< double > &f, std::vector< double > &df)
Creates piecewise linear interpolation.
Definition: interpolant.cc:398
double f_val(double x)
Returns value of the original functor.
Base class for interpolation.
Definition: interpolant.hh:56
std::vector< double > f_vec
Vector of function values at nodes.
Definition: interpolant.hh:367
void set_functor(Func< Type > *func, bool interpolate_derivative=false)
Sets the functor.
double error_
Error of the interpolation.
Definition: interpolant.hh:159
virtual int interpolate()=0
Creates piecewise polynomial interpolation.
unsigned int size() const
Returns the size of the interpolation table.
IFunctorBase< B< double > > * func_diff
Definition: interpolant.hh:504
Interpolant * explicit_interpolant
Definition: interpolant.hh:509
virtual ~InterpolantImplicit(void)
destructor
Definition: interpolant.cc:542
DiffValue diff(double x)
Returns interpolated value of the derivation.
DiffValue diff_p1(double x)
Finds interval on which x lies.
Wp1 norm.
Definition: interpolant.hh:33
long fact(long x)
Recursive factorial function (used in Taylor row expansion in n-th derivative computation).
Definition: interpolant.cc:132
void set_size_automatic(double user_tol, unsigned int init_size, unsigned int max_size=default_max_size)
Sets automatic choice of the size of the table.
Definition: interpolant.cc:67
double val_p1(double x)
Do NOT use, unless you are 100% sure.
means that the linear approximation on the first and last subintervals will be used outside the inter...
Definition: interpolant.hh:21
Structure that keeps statistics of evaluation.
Definition: interpolant.hh:122
unsigned int max_size
Maximal size of the interpolation table.
Definition: interpolant.hh:154
x variable will be fixed with given value
Definition: interpolant.hh:42
double f_diffn(double u, unsigned int n)
FunctorBase< double > * func
Pointer to original functor with double type.
Definition: interpolant.hh:358
DiffValue diff(double u)
Returns interpolated value of the derivation.
means that the values at the boundary points will be used outside the interval_miss_a ...
Definition: interpolant.hh:20
W21 norm.
Definition: interpolant.hh:32
double val(double x)
Returns interpolated value.
double step
Chosen interpolation step.
Definition: interpolant.hh:145
means that the original functor will be called outside interpolation interval
Definition: interpolant.hh:22
IFixVariable::Type fix_
Definition: interpolant.hh:511
void set_size(unsigned int size)
Sets size of the interpolation table. It is also equal to the number of intervals.
Definition: interpolant.cc:51
void set_norm(ErrorNorm::Type norm_type=ErrorNorm::max, double p=2)
Sets the type of norm used for computing estimate of the error of the interpolation.
Definition: interpolant.cc:60
double f_val(double x, double y)
Returns interpolated value of the derivation.
std::vector< bool > checks
Vector of boolean values telling us which parameters are set or not.
Definition: interpolant.hh:184
EvalStatistics stats
Structure which keeps evaluation statistics. See InterpolantBase::eval_statistics.
Definition: interpolant.hh:192
Extrapolation::Type extrapolation
Definition: interpolant.hh:164
The main class for interpolation of functors.
Definition: interpolant.hh:269
void interpolate_p1()
Creates piecewise linear interpolation.
Definition: interpolant.cc:592
void set_extrapolation(Extrapolation::Type extrapolation)
Sets the type of extrapolation. Functor type is default.
Definition: interpolant.cc:79
IFunctorBase< T< double > > * func_diffn
Definition: interpolant.hh:505
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
Definition: interpolant.cc:563
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
Definition: interpolant.cc:176
double bound_a() const
Returns left boundary of the interval.
L2 norm.
Definition: interpolant.hh:30
IFunctorBase< double > * func
Definition: interpolant.hh:503
double bound_a_
Left interval boundary.
Definition: interpolant.hh:145
double val(double u)
Returns interpolated value.
FuncExplicit< double > * func_u
Definition: interpolant.hh:500
bool interpolate_derivative
Is true if we want to interpolate the derivative too.
Definition: interpolant.hh:364
DiffValue f_diff(double x)
Returns 1st derivative of original functor using FADBAD.
double bound_b_
Right interval boundary.
Definition: interpolant.hh:145
void check_all()
Checks that the parameters are set before interpolation.
Definition: interpolant.cc:123
static const unsigned int n_derivatives
Defines how many derivatives we allow to be returned from Taylor's coeficients.
Definition: interpolant.hh:167
Interpolant()
Default constructor.
Definition: interpolant.cc:142
y variable will be fixed with given value
Definition: interpolant.hh:43
double p
Exponent used in norms and when computing error.
Definition: interpolant.hh:157
double min
minimal x for which the evaluation was called outside the interval (initially is equal the left bound...
Definition: interpolant.hh:127
virtual ~Interpolant(void)
Destructor.
Definition: interpolant.cc:151
void swap_middle_values(std::vector< double > &f, std::vector< double > &df)
Definition: interpolant.cc:363
void reset_stat()
Resets all measured statistics.
Definition: interpolant.cc:84
EvalStatistics statistics() const
Returns structure with evaluation statistics.
Maximum norm.
Definition: interpolant.hh:34
unsigned int size_
Number of dividing intervals.
Definition: interpolant.hh:150