OGS
MathLib::PiecewiseConstantInterpolation< T > Class Template Reference

Detailed Description

template<typename T = double>
class MathLib::PiecewiseConstantInterpolation< T >

This class implements a one dimensional piecewise constant interpolation algorithm.

Definition at line 26 of file PiecewiseConstantInterpolation.h.

#include <PiecewiseConstantInterpolation.h>

Public Member Functions

 PiecewiseConstantInterpolation (std::vector< T > const &supporting_points, std::vector< double > const &values_at_supp_pnts)
double value (double const pnt_to_interpolate) const
 Calculates the interpolation value.

Private Attributes

std::vector< T > const & supp_pnts_
std::vector< double > const & values_at_supp_pnts_

Constructor & Destructor Documentation

◆ PiecewiseConstantInterpolation()

template<typename T = double>
MathLib::PiecewiseConstantInterpolation< T >::PiecewiseConstantInterpolation ( std::vector< T > const & supporting_points,
std::vector< double > const & values_at_supp_pnts )
inline

The constructor stores the vector of supporting points \((x_0, x_1, \dots, x_n)\) and the entries of the vector of values at the supporting points \((y_0, y_1, \dots, y_n)\) where \(n\) is the number of entries of the vector. The number of supporting points must be equal to the number of values at the supporting points. It is assumed that \(x_j\) corresponds to \(y_j\) for all \(j \in [0, n]\).

Furthermore, it is assumed that the supporting points are sorted, i.e. \(x_0 < x_1 < \dots < x_n\).

Parameters
supporting_pointsvector of supporting points
values_at_supp_pntsvector of values at the supporting points one can set the switch to true

Definition at line 44 of file PiecewiseConstantInterpolation.h.

49 {
50 if (supp_pnts_.size() != values_at_supp_pnts_.size())
51 {
53 "Inconsistent data given to PiecewiseConstantInterpolation, "
54 "number of given supporting points is {}, number of given "
55 "values is {}.",
56 supp_pnts_.size(), values_at_supp_pnts_.size());
57 }
58 if (supp_pnts_.empty())
59 {
60 ERR("PiecewiseConstantInterpolation: passed empty vector.");
61 }
62 }
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48

References supp_pnts_, and values_at_supp_pnts_.

Member Function Documentation

◆ value()

template<typename T = double>
double MathLib::PiecewiseConstantInterpolation< T >::value ( double const pnt_to_interpolate) const
inline

Calculates the interpolation value.

Parameters
pnt_to_interpolateThe point the interpolation value is calculated for. If the pnt_to_interpolate is outside the interval \([x_{\min}, x_{\max}]\), where \(x_{\min} = \min_{1 \le j \le n} x_j\) and \(x_{\max} = \max_{1 \le j \le n} x_j\). If point_to_interpolate is smaller than \(x_{\min}\) then \(y_{\min}\) is returned. Analogously, if the point_to_interpolate is greater than \(x_{\max}\) then \(y_{\max}\) is returned.
Returns
The interpolated value.

Definition at line 76 of file PiecewiseConstantInterpolation.h.

77 {
78 if (pnt_to_interpolate <= supp_pnts_.front())
79 {
80 return values_at_supp_pnts_.front();
81 }
82
83 if (supp_pnts_.back() <= pnt_to_interpolate)
84 {
85 return values_at_supp_pnts_.back();
86 }
87
88 auto const& it(std::upper_bound(supp_pnts_.begin(), supp_pnts_.end(),
90 // Here access the iterator it without checking is okay since the
91 // corner cases are checked above.
92 auto const interval_idx = std::distance(supp_pnts_.begin(), it) - 1;
93
95 }

References supp_pnts_, and values_at_supp_pnts_.

Member Data Documentation

◆ supp_pnts_

template<typename T = double>
std::vector<T> const& MathLib::PiecewiseConstantInterpolation< T >::supp_pnts_
private

Definition at line 98 of file PiecewiseConstantInterpolation.h.

Referenced by PiecewiseConstantInterpolation(), and value().

◆ values_at_supp_pnts_

template<typename T = double>
std::vector<double> const& MathLib::PiecewiseConstantInterpolation< T >::values_at_supp_pnts_
private

Definition at line 99 of file PiecewiseConstantInterpolation.h.

Referenced by PiecewiseConstantInterpolation(), and value().


The documentation for this class was generated from the following file: