Flow123d  release_1.8.2-1603-g0109a2b
interpolant.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file interpolant.cc
15  * @brief
16  */
17 
18 #include "adaptivesimpson.hh"
19 #include "functors_impl.hh"
20 #include "interpolant_impl.hh"
21 
22 #include "system/xio.h"
23 //#include "system/sys_profiler.hh"
24 
25 #include <limits>
26 #include <iomanip>
27 
28 /********************************** InterpolantBase ******************************/
29 const unsigned int InterpolantBase::n_derivatives = 10;
30 const unsigned int InterpolantBase::default_max_size = 10*1000;
31 const double InterpolantBase::simpson_tolerance = 1e-10;
32 
34  : bound_a_(0),
35  bound_b_(0),
36  max_size(default_max_size),
37  automatic_size(false),
38  norm_type(ErrorNorm::max),
39  error_(-1.0),
40  extrapolation(Extrapolation::functor)
41  //use_statistics(true)
42 {
43  reset_stat();
44  checks.resize(4,false);
45 }
46 
48 {}
49 
50 
52 {
53  OLD_ASSERT(bound_a != bound_b,"Bounds overlap.");
54  OLD_ASSERT(bound_a < bound_b,"a must be lower and b must be upper bound.");
55  this->bound_a_ = bound_a;
56  checks[Check::bound_a] = true;
57  this->bound_b_ = bound_b;
58  checks[Check::bound_b] = true;
59 
60  //used to be use to collect the minimum and maximum "x" through all the evaluations (not only outside interval)
61  //are given oposite to be able to response to all calls
62  //stats.min = std::numeric_limits<double>::max();
63  //stats.max = -std::numeric_limits<double>::max();
64  stats.min = bound_a;
65  stats.max = bound_b;
66 }
67 
68 void InterpolantBase::set_size(unsigned int size)
69 {
70  OLD_ASSERT(size >0, "Size of interpolation table must be positive number!.");
71  this->size_ = size;
72  checks[Check::size] = true;
73 
74  automatic_size = false;
75 }
76 
78 {
79  this->norm_type = norm_type;
80  this->p = p;
81 }
82 
83 
84 void InterpolantBase::set_size_automatic(double user_tol, unsigned int init_size, unsigned int max_size)
85 {
86  OLD_ASSERT(init_size >0, "Maximal size of interpolation table must be positive number!.");
87  OLD_ASSERT(max_size >= init_size, "Maximal size of interpolation table is smaller than initial size.");
88  this->user_tol = user_tol;
89  this->max_size = max_size;
90  size_ = init_size;
91  automatic_size = true;
92 
93  checks[Check::size] = true;
94 }
95 
97 {
98  this->extrapolation = extrapolation;
99 }
100 
102 {
105  stats.total_calls = 0;
106  //stats.min = std::numeric_limits<double>::max();
107  //stats.max = -std::numeric_limits<double>::max();
108  stats.min = bound_a_;
109  stats.max = bound_b_;
110  //switch statistics on
111  //use_statistics = true;
112 }
113 
115 {
116  //DBGMSG("Check and reinterpolate.\n");
117  bool reinterpolate = false; //should we remake interpolation?
118  if((double)stats.interval_miss_a/stats.total_calls > percentage)
119  {
120  //DBGMSG("Check and reinterpolate.\n");
121  bound_a_ = stats.min;
122  reinterpolate = true;
123  }
124  if((double)stats.interval_miss_b/stats.total_calls > percentage)
125  {
126  //DBGMSG("Check and reinterpolate.\n");
127  bound_b_ = stats.max;
128  reinterpolate = true;
129  }
130 
131  if(reinterpolate)
132  {
133  xprintf(Msg, "Interpolation: Reinterpolating...\n");
134  interpolate();
135  reset_stat();
136  }
137 }
138 
139 
141 {
142  OLD_ASSERT(checks[Check::functor], "Functor is not set.");
143  OLD_ASSERT(checks[Check::bound_a], "Left boundary of the interval is not set.");
144  OLD_ASSERT(checks[Check::bound_b], "Right boundary of the interval is not set.");
145  OLD_ASSERT(checks[Check::size], "Step is not set.");
146  OLD_ASSERT(! ((user_tol == 0) && automatic_size), "Tolerance for automatic interpolation is not set.");
147 }
148 
150 {
151  if (n > 1)
152  return n*fact(n-1);
153  else
154  return 1;
155 }
156 
157 /********************************** Interpolant ********************************/
158 
160  : InterpolantBase(),
161  func(NULL),
162  func_diff(NULL),
163  func_diffn(NULL),
164  interpolate_derivative(false)
165  {
166  }
167 
169 {
170  if(func_diff) delete func_diff;
171  if(func_diffn) delete func_diffn;
172 }
173 
174 
175 double Interpolant::f_diffn(double x,unsigned int n)
176 {
177  OLD_ASSERT(n <= n_derivatives,"Not allowed to obtain higher than n-th derivate.");
178  T<double> xx,f;
179 
180  xx = x;
181  xx[1] = 1;
182  f = func_diffn->operator()(xx);
183  f.eval(n_derivatives);
184 
185  for(unsigned int i = 0; i<n_derivatives; i++) //goes through the field of Taylor's coeficients
186  { //and divide them by the factorial to get derivates
187  f[i] = f[i] * this->fact(i);
188  }
189 
190  return f[n]; //returns n-th derivate
191 }
192 
194 {
195  check_all(); //checks if all needed parameters were set
196  unsigned int result = 10;
197 
198  //switch off statistics due to error computation
199  //is switched on automatically by reset_stat()
200  //use_statistics = false;
201 
202  //POSSIBLE WAY TO USE MORE KINDS OF INTERPOLATION
203  //selecting the interpolation
204  /*
205  void (Interpolant::*interpolate_func)(void);
206  switch(degree)
207  {
208  case 0: interpolate_func = &Interpolant::interpolate_p0; break;
209  case 1: interpolate_func = &Interpolant::interpolate_p1; break;
210  default: OLD_ASSERT(degree > 1, "Higher order interpolation is not available at the moment.");
211  }
212  */
213 
214  //temporary vectors for values in the middle of intervals
215  std::vector<double> f_vec_half;
216  std::vector<double> df_vec_half;
217 
218  double tol = 1e-10; //error computation zero tolerance
219 
220  if(automatic_size)
221  {
222  int k = -1;
223  while(1)
224  {
225  k++;
226  //DBGMSG("k = %d\n",k);
227  compute_values(); //computes function (and possibly derivate) values at nodes
228 
230  compute_error(tol, f_vec_half, df_vec_half);
231  else
232  compute_error(tol, p, norm_type);
233 
234  DBGMSG("error: %E\n", error_);
235 
236  //error comparation
237  if(user_tol < error_)
238  {
239  DBGMSG("Interpolating: %d size: %d \t error: %E\n",k, size_, error_);
240  result = 1; //tolerance has not been satisfied
241  }
242  else
243  {
244  xprintf(Msg,"Interpolation: Size of the table set automaticaly to: %d after %d cycles.\n", size_,k);
245  //DBGMSG("Interpolation error estimate is: %f\n", error_);
246  result = 0; //interpolation OK
247  break;
248  }
249 
250  //size comparation
251  if(size_ < max_size/2)
252  {
253  if(norm_type == ErrorNorm::max) // if we compute the maximum norm, we can use the computed values
254  swap_middle_values(f_vec_half, df_vec_half);
255  else //else resize and compute new nodes
256  {
257  size_ *= 2;
258  compute_values(); //computes function (and possibly derivate) values at nodes
259  }
260  }
261  else
262  {
263  xprintf(Warn,"Interpolation: User defined tolerance %E has not been satisfied with size of interpolation table %d.\n",user_tol,size_);
264  break;
265  }
266  }
267  }
268  else
269  {
270  compute_values(); //computes function (and possibly derivate) values at nodes
271 
273  compute_error(tol, f_vec_half, df_vec_half);
274  else
275  compute_error(tol, p, norm_type);
276 
277  result = 0; //interpolation OK
278  }
279  xprintf(Msg,"Interpolation: Interpolation error estimate is: %E.\n", error_);
280  reset_stat();
281  return result;
282 }
283 
284 /*
285  // CONSTANT INTERPOLATION
286  void Interpolant::interpolate_p0()
287  {
288  create_nodes();
289 
290  Functor<double>* norm = new NormW21(this);
291  compute_error(norm); //sets error_
292  delete norm;
293  }
294 
295  // LINEAR INTERPOLATION WITH SAVED COEFICIENTS
296  void Interpolant::interpolate_p1()
297  {
298  p1_vec.resize(size_); //linear coeficients
299 
300  if(interpolate_derivative)
301  {
302  double delta = 0;
303  p1d_vec.resize(size_); //linear coeficients for derivative
304  for(unsigned int i = 0; i != p1_vec.size(); i++)
305  {
306  delta = x_vec[i+1] - x_vec[i];
307  p1_vec[i] = (f_vec[i+1] - f_vec[i]) / delta;
308  p1d_vec[i] = (df_vec[i+1] - df_vec[i]) / delta;
309  }
310  }
311  else
312  {
313  for(unsigned int i = 0; i != p1_vec.size(); i++)
314  {
315  p1_vec[i] = (f_vec[i+1] - f_vec[i]) / (x_vec[i+1] - x_vec[i]);
316  }
317  }
318 
319  //Writes the interpolation table.
320 
321  unsigned int p = 10,
322  pp = 5;
323  for(unsigned int i=0; i != size_-1; i++)
324  {
325  std::cout << "x: " << setw(p) << x_vec[i] << setw(pp) << "f:" << setw(p) << f_vec[i] << setw(pp) << "p1:" << setw(p) << p1_vec[i];
326  if(interpolate_derivative)
327  std::cout << setw(pp) << "df:" << setw(p) << df_vec[i] << setw(pp) << "p1d:" << setw(p) << p1d_vec[i] << std::endl;
328  else
329  std::cout << std::endl;
330  }
331  std::cout << "x: " << setw(p) << x_vec[x_vec.size()-1] << setw(pp) << "f:" << setw(p) << f_vec[f_vec.size()-1] << setw(pp) << "p1:" << setw(p) << "-";
332  if(interpolate_derivative)
333  std::cout << setw(pp) << "df:" << setw(p) << df_vec[df_vec.size()-1] << setw(pp) << "p1d:" << setw(p) << "-" << std::endl;
334  else
335  std::cout << std::endl;
336  }
337 //*/
338 
340 {
341  //setting the step - length of piecewise interpolation intervals
344  n_nodes = size_ + 1; //setting the number of nodes
345 
346  f_vec.resize(n_nodes); //function values in the nodes
347 
348  double temp_x = bound_a_;
350  {
351  df_vec.resize(n_nodes); //function derivates values in the nodes
352  //filling the vector x and f
353  DiffValue value;
354  for(unsigned int i = 0; i < size_; i++)
355  {
356  //DBGMSG("size: %d \tfill vectors: %d\n",size_,i);
357  temp_x = bound_a_ + step*i;
358  value = f_diff(temp_x);
359  f_vec[i] = value.first;
360  df_vec[i] = value.second;
361  }
362  //finish the interval
363  value = f_diff(bound_b_);
364  f_vec[size_] = value.first;
365  df_vec[size_] = value.second;
366  }
367  else
368  {
369  //filling the vector x and f
370  for(unsigned int i = 0; i < size_; i++)
371  {
372  temp_x = bound_a_ + step*i;
373  f_vec[i] = f_val(temp_x);
374  }
375  //finish the interval
377  }
378 }
379 
381 {
382  double new_size = 2*size_;
383  n_nodes = new_size+1;
384  step = (bound_b_-bound_a_)/new_size; //which should be equal also step/2
386 
387  //we will use now the middle points computed in "compute_error" to construct vector of nodes
388  std::vector<double> swap_f_vec;
389  std::vector<double> swap_df_vec;
390  swap_f_vec.reserve(n_nodes);
391 
392  for(unsigned int i=0; i!=size_; i++)
393  {
394  swap_f_vec.push_back(f_vec[i]);
395  swap_f_vec.push_back(f[i]);
396  }
397  swap_f_vec.push_back(f_vec.back());
398  f_vec = swap_f_vec;
399 
401  {
402  swap_df_vec.reserve(n_nodes);
403  for(unsigned int i=0; i!=size_; i++)
404  {
405  swap_df_vec.push_back(df_vec[i]);
406  swap_df_vec.push_back(df[i]);
407  }
408  swap_df_vec.push_back(df_vec.back());
409  df_vec = swap_df_vec;
410  }
411  size_ = new_size;
412 }
413 
414 
416 {
417  double tot_err = 0;
418 
419  f.clear();
420  f.reserve(size_); //function values in the middle nodes
421 
422  double temp_a = bound_a_ + step/2;
423  double temp_x = temp_a;
425  {
426  df.clear();
427  df.reserve(size_); //function derivates values in the middle nodes
428  //filling the vector x and f
429  DiffValue value;
430  DiffValue int_value;
431  for(unsigned int i = 0; i != size_; i++)
432  {
433  //DBGMSG("size: %d \tfill vectors: %d\n",size_,i);
434  temp_x = temp_a + step*i;
435  value = f_diff(temp_x);
436  f.push_back(value.first);
437  df.push_back(value.second);
438 
439  int_value = diff_p1(temp_x); //we can call directly the interpolant evaluation, because we know we are in the interval
440  //double t = std::abs(value.second - int_value.second) / (std::abs(value.second) + tol);
441  tot_err = std::max( tot_err,
442  std::abs(value.first - int_value.first) / (std::abs(value.first) + tol)
443  + std::abs(value.second - int_value.second) / (std::abs(value.second) + tol)
444  );
445  //DBGMSG("x,f,if: \t%f: %f: %f\n",temp_x, value.first, int_value.first);
446  //DBGMSG("temporary tot_error: %f: %f: %f\n",temp_x,tot_err,t);
447  }
448  }
449  else
450  {
451  //filling the vector x and f
452  for(unsigned int i = 0; i != size_; i++)
453  {
454  temp_x = temp_a + step*i;
455  f.push_back(f_val(temp_x));
456  tot_err = std::max( tot_err,
457  std::abs(f.back() - val_p1(temp_x)) / (std::abs(f.back()) + tol)
458  );
459  }
460  }
461 
462  error_ = tot_err;
463 
464  /* PRIORITY QUEUE FOR ADAPTIVE INTERVAL DIVIDING
465  for(unsigned long i = 0; i < g->get_count(); i++ )
466  {
467  LP_Norm norm(f,g->get_polynomial(i),2);
468  p_err.i = i;
469 
470  //absolute polynomial error
471  p_err.err = sqrt(Interpolation::AdaptiveSimpson::AdaptSimpson( norm,
472  g->get_polynomial(i)->get_a(),
473  g->get_polynomial(i)->get_b(),
474  SIMPSON_TOLERANCE) );
475 
476  //increase the absolute total error
477  tot_err += p_err.err;
478 
479  //writes absolute error on a single polynomial
480  if(DEB) std::cout << "\t abs. p_err=" << p_err.err;
481 
482  //p_err convertion absolute -> relative (p_err/(xi+1 - xi))
483  p_err.err /= (g->get_polynomial(i)->get_b()-g->get_polynomial(i)->get_a());
484 
485  //writes relative error on a single polynomial
486  if(DEB) std::cout << "\t rel. p_err=" << p_err.err << std::endl;
487 
488  pq.push(p_err); //puts in priority queue
489  }
490 
491  // writes relative and absolute total error
492  //std::cout << "\trelative err = "
493  // << tot_err/(g->GetA()-g->GetB())
494  // << "\tabsolute err = " << tot_err << std::endl;
495  //*/
496 }
497 
499 {
500  double exponent = 2; //default exponent
501  FunctorBase<double>* norm;
502 
503  switch(norm_type)
504  {
505  case ErrorNorm::w21:
506  norm = new FuncError_wp1(this, 2, tol);
507  break;
508  case ErrorNorm::wp1:
509  norm = new FuncError_wp1(this, p, tol);
510  exponent = p;
511  break;
512  case ErrorNorm::lp:
513  norm = new FuncError_lp(this, p, tol);
514  exponent = p;
515  break;
516  case ErrorNorm::l2:
517  default:
518  norm = new FuncError_lp(this, 2, tol);
519  }
520 
521 
522  double tot_err = 0, // total absolute error on <a,b>
523  p_err = 0; // absolute error on x[i]-x[i+1]
524  double x_node;
525 
526  for(unsigned long i = 0; i < size_; i++ )
527  {
528  x_node = bound_a_ + i*step;
529  p_err = std::abs( AdaptiveSimpson::AdaptSimpson(*norm,
530  x_node,
531  x_node+step,
533 
534  //DBGMSG("error on interval<%f,%f>: %f\n",x_vec[i],x_vec[i+1],p_err);
535  tot_err += p_err;
536  }
537  //DBGMSG("tot_err = %f\n",tot_err);
538  tot_err /= (bound_b_ - bound_a_); //relative to the interval length
539  tot_err = std::pow(tot_err, 1.0/exponent); //p-th root
540  error_ = tot_err;
541 }
542 
543 
544 
545 /********************************** InterpolantImplicit ********************************/
546 
548  : InterpolantBase(),
549  func_u(NULL),
550  func(NULL),
551  func_diff(NULL),
552  func_diffn(NULL),
553  interpolate_derivative(false),
554  explicit_interpolant(NULL),
555  fix_(IFixVariable::no_fix)
556  {
557  }
558 
560 {
562  if(func_diff) delete func_diff;
563  if(func_diffn) delete func_diffn;
564  if(func_u) delete func_u;
565 }
566 
568 {
569  fix_ = fix;
570  fix_val = val;
572 }
573 
575 {
576  return func_u->operator()(u);
577 }
578 
579 
581 {
582  //BUG: FuncExplicit cannot be copied in interpolant constructor with its members !!!
583  /*
584  OLD_ASSERT(fix_ != IFixVariable::no_fix,"Cannot do interpolation. No varible was fixed.");
585  check_all();
586  DBGMSG("seg %f\n",func_u);
587  explicit_interpolant = new Interpolant(func_u, interpolate_derivative);
588  //explicit_interpolant->set_functor(func_u, interpolate_derivative);
589  DBGMSG("seg\n");
590  explicit_interpolant->set_interval(bound_a_,bound_b_);
591  DBGMSG("seg\n");
592  if(automatic_size)
593  {
594  explicit_interpolant->set_size_automatic(user_tol, size_, max_size);
595  }
596  else
597  {
598  explicit_interpolant->set_size(size_);
599  }
600 
601  DBGMSG("seg\n");
602  explicit_interpolant->interpolate();
603  DBGMSG("seg\n");
604  error_ = explicit_interpolant->error();
605  */
606  return 0;
607 }
608 
610 {
611  if(func_u != NULL)
612  delete func_u;
613 
615 }
616 
617 
FunctorBase< B< double > > * func_diff
Pointer to original functor with FADBAD B type.
Definition: interpolant.hh:378
bool automatic_size
Is true if step/size should be chosen automatically.
Definition: interpolant.hh:172
ErrorNorm::Type norm_type
Type of norm used to compute error of the interpolation.
Definition: interpolant.hh:173
#define DBGMSG(...)
Definition: global_defs.h:229
double bound_b() const
Returns right boundary of the interval.
void compute_values()
Creates table of nodes and function values.
Definition: interpolant.cc:339
double a_div_step
bound_ divided by step - precomputed value for evaluation
Definition: interpolant.hh:162
Lp norm.
Definition: interpolant.hh:48
double f_diffn(double x, unsigned int n)
Definition: interpolant.cc:175
static const double simpson_tolerance
Tolerance in Adaptive Simpson intergration.
Definition: interpolant.hh:186
Definition: system.hh:59
unsigned int n_nodes
Number of nodes in the interval .
Definition: interpolant.hh:167
static const unsigned int default_max_size
Default maximal size of the interpolation table.
Definition: interpolant.hh:185
unsigned int interval_miss_b
counts right misses of the interval
Definition: interpolant.hh:140
InterpolantImplicit()
constructor
Definition: interpolant.cc:547
void check_stats_and_reinterpolate(double percentage=0.3)
Can be called to check automatically the evaluation statistics and possibly reinterpolate.
Definition: interpolant.cc:114
void set_interval(double bound_a, double bound_b)
Sets the interpolation interval boundaries.
Definition: interpolant.cc:51
virtual ~InterpolantBase()
Destructor.
Definition: interpolant.cc:47
void fix_variable(IFixVariable::Type fix, double value)
Definition: interpolant.cc:567
unsigned int total_calls
counts total calls of evaluation
Definition: interpolant.hh:140
double user_tol
User set tolerance which is used during automatic step choice.
Definition: interpolant.hh:170
InterpolantBase()
Default constructor.
Definition: interpolant.cc:33
std::vector< double > df_vec
Vector of function derivatives values at nodes.
Definition: interpolant.hh:385
FunctorBase< T< double > > * func_diffn
Pointer to original functor with FADBAD T type.
Definition: interpolant.hh:379
std::pair< double, double > DiffValue
Definition: interpolant.hh:30
I/O functions with filename storing, able to track current line in opened file. All standard stdio fu...
void compute_error(double tol, std::vector< double > &f, std::vector< double > &df)
Creates piecewise linear interpolation.
Definition: interpolant.cc:415
double f_val(double x)
Returns value of the original functor.
Base class for interpolation.
Definition: interpolant.hh:73
std::vector< double > f_vec
Vector of function values at nodes.
Definition: interpolant.hh:384
double error_
Error of the interpolation.
Definition: interpolant.hh:176
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:521
Interpolant * explicit_interpolant
Definition: interpolant.hh:526
double max
maximal x for which the evaluation was called outside the interval ((initially is equal the right bou...
Definition: interpolant.hh:144
virtual ~InterpolantImplicit(void)
destructor
Definition: interpolant.cc:559
DiffValue diff_p1(double x)
Finds interval on which x lies.
Wp1 norm.
Definition: interpolant.hh:50
#define OLD_ASSERT(...)
Definition: global_defs.h:128
long fact(long x)
Recursive factorial function (used in Taylor row expansion in n-th derivative computation).
Definition: interpolant.cc:149
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:84
double val_p1(double x)
Do NOT use, unless you are 100% sure.
Definition: system.hh:59
unsigned int max_size
Maximal size of the interpolation table.
Definition: interpolant.hh:171
FunctorBase< double > * func
Pointer to original functor with double type.
Definition: interpolant.hh:375
W21 norm.
Definition: interpolant.hh:49
#define xprintf(...)
Definition: system.hh:87
double step
Chosen interpolation step.
Definition: interpolant.hh:162
IFixVariable::Type fix_
Definition: interpolant.hh:528
void set_size(unsigned int size)
Sets size of the interpolation table. It is also equal to the number of intervals.
Definition: interpolant.cc:68
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:77
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:201
EvalStatistics stats
Structure which keeps evaluation statistics. See InterpolantBase::eval_statistics.
Definition: interpolant.hh:209
Extrapolation::Type extrapolation
Definition: interpolant.hh:181
void interpolate_p1()
Creates piecewise linear interpolation.
Definition: interpolant.cc:609
void set_extrapolation(Extrapolation::Type extrapolation)
Sets the type of extrapolation. Functor type is default.
Definition: interpolant.cc:96
IFunctorBase< T< double > > * func_diffn
Definition: interpolant.hh:522
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
Definition: interpolant.cc:580
static double AdaptSimpson(FunctorBase< double > &func, const double &a, const double &b, const double &tol)
main method that starts the evaluation and calls the recursion
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
Definition: interpolant.cc:193
double bound_a() const
Returns left boundary of the interval.
L2 norm.
Definition: interpolant.hh:47
IFunctorBase< double > * func
Definition: interpolant.hh:520
double bound_a_
Left interval boundary.
Definition: interpolant.hh:162
unsigned int interval_miss_a
counts left misses of the interval
Definition: interpolant.hh:140
double val(double u)
Returns interpolated value.
FuncExplicit< double > * func_u
Definition: interpolant.hh:517
bool interpolate_derivative
Is true if we want to interpolate the derivative too.
Definition: interpolant.hh:381
DiffValue f_diff(double x)
Returns 1st derivative of original functor using FADBAD.
double bound_b_
Right interval boundary.
Definition: interpolant.hh:162
void check_all()
Checks that the parameters are set before interpolation.
Definition: interpolant.cc:140
static const unsigned int n_derivatives
Defines how many derivatives we allow to be returned from Taylor&#39;s coeficients.
Definition: interpolant.hh:184
Interpolant()
Default constructor.
Definition: interpolant.cc:159
double p
Exponent used in norms and when computing error.
Definition: interpolant.hh:174
double min
minimal x for which the evaluation was called outside the interval (initially is equal the left bound...
Definition: interpolant.hh:144
virtual ~Interpolant(void)
Destructor.
Definition: interpolant.cc:168
void swap_middle_values(std::vector< double > &f, std::vector< double > &df)
Definition: interpolant.cc:380
void reset_stat()
Resets all measured statistics.
Definition: interpolant.cc:101
Maximum norm.
Definition: interpolant.hh:51
unsigned int size_
Number of dividing intervals.
Definition: interpolant.hh:167