Minor improvements to fault calculations

This commit is contained in:
Gaute Lindkvist 2020-05-14 10:11:51 +02:00
parent 8bfcaa0341
commit de824f2543
3 changed files with 26 additions and 6 deletions

View File

@ -43,7 +43,7 @@ cvf::StructGridInterface::FaceType
{
// Try to find the shared face
bool isPossibleNeighborInDirection[6] = {true, true, true, true, true, true};
bool isPossibleNeighborInDirection[6] = { true, true, true, true, true, true };
if ( c1.hostGrid() == c2.hostGrid() )
{
@ -243,7 +243,7 @@ void RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultF
size_t i;
size_t j;
size_t k;
mainGrid->ijkFromCellIndex( sourceReservoirCellIndex, &i, &j, &k );
mainGrid->ijkFromCellIndexNonGuarded( sourceReservoirCellIndex, &i, &j, &k );
mainGrid->neighborIJKAtCellFace( i, j, k, sourceCellFace, &ni, &nj, &nk );
@ -261,14 +261,14 @@ void RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultF
continue;
}
if ( candidateCellIndex == neighborCellIndex )
if ( candidateCellIndex >= mainGrid->cellCount() )
{
// Exclude direct neighbor
continue;
}
if ( candidateCellIndex >= mainGrid->cellCount() )
if ( candidateCellIndex == neighborCellIndex )
{
// Exclude direct neighbor
continue;
}
@ -280,7 +280,7 @@ void RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultF
size_t ci = std::numeric_limits<size_t>::max();
size_t cj = std::numeric_limits<size_t>::max();
size_t ck = std::numeric_limits<size_t>::max();
mainGrid->ijkFromCellIndex( candidateCellIndex, &ci, &cj, &ck );
mainGrid->ijkFromCellIndexNonGuarded( candidateCellIndex, &ci, &cj, &ck );
auto gridAxis = cvf::StructGridInterface::gridAxisFromFace( sourceCellFace );
if ( gridAxis == cvf::StructGridInterface::GridAxisType::AXIS_I )

View File

@ -216,6 +216,25 @@ bool RigGridBase::ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size
return true;
}
//--------------------------------------------------------------------------------------------------
/// This version does no if-guarding. Check that all dimensions of the grid are non-zero before using.
/// Useful for running in a loop after doing the sanity check once.
//--------------------------------------------------------------------------------------------------
void RigGridBase::ijkFromCellIndexNonGuarded( size_t cellIndex, size_t* i, size_t* j, size_t* k ) const
{
size_t index = cellIndex;
size_t cellCountI = m_gridPointDimensions[0] - 1;
size_t cellCountJ = m_gridPointDimensions[1] - 1;
size_t cellCountK = m_gridPointDimensions[2] - 1;
*k = index / ( cellCountI * cellCountJ );
index -= ( *k ) * ( cellCountI * cellCountJ );
*j = index / cellCountI;
index -= ( *j ) * cellCountI;
*i = index;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -93,6 +93,7 @@ public:
size_t cellIndexFromIJK( size_t i, size_t j, size_t k ) const override;
size_t cellIndexFromIJKUnguarded( size_t i, size_t j, size_t k ) const;
bool ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size_t* k ) const override;
void ijkFromCellIndexNonGuarded( size_t cellIndex, size_t* i, size_t* j, size_t* k ) const;
bool cellIJKFromCoordinate( const cvf::Vec3d& coord, size_t* i, size_t* j, size_t* k ) const override;
void cellCornerVertices( size_t cellIndex, cvf::Vec3d vertices[8] ) const override;