Skip to content
GitLab
Menu
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
2abec55c
Commit
2abec55c
authored
Jun 25, 2018
by
Thomas Fetzer
Browse files
[math] Implement weighted means
parent
19075546
Changes
1
Hide whitespace changes
Inline
Side-by-side
dumux/common/math.hh
View file @
2abec55c
...
...
@@ -36,19 +36,40 @@ namespace Dumux
{
/*!
* \ingroup Common
* \brief Calculate the
harmon
ic mean of two scalar values.
* \brief Calculate the
(weighted) arithmet
ic mean of two scalar values.
*
* \param x The first input value
* \param y The second input value
* \param wx The first weight
* \param wy The second weight
*/
template
<
class
Scalar
>
constexpr
Scalar
h
ar
mon
icMean
(
Scalar
x
,
Scalar
y
)
noexcept
constexpr
Scalar
ar
ithmet
icMean
(
Scalar
x
,
Scalar
y
,
Scalar
wx
=
1.0
,
Scalar
wy
=
1.0
)
noexcept
{
static_assert
(
Dune
::
IsNumber
<
Scalar
>::
value
,
"The arguments x and y have to be numbers!"
);
static_assert
(
Dune
::
IsNumber
<
Scalar
>::
value
,
"The arguments x, y, wx, and wy have to be numbers!"
);
if
(
x
*
y
<=
0
)
return
0
;
return
(
x
*
wx
+
y
*
wy
)
/
(
wx
+
wy
);
}
/*!
* \ingroup Common
* \brief Calculate the (weighted) harmonic mean of two scalar values.
*
* \param x The first input value
* \param y The second input value
* \param wx The first weight
* \param wy The second weight
*/
template
<
class
Scalar
>
constexpr
Scalar
harmonicMean
(
Scalar
x
,
Scalar
y
,
Scalar
wx
=
1.0
,
Scalar
wy
=
1.0
)
noexcept
{
static_assert
(
Dune
::
IsNumber
<
Scalar
>::
value
,
"The arguments x, y, wx, and wy have to be numbers!"
);
if
(
x
*
y
<=
0
)
return
0
;
return
(
2
*
x
*
y
)
/
(
x
+
y
);
return
(
wx
+
wy
)
/
(
wx
/
x
+
wy
/
y
);
}
/*!
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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