36 max_size(default_max_size),
37 automatic_size(false),
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.");
70 OLD_ASSERT(size >0,
"Size of interpolation table must be positive number!.");
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.");
117 bool reinterpolate =
false;
122 reinterpolate =
true;
128 reinterpolate =
true;
133 xprintf(
Msg,
"Interpolation: Reinterpolating...\n");
164 interpolate_derivative(false)
187 f[i] = f[i] * this->
fact(i);
196 unsigned int result = 10;
244 xprintf(
Msg,
"Interpolation: Size of the table set automaticaly to: %d after %d cycles.\n",
size_,k);
263 xprintf(
Warn,
"Interpolation: User defined tolerance %E has not been satisfied with size of interpolation table %d.\n",
user_tol,
size_);
279 xprintf(
Msg,
"Interpolation: Interpolation error estimate is: %E.\n",
error_);
354 for(
unsigned int i = 0; i <
size_; i++)
359 f_vec[i] = value.first;
370 for(
unsigned int i = 0; i <
size_; i++)
382 double new_size = 2*
size_;
392 for(
unsigned int i=0; i!=
size_; i++)
394 swap_f_vec.push_back(
f_vec[i]);
395 swap_f_vec.push_back(f[i]);
397 swap_f_vec.push_back(
f_vec.back());
403 for(
unsigned int i=0; i!=
size_; i++)
405 swap_df_vec.push_back(
df_vec[i]);
406 swap_df_vec.push_back(df[i]);
408 swap_df_vec.push_back(
df_vec.back());
423 double temp_x = temp_a;
431 for(
unsigned int i = 0; i !=
size_; i++)
434 temp_x = temp_a +
step*i;
436 f.push_back(value.first);
437 df.push_back(value.second);
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)
452 for(
unsigned int i = 0; i !=
size_; i++)
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)
526 for(
unsigned long i = 0; i <
size_; i++ )
539 tot_err = std::pow(tot_err, 1.0/exponent);
554 explicit_interpolant(NULL),
576 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.
FunctorBase< double > * func
Pointer to original functor with double type.
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.