OGS
PiecewiseConstantInterpolation.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2
// SPDX-License-Identifier: BSD-3-Clause
3
4
#pragma once
5
6
#include <vector>
7
8
#include "
BaseLib/Logging.h
"
9
10
namespace
MathLib
11
{
16
template
<
typename
T =
double
>
17
class
PiecewiseConstantInterpolation
18
{
19
public
:
35
PiecewiseConstantInterpolation
(
36
std::vector<T>
const
& supporting_points,
37
std::vector<double>
const
& values_at_supp_pnts)
38
:
supp_pnts_
(supporting_points),
39
values_at_supp_pnts_
(values_at_supp_pnts)
40
{
41
if
(
supp_pnts_
.size() !=
values_at_supp_pnts_
.size())
42
{
43
OGS_FATAL(
44
"Inconsistent data given to PiecewiseConstantInterpolation, "
45
"number of given supporting points is {}, number of given "
46
"values is {}."
,
47
supp_pnts_.size(), values_at_supp_pnts_.size());
48
}
49
if (
supp_pnts_
.empty())
50
{
51
ERR(
"PiecewiseConstantInterpolation: passed empty vector."
);
52
}
53
}
54
67
double
value
(
double
const
pnt_to_interpolate)
const
68
{
69
if
(pnt_to_interpolate <=
supp_pnts_
.front())
70
{
71
return
values_at_supp_pnts_
.front();
72
}
73
74
if
(
supp_pnts_
.back() <= pnt_to_interpolate)
75
{
76
return
values_at_supp_pnts_
.back();
77
}
78
79
auto
const
& it(std::upper_bound(
supp_pnts_
.begin(),
supp_pnts_
.end(),
80
pnt_to_interpolate));
81
// Here access the iterator it without checking is okay since the
82
// corner cases are checked above.
83
auto
const
interval_idx = std::distance(
supp_pnts_
.begin(), it) - 1;
84
85
return
values_at_supp_pnts_
[interval_idx];
86
}
87
88
private
:
89
std::vector<T>
const
&
supp_pnts_
;
90
std::vector<double>
const
&
values_at_supp_pnts_
;
91
};
92
}
// end namespace MathLib
Logging.h
MathLib::PiecewiseConstantInterpolation::supp_pnts_
std::vector< T > const & supp_pnts_
Definition
PiecewiseConstantInterpolation.h:89
MathLib::PiecewiseConstantInterpolation::values_at_supp_pnts_
std::vector< double > const & values_at_supp_pnts_
Definition
PiecewiseConstantInterpolation.h:90
MathLib::PiecewiseConstantInterpolation::value
double value(double const pnt_to_interpolate) const
Calculates the interpolation value.
Definition
PiecewiseConstantInterpolation.h:67
MathLib::PiecewiseConstantInterpolation::PiecewiseConstantInterpolation
PiecewiseConstantInterpolation(std::vector< T > const &supporting_points, std::vector< double > const &values_at_supp_pnts)
Definition
PiecewiseConstantInterpolation.h:35
MathLib
Definition
CreateComponent.h:23
MathLib
InterpolationAlgorithms
PiecewiseConstantInterpolation.h
Generated by
1.14.0