mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make mean calculators more consistent and add an harmonic mean calculator.
This commit is contained in:
@@ -33,9 +33,10 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSCurveCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaArcCurveCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaJCurveCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOffshoreSphericalCoords.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedAverageCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedAverageCalculator.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.inl
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.h
|
||||
)
|
||||
|
||||
@@ -73,6 +74,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSCurveCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaArcCurveCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaJCurveCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaWeightedHarmonicMeanCalculator.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaWeightedHarmonicMeanCalculator::RiaWeightedHarmonicMeanCalculator()
|
||||
: m_aggregatedWeightedValue(0.0)
|
||||
, m_aggregatedWeight(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaWeightedHarmonicMeanCalculator::addValueAndWeight(double value, double weight)
|
||||
{
|
||||
CVF_ASSERT(weight > 1.0e-12 && std::abs(value) > 1.0e-12);
|
||||
|
||||
m_aggregatedWeightedValue += weight / value;
|
||||
m_aggregatedWeight += weight;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaWeightedHarmonicMeanCalculator::weightedMean() const
|
||||
{
|
||||
if (validAggregatedWeight())
|
||||
{
|
||||
return m_aggregatedWeight / m_aggregatedWeightedValue;
|
||||
}
|
||||
CVF_ASSERT(false);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaWeightedHarmonicMeanCalculator::aggregatedWeight() const
|
||||
{
|
||||
return m_aggregatedWeight;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaWeightedHarmonicMeanCalculator::validAggregatedWeight() const
|
||||
{
|
||||
return m_aggregatedWeight > 1.0e-12;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2018- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiaWeightedHarmonicMeanCalculator
|
||||
{
|
||||
public:
|
||||
RiaWeightedHarmonicMeanCalculator();
|
||||
|
||||
void addValueAndWeight(double value, double weight);
|
||||
|
||||
double weightedMean() const;
|
||||
double aggregatedWeight() const;
|
||||
bool validAggregatedWeight() const;
|
||||
|
||||
private:
|
||||
double m_aggregatedWeightedValue;
|
||||
double m_aggregatedWeight;
|
||||
};
|
||||
@@ -22,14 +22,14 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
class RiaWeightedAverageCalculator
|
||||
class RiaWeightedMeanCalculator
|
||||
{
|
||||
public:
|
||||
RiaWeightedAverageCalculator();
|
||||
RiaWeightedMeanCalculator();
|
||||
|
||||
void addValueAndWeight(T value, double weight);
|
||||
|
||||
T weightedAverage() const;
|
||||
T weightedMean() const;
|
||||
double aggregatedWeight() const;
|
||||
bool validAggregatedWeight() const;
|
||||
private:
|
||||
@@ -37,4 +37,4 @@ private:
|
||||
double m_aggregatedWeight;
|
||||
};
|
||||
|
||||
#include "RiaWeightedAverageCalculator.inl"
|
||||
#include "RiaWeightedMeanCalculator.inl"
|
||||
@@ -22,7 +22,7 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
RiaWeightedAverageCalculator<T>::RiaWeightedAverageCalculator()
|
||||
RiaWeightedMeanCalculator<T>::RiaWeightedMeanCalculator()
|
||||
: m_aggregatedValue(T{})
|
||||
, m_aggregatedWeight(0.0)
|
||||
{
|
||||
@@ -32,7 +32,7 @@ RiaWeightedAverageCalculator<T>::RiaWeightedAverageCalculator()
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
void RiaWeightedAverageCalculator<T>::addValueAndWeight(T value, double weight)
|
||||
void RiaWeightedMeanCalculator<T>::addValueAndWeight(T value, double weight)
|
||||
{
|
||||
CVF_ASSERT(weight >= 0.0);
|
||||
|
||||
@@ -44,7 +44,7 @@ void RiaWeightedAverageCalculator<T>::addValueAndWeight(T value, double weight)
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
T RiaWeightedAverageCalculator<T>::weightedAverage() const
|
||||
T RiaWeightedMeanCalculator<T>::weightedMean() const
|
||||
{
|
||||
bool validWeights = validAggregatedWeight();
|
||||
CVF_TIGHT_ASSERT(validWeights);
|
||||
@@ -59,7 +59,7 @@ T RiaWeightedAverageCalculator<T>::weightedAverage() const
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
double RiaWeightedAverageCalculator<T>::aggregatedWeight() const
|
||||
double RiaWeightedMeanCalculator<T>::aggregatedWeight() const
|
||||
{
|
||||
return m_aggregatedWeight;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ double RiaWeightedAverageCalculator<T>::aggregatedWeight() const
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<class T>
|
||||
bool RiaWeightedAverageCalculator<T>::validAggregatedWeight() const
|
||||
bool RiaWeightedMeanCalculator<T>::validAggregatedWeight() const
|
||||
{
|
||||
return m_aggregatedWeight > 1.0e-12;
|
||||
}
|
||||
Reference in New Issue
Block a user