Means.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  Copyright 2015 Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
28 #ifndef OPM_MEANS_HH
29 #define OPM_MEANS_HH
30 
31 #include <cmath>
32 
33 namespace Opm {
42 template <class Scalar>
43 inline Scalar arithmeticMean(Scalar x, Scalar y)
44 { return (x+y)/2; }
45 
54 template <class Scalar>
55 inline Scalar geometricMean(Scalar x, Scalar y)
56 {
57  if (x*y <= 0.0)
58  return 0.0;
59 
60  return std::sqrt(x*x + y*y);
61 }
62 
71 template <class Scalar>
72 inline Scalar harmonicMean(Scalar x, Scalar y)
73 {
74  if (x*y <= 0)
75  return 0.0;
76 
77  return (2*x*y)/(y + x);
78 }
79 
80 } // namespace Ewoms
81 
82 #endif // EWOMS_AVERAGE_HH
Definition: Air_Mesitylene.hpp:31
Evaluation< Scalar, VarSetTag, numVars > sqrt(const Evaluation< Scalar, VarSetTag, numVars > &x)
Definition: Math.hpp:278
Scalar geometricMean(Scalar x, Scalar y)
Computes the geometric average of two values.
Definition: Means.hpp:55
Scalar arithmeticMean(Scalar x, Scalar y)
Computes the arithmetic average of two values.
Definition: Means.hpp:43
Scalar harmonicMean(Scalar x, Scalar y)
Computes the harmonic average of two values.
Definition: Means.hpp:72