mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-12 16:32:12 -05:00
Make mean calculators more consistent and add an harmonic mean calculator.
This commit is contained in:
1 parent
6f42d6ae1f
commit
9953c56c35
12 files changed
+224
-36
No files matched your search
@@ -33,9 +33,10 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSCurveCalculator.h
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RiaArcCurveCalculator.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaArcCurveCalculator.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaJCurveCalculator.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaJCurveCalculator.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaOffshoreSphericalCoords.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaOffshoreSphericalCoords.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedAverageCalculator.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedAverageCalculator.inl
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.inl
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.h
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.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}/RiaArcCurveCalculator.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaJCurveCalculator.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaJCurveCalculator.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.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;
|
||||||
|
};
|
||||||
+4
-4
@@ -22,14 +22,14 @@
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<class T>
|
template<class T>
|
||||||
class RiaWeightedAverageCalculator
|
class RiaWeightedMeanCalculator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RiaWeightedAverageCalculator();
|
RiaWeightedMeanCalculator();
|
||||||
|
|
||||||
void addValueAndWeight(T value, double weight);
|
void addValueAndWeight(T value, double weight);
|
||||||
|
|
||||||
T weightedAverage() const;
|
T weightedMean() const;
|
||||||
double aggregatedWeight() const;
|
double aggregatedWeight() const;
|
||||||
bool validAggregatedWeight() const;
|
bool validAggregatedWeight() const;
|
||||||
private:
|
private:
|
||||||
@@ -37,4 +37,4 @@ private:
|
|||||||
double m_aggregatedWeight;
|
double m_aggregatedWeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "RiaWeightedAverageCalculator.inl"
|
#include "RiaWeightedMeanCalculator.inl"
|
||||||
+5
-5
@@ -22,7 +22,7 @@
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<class T>
|
template<class T>
|
||||||
RiaWeightedAverageCalculator<T>::RiaWeightedAverageCalculator()
|
RiaWeightedMeanCalculator<T>::RiaWeightedMeanCalculator()
|
||||||
: m_aggregatedValue(T{})
|
: m_aggregatedValue(T{})
|
||||||
, m_aggregatedWeight(0.0)
|
, m_aggregatedWeight(0.0)
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ RiaWeightedAverageCalculator<T>::RiaWeightedAverageCalculator()
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<class T>
|
template<class T>
|
||||||
void RiaWeightedAverageCalculator<T>::addValueAndWeight(T value, double weight)
|
void RiaWeightedMeanCalculator<T>::addValueAndWeight(T value, double weight)
|
||||||
{
|
{
|
||||||
CVF_ASSERT(weight >= 0.0);
|
CVF_ASSERT(weight >= 0.0);
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ void RiaWeightedAverageCalculator<T>::addValueAndWeight(T value, double weight)
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<class T>
|
template<class T>
|
||||||
T RiaWeightedAverageCalculator<T>::weightedAverage() const
|
T RiaWeightedMeanCalculator<T>::weightedMean() const
|
||||||
{
|
{
|
||||||
bool validWeights = validAggregatedWeight();
|
bool validWeights = validAggregatedWeight();
|
||||||
CVF_TIGHT_ASSERT(validWeights);
|
CVF_TIGHT_ASSERT(validWeights);
|
||||||
@@ -59,7 +59,7 @@ T RiaWeightedAverageCalculator<T>::weightedAverage() const
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<class T>
|
template<class T>
|
||||||
double RiaWeightedAverageCalculator<T>::aggregatedWeight() const
|
double RiaWeightedMeanCalculator<T>::aggregatedWeight() const
|
||||||
{
|
{
|
||||||
return m_aggregatedWeight;
|
return m_aggregatedWeight;
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ double RiaWeightedAverageCalculator<T>::aggregatedWeight() const
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<class T>
|
template<class T>
|
||||||
bool RiaWeightedAverageCalculator<T>::validAggregatedWeight() const
|
bool RiaWeightedMeanCalculator<T>::validAggregatedWeight() const
|
||||||
{
|
{
|
||||||
return m_aggregatedWeight > 1.0e-12;
|
return m_aggregatedWeight > 1.0e-12;
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,6 @@
|
|||||||
#include "RicWellPathFractureReportItem.h"
|
#include "RicWellPathFractureReportItem.h"
|
||||||
|
|
||||||
#include "RiaLogging.h"
|
#include "RiaLogging.h"
|
||||||
#include "RiaWeightedAverageCalculator.h"
|
|
||||||
|
|
||||||
#include "RimEclipseCase.h"
|
#include "RimEclipseCase.h"
|
||||||
#include "RimEclipseView.h"
|
#include "RimEclipseView.h"
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include "RiaCompletionTypeCalculationScheduler.h"
|
#include "RiaCompletionTypeCalculationScheduler.h"
|
||||||
#include "RiaFractureDefines.h"
|
#include "RiaFractureDefines.h"
|
||||||
#include "RiaLogging.h"
|
#include "RiaLogging.h"
|
||||||
#include "RiaWeightedAverageCalculator.h"
|
#include "RiaWeightedMeanCalculator.h"
|
||||||
|
|
||||||
#include "RifStimPlanXmlReader.h"
|
#include "RifStimPlanXmlReader.h"
|
||||||
|
|
||||||
@@ -474,8 +474,8 @@ FractureWidthAndConductivity
|
|||||||
nameUnit.first, nameUnit.second, m_activeTimeStepIndex, fractureTemplateUnit());
|
nameUnit.first, nameUnit.second, m_activeTimeStepIndex, fractureTemplateUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
RiaWeightedAverageCalculator<double> widthCalc;
|
RiaWeightedMeanCalculator<double> widthCalc;
|
||||||
RiaWeightedAverageCalculator<double> conductivityCalc;
|
RiaWeightedMeanCalculator<double> conductivityCalc;
|
||||||
|
|
||||||
RigWellPathStimplanIntersector intersector(rimWellPath->wellPathGeometry(), fractureInstance);
|
RigWellPathStimplanIntersector intersector(rimWellPath->wellPathGeometry(), fractureInstance);
|
||||||
for (const auto& v : intersector.intersections())
|
for (const auto& v : intersector.intersections())
|
||||||
@@ -496,11 +496,11 @@ FractureWidthAndConductivity
|
|||||||
}
|
}
|
||||||
if (conductivityCalc.validAggregatedWeight())
|
if (conductivityCalc.validAggregatedWeight())
|
||||||
{
|
{
|
||||||
weightedConductivity = conductivityCalc.weightedAverage();
|
weightedConductivity = conductivityCalc.weightedMean();
|
||||||
}
|
}
|
||||||
if (widthCalc.validAggregatedWeight())
|
if (widthCalc.validAggregatedWeight())
|
||||||
{
|
{
|
||||||
weightedWidth = widthCalc.weightedAverage();
|
weightedWidth = widthCalc.weightedMean();
|
||||||
totalLength = widthCalc.aggregatedWeight();
|
totalLength = widthCalc.aggregatedWeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#include "RigResultAccessorFactory.h"
|
#include "RigResultAccessorFactory.h"
|
||||||
#include "RigTransmissibilityCondenser.h"
|
#include "RigTransmissibilityCondenser.h"
|
||||||
|
|
||||||
#include "RiaWeightedAverageCalculator.h"
|
#include "RiaWeightedMeanCalculator.h"
|
||||||
#include "RimEclipseCase.h"
|
#include "RimEclipseCase.h"
|
||||||
#include "RimEllipseFractureTemplate.h"
|
#include "RimEllipseFractureTemplate.h"
|
||||||
#include "RimFracture.h"
|
#include "RimFracture.h"
|
||||||
@@ -146,7 +146,7 @@ double RigEclipseToStimPlanCalculator::totalEclipseAreaOpenForFlow() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
double RigEclipseToStimPlanCalculator::areaWeightedMatrixTransmissibility() const
|
double RigEclipseToStimPlanCalculator::areaWeightedMatrixTransmissibility() const
|
||||||
{
|
{
|
||||||
RiaWeightedAverageCalculator<double> calc;
|
RiaWeightedMeanCalculator<double> calc;
|
||||||
|
|
||||||
for (const auto& singleCellCalc : m_singleFractureCellCalculators)
|
for (const auto& singleCellCalc : m_singleFractureCellCalculators)
|
||||||
{
|
{
|
||||||
@@ -155,7 +155,7 @@ double RigEclipseToStimPlanCalculator::areaWeightedMatrixTransmissibility() cons
|
|||||||
calc.addValueAndWeight(calulator.aggregatedMatrixTransmissibility(), calulator.areaOpenForFlow());
|
calc.addValueAndWeight(calulator.aggregatedMatrixTransmissibility(), calulator.areaOpenForFlow());
|
||||||
}
|
}
|
||||||
|
|
||||||
return calc.weightedAverage();
|
return calc.weightedMean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -174,7 +174,7 @@ double RigEclipseToStimPlanCalculator::areaWeightedWidth() const
|
|||||||
auto stimPlanFractureTemplate = dynamic_cast<const RimStimPlanFractureTemplate*>(m_fracture->fractureTemplate());
|
auto stimPlanFractureTemplate = dynamic_cast<const RimStimPlanFractureTemplate*>(m_fracture->fractureTemplate());
|
||||||
if (stimPlanFractureTemplate)
|
if (stimPlanFractureTemplate)
|
||||||
{
|
{
|
||||||
RiaWeightedAverageCalculator<double> calc;
|
RiaWeightedMeanCalculator<double> calc;
|
||||||
|
|
||||||
auto widthValues = stimPlanFractureTemplate->widthResultValues();
|
auto widthValues = stimPlanFractureTemplate->widthResultValues();
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ double RigEclipseToStimPlanCalculator::areaWeightedWidth() const
|
|||||||
calc.addValueAndWeight(widthValue, cellArea);
|
calc.addValueAndWeight(widthValue, cellArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
width = calc.weightedAverage();
|
width = calc.weightedMean();
|
||||||
}
|
}
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
@@ -199,7 +199,7 @@ double RigEclipseToStimPlanCalculator::areaWeightedWidth() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
double RigEclipseToStimPlanCalculator::areaWeightedConductivity() const
|
double RigEclipseToStimPlanCalculator::areaWeightedConductivity() const
|
||||||
{
|
{
|
||||||
RiaWeightedAverageCalculator<double> calc;
|
RiaWeightedMeanCalculator<double> calc;
|
||||||
|
|
||||||
for (const auto& singleCellCalc : m_singleFractureCellCalculators)
|
for (const auto& singleCellCalc : m_singleFractureCellCalculators)
|
||||||
{
|
{
|
||||||
@@ -208,7 +208,7 @@ double RigEclipseToStimPlanCalculator::areaWeightedConductivity() const
|
|||||||
calc.addValueAndWeight(singleCellCalc.second.fractureCell().getConductivityValue(), cellArea);
|
calc.addValueAndWeight(singleCellCalc.second.fractureCell().getConductivityValue(), cellArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
return calc.weightedAverage();
|
return calc.weightedMean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "RigGeoMechWellLogExtractor.h"
|
#include "RigGeoMechWellLogExtractor.h"
|
||||||
|
|
||||||
#include "RiaDefines.h"
|
#include "RiaDefines.h"
|
||||||
#include "RiaWeightedAverageCalculator.h"
|
#include "RiaWeightedMeanCalculator.h"
|
||||||
#include "RigFemTypes.h"
|
#include "RigFemTypes.h"
|
||||||
#include "RigGeoMechBoreHoleStressCalculator.h"
|
#include "RigGeoMechBoreHoleStressCalculator.h"
|
||||||
#include "RigFemPart.h"
|
#include "RigFemPart.h"
|
||||||
@@ -316,7 +316,7 @@ void RigGeoMechWellLogExtractor::wellPathScaledCurveData(const RigFemResultAddre
|
|||||||
float averageUnscaledValue = std::numeric_limits<float>::infinity();
|
float averageUnscaledValue = std::numeric_limits<float>::infinity();
|
||||||
bool validAverage = averageIntersectionValuesToSegmentValue(intersectionIdx, interpolatedInterfaceValues, std::numeric_limits<float>::infinity(), &averageUnscaledValue);
|
bool validAverage = averageIntersectionValuesToSegmentValue(intersectionIdx, interpolatedInterfaceValues, std::numeric_limits<float>::infinity(), &averageUnscaledValue);
|
||||||
|
|
||||||
if (resAddr.fieldName == "PP")
|
if (resAddr.fieldName == "PP" && validAverage)
|
||||||
{
|
{
|
||||||
double segmentPorePressureFromGrid = averageUnscaledValue;
|
double segmentPorePressureFromGrid = averageUnscaledValue;
|
||||||
averageUnscaledValue = calculatePorePressureInSegment(intersectionIdx, segmentPorePressureFromGrid, hydroStaticPorePressureBar, effectiveDepthMeters, poreElementPressuresPascal);
|
averageUnscaledValue = calculatePorePressureInSegment(intersectionIdx, segmentPorePressureFromGrid, hydroStaticPorePressureBar, effectiveDepthMeters, poreElementPressuresPascal);
|
||||||
@@ -776,7 +776,7 @@ double RigGeoMechWellLogExtractor::getWellLogSegmentValue(size_t intersectionIdx
|
|||||||
endMD = m_intersectionMeasuredDepths[intersectionIdx];
|
endMD = m_intersectionMeasuredDepths[intersectionIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
RiaWeightedAverageCalculator<double> averageCalc;
|
RiaWeightedMeanCalculator<double> averageCalc;
|
||||||
for (auto& depthAndValue : wellLogValues)
|
for (auto& depthAndValue : wellLogValues)
|
||||||
{
|
{
|
||||||
if (cvf::Math::valueInRange(depthAndValue.first, startMD, endMD))
|
if (cvf::Math::valueInRange(depthAndValue.first, startMD, endMD))
|
||||||
@@ -794,7 +794,7 @@ double RigGeoMechWellLogExtractor::getWellLogSegmentValue(size_t intersectionIdx
|
|||||||
}
|
}
|
||||||
if (averageCalc.validAggregatedWeight())
|
if (averageCalc.validAggregatedWeight())
|
||||||
{
|
{
|
||||||
return averageCalc.weightedAverage();
|
return averageCalc.weightedMean();
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::numeric_limits<double>::infinity();
|
return std::numeric_limits<double>::infinity();
|
||||||
@@ -842,12 +842,12 @@ bool RigGeoMechWellLogExtractor::averageIntersectionValuesToSegmentValue(size_t
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RiaWeightedAverageCalculator<T> averageCalc;
|
RiaWeightedMeanCalculator<T> averageCalc;
|
||||||
averageCalc.addValueAndWeight(value1, dist2);
|
averageCalc.addValueAndWeight(value1, dist2);
|
||||||
averageCalc.addValueAndWeight(value2, dist1);
|
averageCalc.addValueAndWeight(value2, dist1);
|
||||||
if (averageCalc.validAggregatedWeight())
|
if (averageCalc.validAggregatedWeight())
|
||||||
{
|
{
|
||||||
*averagedCellValue = averageCalc.weightedAverage();
|
*averagedCellValue = averageCalc.weightedMean();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -47,8 +47,9 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveTools-Test.cpp
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/SolveSpaceSolver-Test.cpp
|
${CMAKE_CURRENT_LIST_DIR}/SolveSpaceSolver-Test.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaPolyArcLineSampler-Test.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaPolyArcLineSampler-Test.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RifEclipseDataTableFormatter-Test.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RifEclipseDataTableFormatter-Test.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedAverage-Test.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMean-Test.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator-Test.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator-Test.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator-Test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND CODE_HEADER_FILES
|
list(APPEND CODE_HEADER_FILES
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "RiaWeightedHarmonicMeanCalculator.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TEST(RiaWeightedHarmonicMeanCalculator, BasicUsage)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RiaWeightedHarmonicMeanCalculator calc;
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(0.0, calc.aggregatedWeight());
|
||||||
|
EXPECT_FALSE(calc.validAggregatedWeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
RiaWeightedHarmonicMeanCalculator calc;
|
||||||
|
|
||||||
|
std::vector<double> values {1, 4, 4};
|
||||||
|
std::vector<double> weights {1, 1, 1};
|
||||||
|
|
||||||
|
for (size_t i = 0; i< values.size(); i++)
|
||||||
|
{
|
||||||
|
calc.addValueAndWeight(values[i], weights[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
double expectedValue = 2.0;
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(3.0, calc.aggregatedWeight());
|
||||||
|
EXPECT_NEAR(expectedValue, calc.weightedMean(), 1e-10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TEST(RiaWeightedHarmonicMeanCalculator, WeightedValues)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RiaWeightedHarmonicMeanCalculator calc;
|
||||||
|
|
||||||
|
std::vector<double> values{ 10, 5, 4, 3 };
|
||||||
|
std::vector<double> weights{ 10, 5, 4, 3 };
|
||||||
|
|
||||||
|
for (size_t i = 0; i < values.size(); i++)
|
||||||
|
{
|
||||||
|
calc.addValueAndWeight(values[i], weights[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
double sumWeights = std::accumulate(weights.begin(), weights.end(), 0.0);
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(sumWeights, calc.aggregatedWeight());
|
||||||
|
EXPECT_NEAR(sumWeights, calc.weightedMean(), 1e-8);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
RiaWeightedHarmonicMeanCalculator calc;
|
||||||
|
|
||||||
|
std::vector<double> values{ 2.0, 3.0, 1.0, 4.0 };
|
||||||
|
std::vector<double> weights{ 1.0, 2.0, 7.0, 3.0 };
|
||||||
|
for (size_t i = 0; i < values.size(); i++)
|
||||||
|
{
|
||||||
|
calc.addValueAndWeight(values[i], weights[i]);
|
||||||
|
}
|
||||||
|
double sumWeights = std::accumulate(weights.begin(), weights.end(), 0.0);
|
||||||
|
double aggregatedWeightAndValues = 1.0 / 2.0 + 2.0 / 3.0 + 7.0 / 1.0 + 3.0 / 4.0;
|
||||||
|
double expectedValue = sumWeights / aggregatedWeightAndValues;
|
||||||
|
EXPECT_DOUBLE_EQ(sumWeights, calc.aggregatedWeight());
|
||||||
|
EXPECT_NEAR(expectedValue, calc.weightedMean(), 1.0e-8);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -1,22 +1,22 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include "RiaWeightedAverageCalculator.h"
|
#include "RiaWeightedMeanCalculator.h"
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
TEST(RiaWeightedAverageCalculator, BasicUsage)
|
TEST(RiaWeightedMeanCalculator, BasicUsage)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RiaWeightedAverageCalculator<double> calc;
|
RiaWeightedMeanCalculator<double> calc;
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(0.0, calc.aggregatedWeight());
|
EXPECT_DOUBLE_EQ(0.0, calc.aggregatedWeight());
|
||||||
EXPECT_FALSE(calc.validAggregatedWeight());
|
EXPECT_FALSE(calc.validAggregatedWeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
RiaWeightedAverageCalculator<double> calc;
|
RiaWeightedMeanCalculator<double> calc;
|
||||||
|
|
||||||
std::vector<double> values {3.0, 6.0};
|
std::vector<double> values {3.0, 6.0};
|
||||||
std::vector<double> weights {1.0, 2.0};
|
std::vector<double> weights {1.0, 2.0};
|
||||||
@@ -27,6 +27,6 @@ TEST(RiaWeightedAverageCalculator, BasicUsage)
|
|||||||
}
|
}
|
||||||
EXPECT_TRUE(calc.validAggregatedWeight());
|
EXPECT_TRUE(calc.validAggregatedWeight());
|
||||||
EXPECT_DOUBLE_EQ(3.0, calc.aggregatedWeight());
|
EXPECT_DOUBLE_EQ(3.0, calc.aggregatedWeight());
|
||||||
EXPECT_DOUBLE_EQ(5.0, calc.weightedAverage());
|
EXPECT_DOUBLE_EQ(5.0, calc.weightedMean());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user