Skip to content

Commit

Permalink
#11088 Use non-optimized version for old projects to compute active c…
Browse files Browse the repository at this point in the history
…ells BB

The performance to compute geometry BB for active cells has improved. The original code also set displayModelOffset based on the BB of active cells. To make sure that existing project files produce identically the the same, the non-optimized version is used in this case.
  • Loading branch information
magnesj committed Jan 31, 2024
1 parent 111eeb6 commit 5151717
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void RicCreateTemporaryLgrFeature::computeCachedData( RimEclipseCase* eclipseCas
if ( eclipseCaseData )
{
eclipseCaseData->mainGrid()->computeCachedData();
eclipseCaseData->computeActiveCellBoundingBoxes();
eclipseCase->computeActiveCellsBoundingBox();
}

if ( cellResultsDataMatrix )
Expand Down
22 changes: 21 additions & 1 deletion ApplicationLibCode/ProjectDataModel/RimEclipseCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ void RimEclipseCase::computeCachedData()

{
auto task = pInf.task( "", 1 );
rigEclipseCase->computeActiveCellBoundingBoxes();
computeActiveCellsBoundingBox();
}

{
Expand Down Expand Up @@ -771,6 +771,26 @@ void RimEclipseCase::createDisplayModelAndUpdateAllViews()
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase::computeActiveCellsBoundingBox()
{
if ( !eclipseCaseData() ) return;

bool useOptimizedVersion = true;

if ( auto proj = RimProject::current() )
{
if ( proj->isProjectFileVersionEqualOrOlderThan( "2023.12.0" ) )
{
useOptimizedVersion = false;
}
}

eclipseCaseData()->computeActiveCellBoundingBoxes( useOptimizedVersion );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/ProjectDataModel/RimEclipseCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class RimEclipseCase : public RimCase
void ensureFaultDataIsComputed();
bool ensureNncDataIsComputed();
void createDisplayModelAndUpdateAllViews();
void computeActiveCellsBoundingBox();

void setReaderSettings( std::shared_ptr<RifReaderSettings> readerSettings );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ bool RimEclipseResultCase::openAndReadActiveCellData( RigEclipseCaseData* mainEc
CVF_ASSERT( eclipseCaseData() );
CVF_ASSERT( readerInterface.notNull() );

eclipseCaseData()->computeActiveCellBoundingBoxes();
computeActiveCellsBoundingBox();

m_activeCellInfoIsReadFromFile = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo()

if ( i == 0 )
{
rimReservoir->eclipseCaseData()->computeActiveCellBoundingBoxes();
rimReservoir->computeActiveCellsBoundingBox();
}
}
}
Expand Down Expand Up @@ -375,7 +375,7 @@ void RimIdenticalGridCaseGroup::updateMainGridAndActiveCellsForStatisticsCases()

if ( i == 0 )
{
rimStaticsCase->eclipseCaseData()->computeActiveCellBoundingBoxes();
rimStaticsCase->computeActiveCellsBoundingBox();
}
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ RimEclipseStatisticsCase* RimIdenticalGridCaseGroup::createStatisticsCase( bool
if ( selectDefaultResults ) newStatisticsCase->populateResultSelectionAfterLoadingGrid();

newStatisticsCase->openEclipseGridFile();
newStatisticsCase->eclipseCaseData()->computeActiveCellBoundingBoxes();
newStatisticsCase->computeActiveCellsBoundingBox();
newStatisticsCase->selectAllTimeSteps();

return newStatisticsCase;
Expand Down
69 changes: 65 additions & 4 deletions ApplicationLibCode/ReservoirDataModel/RigEclipseCaseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,14 @@ void RigEclipseCaseData::computeActiveCellIJKBBox()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigEclipseCaseData::computeActiveCellBoundingBoxes()
void RigEclipseCaseData::computeActiveCellBoundingBoxes( bool useOptimizedVersion )
{
computeActiveCellIJKBBox();
computeActiveCellsGeometryBoundingBox();

if ( useOptimizedVersion )
computeActiveCellsGeometryBoundingBoxOptimized();
else
computeActiveCellsGeometryBoundingBoxSlow();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -627,7 +631,7 @@ bool RigEclipseCaseData::hasFractureResults() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigEclipseCaseData::computeActiveCellsGeometryBoundingBox()
void RigEclipseCaseData::computeActiveCellsGeometryBoundingBoxSlow()
{
if ( m_activeCellInfo.isNull() || m_fractureActiveCellInfo.isNull() )
{
Expand All @@ -646,6 +650,60 @@ void RigEclipseCaseData::computeActiveCellsGeometryBoundingBox()
activeInfos[0] = m_fractureActiveCellInfo.p();
activeInfos[1] = m_activeCellInfo.p(); // Last, to make this bb.min become display offset

cvf::BoundingBox bb;
for ( int acIdx = 0; acIdx < 2; ++acIdx )
{
bb.reset();
if ( m_mainGrid->nodes().empty() )
{
bb.add( cvf::Vec3d::ZERO );
}
else
{
std::array<cvf::Vec3d, 8> hexCorners;
for ( size_t i = 0; i < m_mainGrid->cellCount(); i++ )
{
if ( activeInfos[acIdx]->isActive( i ) )
{
m_mainGrid->cellCornerVertices( i, hexCorners.data() );
for ( const auto& corner : hexCorners )
{
bb.add( corner );
}
}
}
}

activeInfos[acIdx]->setGeometryBoundingBox( bb );
}

// This design choice is unfortunate, as the bounding box of active cells can be computed in different ways.
// Must keep the code to make sure existing projects display 3D model at the same location in the scene.
m_mainGrid->setDisplayModelOffset( bb.min() );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigEclipseCaseData::computeActiveCellsGeometryBoundingBoxOptimized()
{
if ( m_activeCellInfo.isNull() || m_fractureActiveCellInfo.isNull() )
{
return;
}

if ( m_mainGrid.isNull() )
{
cvf::BoundingBox bb;
m_activeCellInfo->setGeometryBoundingBox( bb );
m_fractureActiveCellInfo->setGeometryBoundingBox( bb );
return;
}

RigActiveCellInfo* activeInfos[2];
activeInfos[0] = m_fractureActiveCellInfo.p();
activeInfos[1] = m_activeCellInfo.p();

cvf::BoundingBox bb;
for ( int acIdx = 0; acIdx < 2; ++acIdx )
{
Expand Down Expand Up @@ -682,7 +740,10 @@ void RigEclipseCaseData::computeActiveCellsGeometryBoundingBox()
activeInfos[acIdx]->setGeometryBoundingBox( bb );
}

m_mainGrid->setDisplayModelOffset( bb.min() );
auto bbMainGrid = m_mainGrid->boundingBox();

// Use center of bounding box as display offset. This point will be stable and independent of the active cell bounding box.
m_mainGrid->setDisplayModelOffset( bbMainGrid.center() );
}

//--------------------------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions ApplicationLibCode/ReservoirDataModel/RigEclipseCaseData.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class RigEclipseCaseData : public cvf::Object
const RigWellResultPoint& sourceWellCellResult,
const RigWellResultPoint& otherWellCellResult ) const;

void computeActiveCellBoundingBoxes();
void computeActiveCellBoundingBoxes( bool useOptimizedVersion );

RiaDefines::EclipseUnitSystem unitsType() const { return m_unitsType; }
void setUnitsType( RiaDefines::EclipseUnitSystem unitsType ) { m_unitsType = unitsType; }
Expand All @@ -126,7 +126,8 @@ class RigEclipseCaseData : public cvf::Object
private:
void computeActiveCellIJKBBox();
void computeWellCellsPrGrid();
void computeActiveCellsGeometryBoundingBox();
void computeActiveCellsGeometryBoundingBoxSlow();
void computeActiveCellsGeometryBoundingBoxOptimized();

const RigFormationNames* activeFormationNames() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ void RigReservoirBuilder::createGridsAndCells( RigEclipseCaseData* eclipseCase )
activeCellInfo->setGridActiveCellCounts( 0, eclipseCase->mainGrid()->globalCellArray().size() );
activeCellInfo->computeDerivedData();

eclipseCase->computeActiveCellBoundingBoxes();
bool useOptimizedVersion = true;
eclipseCase->computeActiveCellBoundingBoxes( useOptimizedVersion );
}

//--------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 5151717

Please sign in to comment.