EGSnrc C++ class library
Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
|
A class for fast run-time interpolations. More...
#include <egs_interpolator.h>
Public Member Functions | |
EGS_Interpolator () | |
Create an empty (unitialized) interpolator. | |
EGS_Interpolator (int nbin, EGS_Float Xmin, EGS_Float Xmax, const EGS_Float *values) | |
Create an interpolator for the data values using nbin bins. More... | |
EGS_Interpolator (int nbin, EGS_Float Xmin, EGS_Float Xmax, EGS_InterpolatorFuncion func, void *data) | |
Create an interpolator for the function func in Xmin...Xmax. More... | |
EGS_Interpolator (EGS_Float Xmin, EGS_Float Xmax, EGS_InterpolatorFuncion func, void *data, int nmax=1024, EGS_Float accu=1e-4) | |
Create an interpolator for the function func in Xmin...Xmax. More... | |
EGS_Interpolator (int nbin, EGS_Float Xmin, EGS_Float Xmax, EGS_Float *a, EGS_Float *b) | |
Create an interpolator using the existing coefficients a and b. More... | |
~EGS_Interpolator () | |
Destructor. | |
void | initialize (int nbin, EGS_Float Xmin, EGS_Float Xmax, const EGS_Float *values) |
Initialize the interpolator. More... | |
void | initialize (int nbin, EGS_Float Xmin, EGS_Float Xmax, EGS_InterpolatorFuncion func, void *data) |
Initialize the interpolator. More... | |
void | initialize (EGS_Float Xmin, EGS_Float Xmax, EGS_InterpolatorFuncion func, void *data, int nmax=1024, EGS_Float accu=1e-4) |
void | initialize (int nbin, EGS_Float Xmin, EGS_Float Xmax, EGS_Float *a, EGS_Float *b) |
Initialize the interpolator. More... | |
EGS_Float | interpolate (EGS_Float x) const |
Interpolate the function value at x. More... | |
EGS_Float | interpolateFast (EGS_Float x) const |
Interpolate the function value at x. More... | |
int | getIndex (EGS_Float x) const |
Get the interpolation index corresponding to x. More... | |
int | getIndexFast (EGS_Float x) const |
Get the interpolation index corresponding to x. More... | |
EGS_Float | interpolateFast (int i, EGS_Float x) const |
Interpolate the function value at x assuming that belongs to the interpolation interval i. More... | |
EGS_Float | getXmin () const |
Get the lower interpolation interval limit. | |
EGS_Float | getXmax () const |
Get the upper interpolation interval limit. | |
EGS_Float | get_a (int i) const |
Get i-th interval interpolation parameter a[i]. | |
EGS_Float | get_b (int i) const |
Get i-th interval interpolation parameter b[i]. | |
A class for fast run-time interpolations.
Definition at line 49 of file egs_interpolator.h.
EGS_Interpolator::EGS_Interpolator | ( | int | nbin, |
EGS_Float | Xmin, | ||
EGS_Float | Xmax, | ||
const EGS_Float * | values | ||
) |
Create an interpolator for the data values using nbin bins.
The data is assumed to be uniformely distributed between Xmin and Xmax.
Definition at line 44 of file egs_interpolator.cpp.
References initialize().
EGS_Interpolator::EGS_Interpolator | ( | int | nbin, |
EGS_Float | Xmin, | ||
EGS_Float | Xmax, | ||
EGS_InterpolatorFuncion | func, | ||
void * | data | ||
) |
Create an interpolator for the function func in Xmin...Xmax.
The interval Xmin...Xmax is divided into nbin uniform bins and the interpolator is initialized to perform a linear intepolation between the function values returned by func at the bin edges.
Definition at line 49 of file egs_interpolator.cpp.
References initialize().
EGS_Interpolator::EGS_Interpolator | ( | EGS_Float | Xmin, |
EGS_Float | Xmax, | ||
EGS_InterpolatorFuncion | func, | ||
void * | data, | ||
int | nmax = 1024 , |
||
EGS_Float | accu = 1e-4 |
||
) |
Create an interpolator for the function func in Xmin...Xmax.
The interval Xmin...Xmax is divided into a sufficient number of bins so that the relative interpolation error does not exeed accu. If the number of required bins becomes greater than nmax, nmax bins are used.
Definition at line 59 of file egs_interpolator.cpp.
References initialize().
EGS_Interpolator::EGS_Interpolator | ( | int | nbin, |
EGS_Float | Xmin, | ||
EGS_Float | Xmax, | ||
EGS_Float * | a, | ||
EGS_Float * | b | ||
) |
Create an interpolator using the existing coefficients a and b.
The interpolation is given as a[i] + x*b[i], where i is the index corresponding to x. This type of interpolator is used to have convenient access to the mortran EGSnrc interpolation arrays without duplicating the interpolation coefficients.
Definition at line 54 of file egs_interpolator.cpp.
References initialize().
void EGS_Interpolator::initialize | ( | int | nbin, |
EGS_Float | Xmin, | ||
EGS_Float | Xmax, | ||
const EGS_Float * | values | ||
) |
Initialize the interpolator.
See the constructor with same argument list for more details
Definition at line 84 of file egs_interpolator.cpp.
Referenced by EGS_Interpolator().
void EGS_Interpolator::initialize | ( | int | nbin, |
EGS_Float | Xmin, | ||
EGS_Float | Xmax, | ||
EGS_InterpolatorFuncion | func, | ||
void * | data | ||
) |
Initialize the interpolator.
See the constructor with the same argument list for more details
Definition at line 111 of file egs_interpolator.cpp.
References initialize().
Referenced by initialize().
void EGS_Interpolator::initialize | ( | int | nbin, |
EGS_Float | Xmin, | ||
EGS_Float | Xmax, | ||
EGS_Float * | a, | ||
EGS_Float * | b | ||
) |
Initialize the interpolator.
See the constructor with the same argument list for more details
Definition at line 122 of file egs_interpolator.cpp.
EGS_Float EGS_Interpolator::interpolate | ( | EGS_Float | x | ) | const |
Interpolate the function value at x.
This function returns the function value at x, if x is within the initialized interpolation interval Xmin...Xmax, f(Xmin) if x < Xmin and f(Xmax), if x > Xmax.
Definition at line 150 of file egs_interpolator.h.
EGS_Float EGS_Interpolator::interpolateFast | ( | EGS_Float | x | ) | const |
Interpolate the function value at x.
This function can be used when it is guaranteed that x is in the interval xmin...xmax as no checks are made.
Definition at line 173 of file egs_interpolator.h.
int EGS_Interpolator::getIndex | ( | EGS_Float | x | ) | const |
Get the interpolation index corresponding to x.
Definition at line 182 of file egs_interpolator.h.
int EGS_Interpolator::getIndexFast | ( | EGS_Float | x | ) | const |
Get the interpolation index corresponding to x.
This function can only be used if it is guaranteed that x is in the interval xmin...xmax as no checks are made.
Definition at line 201 of file egs_interpolator.h.
EGS_Float EGS_Interpolator::interpolateFast | ( | int | i, |
EGS_Float | x | ||
) | const |
Interpolate the function value at x assuming that belongs to the interpolation interval i.
This function can be used together with getIndex() or getIndexFast() for performing the interpolation. If several quantities are to be interpolated for the same value of x from different interpolator objects all initialized within the same interval using the same number of bins, it is much faster to first call getIndex() or getIndexFast() to get the interpolation index and then use this function instead of repeating the interpolation index determination in each individual call of interpolate() or interpolateFast(). The getIndexFast() function closely corresponds to the $SET INTERVAL
mortran macro and interpolateFast(int,EGS_Float) to the $EVALUATE USING
mortran macro.
Definition at line 221 of file egs_interpolator.h.