From da6c7cf621c5fa4a006542dff7255e756e2c944f Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Fri, 27 Sep 2019 10:04:47 +0200 Subject: [PATCH] #4788 Ensemble RFT: fix missing statistics curves by having better bounds calculation for the curves. --- .../Application/Tools/RiaCurveMerger.inl | 216 +++++++++--------- 1 file changed, 108 insertions(+), 108 deletions(-) diff --git a/ApplicationCode/Application/Tools/RiaCurveMerger.inl b/ApplicationCode/Application/Tools/RiaCurveMerger.inl index e2a77de309..00f453e780 100644 --- a/ApplicationCode/Application/Tools/RiaCurveMerger.inl +++ b/ApplicationCode/Application/Tools/RiaCurveMerger.inl @@ -1,43 +1,42 @@ ///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 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 +// +// See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include -#include // Needed for HUGE_VAL on Linux - +#include // Needed for HUGE_VAL on Linux //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -template -bool XValueComparator::operator()(const XValueType& lhs, const XValueType& rhs) const +template +bool XValueComparator::operator()( const XValueType& lhs, const XValueType& rhs ) const { - if (XValueComparator::equals(lhs, rhs)) - { + if ( XValueComparator::equals( lhs, rhs ) ) + { return false; - } + } return lhs < rhs; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -template -double XValueComparator::diff(const XValueType& lhs, const XValueType& rhs) +template +double XValueComparator::diff( const XValueType& lhs, const XValueType& rhs ) { return lhs - rhs; } @@ -45,118 +44,119 @@ double XValueComparator::diff(const XValueType& lhs, const XValueTyp //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -template -bool XValueComparator::equals(const XValueType& lhs, const XValueType& rhs) +template +bool XValueComparator::equals( const XValueType& lhs, const XValueType& rhs ) { return lhs == rhs; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -template -RiaCurveMerger::RiaCurveMerger() -{ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -template -void RiaCurveMerger::addCurveData(const std::vector& xValues, const std::vector& yValues) -{ - CVF_ASSERT(xValues.size() == yValues.size()); - - m_originalValues.push_back(std::make_pair(xValues, yValues)); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -template +template +RiaCurveMerger::RiaCurveMerger() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void RiaCurveMerger::addCurveData( const std::vector& xValues, const std::vector& yValues ) +{ + CVF_ASSERT( xValues.size() == yValues.size() ); + + m_originalValues.push_back( std::make_pair( xValues, yValues ) ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template size_t RiaCurveMerger::curveCount() const { return m_interpolatedValuesForAllCurves.size(); } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template +template RiaCurveDataTools::CurveIntervals RiaCurveMerger::validIntervalsForAllXValues() const { return m_validIntervalsForAllXValues; } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template +template const std::vector& RiaCurveMerger::allXValues() const { return m_allXValues; } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template -const std::vector& RiaCurveMerger::interpolatedYValuesForAllXValues(size_t curveIdx) const +template +const std::vector& RiaCurveMerger::interpolatedYValuesForAllXValues( size_t curveIdx ) const { - CVF_ASSERT(curveIdx < m_interpolatedValuesForAllCurves.size()); + CVF_ASSERT( curveIdx < m_interpolatedValuesForAllCurves.size() ); return m_interpolatedValuesForAllCurves[curveIdx]; } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template -std::vector& RiaCurveMerger::interpolatedYValuesForAllXValues(size_t curveIdx) +template +std::vector& RiaCurveMerger::interpolatedYValuesForAllXValues( size_t curveIdx ) { - CVF_ASSERT(curveIdx < m_interpolatedValuesForAllCurves.size()); + CVF_ASSERT( curveIdx < m_interpolatedValuesForAllCurves.size() ); return m_interpolatedValuesForAllCurves[curveIdx]; } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template -void RiaCurveMerger::computeInterpolatedValues(bool includeValuesFromPartialCurves) +template +void RiaCurveMerger::computeInterpolatedValues( bool includeValuesFromPartialCurves ) { m_validIntervalsForAllXValues.clear(); m_allXValues.clear(); m_interpolatedValuesForAllCurves.clear(); - computeUnionOfXValues(includeValuesFromPartialCurves); + computeUnionOfXValues( includeValuesFromPartialCurves ); const size_t curveCount = m_originalValues.size(); - if (curveCount == 0) + if ( curveCount == 0 ) { return; } const size_t dataValueCount = m_allXValues.size(); - if (dataValueCount == 0) + if ( dataValueCount == 0 ) { return; } - m_interpolatedValuesForAllCurves.resize(curveCount); + m_interpolatedValuesForAllCurves.resize( curveCount ); - std::vector accumulatedValidValues(dataValueCount, 1.0); + std::vector accumulatedValidValues( dataValueCount, 1.0 ); - for (size_t curveIdx = 0; curveIdx < curveCount; curveIdx++) + for ( size_t curveIdx = 0; curveIdx < curveCount; curveIdx++ ) { std::vector& curveValues = m_interpolatedValuesForAllCurves[curveIdx]; - curveValues.resize(dataValueCount); + curveValues.resize( dataValueCount ); - for (size_t valueIndex = 0; valueIndex < dataValueCount; valueIndex++) + for ( size_t valueIndex = 0; valueIndex < dataValueCount; valueIndex++ ) { - double interpolValue = interpolatedYValue(m_allXValues[valueIndex], m_originalValues[curveIdx].first, m_originalValues[curveIdx].second); - if (!RiaCurveDataTools::isValidValue(interpolValue, false)) + double interpolValue = interpolatedYValue( m_allXValues[valueIndex], + m_originalValues[curveIdx].first, + m_originalValues[curveIdx].second ); + if ( !RiaCurveDataTools::isValidValue( interpolValue, false ) ) { accumulatedValidValues[valueIndex] = HUGE_VAL; } @@ -165,45 +165,46 @@ void RiaCurveMerger::computeInterpolatedValues(bool includeValuesFro } } - m_validIntervalsForAllXValues = RiaCurveDataTools::calculateIntervalsOfValidValues(accumulatedValidValues, false); + m_validIntervalsForAllXValues = RiaCurveDataTools::calculateIntervalsOfValidValues( accumulatedValidValues, false ); } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template -void RiaCurveMerger::computeUnionOfXValues(bool includeValuesForPartialCurves) +template +void RiaCurveMerger::computeUnionOfXValues( bool includeValuesForPartialCurves ) { m_allXValues.clear(); - std::set unionOfXValues; + std::set unionOfXValues; - for (const auto& curveData : m_originalValues) + std::vector> originalXBounds; + for ( const auto& curveData : m_originalValues ) { - for (const auto& x : curveData.first) + for ( const auto& x : curveData.first ) { - unionOfXValues.insert(x); + unionOfXValues.insert( x ); } + auto minmax_it = std::minmax_element( curveData.first.begin(), curveData.first.end() ); + originalXBounds.push_back( std::make_pair( *( minmax_it.first ), *( minmax_it.second ) ) ); } - if (!includeValuesForPartialCurves) + if ( !includeValuesForPartialCurves ) { - for (auto it = unionOfXValues.begin(); it != unionOfXValues.end();) + for ( auto it = unionOfXValues.begin(); it != unionOfXValues.end(); ) { bool outsideBounds = false; - for (const auto& curveData : m_originalValues) + for ( const auto& curveXBounds : originalXBounds ) { - if (curveData.first.empty()) continue; - - if (*it < curveData.first.front() || *it > curveData.first.back()) + if ( *it < curveXBounds.first || *it > curveXBounds.second ) { outsideBounds = true; break; } } - if (outsideBounds) + if ( outsideBounds ) { - it = unionOfXValues.erase(it); + it = unionOfXValues.erase( it ); } else { @@ -212,27 +213,27 @@ void RiaCurveMerger::computeUnionOfXValues(bool includeValuesForPart } } - m_allXValues = std::vector(unionOfXValues.begin(), unionOfXValues.end()); + m_allXValues = std::vector( unionOfXValues.begin(), unionOfXValues.end() ); } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -template -double RiaCurveMerger::interpolatedYValue(const XValueType& interpolationXValue, - const std::vector& xValues, - const std::vector& yValues) +template +double RiaCurveMerger::interpolatedYValue( const XValueType& interpolationXValue, + const std::vector& xValues, + const std::vector& yValues ) { - if (yValues.size() != xValues.size()) return HUGE_VAL; + if ( yValues.size() != xValues.size() ) return HUGE_VAL; const bool removeInterpolatedValues = false; - for (size_t firstI = 0; firstI < xValues.size(); firstI++) + for ( size_t firstI = 0; firstI < xValues.size(); firstI++ ) { - if (XComparator::equals(xValues.at(firstI), interpolationXValue)) + if ( XComparator::equals( xValues.at( firstI ), interpolationXValue ) ) { - const double& firstValue = yValues.at(firstI); - if (!RiaCurveDataTools::isValidValue(firstValue, removeInterpolatedValues)) + const double& firstValue = yValues.at( firstI ); + if ( !RiaCurveDataTools::isValidValue( firstValue, removeInterpolatedValues ) ) { return HUGE_VAL; } @@ -242,12 +243,12 @@ double RiaCurveMerger::interpolatedYValue(const XValueType& size_t secondI = firstI + 1; - if (secondI < xValues.size()) - { - if (XComparator::equals(xValues.at(secondI), interpolationXValue)) + if ( secondI < xValues.size() ) + { + if ( XComparator::equals( xValues.at( secondI ), interpolationXValue ) ) { - const double& secondValue = yValues.at(secondI); - if (!RiaCurveDataTools::isValidValue(secondValue, removeInterpolatedValues)) + const double& secondValue = yValues.at( secondI ); + if ( !RiaCurveDataTools::isValidValue( secondValue, removeInterpolatedValues ) ) { return HUGE_VAL; } @@ -255,32 +256,31 @@ double RiaCurveMerger::interpolatedYValue(const XValueType& return secondValue; } - if (xValues.at(firstI) < interpolationXValue && xValues.at(secondI) > interpolationXValue) + if ( xValues.at( firstI ) < interpolationXValue && xValues.at( secondI ) > interpolationXValue ) { - const double& firstValue = yValues.at(firstI); - const double& secondValue = yValues.at(secondI); + const double& firstValue = yValues.at( firstI ); + const double& secondValue = yValues.at( secondI ); - bool isFirstValid = RiaCurveDataTools::isValidValue(firstValue, removeInterpolatedValues); - if (!isFirstValid) return HUGE_VAL; + bool isFirstValid = RiaCurveDataTools::isValidValue( firstValue, removeInterpolatedValues ); + if ( !isFirstValid ) return HUGE_VAL; - bool isSecondValid = RiaCurveDataTools::isValidValue(secondValue, removeInterpolatedValues); - if (!isSecondValid) return HUGE_VAL; + bool isSecondValid = RiaCurveDataTools::isValidValue( secondValue, removeInterpolatedValues ); + if ( !isSecondValid ) return HUGE_VAL; - double firstDiff = fabs(XComparator::diff(interpolationXValue, xValues.at(firstI))); - double secondDiff = fabs(XComparator::diff(xValues.at(secondI), interpolationXValue)); + double firstDiff = fabs( XComparator::diff( interpolationXValue, xValues.at( firstI ) ) ); + double secondDiff = fabs( XComparator::diff( xValues.at( secondI ), interpolationXValue ) ); - double firstWeight = secondDiff / (firstDiff + secondDiff); - double secondWeight = firstDiff / (firstDiff + secondDiff); + double firstWeight = secondDiff / ( firstDiff + secondDiff ); + double secondWeight = firstDiff / ( firstDiff + secondDiff ); - double val = (firstValue * firstWeight) + (secondValue * secondWeight); + double val = ( firstValue * firstWeight ) + ( secondValue * secondWeight ); - CVF_ASSERT(RiaCurveDataTools::isValidValue(val, removeInterpolatedValues)); + CVF_ASSERT( RiaCurveDataTools::isValidValue( val, removeInterpolatedValues ) ); return val; } - } + } } return HUGE_VAL; } -