Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
5662f943
Commit
5662f943
authored
Jul 21, 2020
by
Timo Koch
Browse files
[math] Add linear table interpolation with two arguments
parent
9b9db541
Changes
1
Hide whitespace changes
Inline
Side-by-side
dumux/common/math.hh
View file @
5662f943
...
...
@@ -500,9 +500,9 @@ namespace InterpolationPolicy { struct Linear; }
* \param params the parameters used for interpolation (depends on the policy used)
* \param ip the interpolation point
*/
template
<
class
Policy
=
InterpolationPolicy
::
Linear
,
class
Scalar
,
class
Parameter
>
Scalar
interpolate
(
Scalar
ip
,
Parameter
&&
params
)
{
return
Policy
::
interpolate
(
ip
,
std
::
forward
<
Parameter
>
(
params
));
}
template
<
class
Policy
=
InterpolationPolicy
::
Linear
,
class
Scalar
,
class
...
Parameter
>
Scalar
interpolate
(
Scalar
ip
,
Parameter
&&
...
params
)
{
return
Policy
::
interpolate
(
ip
,
std
::
forward
<
Parameter
>
(
params
)
...
);
}
/*!
* \ingroup Common
...
...
@@ -540,12 +540,9 @@ struct LinearTable
* \param table the table as a pair of sorted vectors (have to be same size)
* \note if the interpolation point is out of bounds this will return the bounds
*/
template
<
class
Scalar
,
class
RandomAccessContainer
>
static
constexpr
Scalar
interpolate
(
Scalar
ip
,
const
std
::
pair
<
RandomAccessContainer
,
RandomAccessContainer
>
&
table
)
template
<
class
Scalar
,
class
RandomAccessContainer
0
,
class
RandomAccessContainer1
>
static
constexpr
Scalar
interpolate
(
Scalar
ip
,
const
RandomAccessContainer
0
&
range
,
const
RandomAccessContainer
1
&
values
)
{
const
auto
&
range
=
table
.
first
;
const
auto
&
values
=
table
.
second
;
// check bounds
if
(
ip
>
range
.
back
())
return
values
.
back
();
if
(
ip
<
range
[
0
])
return
values
[
0
];
...
...
@@ -558,6 +555,13 @@ struct LinearTable
const
auto
ipLinear
=
(
ip
-
range
[
lookUpIndex
-
1
])
/
(
range
[
lookUpIndex
]
-
range
[
lookUpIndex
-
1
]);
return
Dumux
::
interpolate
<
Linear
>
(
ipLinear
,
std
::
array
<
Scalar
,
2
>
{{
values
[
lookUpIndex
-
1
],
values
[
lookUpIndex
]}});
}
template
<
class
Scalar
,
class
RandomAccessContainer
>
static
constexpr
Scalar
interpolate
(
Scalar
ip
,
const
std
::
pair
<
RandomAccessContainer
,
RandomAccessContainer
>&
table
)
{
const
auto
&
[
range
,
values
]
=
table
;
return
interpolate
(
ip
,
range
,
values
);
}
};
}
// end namespace InterpolationPolicy
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment