19 max_size(default_max_size),
20 automatic_size(false),
36 ASSERT(bound_a != bound_b,
"Bounds overlap.");
37 ASSERT(bound_a < bound_b,
"a must be lower and b must be upper bound.");
53 ASSERT(size >0,
"Size of interpolation table must be positive number!.");
69 ASSERT(init_size >0,
"Maximal size of interpolation table must be positive number!.");
70 ASSERT(max_size >= init_size,
"Maximal size of interpolation table is smaller than initial size.");
100 bool reinterpolate =
false;
105 reinterpolate =
true;
111 reinterpolate =
true;
116 xprintf(
Msg,
"Interpolation: Reinterpolating...\n");
147 interpolate_derivative(false)
170 f[i] = f[i] * this->
fact(i);
179 unsigned int result = 10;
227 xprintf(
Msg,
"Interpolation: Size of the table set automaticaly to: %d after %d cycles.\n",
size_,k);
246 xprintf(
Warn,
"Interpolation: User defined tolerance %E has not been satisfied with size of interpolation table %d.\n",
user_tol,
size_);
262 xprintf(
Msg,
"Interpolation: Interpolation error estimate is: %E.\n",
error_);
337 for(
unsigned int i = 0; i <
size_; i++)
342 f_vec[i] = value.first;
353 for(
unsigned int i = 0; i <
size_; i++)
365 double new_size = 2*
size_;
375 for(
unsigned int i=0; i!=
size_; i++)
377 swap_f_vec.push_back(
f_vec[i]);
378 swap_f_vec.push_back(f[i]);
380 swap_f_vec.push_back(
f_vec.back());
386 for(
unsigned int i=0; i!=
size_; i++)
388 swap_df_vec.push_back(
df_vec[i]);
389 swap_df_vec.push_back(df[i]);
391 swap_df_vec.push_back(
df_vec.back());
406 double temp_x = temp_a;
414 for(
unsigned int i = 0; i !=
size_; i++)
417 temp_x = temp_a +
step*i;
419 f.push_back(value.first);
420 df.push_back(value.second);
424 tot_err = std::max( tot_err,
425 std::abs(value.first - int_value.first) / (std::abs(value.first) + tol)
426 + std::abs(value.second - int_value.second) / (std::abs(value.second) + tol)
435 for(
unsigned int i = 0; i !=
size_; i++)
437 temp_x = temp_a +
step*i;
438 f.push_back(
f_val(temp_x));
439 tot_err = std::max( tot_err,
440 std::abs(f.back() -
val_p1(temp_x)) / (std::abs(f.back()) + tol)
509 for(
unsigned long i = 0; i <
size_; i++ )
522 tot_err = std::pow(tot_err, 1.0/exponent);
536 interpolate_derivative(false),
537 explicit_interpolant(NULL),
559 return func_u->operator()(u);
FunctorBase< B< double > > * func_diff
Pointer to original functor with FADBAD B type.
bool automatic_size
Is true if step/size should be chosen automatically.
ErrorNorm::Type norm_type
Type of norm used to compute error of the interpolation.
double bound_b() const
Returns right boundary of the interval.
void compute_values()
Creates table of nodes and function values.
double a_div_step
bound_ divided by step - precomputed value for evaluation
double f_diffn(double x, unsigned int n)
static const double simpson_tolerance
Tolerance in Adaptive Simpson intergration.
unsigned int n_nodes
Number of nodes in the interval .
static const unsigned int default_max_size
Default maximal size of the interpolation table.
unsigned int interval_miss_b
counts right misses of the interval
InterpolantImplicit()
constructor
void check_stats_and_reinterpolate(double percentage=0.3)
Can be called to check automatically the evaluation statistics and possibly reinterpolate.
void set_interval(double bound_a, double bound_b)
Sets the interpolation interval boundaries.
virtual ~InterpolantBase()
Destructor.
void fix_variable(IFixVariable::Type fix, double value)
unsigned int total_calls
counts total calls of evaluation
double user_tol
User set tolerance which is used during automatic step choice.
InterpolantBase()
Default constructor.
std::vector< double > df_vec
Vector of function derivatives values at nodes.
FunctorBase< T< double > > * func_diffn
Pointer to original functor with FADBAD T type.
std::pair< double, double > DiffValue
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.
double f_val(double x)
Returns value of the original functor.
Base class for interpolation.
std::vector< double > f_vec
Vector of function values at nodes.
double error_
Error of the interpolation.
virtual int interpolate()=0
Creates piecewise polynomial interpolation.
unsigned int size() const
Returns the size of the interpolation table.
IFunctorBase< B< double > > * func_diff
Interpolant * explicit_interpolant
double max
maximal x for which the evaluation was called outside the interval ((initially is equal the right bou...
virtual ~InterpolantImplicit(void)
destructor
DiffValue diff_p1(double x)
Finds interval on which x lies.
long fact(long x)
Recursive factorial function (used in Taylor row expansion in n-th derivative computation).
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.
double val_p1(double x)
Do NOT use, unless you are 100% sure.
unsigned int max_size
Maximal size of the interpolation table.
double step
Chosen interpolation step.
void set_size(unsigned int size)
Sets size of the interpolation table. It is also equal to the number of intervals.
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.
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.
EvalStatistics stats
Structure which keeps evaluation statistics. See InterpolantBase::eval_statistics.
Extrapolation::Type extrapolation
void interpolate_p1()
Creates piecewise linear interpolation.
void set_extrapolation(Extrapolation::Type extrapolation)
Sets the type of extrapolation. Functor type is default.
IFunctorBase< T< double > > * func_diffn
virtual int interpolate()
Creates piecewise interpolation with polynomials of selected degree.
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.
double bound_a() const
Returns left boundary of the interval.
IFunctorBase< double > * func
double bound_a_
Left interval boundary.
unsigned int interval_miss_a
counts left misses of the interval
double val(double u)
Returns interpolated value.
FuncExplicit< double > * func_u
bool interpolate_derivative
Is true if we want to interpolate the derivative too.
DiffValue f_diff(double x)
Returns 1st derivative of original functor using FADBAD.
double bound_b_
Right interval boundary.
void check_all()
Checks that the parameters are set before interpolation.
static const unsigned int n_derivatives
Defines how many derivatives we allow to be returned from Taylor's coeficients.
Interpolant()
Default constructor.
double p
Exponent used in norms and when computing error.
double min
minimal x for which the evaluation was called outside the interval (initially is equal the left bound...
virtual ~Interpolant(void)
Destructor.
void swap_middle_values(std::vector< double > &f, std::vector< double > &df)
void reset_stat()
Resets all measured statistics.
unsigned int size_
Number of dividing intervals.