Some performance updates

This commit is contained in:
Jon Jenssen 2024-10-29 14:15:30 +01:00 committed by jonjenssen
parent f7ecd38592
commit 8a2a1c218b
3 changed files with 28 additions and 48 deletions

View File

@ -50,7 +50,10 @@ RigActiveCellGrid::~RigActiveCellGrid()
//--------------------------------------------------------------------------------------------------
RigCell& RigActiveCellGrid::cell( size_t gridLocalCellIndex )
{
if ( m_nativeCells.contains( gridLocalCellIndex ) ) return m_nativeCells[gridLocalCellIndex];
if ( auto it = m_nativeCells.find( gridLocalCellIndex ); it != m_nativeCells.end() )
{
return it->second;
}
return m_invalidCell;
}
@ -59,7 +62,10 @@ RigCell& RigActiveCellGrid::cell( size_t gridLocalCellIndex )
//--------------------------------------------------------------------------------------------------
const RigCell& RigActiveCellGrid::cell( size_t gridLocalCellIndex ) const
{
if ( m_nativeCells.contains( gridLocalCellIndex ) ) return m_nativeCells.at( gridLocalCellIndex );
if ( const auto it = m_nativeCells.find( gridLocalCellIndex ); it != m_nativeCells.end() )
{
return it->second;
}
return m_invalidCell;
}

View File

@ -32,6 +32,8 @@ RigGridBase::RigGridBase( RigMainGrid* mainGrid )
: m_gridPointDimensions( 0, 0, 0 )
, m_indexToStartOfCells( 0 )
, m_mainGrid( mainGrid )
, m_cellCountIJK( 0 )
, m_cellCountIJ( 0 )
{
if ( mainGrid == nullptr )
{
@ -59,6 +61,9 @@ void RigGridBase::setGridPointDimensions( const cvf::Vec3st& gridDimensions )
m_cellCount.x() = ( m_gridPointDimensions.x() > 0 ? m_gridPointDimensions.x() - 1 : 0 );
m_cellCount.y() = ( m_gridPointDimensions.y() > 0 ? m_gridPointDimensions.y() - 1 : 0 );
m_cellCount.z() = ( m_gridPointDimensions.z() > 0 ? m_gridPointDimensions.z() - 1 : 0 );
m_cellCountIJ = cellCountI() * cellCountJ();
m_cellCountIJK = m_cellCountIJ * cellCountK();
}
//--------------------------------------------------------------------------------------------------
@ -78,12 +83,11 @@ std::string RigGridBase::gridName() const
}
//--------------------------------------------------------------------------------------------------
/// Do we need this ?
///
//--------------------------------------------------------------------------------------------------
RigCell& RigGridBase::cell( size_t gridLocalCellIndex )
{
CVF_TIGHT_ASSERT( m_mainGrid );
CVF_TIGHT_ASSERT( m_indexToStartOfCells + gridLocalCellIndex < m_mainGrid->reservoirCells().size() );
return m_mainGrid->reservoirCells()[m_indexToStartOfCells + gridLocalCellIndex];
@ -185,7 +189,7 @@ 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() );
return i + j * cellCountI() + k * cellCountI() * cellCountJ();
return i + j * m_cellCount.x() + k * m_cellCountIJ;
}
//--------------------------------------------------------------------------------------------------
@ -193,7 +197,7 @@ size_t RigGridBase::cellIndexFromIJK( size_t i, size_t j, size_t k ) const
//--------------------------------------------------------------------------------------------------
size_t RigGridBase::cellIndexFromIJKUnguarded( size_t i, size_t j, size_t k ) const
{
return i + j * cellCountI() + k * cellCountI() * cellCountJ();
return i + j * m_cellCount.x() + k * m_cellCountIJ;
}
//--------------------------------------------------------------------------------------------------
@ -208,7 +212,7 @@ void RigGridBase::cellMinMaxCordinates( size_t cellIndex, cvf::Vec3d* minCoordin
//--------------------------------------------------------------------------------------------------
bool RigGridBase::ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size_t* k ) const
{
CVF_TIGHT_ASSERT( cellIndex < RigGridBase::cellCount() );
CVF_TIGHT_ASSERT( cellIndex < m_cellCountIJK );
size_t index = cellIndex;
@ -217,8 +221,8 @@ bool RigGridBase::ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size
return false;
}
const size_t cellCountI = this->cellCountI();
const size_t cellCountJ = this->cellCountJ();
const size_t cellCountI = m_cellCount.x();
const size_t cellCountJ = m_cellCount.y();
*i = index % cellCountI;
index /= cellCountI;
@ -264,8 +268,8 @@ void RigGridBase::ijkFromCellIndexUnguarded( size_t cellIndex, size_t* i, size_t
{
size_t index = cellIndex;
const size_t cellCountI = this->cellCountI();
const size_t cellCountJ = this->cellCountJ();
const size_t cellCountI = m_cellCount.x();
const size_t cellCountJ = m_cellCount.y();
*i = index % cellCountI;
index /= cellCountI;
@ -334,7 +338,7 @@ cvf::Vec3d RigGridBase::maxCoordinate() const
//--------------------------------------------------------------------------------------------------
bool RigGridBase::isCellValid( size_t i, size_t j, size_t k ) const
{
if ( i >= cellCountI() || j >= cellCountJ() || k >= cellCountK() )
if ( i >= m_cellCount.x() || j >= m_cellCount.y() || k >= m_cellCount.z() )
{
return false;
}
@ -519,38 +523,6 @@ cvf::BoundingBox RigGridBase::boundingBox()
return m_boundingBox;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigGridBase::cellCountI() const
{
return m_cellCount.x();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigGridBase::cellCountJ() const
{
return m_cellCount.y();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigGridBase::cellCountK() const
{
return m_cellCount.z();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigGridBase::cellCount() const
{
return cellCountI() * cellCountJ() * cellCountK();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -45,11 +45,11 @@ public:
void setGridPointDimensions( const cvf::Vec3st& gridDimensions );
size_t cellCountI() const override;
size_t cellCountJ() const override;
size_t cellCountK() const override;
size_t cellCountI() const override { return m_cellCount.x(); }
size_t cellCountJ() const override { return m_cellCount.y(); }
size_t cellCountK() const override { return m_cellCount.z(); }
virtual size_t cellCount() const { return m_cellCountIJK; }
virtual size_t cellCount() const;
virtual RigCell& cell( size_t gridLocalCellIndex );
virtual const RigCell& cell( size_t gridLocalCellIndex ) const;
@ -116,6 +116,8 @@ public:
protected:
size_t m_indexToStartOfCells; ///< Index into the global cell array stored in main-grid where this grids cells starts.
size_t m_cellCountIJK;
size_t m_cellCountIJ;
private:
std::string m_gridName;