2018-08-15 08:38:54 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2019-01-09 15:15:34 +01:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-08-15 08:38:54 +02:00
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-09-14 09:12:05 +02:00
|
|
|
#include "RiaWeightedHarmonicMeanCalculator.h"
|
|
|
|
|
|
2018-08-15 15:52:00 +02:00
|
|
|
#include "cvfAssert.h"
|
|
|
|
|
|
2018-09-14 09:12:05 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
|
2018-08-15 08:38:54 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-09-14 09:12:05 +02:00
|
|
|
RiaWeightedHarmonicMeanCalculator::RiaWeightedHarmonicMeanCalculator()
|
2019-09-06 10:40:57 +02:00
|
|
|
: m_aggregatedWeightedValue( 0.0 )
|
|
|
|
|
, m_aggregatedWeight( 0.0 )
|
2018-08-15 08:38:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RiaWeightedHarmonicMeanCalculator::addValueAndWeight( double value, double weight )
|
2018-08-15 08:38:54 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
CVF_ASSERT( weight > 1.0e-12 && std::abs( value ) > 1.0e-12 );
|
2018-08-15 15:52:00 +02:00
|
|
|
|
2018-09-14 09:12:05 +02:00
|
|
|
m_aggregatedWeightedValue += weight / value;
|
2018-08-15 08:38:54 +02:00
|
|
|
m_aggregatedWeight += weight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-09-14 09:12:05 +02:00
|
|
|
double RiaWeightedHarmonicMeanCalculator::weightedMean() const
|
2019-09-06 10:40:57 +02:00
|
|
|
{
|
|
|
|
|
if ( validAggregatedWeight() )
|
2018-08-15 08:38:54 +02:00
|
|
|
{
|
2018-09-14 09:12:05 +02:00
|
|
|
return m_aggregatedWeight / m_aggregatedWeightedValue;
|
2018-08-15 08:38:54 +02:00
|
|
|
}
|
2019-09-06 10:40:57 +02:00
|
|
|
CVF_ASSERT( false );
|
2018-09-14 09:12:05 +02:00
|
|
|
return 0.0;
|
2018-08-15 08:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-09-14 09:12:05 +02:00
|
|
|
double RiaWeightedHarmonicMeanCalculator::aggregatedWeight() const
|
2018-08-15 08:38:54 +02:00
|
|
|
{
|
|
|
|
|
return m_aggregatedWeight;
|
|
|
|
|
}
|
2018-09-06 19:58:28 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-09-14 09:12:05 +02:00
|
|
|
bool RiaWeightedHarmonicMeanCalculator::validAggregatedWeight() const
|
2018-09-06 19:58:28 +02:00
|
|
|
{
|
|
|
|
|
return m_aggregatedWeight > 1.0e-12;
|
2018-09-14 09:12:05 +02:00
|
|
|
}
|