Skip to content

Commit

Permalink
Refactor use of grid dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Jan 22, 2024
1 parent 3084b9e commit d7e06d1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifReaderEclipseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool RifReaderEclipseInput::open( const QString& fileName, RigEclipseCaseData* e
// create InputProperty object

bool isOk = false;
if ( eclipseCase->mainGrid()->gridPointDimensions() == cvf::Vec3st( 0, 0, 0 ) )
if ( eclipseCase->mainGrid()->cellCount() == 0 )
{
QString errorMesssages;
isOk = RifEclipseInputFileTools::openGridFile( fileName, eclipseCase, isFaultImportEnabled(), &errorMesssages );
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/ProjectDataModel/RimEclipseCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ void RimEclipseCase::loadAndSynchronizeInputProperties( bool importGridOrFaultDa
// Make sure we actually have reservoir data

CVF_ASSERT( eclipseCaseData() );
CVF_ASSERT( eclipseCaseData()->mainGrid()->gridPointDimensions() != cvf::Vec3st( 0, 0, 0 ) );
CVF_ASSERT( eclipseCaseData()->mainGrid()->cellCount() != 0 );

// Then read the properties from all the files referenced by the InputReservoir

Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/ProjectDataModel/RimEclipseInputCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool RimEclipseInputCase::openDataFileSet( const QStringList& fileNames )
QString gridFileName;

// First find and read the grid data
if ( eclipseCaseData()->mainGrid()->gridPointDimensions() == cvf::Vec3st( 0, 0, 0 ) )
if ( eclipseCaseData()->mainGrid()->cellCount() == 0 )
{
for ( int i = 0; i < fileNames.size(); i++ )
{
Expand Down Expand Up @@ -142,7 +142,7 @@ bool RimEclipseInputCase::openDataFileSet( const QStringList& fileNames )
}
}

if ( eclipseCaseData()->mainGrid()->gridPointDimensions() == cvf::Vec3st( 0, 0, 0 ) )
if ( eclipseCaseData()->mainGrid()->cellCount() == 0 )
{
for ( QString errorMessages : allErrorMessages )
{
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/ProjectDataModel/RimRoffCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool RimRoffCase::openEclipseGridFile()
QString fileName = gridFileName();

// First find and read the grid data
if ( eclipseCaseData()->mainGrid()->gridPointDimensions() == cvf::Vec3st( 0, 0, 0 ) )
if ( eclipseCaseData()->mainGrid()->cellCount() == 0 )
{
QString errorMessages;
if ( RifRoffFileTools::openGridFile( fileName, eclipseCaseData(), &errorMessages ) )
Expand Down
22 changes: 6 additions & 16 deletions ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ void RigGridBase::setGridPointDimensions( const cvf::Vec3st& gridDimensions )
m_cellCount.z() = ( m_gridPointDimensions.z() > 0 ? m_gridPointDimensions.z() - 1 : 0 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Vec3st RigGridBase::gridPointDimensions()
{
return m_gridPointDimensions;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -193,17 +185,15 @@ size_t RigGridBase::cellIndexFromIJK( size_t i, size_t j, size_t k ) const
CVF_TIGHT_ASSERT( i != cvf::UNDEFINED_SIZE_T && j != cvf::UNDEFINED_SIZE_T && k != cvf::UNDEFINED_SIZE_T );
CVF_TIGHT_ASSERT( i < m_gridPointDimensions.x() && j < m_gridPointDimensions.y() && k < m_gridPointDimensions.z() );

size_t ci = i + j * ( m_gridPointDimensions.x() - 1 ) + k * ( ( m_gridPointDimensions.x() - 1 ) * ( m_gridPointDimensions.y() - 1 ) );
return ci;
return i + j * cellCountI() + k * cellCountI() * cellCountJ();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigGridBase::cellIndexFromIJKUnguarded( size_t i, size_t j, size_t k ) const
{
size_t ci = i + j * ( m_gridPointDimensions.x() - 1 ) + k * ( ( m_gridPointDimensions.x() - 1 ) * ( m_gridPointDimensions.y() - 1 ) );
return ci;
return i + j * cellCountI() + k * cellCountI() * cellCountJ();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -227,8 +217,8 @@ bool RigGridBase::ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size
return false;
}

const size_t cellCountI = m_gridPointDimensions[0] - 1u;
const size_t cellCountJ = m_gridPointDimensions[1] - 1u;
const size_t cellCountI = this->cellCountI();
const size_t cellCountJ = this->cellCountJ();

*i = index % cellCountI;
index /= cellCountI;
Expand Down Expand Up @@ -274,8 +264,8 @@ void RigGridBase::ijkFromCellIndexUnguarded( size_t cellIndex, size_t* i, size_t
{
size_t index = cellIndex;

const size_t cellCountI = m_gridPointDimensions[0] - 1u;
const size_t cellCountJ = m_gridPointDimensions[1] - 1u;
const size_t cellCountI = this->cellCountI();
const size_t cellCountJ = this->cellCountJ();

*i = index % cellCountI;
index /= cellCountI;
Expand Down
5 changes: 2 additions & 3 deletions ApplicationLibCode/ReservoirDataModel/RigGridBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ class RigGridBase : public cvf::StructGridInterface
explicit RigGridBase( RigMainGrid* mainGrid );
~RigGridBase() override;

void setGridPointDimensions( const cvf::Vec3st& gridDimensions );
cvf::Vec3st gridPointDimensions();
void setGridPointDimensions( const cvf::Vec3st& gridDimensions );

size_t cellCountI() const override;
size_t cellCountJ() const override;
size_t cellCountK() const override;

size_t cellCount() const { return cellCountI() * cellCountJ() * cellCountK(); }
size_t cellCount() const;
RigCell& cell( size_t gridLocalCellIndex );
const RigCell& cell( size_t gridLocalCellIndex ) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void RigReservoirBuilderMock::addWellData( RigEclipseCaseData* eclipseCase, RigG
CVF_ASSERT( eclipseCase );
CVF_ASSERT( grid );

cvf::Vec3st dim = grid->gridPointDimensions();
auto cellCountJ = grid->cellCountJ();
auto cellCountK = grid->cellCountK();

cvf::Collection<RigSimWellData> wells;

Expand All @@ -208,7 +209,7 @@ void RigReservoirBuilderMock::addWellData( RigEclipseCaseData* eclipseCase, RigG

// Connections
// int connectionCount = std::min(dim.x(), std::min(dim.y(), dim.z())) - 2;
size_t connectionCount = dim.z() - 2;
size_t connectionCount = cellCountK - 2;
if ( connectionCount > 0 )
{
// Only main grid supported by now. Must be taken care of when LGRs are supported
Expand All @@ -224,10 +225,10 @@ void RigReservoirBuilderMock::addWellData( RigEclipseCaseData* eclipseCase, RigG
RigWellResultPoint data;
data.setGridIndex( 0 );

if ( connIdx < dim.y() - 2 )
if ( connIdx < cellCountJ - 2 )
data.setGridCellIndex( grid->cellIndexFromIJK( 1, 1 + connIdx, 1 + connIdx ) );
else
data.setGridCellIndex( grid->cellIndexFromIJK( 1, dim.y() - 2, 1 + connIdx ) );
data.setGridCellIndex( grid->cellIndexFromIJK( 1, cellCountJ - 2, 1 + connIdx ) );

if ( connIdx < connectionCount / 2 )
{
Expand Down Expand Up @@ -262,7 +263,7 @@ void RigReservoirBuilderMock::addWellData( RigEclipseCaseData* eclipseCase, RigG
}
}

if ( connIdx < dim.y() - 2 )
if ( connIdx < cellCountJ - 2 )
{
data.setGridCellIndex( grid->cellIndexFromIJK( 1, 1 + connIdx, 2 + connIdx ) );

Expand Down

0 comments on commit d7e06d1

Please sign in to comment.