OGS
PiecewiseConstantInterpolation.h
Go to the documentation of this file.
1
13
#pragma once
14
15
#include <vector>
16
17
#include "
BaseLib/Logging.h
"
18
19
namespace
MathLib
20
{
25
template
<
typename
T =
double
>
26
class
PiecewiseConstantInterpolation
27
{
28
public
:
44
PiecewiseConstantInterpolation
(
45
std::vector<T>
const
& supporting_points,
46
std::vector<double>
const
& values_at_supp_pnts)
47
:
supp_pnts_
(supporting_points),
48
values_at_supp_pnts_
(values_at_supp_pnts)
49
{
50
if
(
supp_pnts_
.size() !=
values_at_supp_pnts_
.size())
51
{
52
OGS_FATAL(
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
}
63
76
double
value
(
double
const
pnt_to_interpolate)
const
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(),
89
pnt_to_interpolate));
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
94
return
values_at_supp_pnts_
[interval_idx];
95
}
96
97
private
:
98
std::vector<T>
const
&
supp_pnts_
;
99
std::vector<double>
const
&
values_at_supp_pnts_
;
100
};
101
}
// end namespace MathLib
Logging.h
MathLib::PiecewiseConstantInterpolation
Definition
PiecewiseConstantInterpolation.h:27
MathLib::PiecewiseConstantInterpolation::supp_pnts_
std::vector< T > const & supp_pnts_
Definition
PiecewiseConstantInterpolation.h:98
MathLib::PiecewiseConstantInterpolation::values_at_supp_pnts_
std::vector< double > const & values_at_supp_pnts_
Definition
PiecewiseConstantInterpolation.h:99
MathLib::PiecewiseConstantInterpolation::value
double value(double const pnt_to_interpolate) const
Calculates the interpolation value.
Definition
PiecewiseConstantInterpolation.h:76
MathLib::PiecewiseConstantInterpolation::PiecewiseConstantInterpolation
PiecewiseConstantInterpolation(std::vector< T > const &supporting_points, std::vector< double > const &values_at_supp_pnts)
Definition
PiecewiseConstantInterpolation.h:44
MathLib
Definition
CreateComponent.h:32
MathLib
InterpolationAlgorithms
PiecewiseConstantInterpolation.h
Generated by
1.12.0