Refactor: Change RigGridBase::cellCornerVertices to return std::array

Refactored RigGridBase::cellCornerVertices to return std::array<cvf::Vec3d, 8> by value instead of taking a reference to std::array as an output parameter. This change improves code readability and leverages modern C++ return value optimizations.

Updated all call sites across the codebase to reflect the new function signature.
This commit is contained in:
Kristian Bendiksen committed 2025-09-03 14:21:19 +02:00
1 parent da69eef72b
commit 10182e99a7
41 files changed
+148 -214

No files matched your search

@@ -195,8 +195,7 @@ void RigEclipseToStimPlanCellTransmissibilityCalculator::calculateStimPlanCellsM
const RigMainGrid* mainGrid = m_case->eclipseCaseData()->mainGrid();
if ( !m_fracture->isEclipseCellOpenForFlow( mainGrid, reservoirCellIndicesOpenForFlow, reservoirCellIndex ) ) continue;
std::array<cvf::Vec3d, 8> hexCorners;
mainGrid->cellCornerVertices( reservoirCellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = mainGrid->cellCornerVertices( reservoirCellIndex );
std::vector<std::vector<cvf::Vec3d>> planeCellPolygons;
bool isPlanIntersected = RigHexIntersectionTools::planeHexIntersectionPolygons( hexCorners, m_fractureTransform, planeCellPolygons );
@@ -257,14 +257,12 @@ size_t RigEclipseContourMapProjection::kLayers() const
//--------------------------------------------------------------------------------------------------
double RigEclipseContourMapProjection::calculateOverlapVolume( size_t globalCellIdx, const cvf::BoundingBox& bbox ) const
{
std::array<cvf::Vec3d, 8> hexCorners;
const RigCell& cell = m_mainGrid->cell( globalCellIdx );
size_t localCellIdx = cell.gridLocalCellIndex();
RigGridBase* localGrid = cell.hostGrid();
localGrid->cellCornerVertices( localCellIdx, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = localGrid->cellCornerVertices( localCellIdx );
cvf::BoundingBox overlapBBox;
std::array<cvf::Vec3d, 8> overlapCorners;
@@ -283,17 +281,15 @@ double RigEclipseContourMapProjection::calculateRayLengthInCell( size_t
const cvf::Vec3d& highestPoint,
const cvf::Vec3d& lowestPoint ) const
{
std::array<cvf::Vec3d, 8> hexCorners;
const RigCell& cell = m_mainGrid->cell( globalCellIdx );
size_t localCellIdx = cell.gridLocalCellIndex();
RigGridBase* localGrid = cell.hostGrid();
localGrid->cellCornerVertices( localCellIdx, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = localGrid->cellCornerVertices( localCellIdx );
std::vector<HexIntersectionInfo> intersections;
if ( RigHexIntersectionTools::lineHexCellIntersection( highestPoint, lowestPoint, hexCorners.data(), 0, &intersections ) )
if ( RigHexIntersectionTools::lineHexCellIntersection( highestPoint, lowestPoint, hexCorners, 0, &intersections ) )
{
double lengthInCell = ( intersections.back().m_intersectionPoint - intersections.front().m_intersectionPoint ).length();
return lengthInCell;
@@ -89,8 +89,7 @@ cvf::BoundingBox RigGeoMechContourMapProjection::calculateExpandedPorBarBBox( Ri
if ( validPorValue )
{
std::array<cvf::Vec3d, 8> hexCorners;
femPartGrid->cellCornerVertices( i, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = femPartGrid->cellCornerVertices( i );
for ( size_t c = 0; c < 8; ++c )
{
boundingBox.add( hexCorners[c] );
@@ -287,8 +286,7 @@ size_t RigGeoMechContourMapProjection::kLayers() const
//--------------------------------------------------------------------------------------------------
double RigGeoMechContourMapProjection::calculateOverlapVolume( size_t globalCellIdx, const cvf::BoundingBox& bbox ) const
{
std::array<cvf::Vec3d, 8> hexCorners;
m_femPartGrid->cellCornerVertices( globalCellIdx, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = m_femPartGrid->cellCornerVertices( globalCellIdx );
cvf::BoundingBox overlapBBox;
std::array<cvf::Vec3d, 8> overlapCorners;
@@ -307,23 +305,11 @@ double RigGeoMechContourMapProjection::calculateRayLengthInCell( size_t
const cvf::Vec3d& highestPoint,
const cvf::Vec3d& lowestPoint ) const
{
std::array<cvf::Vec3d, 8> hexCorners;
const std::vector<cvf::Vec3f>& nodeCoords = m_femPart->nodes().coordinates;
const int* cornerIndices = m_femPart->connectivities( globalCellIdx );
hexCorners[0] = cvf::Vec3d( nodeCoords[cornerIndices[0]] );
hexCorners[1] = cvf::Vec3d( nodeCoords[cornerIndices[1]] );
hexCorners[2] = cvf::Vec3d( nodeCoords[cornerIndices[2]] );
hexCorners[3] = cvf::Vec3d( nodeCoords[cornerIndices[3]] );
hexCorners[4] = cvf::Vec3d( nodeCoords[cornerIndices[4]] );
hexCorners[5] = cvf::Vec3d( nodeCoords[cornerIndices[5]] );
hexCorners[6] = cvf::Vec3d( nodeCoords[cornerIndices[6]] );
hexCorners[7] = cvf::Vec3d( nodeCoords[cornerIndices[7]] );
std::array<cvf::Vec3d, 8> hexCorners = m_femPartGrid->cellCornerVertices( globalCellIdx );
std::vector<HexIntersectionInfo> intersections;
if ( RigHexIntersectionTools::lineHexCellIntersection( highestPoint, lowestPoint, hexCorners.data(), 0, &intersections ) )
if ( RigHexIntersectionTools::lineHexCellIntersection( highestPoint, lowestPoint, hexCorners, 0, &intersections ) )
{
double lengthInCell = ( intersections.back().m_intersectionPoint - intersections.front().m_intersectionPoint ).length();
return lengthInCell;
@@ -417,17 +417,17 @@ void RigCell::faceIndices( cvf::StructGridInterface::FaceType face, std::array<s
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox RigCell::boundingBox() const
{
cvf::BoundingBox bb;
std::array<cvf::Vec3d, 8> hexCorners;
cvf::BoundingBox bb;
if ( m_hostGrid )
{
m_hostGrid->cellCornerVertices( m_gridLocalCellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = m_hostGrid->cellCornerVertices( m_gridLocalCellIndex );
for ( const auto& corner : hexCorners )
{
bb.add( corner );
}
}
return bb;
}
@@ -663,12 +663,11 @@ void RigEclipseCaseData::computeActiveCellsGeometryBoundingBoxSlow()
}
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 );
std::array<cvf::Vec3d, 8> hexCorners = m_mainGrid->cellCornerVertices( i );
for ( const auto& corner : hexCorners )
{
bb.add( corner );
@@ -731,8 +730,7 @@ void RigEclipseCaseData::computeActiveCellsGeometryBoundingBoxOptimized()
{
size_t cellIndex = m_mainGrid->cellIndexFromIJK( i, j, k );
std::array<cvf::Vec3d, 8> hexCorners;
m_mainGrid->cellCornerVertices( cellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = m_mainGrid->cellCornerVertices( cellIndex );
for ( const auto& corner : hexCorners )
{
bb.add( corner );
@@ -167,8 +167,9 @@ void RigGridBase::initSubCellsMainGridCellIndex()
/// the cell() call retreives correct cell, because main grid has offset of 0, and we access the global
/// cell array in main grid.
//--------------------------------------------------------------------------------------------------
void RigGridBase::cellCornerVertices( size_t cellIndex, std::array<cvf::Vec3d, 8>& vertices ) const
std::array<cvf::Vec3d, 8> RigGridBase::cellCornerVertices( size_t cellIndex ) const
{
std::array<cvf::Vec3d, 8> vertices;
const std::array<size_t, 8>& indices = cell( cellIndex ).cornerIndices();
vertices[0].set( m_mainGrid->nodes()[indices[0]] );
@@ -179,6 +180,8 @@ void RigGridBase::cellCornerVertices( size_t cellIndex, std::array<cvf::Vec3d, 8
vertices[5].set( m_mainGrid->nodes()[indices[5]] );
vertices[6].set( m_mainGrid->nodes()[indices[6]] );
vertices[7].set( m_mainGrid->nodes()[indices[7]] );
return vertices;
}
//--------------------------------------------------------------------------------------------------
@@ -493,12 +496,9 @@ cvf::BoundingBox RigGridBase::boundingBox()
{
if ( !m_boundingBox.isValid() )
{
std::array<cvf::Vec3d, 8> cornerVerts;
for ( size_t i = 0; i < cellCount(); i++ )
{
cellCornerVertices( i, cornerVerts );
std::array<cvf::Vec3d, 8> cornerVerts = cellCornerVertices( i );
for ( size_t j = 0; j < 8; j++ )
{
m_boundingBox.add( cornerVerts[j] );
@@ -104,8 +104,8 @@ public:
bool cellIJKFromCoordinate( const cvf::Vec3d& coord, size_t* i, size_t* j, size_t* k ) const override; // unused
void cellMinMaxCordinates( size_t cellIndex, cvf::Vec3d* minCoordinate, cvf::Vec3d* maxCoordinate ) const override; // unused
void cellCornerVertices( size_t cellIndex, std::array<cvf::Vec3d, 8>& vertices ) const override;
cvf::Vec3d cellCentroid( size_t cellIndex ) const override;
std::array<cvf::Vec3d, 8> cellCornerVertices( size_t cellIndex ) const override;
cvf::Vec3d cellCentroid( size_t cellIndex ) const override;
size_t gridPointIndexFromIJK( size_t i, size_t j, size_t k ) const override;
cvf::Vec3d gridPointCoordinate( size_t i, size_t j, size_t k ) const override;
@@ -28,9 +28,9 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RigHexIntersectionTools::lineHexCellIntersection( const cvf::Vec3d p1,
const cvf::Vec3d p2,
const cvf::Vec3d hexCorners[8],
int RigHexIntersectionTools::lineHexCellIntersection( const cvf::Vec3d& p1,
const cvf::Vec3d& p2,
const std::array<cvf::Vec3d, 8>& hexCorners,
const size_t hexIndex,
std::vector<HexIntersectionInfo>* intersections )
{
@@ -82,7 +82,7 @@ int RigHexIntersectionTools::lineHexCellIntersection( const cvf::Vec3d
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigHexIntersectionTools::lineIntersectsHexCell( const cvf::Vec3d p1, const cvf::Vec3d p2, const cvf::Vec3d hexCorners[8] )
bool RigHexIntersectionTools::lineIntersectsHexCell( const cvf::Vec3d& p1, const cvf::Vec3d& p2, const std::array<cvf::Vec3d, 8>& hexCorners )
{
for ( int face = 0; face < 6; ++face )
{
@@ -119,7 +119,7 @@ bool RigHexIntersectionTools::lineIntersectsHexCell( const cvf::Vec3d p1, const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigHexIntersectionTools::isPointInCell( const cvf::Vec3d point, const std::array<cvf::Vec3d, 8>& hexCorners )
bool RigHexIntersectionTools::isPointInCell( const cvf::Vec3d& point, const std::array<cvf::Vec3d, 8>& hexCorners )
{
cvf::Ray ray;
ray.setOrigin( point );
@@ -149,7 +149,7 @@ bool RigHexIntersectionTools::isPointInCell( const cvf::Vec3d point, const std::
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigHexIntersectionTools::planeHexCellIntersection( cvf::Vec3d* hexCorners,
bool RigHexIntersectionTools::planeHexCellIntersection( const std::array<cvf::Vec3d, 8>& hexCorners,
const cvf::Plane& fracturePlane,
std::list<std::pair<cvf::Vec3d, cvf::Vec3d>>& intersectionLineSegments )
{
@@ -196,7 +196,7 @@ bool RigHexIntersectionTools::planeHexCellIntersection( cvf::Vec3d*
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigHexIntersectionTools::planeHexIntersectionPolygons( std::array<cvf::Vec3d, 8> hexCorners,
bool RigHexIntersectionTools::planeHexIntersectionPolygons( const std::array<cvf::Vec3d, 8>& hexCorners,
cvf::Mat4d transformMatrixForPlane,
std::vector<std::vector<cvf::Vec3d>>& polygons )
{
@@ -208,7 +208,7 @@ bool RigHexIntersectionTools::planeHexIntersectionPolygons( std::array<cvf::Vec3
// Find line-segments where cell and fracture plane intersects
std::list<std::pair<cvf::Vec3d, cvf::Vec3d>> intersectionLineSegments;
isCellIntersected = planeHexCellIntersection( hexCorners.data(), fracturePlane, intersectionLineSegments );
isCellIntersected = planeHexCellIntersection( hexCorners, fracturePlane, intersectionLineSegments );
RigCellGeometryTools::createPolygonFromLineSegments( intersectionLineSegments, polygons );
@@ -52,21 +52,21 @@ bool operator<( const HexIntersectionInfo& hi1, const HexIntersectionInfo& hi2 )
//--------------------------------------------------------------------------------------------------
struct RigHexIntersectionTools
{
static int lineHexCellIntersection( const cvf::Vec3d p1,
const cvf::Vec3d p2,
const cvf::Vec3d hexCorners[8],
static int lineHexCellIntersection( const cvf::Vec3d& p1,
const cvf::Vec3d& p2,
const std::array<cvf::Vec3d, 8>& hexCorners,
const size_t hexIndex,
std::vector<HexIntersectionInfo>* intersections );
static bool lineIntersectsHexCell( const cvf::Vec3d p1, const cvf::Vec3d p2, const cvf::Vec3d hexCorners[8] );
static bool lineIntersectsHexCell( const cvf::Vec3d& p1, const cvf::Vec3d& p2, const std::array<cvf::Vec3d, 8>& hexCorners );
static bool isPointInCell( const cvf::Vec3d point, const std::array<cvf::Vec3d, 8>& hexCorners );
static bool isPointInCell( const cvf::Vec3d& point, const std::array<cvf::Vec3d, 8>& hexCorners );
static bool planeHexCellIntersection( cvf::Vec3d* hexCorners,
static bool planeHexCellIntersection( const std::array<cvf::Vec3d, 8>& hexCorners,
const cvf::Plane& fracturePlane,
std::list<std::pair<cvf::Vec3d, cvf::Vec3d>>& intersectionLineSegments );
static bool planeHexIntersectionPolygons( std::array<cvf::Vec3d, 8> hexCorners,
static bool planeHexIntersectionPolygons( const std::array<cvf::Vec3d, 8>& hexCorners,
cvf::Mat4d transformMatrixForPlane,
std::vector<std::vector<cvf::Vec3d>>& polygons );
};
@@ -156,26 +156,21 @@ size_t RigMainGrid::reservoirCellIndexByGridAndGridLocalCellIndex( size_t gridId
//--------------------------------------------------------------------------------------------------
size_t RigMainGrid::findReservoirCellIndexFromPoint( const cvf::Vec3d& point ) const
{
size_t cellContainingPoint = cvf::UNDEFINED_SIZE_T;
cvf::BoundingBox pointBBox;
pointBBox.add( point );
std::vector<size_t> cellIndices = m_mainGrid->findIntersectingCells( pointBBox );
std::array<cvf::Vec3d, 8> hexCorners;
for ( size_t cellIndex : cellIndices )
{
m_mainGrid->cellCornerVertices( cellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = m_mainGrid->cellCornerVertices( cellIndex );
if ( RigHexIntersectionTools::isPointInCell( point, hexCorners ) )
{
cellContainingPoint = cellIndex;
break;
return cellIndex;
}
}
return cellContainingPoint;
return cvf::UNDEFINED_SIZE_T;
}
//--------------------------------------------------------------------------------------------------
@@ -75,16 +75,14 @@ void RigEclipseWellLogExtractor::calculateIntersection()
std::vector<size_t> closeCellIndices = findCloseCellIndices( bb );
std::array<cvf::Vec3d, 8> hexCorners;
for ( const auto& globalCellIndex : closeCellIndices )
{
const RigCell& cell = m_caseData->mainGrid()->cell( globalCellIndex );
if ( cell.isInvalid() || cell.subGrid() != nullptr ) continue;
m_caseData->mainGrid()->cellCornerVertices( globalCellIndex, hexCorners );
RigHexIntersectionTools::lineHexCellIntersection( p1, p2, hexCorners.data(), globalCellIndex, &intersections );
std::array<cvf::Vec3d, 8> hexCorners = m_caseData->mainGrid()->cellCornerVertices( globalCellIndex );
RigHexIntersectionTools::lineHexCellIntersection( p1, p2, hexCorners, globalCellIndex, &intersections );
}
if ( !isCellFaceNormalsOut )
@@ -121,15 +119,13 @@ void RigEclipseWellLogExtractor::calculateIntersection()
std::vector<size_t> closeCellIndices = findCloseCellIndices( bb );
std::array<cvf::Vec3d, 8> hexCorners;
for ( const auto& globalCellIndex : closeCellIndices )
{
const RigCell& cell = m_caseData->mainGrid()->cell( globalCellIndex );
if ( cell.isInvalid() ) continue;
m_caseData->mainGrid()->cellCornerVertices( globalCellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = m_caseData->mainGrid()->cellCornerVertices( globalCellIndex );
if ( RigHexIntersectionTools::isPointInCell( firstPoint, hexCorners ) )
{
if ( RigHexIntersectionTools::isPointInCell( lastPoint, hexCorners ) )
@@ -202,8 +198,7 @@ std::vector<size_t> RigEclipseWellLogExtractor::findCloseCellIndices( const cvf:
//--------------------------------------------------------------------------------------------------
cvf::Vec3d RigEclipseWellLogExtractor::calculateLengthInCell( size_t cellIndex, const cvf::Vec3d& startPoint, const cvf::Vec3d& endPoint ) const
{
std::array<cvf::Vec3d, 8> hexCorners;
m_caseData->mainGrid()->cellCornerVertices( cellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = m_caseData->mainGrid()->cellCornerVertices( cellIndex );
return RigWellPathIntersectionTools::calculateLengthInCell( hexCorners, startPoint, endPoint );
}
@@ -1139,7 +1139,6 @@ void RigGeoMechWellLogExtractor::calculateIntersection()
std::vector<size_t> closeCells = findCloseCells( bb );
cvf::Vec3d hexCorners[8];
for ( size_t ccIdx = 0; ccIdx < closeCells.size(); ++ccIdx )
{
RigElementType elmType = femPart->elementType( closeCells[ccIdx] );
@@ -1147,6 +1146,8 @@ void RigGeoMechWellLogExtractor::calculateIntersection()
const int* cornerIndices = femPart->connectivities( closeCells[ccIdx] );
std::array<cvf::Vec3d, 8> hexCorners;
hexCorners[0] = cvf::Vec3d( nodeCoords[cornerIndices[0]] );
hexCorners[1] = cvf::Vec3d( nodeCoords[cornerIndices[1]] );
hexCorners[2] = cvf::Vec3d( nodeCoords[cornerIndices[2]] );
@@ -142,8 +142,7 @@ cvf::Vec3d RigWellPathIntersectionTools::calculateLengthInCell( const RigMainGri
const cvf::Vec3d& startPoint,
const cvf::Vec3d& endPoint )
{
std::array<cvf::Vec3d, 8> hexCorners;
grid->cellCornerVertices( cellIndex, hexCorners );
std::array<cvf::Vec3d, 8> hexCorners = grid->cellCornerVertices( cellIndex );
return calculateLengthInCell( hexCorners, startPoint, endPoint );
}