From f5685a9bbee17d324211e0bc71d4ff44a1304004 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Mon, 4 Nov 2024 13:42:42 +0100 Subject: [PATCH] Fix min max all time steps. --- .../RimGeoMechContourMapProjection.cpp | 21 ++++-- .../RimContourMapProjection.cpp | 70 ++++++------------- .../RimContourMapProjection.h | 5 +- .../RimEclipseContourMapProjection.cpp | 24 ++++++- .../RimEclipseContourMapProjection.h | 2 + .../RigContourMapProjection.cpp | 51 +------------- .../RigContourMapProjection.h | 17 ++--- .../RigEclipseContourMapProjection.cpp | 3 - .../RigGeoMechContourMapProjection.cpp | 33 --------- 9 files changed, 72 insertions(+), 154 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp index f5355ff6bc..a0978adca6 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapProjection.cpp @@ -384,9 +384,20 @@ void RimGeoMechContourMapProjection::defineEditorAttribute( const caf::PdmFieldH //-------------------------------------------------------------------------------------------------- std::pair RimGeoMechContourMapProjection::minmaxValuesAllTimeSteps() { - int steps = geoMechCase()->geoMechData()->femPartResults()->totalSteps(); - std::vector timeSteps; - for ( int i = 0; i < steps; i++ ) - timeSteps.push_back( i ); - return m_contourMapProjection->minmaxValuesAllTimeSteps( timeSteps ); + if ( !resultRangeIsValid() ) + { + clearTimeStepRange(); + + if ( geoMechCase()->geoMechData()->femPartResults() ) + { + int steps = geoMechCase()->geoMechData()->femPartResults()->totalSteps(); + for ( int stepIdx = 0; stepIdx < steps; stepIdx++ ) + { + std::vector aggregatedResults = generateResults( stepIdx ); + m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, RigContourMapProjection::minValue( aggregatedResults ) ); + m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, RigContourMapProjection::maxValue( aggregatedResults ) ); + } + } + } + return std::make_pair( m_minResultAllTimeSteps, m_maxResultAllTimeSteps ); } diff --git a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp index f7b24c9077..d4564f403a 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp @@ -65,6 +65,7 @@ void RimContourMapProjection::ResultAggregation::setUp() setDefault( RigContourMapCalculator::RESULTS_MEAN_VALUE ); } } // namespace caf + CAF_PDM_ABSTRACT_SOURCE_INIT( RimContourMapProjection, "RimContourMapProjection" ); //-------------------------------------------------------------------------------------------------- @@ -73,6 +74,9 @@ CAF_PDM_ABSTRACT_SOURCE_INIT( RimContourMapProjection, "RimContourMapProjection" RimContourMapProjection::RimContourMapProjection() : m_pickPoint( cvf::Vec2d::UNDEFINED ) , m_currentResultTimestep( -1 ) + , m_minResultAllTimeSteps( std::numeric_limits::infinity() ) + , m_maxResultAllTimeSteps( -std::numeric_limits::infinity() ) + { CAF_PDM_InitObject( "RimContourMapProjection", ":/2DMapProjection16x16.png" ); @@ -450,15 +454,6 @@ bool RimContourMapProjection::geometryNeedsUpdating() const return m_contourPolygons.empty() || m_trianglesWithVertexValues.empty(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimContourMapProjection::resultRangeIsValid() const -{ - if ( m_contourMapProjection ) return m_contourMapProjection->resultRangeIsValid(); - return false; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -487,45 +482,6 @@ void RimContourMapProjection::clearResults() clearResultVariable(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimContourMapProjection::clearTimeStepRange() -{ - if ( m_contourMapProjection ) m_contourMapProjection->clearTimeStepRange(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::pair RimContourMapProjection::minmaxValuesAllTimeSteps() -{ - std::vector timeSteps; - for ( int i = 0; i < (int)baseView()->ownerCase()->timeStepStrings().size() - 1; ++i ) - timeSteps.push_back( i ); - - return m_contourMapProjection->minmaxValuesAllTimeSteps( timeSteps ); - - // if ( !resultRangeIsValid() ) - // { - // clearTimeStepRange(); - - // m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, minValue( m_aggregatedResults ) ); - // m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, maxValue( m_aggregatedResults ) ); - - // for ( int i = 0; i < (int)baseView()->ownerCase()->timeStepStrings().size() - 1; ++i ) - // { - // if ( i != m_currentResultTimestep ) - // { - // std::vector aggregatedResults; // = generateResults( i ); - // m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, minValue( aggregatedResults ) ); - // m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, maxValue( aggregatedResults ) ); - // } - // } - // } - // return std::make_pair( m_minResultAllTimeSteps, m_maxResultAllTimeSteps ); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1028,3 +984,21 @@ void RimContourMapProjection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTr void RimContourMapProjection::initAfterRead() { } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimContourMapProjection::resultRangeIsValid() const +{ + return m_minResultAllTimeSteps != std::numeric_limits::infinity() && + m_maxResultAllTimeSteps != -std::numeric_limits::infinity(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimContourMapProjection::clearTimeStepRange() +{ + m_minResultAllTimeSteps = std::numeric_limits::infinity(); + m_maxResultAllTimeSteps = -std::numeric_limits::infinity(); +} diff --git a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h index 2d44e3b006..23e2759bed 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h +++ b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.h @@ -130,7 +130,7 @@ class RimContourMapProjection : public RimCheckableNamedObject void clearResults(); void clearTimeStepRange(); - virtual std::pair minmaxValuesAllTimeSteps(); + virtual std::pair minmaxValuesAllTimeSteps() = 0; bool mapCellVisibilityNeedsUpdating(); static std::vector>> generateGridMapping( RimContourMapProjection& contourMapProjection, @@ -173,6 +173,9 @@ class RimContourMapProjection : public RimCheckableNamedObject int m_currentResultTimestep; std::vector m_mapCellVisibility; + double m_minResultAllTimeSteps; + double m_maxResultAllTimeSteps; + std::unique_ptr m_contourMapGrid; std::unique_ptr m_contourMapProjection; }; diff --git a/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.cpp index 0486034bad..8dc9227b6a 100644 --- a/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.cpp @@ -103,8 +103,8 @@ void RimEclipseContourMapProjection::updateLegend() { RimEclipseCellColors* cellColors = view()->cellResult(); - double minVal = minValue(); // m_aggregatedResults ); - double maxVal = maxValue(); // m_aggregatedResults ); + double minVal = minValue(); + double maxVal = maxValue(); auto [minValAllTimeSteps, maxValAllTimeSteps] = minmaxValuesAllTimeSteps(); @@ -387,3 +387,23 @@ void RimEclipseContourMapProjection::initAfterRead() m_weightingResult->setEclipseCase( eclipseCase() ); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RimEclipseContourMapProjection::minmaxValuesAllTimeSteps() +{ + if ( !resultRangeIsValid() ) + { + clearTimeStepRange(); + + int timeStepCount = static_cast( eclipseCase()->timeStepStrings().size() ); + for ( int i = 0; i < (int)timeStepCount; ++i ) + { + std::vector aggregatedResults = generateResults( i ); + m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, RigContourMapProjection::minValue( aggregatedResults ) ); + m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, RigContourMapProjection::maxValue( aggregatedResults ) ); + } + } + return std::make_pair( m_minResultAllTimeSteps, m_maxResultAllTimeSteps ); +} diff --git a/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.h b/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.h index dd168bd28c..4b6aac271e 100644 --- a/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.h +++ b/ApplicationLibCode/ProjectDataModel/RimEclipseContourMapProjection.h @@ -70,6 +70,8 @@ class RimEclipseContourMapProjection : public RimContourMapProjection RimEclipseCase* eclipseCase() const; RimEclipseContourMapView* view() const; + std::pair minmaxValuesAllTimeSteps() override; + void updateAfterResultGeneration( int timeStep ) override; protected: diff --git a/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.cpp b/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.cpp index de35bb1a00..d5e126b956 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.cpp @@ -35,8 +35,6 @@ RigContourMapProjection::RigContourMapProjection( const RigContourMapGrid& contourMapGrid ) : m_contourMapGrid( contourMapGrid ) , m_currentResultTimestep( -1 ) - , m_minResultAllTimeSteps( std::numeric_limits::infinity() ) - , m_maxResultAllTimeSteps( -std::numeric_limits::infinity() ) { } @@ -215,28 +213,10 @@ double RigContourMapProjection::calculateValueInMapCell( uint return RigContourMapCalculator::calculateValueInMapCell( *this, matchingCells, gridCellValues, resultAggregation ); } -// //-------------------------------------------------------------------------------------------------- -// /// -// //-------------------------------------------------------------------------------------------------- -bool RigContourMapProjection::resultRangeIsValid() const -{ - return m_minResultAllTimeSteps != std::numeric_limits::infinity() && - m_maxResultAllTimeSteps != -std::numeric_limits::infinity(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigContourMapProjection::clearTimeStepRange() -{ - m_minResultAllTimeSteps = std::numeric_limits::infinity(); - m_maxResultAllTimeSteps = -std::numeric_limits::infinity(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double RigContourMapProjection::maxValue( const std::vector& aggregatedResults ) const +double RigContourMapProjection::maxValue( const std::vector& aggregatedResults ) { double maxV = -std::numeric_limits::infinity(); @@ -253,7 +233,7 @@ double RigContourMapProjection::maxValue( const std::vector& aggregatedR //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double RigContourMapProjection::minValue( const std::vector& aggregatedResults ) const +double RigContourMapProjection::minValue( const std::vector& aggregatedResults ) { double minV = std::numeric_limits::infinity(); @@ -267,33 +247,6 @@ double RigContourMapProjection::minValue( const std::vector& aggregatedR return minV; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::pair RigContourMapProjection::minmaxValuesAllTimeSteps( const std::vector& timeSteps ) -{ - if ( !resultRangeIsValid() ) - { - clearTimeStepRange(); - - m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, minValue( m_aggregatedResults ) ); - m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, maxValue( m_aggregatedResults ) ); - - // (int)baseView()->ownerCase()->timeStepStrings().size() - 1; ++i ) - for ( int i : timeSteps ) - { - if ( i != m_currentResultTimestep ) - { - // TODO: generate results !!!!! - std::vector aggregatedResults; // = generateResults( i ); - m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, minValue( aggregatedResults ) ); - m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, maxValue( aggregatedResults ) ); - } - } - } - return std::make_pair( m_minResultAllTimeSteps, m_maxResultAllTimeSteps ); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.h b/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.h index b81345eb1d..8eafccce7d 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.h +++ b/ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.h @@ -83,13 +83,7 @@ class RigContourMapProjection std::vector>> generateGridMapping( RigContourMapCalculator::ResultAggregationEnum resultAggregation, const std::vector& weights ); - double interpolateValue( const cvf::Vec2d& gridPosition2d ) const; - virtual std::pair minmaxValuesAllTimeSteps( const std::vector& timeSteps ); - - void clearTimeStepRange(); - - // Keep track of whether cached data needs updating - bool resultRangeIsValid() const; + double interpolateValue( const cvf::Vec2d& gridPosition2d ) const; const std::vector& aggregatedResults() const { return m_aggregatedResults; } const std::vector& aggregatedVertexResults() const { return m_aggregatedVertexResults; } @@ -100,6 +94,9 @@ class RigContourMapProjection virtual std::vector getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationEnum resultAggregation ) = 0; + static double maxValue( const std::vector& aggregatedResults ); + static double minValue( const std::vector& aggregatedResults ); + protected: double calculateValueInMapCell( uint i, uint j, @@ -107,9 +104,6 @@ class RigContourMapProjection RigContourMapCalculator::ResultAggregationEnum resultAggregation ) const; protected: - double maxValue( const std::vector& aggregatedResults ) const; - double minValue( const std::vector& aggregatedResults ) const; - static std::vector>> generateGridMapping( RigContourMapProjection& contourMapProjection, const RigContourMapGrid& contourMapGrid ); @@ -128,8 +122,5 @@ class RigContourMapProjection int m_currentResultTimestep; std::vector m_mapCellVisibility; - double m_minResultAllTimeSteps; - double m_maxResultAllTimeSteps; - const RigContourMapGrid& m_contourMapGrid; }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigEclipseContourMapProjection.cpp b/ApplicationLibCode/ReservoirDataModel/RigEclipseContourMapProjection.cpp index 51f1bde475..e63e026dd3 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigEclipseContourMapProjection.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigEclipseContourMapProjection.cpp @@ -62,9 +62,6 @@ std::vector RigEclipseContourMapProjection::generateResults( const RigEc RigContourMapCalculator::ResultAggregationEnum resultAggregation, int timeStep ) { - // TODO: handle this.... - // m_weightingResult->loadResult(); - size_t nCells = numberOfCells(); std::vector aggregatedResults = std::vector( nCells, std::numeric_limits::infinity() ); diff --git a/ApplicationLibCode/ReservoirDataModel/RigGeoMechContourMapProjection.cpp b/ApplicationLibCode/ReservoirDataModel/RigGeoMechContourMapProjection.cpp index f8ce6da32c..957aa4a006 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGeoMechContourMapProjection.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigGeoMechContourMapProjection.cpp @@ -382,36 +382,3 @@ std::vector RigGeoMechContourMapProjection::gridCellValues( RigFemResult } return gridCellValues; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::pair RigGeoMechContourMapProjection::minmaxValuesAllTimeSteps() -{ - if ( !resultRangeIsValid() ) - { - clearTimeStepRange(); - - m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, minValue( m_aggregatedResults ) ); - m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, maxValue( m_aggregatedResults ) ); - - if ( m_caseData.femPartResults() ) - { - int steps = m_caseData.femPartResults()->totalSteps(); - - for ( int stepIdx = 0; stepIdx < steps; stepIdx++ ) - { - if ( stepIdx == m_currentResultTimestep ) continue; - - // TODO: get this from somewhere??? - RigContourMapCalculator::ResultAggregationEnum resultAggregation = - RigContourMapCalculator::ResultAggregationEnum::RESULTS_MEAN_VALUE; - - std::vector aggregatedResults = generateResults( m_currentResultAddr, resultAggregation, stepIdx ); - m_minResultAllTimeSteps = std::min( m_minResultAllTimeSteps, minValue( aggregatedResults ) ); - m_maxResultAllTimeSteps = std::max( m_maxResultAllTimeSteps, maxValue( aggregatedResults ) ); - } - } - } - return std::make_pair( m_minResultAllTimeSteps, m_maxResultAllTimeSteps ); -}