Skip to content

Commit

Permalink
Fix min max all time steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Nov 4, 2024
1 parent bfee2dd commit f5685a9
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,20 @@ void RimGeoMechContourMapProjection::defineEditorAttribute( const caf::PdmFieldH
//--------------------------------------------------------------------------------------------------
std::pair<double, double> RimGeoMechContourMapProjection::minmaxValuesAllTimeSteps()
{
int steps = geoMechCase()->geoMechData()->femPartResults()->totalSteps();
std::vector<int> 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<double> 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 );
}
70 changes: 22 additions & 48 deletions ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void RimContourMapProjection::ResultAggregation::setUp()
setDefault( RigContourMapCalculator::RESULTS_MEAN_VALUE );
}
} // namespace caf

CAF_PDM_ABSTRACT_SOURCE_INIT( RimContourMapProjection, "RimContourMapProjection" );

//--------------------------------------------------------------------------------------------------
Expand All @@ -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<double>::infinity() )
, m_maxResultAllTimeSteps( -std::numeric_limits<double>::infinity() )

{
CAF_PDM_InitObject( "RimContourMapProjection", ":/2DMapProjection16x16.png" );

Expand Down Expand Up @@ -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;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -487,45 +482,6 @@ void RimContourMapProjection::clearResults()
clearResultVariable();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimContourMapProjection::clearTimeStepRange()
{
if ( m_contourMapProjection ) m_contourMapProjection->clearTimeStepRange();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<double, double> RimContourMapProjection::minmaxValuesAllTimeSteps()
{
std::vector<int> 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<double> 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 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1028,3 +984,21 @@ void RimContourMapProjection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTr
void RimContourMapProjection::initAfterRead()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimContourMapProjection::resultRangeIsValid() const
{
return m_minResultAllTimeSteps != std::numeric_limits<double>::infinity() &&
m_maxResultAllTimeSteps != -std::numeric_limits<double>::infinity();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimContourMapProjection::clearTimeStepRange()
{
m_minResultAllTimeSteps = std::numeric_limits<double>::infinity();
m_maxResultAllTimeSteps = -std::numeric_limits<double>::infinity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class RimContourMapProjection : public RimCheckableNamedObject
void clearResults();
void clearTimeStepRange();

virtual std::pair<double, double> minmaxValuesAllTimeSteps();
virtual std::pair<double, double> minmaxValuesAllTimeSteps() = 0;

bool mapCellVisibilityNeedsUpdating();
static std::vector<std::vector<std::pair<size_t, double>>> generateGridMapping( RimContourMapProjection& contourMapProjection,
Expand Down Expand Up @@ -173,6 +173,9 @@ class RimContourMapProjection : public RimCheckableNamedObject
int m_currentResultTimestep;
std::vector<bool> m_mapCellVisibility;

double m_minResultAllTimeSteps;
double m_maxResultAllTimeSteps;

std::unique_ptr<RigContourMapGrid> m_contourMapGrid;
std::unique_ptr<RigContourMapProjection> m_contourMapProjection;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -387,3 +387,23 @@ void RimEclipseContourMapProjection::initAfterRead()
m_weightingResult->setEclipseCase( eclipseCase() );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<double, double> RimEclipseContourMapProjection::minmaxValuesAllTimeSteps()
{
if ( !resultRangeIsValid() )
{
clearTimeStepRange();

int timeStepCount = static_cast<int>( eclipseCase()->timeStepStrings().size() );
for ( int i = 0; i < (int)timeStepCount; ++i )
{
std::vector<double> 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 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class RimEclipseContourMapProjection : public RimContourMapProjection
RimEclipseCase* eclipseCase() const;
RimEclipseContourMapView* view() const;

std::pair<double, double> minmaxValuesAllTimeSteps() override;

void updateAfterResultGeneration( int timeStep ) override;

protected:
Expand Down
51 changes: 2 additions & 49 deletions ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
RigContourMapProjection::RigContourMapProjection( const RigContourMapGrid& contourMapGrid )
: m_contourMapGrid( contourMapGrid )
, m_currentResultTimestep( -1 )
, m_minResultAllTimeSteps( std::numeric_limits<double>::infinity() )
, m_maxResultAllTimeSteps( -std::numeric_limits<double>::infinity() )
{
}

Expand Down Expand Up @@ -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<double>::infinity() &&
m_maxResultAllTimeSteps != -std::numeric_limits<double>::infinity();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigContourMapProjection::clearTimeStepRange()
{
m_minResultAllTimeSteps = std::numeric_limits<double>::infinity();
m_maxResultAllTimeSteps = -std::numeric_limits<double>::infinity();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigContourMapProjection::maxValue( const std::vector<double>& aggregatedResults ) const
double RigContourMapProjection::maxValue( const std::vector<double>& aggregatedResults )
{
double maxV = -std::numeric_limits<double>::infinity();

Expand All @@ -253,7 +233,7 @@ double RigContourMapProjection::maxValue( const std::vector<double>& aggregatedR
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigContourMapProjection::minValue( const std::vector<double>& aggregatedResults ) const
double RigContourMapProjection::minValue( const std::vector<double>& aggregatedResults )
{
double minV = std::numeric_limits<double>::infinity();

Expand All @@ -267,33 +247,6 @@ double RigContourMapProjection::minValue( const std::vector<double>& aggregatedR
return minV;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<double, double> RigContourMapProjection::minmaxValuesAllTimeSteps( const std::vector<int>& 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<double> 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 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
17 changes: 4 additions & 13 deletions ApplicationLibCode/ReservoirDataModel/RigContourMapProjection.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ class RigContourMapProjection
std::vector<std::vector<std::pair<size_t, double>>>
generateGridMapping( RigContourMapCalculator::ResultAggregationEnum resultAggregation, const std::vector<double>& weights );

double interpolateValue( const cvf::Vec2d& gridPosition2d ) const;
virtual std::pair<double, double> minmaxValuesAllTimeSteps( const std::vector<int>& timeSteps );

void clearTimeStepRange();

// Keep track of whether cached data needs updating
bool resultRangeIsValid() const;
double interpolateValue( const cvf::Vec2d& gridPosition2d ) const;

const std::vector<double>& aggregatedResults() const { return m_aggregatedResults; }
const std::vector<double>& aggregatedVertexResults() const { return m_aggregatedVertexResults; }
Expand All @@ -100,16 +94,16 @@ class RigContourMapProjection

virtual std::vector<bool> getMapCellVisibility( int viewStepIndex, RigContourMapCalculator::ResultAggregationEnum resultAggregation ) = 0;

static double maxValue( const std::vector<double>& aggregatedResults );
static double minValue( const std::vector<double>& aggregatedResults );

protected:
double calculateValueInMapCell( uint i,
uint j,
const std::vector<double>& gridCellValues,
RigContourMapCalculator::ResultAggregationEnum resultAggregation ) const;

protected:
double maxValue( const std::vector<double>& aggregatedResults ) const;
double minValue( const std::vector<double>& aggregatedResults ) const;

static std::vector<std::vector<std::pair<size_t, double>>> generateGridMapping( RigContourMapProjection& contourMapProjection,
const RigContourMapGrid& contourMapGrid );

Expand All @@ -128,8 +122,5 @@ class RigContourMapProjection
int m_currentResultTimestep;
std::vector<bool> m_mapCellVisibility;

double m_minResultAllTimeSteps;
double m_maxResultAllTimeSteps;

const RigContourMapGrid& m_contourMapGrid;
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ std::vector<double> RigEclipseContourMapProjection::generateResults( const RigEc
RigContourMapCalculator::ResultAggregationEnum resultAggregation,
int timeStep )
{
// TODO: handle this....
// m_weightingResult->loadResult();

size_t nCells = numberOfCells();

std::vector<double> aggregatedResults = std::vector<double>( nCells, std::numeric_limits<double>::infinity() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,36 +382,3 @@ std::vector<double> RigGeoMechContourMapProjection::gridCellValues( RigFemResult
}
return gridCellValues;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::pair<double, double> 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<double> 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 );
}

0 comments on commit f5685a9

Please sign in to comment.