From 10182e99a74ebc88f4e354edb2a170d1308df2ce Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 27 Aug 2025 14:41:06 +0000 Subject: [PATCH] Refactor: Change RigGridBase::cellCornerVertices to return std::array Refactored RigGridBase::cellCornerVertices to return std::array 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. --- .../Commands/RicCreateTemporaryLgrFeature.cpp | 3 +- .../RicCreateWellTargetsPickEventHandler.cpp | 6 ++-- .../RifEclipseInputFileTools.cpp | 3 +- .../FileInterface/RifReaderEclipseWell.cpp | 9 +++--- .../GeoMechDataModel/RigFemPartGrid.cpp | 7 +++-- .../GeoMech/GeoMechDataModel/RigFemPartGrid.h | 2 +- .../RigFemPartResultCalculatorCompaction.cpp | 26 ++++++++-------- .../Faults/RivFaultGeometryGenerator.cpp | 5 ++-- .../RivBoxIntersectionGeometryGenerator.cpp | 6 ++-- .../RivEclipseIntersectionGrid.cpp | 10 +++---- .../RivEclipseIntersectionGrid.h | 12 ++++---- ...udedCurveIntersectionGeometryGenerator.cpp | 6 ++-- .../Intersections/RivFemIntersectionGrid.cpp | 11 +++++-- .../Intersections/RivFemIntersectionGrid.h | 12 ++++---- .../RivIntersectionHexGridInterface.h | 12 ++++---- .../RivWellFracturePartMgr.cpp | 10 ++----- ...ivSurfaceIntersectionGeometryGenerator.cpp | 7 ++--- .../CellFilters/RimPolygonFilter.cpp | 30 +++++++------------ .../RimFractureContainmentTools.cpp | 6 ++-- .../GeoMech/RimGeoMechCase.cpp | 3 +- .../Surfaces/RimGridCaseSurface.cpp | 11 +++---- ...StimPlanCellTransmissibilityCalculator.cpp | 3 +- .../RigEclipseContourMapProjection.cpp | 10 ++----- .../RigGeoMechContourMapProjection.cpp | 22 +++----------- .../ReservoirDataModel/RigCell.cpp | 6 ++-- .../ReservoirDataModel/RigEclipseCaseData.cpp | 6 ++-- .../ReservoirDataModel/RigGridBase.cpp | 10 +++---- .../ReservoirDataModel/RigGridBase.h | 4 +-- .../RigHexIntersectionTools.cpp | 16 +++++----- .../RigHexIntersectionTools.h | 14 ++++----- .../ReservoirDataModel/RigMainGrid.cpp | 11 ++----- .../Well/RigEclipseWellLogExtractor.cpp | 13 +++----- .../Well/RigGeoMechWellLogExtractor.cpp | 3 +- .../Well/RigWellPathIntersectionTools.cpp | 3 +- .../SocketInterface/RiaGeometryCommands.cpp | 17 +++++------ .../RigHexIntersectionTools-Test.cpp | 4 +-- Fwk/AppFwk/CommonCode/cvfStructGrid.cpp | 5 ++-- Fwk/AppFwk/CommonCode/cvfStructGrid.h | 4 +-- .../cvfStructGridGeometryGenerator.cpp | 6 ++-- GrpcInterface/RiaGrpcCaseService.cpp | 5 ++-- GrpcInterface/RiaGrpcGridService.cpp | 3 +- 41 files changed, 148 insertions(+), 214 deletions(-) diff --git a/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp b/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp index ad7156cfed..618257bf78 100644 --- a/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp +++ b/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp @@ -242,8 +242,7 @@ void RicCreateTemporaryLgrFeature::createLgr( const LgrInfo& lgrInfo, RigMainGri // Corner coordinates { size_t cIdx; - std::array vertices; - mainGrid->cellCornerVertices( mainCellIndex, vertices ); + std::array vertices = mainGrid->cellCornerVertices( mainCellIndex ); auto cellCounts = lgrInfo.sizesPerMainGridCell(); auto lgrCoords = RiaCellDividingTools::createHexCornerCoords( vertices, cellCounts.i(), cellCounts.j(), cellCounts.k() ); diff --git a/ApplicationLibCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp b/ApplicationLibCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp index f230b2e55a..d34396fbc6 100644 --- a/ApplicationLibCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp +++ b/ApplicationLibCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp @@ -223,7 +223,7 @@ cvf::Vec3d RicCreateWellTargetsPickEventHandler::findHexElementIntersection( gsl if ( eclipseView && eclipseView->mainGrid() ) { RigGridBase* hitGrid = eclipseView->mainGrid()->gridByIndex( gridIndex ); - hitGrid->cellCornerVertices( cellIndex, cornerVertices ); + cornerVertices = hitGrid->cellCornerVertices( cellIndex ); } } } @@ -244,7 +244,7 @@ cvf::Vec3d RicCreateWellTargetsPickEventHandler::findHexElementIntersection( gsl { cellIndex = elementIndex; const RigFemPartGrid* femGrid = femPart->getOrCreateStructGrid(); - femGrid->cellCornerVertices( cellIndex, cornerVertices ); + cornerVertices = femGrid->cellCornerVertices( cellIndex ); } } } @@ -253,7 +253,7 @@ cvf::Vec3d RicCreateWellTargetsPickEventHandler::findHexElementIntersection( gsl if ( cellIndex ) { std::vector intersectionInfo; - RigHexIntersectionTools::lineHexCellIntersection( domainRayOrigin, domainRayEnd, cornerVertices.data(), cellIndex, &intersectionInfo ); + RigHexIntersectionTools::lineHexCellIntersection( domainRayOrigin, domainRayEnd, cornerVertices, cellIndex, &intersectionInfo ); if ( intersectionInfo.empty() ) return cvf::Vec3d::UNDEFINED; diff --git a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp index 2e707e72ad..6a8ec4077c 100644 --- a/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp +++ b/ApplicationLibCode/FileInterface/RifEclipseInputFileTools.cpp @@ -291,8 +291,7 @@ bool RifEclipseInputFileTools::exportGrid( const QString& fileName, { active = ( *cellVisibilityOverrideForActnum )[mainIndex]; } - std::array cellCorners; - mainGrid->cellCornerVertices( mainIndex, cellCorners ); + std::array cellCorners = mainGrid->cellCornerVertices( mainIndex ); if ( mainGrid->useMapAxes() ) { diff --git a/ApplicationLibCode/FileInterface/RifReaderEclipseWell.cpp b/ApplicationLibCode/FileInterface/RifReaderEclipseWell.cpp index b18c49e6d8..6d5edd12ca 100644 --- a/ApplicationLibCode/FileInterface/RifReaderEclipseWell.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderEclipseWell.cpp @@ -652,11 +652,10 @@ void RifReaderEclipseWell::readWellCells( RifEclipseRestartDataAccess* restartDa well_conn_type* ert_connection = well_conn_collection_iget( connections, 0 ); RigWellResultPoint point = RifReaderEclipseWell::createWellResultPoint( eclipseCaseData, grids[gridNr], ert_connection, segment, wellName ); - lastConnectionPos = grids[gridNr]->cell( point.cellIndex() ).center(); - std::array cellVxes; - grids[gridNr]->cellCornerVertices( point.cellIndex(), cellVxes ); - lastConnectionCellCorner = cellVxes[0]; - lastConnectionCellSize = ( lastConnectionPos - cellVxes[0] ).length(); + lastConnectionPos = grids[gridNr]->cell( point.cellIndex() ).center(); + std::array cellVxes = grids[gridNr]->cellCornerVertices( point.cellIndex() ); + lastConnectionCellCorner = cellVxes[0]; + lastConnectionCellSize = ( lastConnectionPos - cellVxes[0] ).length(); lastConnectionSegmentId = well_segment_get_id( segment ); accLengthFromLastConnection = well_segment_get_length( segment ) / ( connectionCount + 1 ); diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp index fbcb8e56e6..af73aa3d56 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.cpp @@ -440,15 +440,17 @@ bool RigFemPartGrid::cellIJKFromCoordinate( const cvf::Vec3d& coord, size_t* i, //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigFemPartGrid::cellCornerVertices( size_t cellIndex, std::array& vertices ) const +std::array RigFemPartGrid::cellCornerVertices( size_t cellIndex ) const { const std::vector& nodeCoords = m_femPart->nodes().coordinates; const int* cornerIndices = m_femPart->connectivities( cellIndex ); + std::array vertices; for ( size_t i = 0; i < 8; ++i ) { vertices[i] = cvf::Vec3d( nodeCoords[cornerIndices[i]] ); } + return vertices; } //-------------------------------------------------------------------------------------------------- @@ -456,8 +458,7 @@ void RigFemPartGrid::cellCornerVertices( size_t cellIndex, std::array cellVertices; - cellCornerVertices( cellIndex, cellVertices ); + std::array cellVertices = cellCornerVertices( cellIndex ); cvf::Vec3d centroid( 0.0, 0.0, 0.0 ); for ( int i = 0; i < 8; ++i ) diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h index 4dd9eb1a05..926e432a4d 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartGrid.h @@ -43,7 +43,7 @@ public: cvf::Vec3i findMainIJKFaces( int elementIndex ) const; std::pair reservoirIJKBoundingBox() const; - void cellCornerVertices( size_t cellIndex, std::array& vertices ) const override; + std::array cellCornerVertices( size_t cellIndex ) const override; cvf::Vec3d cellCentroid( size_t cellIndex ) const override; private: diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorCompaction.cpp b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorCompaction.cpp index bc09c421bf..7e9753a510 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorCompaction.cpp +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartResultCalculatorCompaction.cpp @@ -44,9 +44,9 @@ public: std::vector elementFaceNodeIdxs; }; -static std::vector coordsFromNodeIndices( const RigFemPart& part, const std::vector& nodeIdxs ); -static std::vector nodesForElement( const RigFemPart& part, size_t elementIdx ); -static float horizontalDistance( const cvf::Vec3f& p1, const cvf::Vec3f& p2 ); +static std::array coordsFromNodeIndices( const RigFemPart& part, const std::array& nodeIdxs ); +static std::array nodesForElement( const RigFemPart& part, size_t elementIdx ); +static float horizontalDistance( const cvf::Vec3f& p1, const cvf::Vec3f& p2 ); static void findReferenceElementForNode( const RigFemPart& part, size_t nodeIdx, size_t kRefLayer, RefElement* refElement ); //-------------------------------------------------------------------------------------------------- @@ -175,13 +175,13 @@ void findReferenceElementForNode( const RigFemPart& part, size_t nodeIdx, size_t bool validIndex = grid->ijkFromCellIndex( elemIdx, &i, &j, &k ); if ( validIndex && k == kRefLayer ) { - const std::vector nodeIndices = nodesForElement( part, elemIdx ); + const std::array nodeIndices = nodesForElement( part, elemIdx ); CVF_ASSERT( nodeIndices.size() == 8 ); std::vector intersections; RigHexIntersectionTools::lineHexCellIntersection( cvf::Vec3d( p1 ), cvf::Vec3d( p2 ), - coordsFromNodeIndices( part, nodeIndices ).data(), + coordsFromNodeIndices( part, nodeIndices ), elemIdx, &intersections ); @@ -210,23 +210,23 @@ void findReferenceElementForNode( const RigFemPart& part, size_t nodeIdx, size_t //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector coordsFromNodeIndices( const RigFemPart& part, const std::vector& nodeIdxs ) +std::array coordsFromNodeIndices( const RigFemPart& part, const std::array& nodeIdxs ) { - std::vector out; - for ( const auto& nodeIdx : nodeIdxs ) - out.push_back( cvf::Vec3d( part.nodes().coordinates[nodeIdx] ) ); + std::array out; + for ( size_t i = 0; i < nodeIdxs.size(); i++ ) + out[i] = cvf::Vec3d( part.nodes().coordinates[nodeIdxs[i]] ); return out; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector nodesForElement( const RigFemPart& part, size_t elementIdx ) +std::array nodesForElement( const RigFemPart& part, size_t elementIdx ) { - std::vector nodeIdxs; - const int* nodeConn = part.connectivities( elementIdx ); + std::array nodeIdxs; + const int* nodeConn = part.connectivities( elementIdx ); for ( int n = 0; n < 8; n++ ) - nodeIdxs.push_back( nodeConn[n] ); + nodeIdxs[n] = nodeConn[n]; return nodeIdxs; } diff --git a/ApplicationLibCode/ModelVisualization/Faults/RivFaultGeometryGenerator.cpp b/ApplicationLibCode/ModelVisualization/Faults/RivFaultGeometryGenerator.cpp index e222711108..a9840dbbe3 100644 --- a/ApplicationLibCode/ModelVisualization/Faults/RivFaultGeometryGenerator.cpp +++ b/ApplicationLibCode/ModelVisualization/Faults/RivFaultGeometryGenerator.cpp @@ -178,8 +178,7 @@ void RivFaultGeometryGenerator::computeArrays( bool onlyShowFacesWithDefinedNeig { int myThread = RiaOpenMPTools::currentThreadIndex(); - std::array cornerVerts; - cvf::ubyte faceConn[4]; + cvf::ubyte faceConn[4]; // NB! We are inside a parallel section, do not use "parallel for" here #pragma omp for @@ -200,7 +199,7 @@ void RivFaultGeometryGenerator::computeArrays( bool onlyShowFacesWithDefinedNeig if ( onlyShowFacesWithDefinedNeighbors && !hasConnection( cellIndex, face, connections, connIndices ) ) continue; - m_grid->cellCornerVertices( cellIndex, cornerVerts ); + std::array cornerVerts = m_grid->cellCornerVertices( cellIndex ); cvf::StructGridInterface::cellFaceVertexIndices( face, faceConn ); for ( int n = 0; n < 4; n++ ) diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivBoxIntersectionGeometryGenerator.cpp b/ApplicationLibCode/ModelVisualization/Intersections/RivBoxIntersectionGeometryGenerator.cpp index 9a91c2a9db..f3a687ef9f 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivBoxIntersectionGeometryGenerator.cpp +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivBoxIntersectionGeometryGenerator.cpp @@ -295,8 +295,6 @@ void RivBoxIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray* visi hexPlaneCutTriangleVxes.reserve( 5 * 3 ); std::vector cellFaceForEachTriangleEdge; cellFaceForEachTriangleEdge.reserve( 5 * 3 ); - std::array cellCorners; - std::array cornerIndices; for ( size_t cccIdx = 0; cccIdx < columnCellCandidates.size(); ++cccIdx ) { @@ -306,8 +304,8 @@ void RivBoxIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray* visi if ( !m_hexGrid->useCell( globalCellIdx ) ) continue; hexPlaneCutTriangleVxes.clear(); - m_hexGrid->cellCornerVertices( globalCellIdx, cellCorners ); - m_hexGrid->cellCornerIndices( globalCellIdx, cornerIndices ); + const std::array cellCorners = m_hexGrid->cellCornerVertices( globalCellIdx ); + const std::array cornerIndices = m_hexGrid->cellCornerIndices( globalCellIdx ); caf::HexGridIntersectionTools::planeHexIntersectionMC( plane, cellCorners, diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.cpp b/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.cpp index 434efc6a3a..e67b98fe8b 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.cpp +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.cpp @@ -78,19 +78,17 @@ bool RivEclipseIntersectionGrid::useCell( size_t cellIndex ) const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivEclipseIntersectionGrid::cellCornerVertices( size_t cellIndex, std::array& cellCorners ) const +std::array RivEclipseIntersectionGrid::cellCornerVertices( size_t cellIndex ) const { - m_mainGrid->cellCornerVertices( cellIndex, cellCorners ); + return m_mainGrid->cellCornerVertices( cellIndex ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivEclipseIntersectionGrid::cellCornerIndices( size_t cellIndex, std::array& cornerIndices ) const +std::array RivEclipseIntersectionGrid::cellCornerIndices( size_t cellIndex ) const { - const std::array& cornerIndicesSource = m_mainGrid->cell( cellIndex ).cornerIndices(); - - cornerIndices = cornerIndicesSource; + return m_mainGrid->cell( cellIndex ).cornerIndices(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.h b/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.h index ad1e0f424b..6f65fe215e 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.h +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivEclipseIntersectionGrid.h @@ -40,12 +40,12 @@ class RivEclipseIntersectionGrid : public RivIntersectionHexGridInterface public: RivEclipseIntersectionGrid( const RigMainGrid* mainGrid, const RigActiveCellInfo* activeCellInfo, bool showInactiveCells ); - cvf::Vec3d displayOffset() const override; - cvf::BoundingBox boundingBox() const override; - std::vector findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const override; - bool useCell( size_t cellIndex ) const override; - void cellCornerVertices( size_t cellIndex, std::array& cellCorners ) const override; - void cellCornerIndices( size_t cellIndex, std::array& cornerIndices ) const override; + cvf::Vec3d displayOffset() const override; + cvf::BoundingBox boundingBox() const override; + std::vector findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const override; + bool useCell( size_t cellIndex ) const override; + std::array cellCornerVertices( size_t cellIndex ) const override; + std::array cellCornerIndices( size_t cellIndex ) const override; const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const override; void setKIntervalFilter( bool enabled, std::string kIntervalStr ) override; diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivExtrudedCurveIntersectionGeometryGenerator.cpp b/ApplicationLibCode/ModelVisualization/Intersections/RivExtrudedCurveIntersectionGeometryGenerator.cpp index 7583cafc08..606db6e952 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivExtrudedCurveIntersectionGeometryGenerator.cpp +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivExtrudedCurveIntersectionGeometryGenerator.cpp @@ -377,8 +377,6 @@ void RivExtrudedCurveIntersectionGeometryGenerator::calculateArrays( cvf::UByteA hexPlaneCutTriangleVxes.reserve( 5 * 3 ); std::vector cellFaceForEachTriangleEdge; cellFaceForEachTriangleEdge.reserve( 5 * 3 ); - std::array cellCorners; - std::array cornerIndices; cvf::Mat4d invSectionCS = m_lineSegmentTransforms[pLineIdx][lIdx]; @@ -388,8 +386,8 @@ void RivExtrudedCurveIntersectionGeometryGenerator::calculateArrays( cvf::UByteA if ( !m_hexGrid->useCell( globalCellIdx ) ) continue; hexPlaneCutTriangleVxes.clear(); - m_hexGrid->cellCornerVertices( globalCellIdx, cellCorners ); - m_hexGrid->cellCornerIndices( globalCellIdx, cornerIndices ); + std::array cellCorners = m_hexGrid->cellCornerVertices( globalCellIdx ); + std::array cornerIndices = m_hexGrid->cellCornerIndices( globalCellIdx ); caf::HexGridIntersectionTools::planeHexIntersectionMC( plane, cellCorners, diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.cpp b/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.cpp index 8bc65ea7bb..fc1fd92dc0 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.cpp +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.cpp @@ -71,7 +71,7 @@ bool RivFemIntersectionGrid::useCell( size_t globalCellIndex ) const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivFemIntersectionGrid::cellCornerVertices( size_t globalCellIndex, std::array& cellCorners ) const +std::array RivFemIntersectionGrid::cellCornerVertices( size_t globalCellIndex ) const { auto [part, elementIdx] = m_femParts->partAndElementIndex( globalCellIndex ); @@ -80,6 +80,7 @@ void RivFemIntersectionGrid::cellCornerVertices( size_t globalCellIndex, std::ar const std::vector& nodeCoords = part->nodes().coordinates; const int* cornerIndices = part->connectivities( elementIdx ); + std::array cellCorners; if ( useDisplacements ) { const double scaleFactor = m_parts->currentDisplacementScaleFactor(); @@ -97,25 +98,29 @@ void RivFemIntersectionGrid::cellCornerVertices( size_t globalCellIndex, std::ar cellCorners[i] = cvf::Vec3d( nodeCoords[cornerIndices[i]] ); } } + + return cellCorners; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RivFemIntersectionGrid::cellCornerIndices( size_t globalCellIndex, std::array& cornerIndices ) const +std::array RivFemIntersectionGrid::cellCornerIndices( size_t globalCellIndex ) const { auto [part, elementIdx] = m_femParts->partAndElementIndex( globalCellIndex ); RigElementType elmType = part->elementType( elementIdx ); - if ( !RigFemTypes::is8NodeElement( elmType ) ) return; + if ( !RigFemTypes::is8NodeElement( elmType ) ) return {}; int elmIdx = static_cast( elementIdx ); const int partId = part->elementPartId(); + std::array cornerIndices; for ( int i = 0; i < 8; i++ ) { cornerIndices[i] = m_femParts->globalElementNodeResultIdx( partId, elmIdx, i ); } + return cornerIndices; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.h b/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.h index 0a089ee013..7d7bcbeb33 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.h +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivFemIntersectionGrid.h @@ -38,12 +38,12 @@ class RivFemIntersectionGrid : public RivIntersectionHexGridInterface public: explicit RivFemIntersectionGrid( const RigFemPartCollection* femParts, const RimGeoMechPartCollection* parts ); - cvf::Vec3d displayOffset() const override; - cvf::BoundingBox boundingBox() const override; - std::vector findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const override; - bool useCell( size_t cellIndex ) const override; - void cellCornerVertices( size_t cellIndex, std::array& cellCorners ) const override; - void cellCornerIndices( size_t cellIndex, std::array& cornerIndices ) const override; + cvf::Vec3d displayOffset() const override; + cvf::BoundingBox boundingBox() const override; + std::vector findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const override; + bool useCell( size_t cellIndex ) const override; + std::array cellCornerVertices( size_t cellIndex ) const override; + std::array cellCornerIndices( size_t cellIndex ) const override; const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const override; void setKIntervalFilter( bool enabled, std::string kIntervalStr ) override; diff --git a/ApplicationLibCode/ModelVisualization/Intersections/RivIntersectionHexGridInterface.h b/ApplicationLibCode/ModelVisualization/Intersections/RivIntersectionHexGridInterface.h index 5548087885..1b8f505861 100644 --- a/ApplicationLibCode/ModelVisualization/Intersections/RivIntersectionHexGridInterface.h +++ b/ApplicationLibCode/ModelVisualization/Intersections/RivIntersectionHexGridInterface.h @@ -35,12 +35,12 @@ class RigFault; class RivIntersectionHexGridInterface : public cvf::Object { public: - virtual cvf::Vec3d displayOffset() const = 0; - virtual cvf::BoundingBox boundingBox() const = 0; - virtual std::vector findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const = 0; - virtual bool useCell( size_t cellIndex ) const = 0; - virtual void cellCornerVertices( size_t cellIndex, std::array& cellCorners ) const = 0; - virtual void cellCornerIndices( size_t cellIndex, std::array& cornerIndices ) const = 0; + virtual cvf::Vec3d displayOffset() const = 0; + virtual cvf::BoundingBox boundingBox() const = 0; + virtual std::vector findIntersectingCells( const cvf::BoundingBox& intersectingBB ) const = 0; + virtual bool useCell( size_t cellIndex ) const = 0; + virtual std::array cellCornerVertices( size_t cellIndex ) const = 0; + virtual std::array cellCornerIndices( size_t cellIndex ) const = 0; virtual const RigFault* findFaultFromCellIndexAndCellFace( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const = 0; virtual void setKIntervalFilter( bool enabled, std::string kIntervalStr ) = 0; }; diff --git a/ApplicationLibCode/ModelVisualization/RivWellFracturePartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivWellFracturePartMgr.cpp index f10b7ca00f..812031fa6b 100644 --- a/ApplicationLibCode/ModelVisualization/RivWellFracturePartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivWellFracturePartMgr.cpp @@ -669,8 +669,7 @@ cvf::ref RivWellFracturePartMgr::createContainmentMaskPart( const Rim { // Calculate Eclipse cell intersection with fracture plane - std::array corners; - activeView.mainGrid()->cellCornerVertices( resCellIdx, corners ); + std::array corners = activeView.mainGrid()->cellCornerVertices( resCellIdx ); std::vector> eclCellPolygons; bool hasIntersection = RigHexIntersectionTools::planeHexIntersectionPolygons( corners, frMx, eclCellPolygons ); @@ -796,11 +795,9 @@ cvf::ref RivWellFracturePartMgr::createMaskOfFractureOutsideGrid( con bool pointInsideGrid = false; RigMainGrid* mainGrid = activeView.mainGrid(); - std::array corners; for ( size_t cellIndex : cellCandidates ) { - mainGrid->cellCornerVertices( cellIndex, corners ); - + std::array corners = mainGrid->cellCornerVertices( cellIndex ); if ( RigHexIntersectionTools::isPointInCell( pointInDomainCoords, corners ) ) { pointInsideGrid = true; @@ -822,8 +819,7 @@ cvf::ref RivWellFracturePartMgr::createMaskOfFractureOutsideGrid( con { // Calculate Eclipse cell intersection with fracture plane - std::array corners; - activeView.mainGrid()->cellCornerVertices( resCellIdx, corners ); + std::array corners = activeView.mainGrid()->cellCornerVertices( resCellIdx ); std::vector> eclCellPolygons; bool hasIntersection = RigHexIntersectionTools::planeHexIntersectionPolygons( corners, frMx, eclCellPolygons ); diff --git a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfaceIntersectionGeometryGenerator.cpp b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfaceIntersectionGeometryGenerator.cpp index c6584f285d..8e25f6a0cc 100644 --- a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfaceIntersectionGeometryGenerator.cpp +++ b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfaceIntersectionGeometryGenerator.cpp @@ -197,9 +197,6 @@ void RivSurfaceIntersectionGeometryGenerator::calculateArrays() cvf::Plane plane; plane.setFromPoints( p0, p1, p2 ); - std::array cellCorners; - std::array cornerIndices; - for ( size_t globalCellIdx : triIntersectedCellCandidates ) { if ( !m_hexGrid->useCell( globalCellIdx ) ) continue; @@ -208,8 +205,8 @@ void RivSurfaceIntersectionGeometryGenerator::calculateArrays() cellFaceForEachTriangleEdge.clear(); cellCutTriangles.clear(); - m_hexGrid->cellCornerVertices( globalCellIdx, cellCorners ); - m_hexGrid->cellCornerIndices( globalCellIdx, cornerIndices ); + const std::array cellCorners = m_hexGrid->cellCornerVertices( globalCellIdx ); + const std::array cornerIndices = m_hexGrid->cellCornerIndices( globalCellIdx ); int triangleCount = caf::HexGridIntersectionTools::planeHexIntersectionMCTet( plane, cellCorners, diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp index 87e0a913d5..92422dbe00 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimPolygonFilter.cpp @@ -478,8 +478,7 @@ void RimPolygonFilter::updateCellsDepthEclipse( const std::vector& p if ( cell.isInvalid() ) continue; // get corner coordinates - std::array hexCorners; - grid->cellCornerVertices( n, hexCorners ); + std::array hexCorners = grid->cellCornerVertices( n ); // get cell ijk for k filter size_t i, j, k; @@ -521,8 +520,7 @@ void RimPolygonFilter::updateCellsKIndexEclipse( const std::vector& if ( cell.isInvalid() ) continue; // get corner coordinates - std::array hexCorners; - grid->cellCornerVertices( cellIdx, hexCorners ); + std::array hexCorners = grid->cellCornerVertices( cellIdx ); if ( closedPolygon ) { @@ -624,16 +622,11 @@ void RimPolygonFilter::updateCellsDepthGeoMech( const std::vector& p size_t cellIdx = grid->cellIndexFromIJK( i, j, k ); if ( cellIdx == cvf::UNDEFINED_SIZE_T ) continue; - std::array vertices; - grid->cellCornerVertices( cellIdx, vertices ); - cvf::Vec3d center = grid->cellCentroid( cellIdx ); - - std::array corners; - for ( size_t n = 0; n < 8; n++ ) - corners[n] = vertices[n]; + std::array vertices = grid->cellCornerVertices( cellIdx ); + cvf::Vec3d center = grid->cellCentroid( cellIdx ); // check if the polygon includes the cell - if ( cellInsidePolygon2D( center, corners, points ) ) + if ( cellInsidePolygon2D( center, vertices, points ) ) { #pragma omp critical m_cells[partId].push_back( cellIdx ); @@ -673,9 +666,8 @@ void RimPolygonFilter::updateCellsKIndexGeoMech( const std::vector& size_t cellIdx = grid->cellIndexFromIJK( i, j, k ); if ( cellIdx == cvf::UNDEFINED_SIZE_T ) continue; - cvf::BoundingBox bb; - std::array vertices; - grid->cellCornerVertices( cellIdx, vertices ); + cvf::BoundingBox bb; + std::array vertices = grid->cellCornerVertices( cellIdx ); for ( const auto& point : vertices ) bb.add( point ); @@ -714,9 +706,8 @@ void RimPolygonFilter::updateCellsKIndexGeoMech( const std::vector& if ( cellIdx == cvf::UNDEFINED_SIZE_T ) continue; // get corner coordinates - std::array hexCorners; - grid->cellCornerVertices( cellIdx, hexCorners ); - cvf::Vec3d center = grid->cellCentroid( cellIdx ); + std::array hexCorners = grid->cellCornerVertices( cellIdx ); + cvf::Vec3d center = grid->cellCentroid( cellIdx ); if ( closedPolygon ) { @@ -1112,8 +1103,7 @@ int RimPolygonFilter::findEclipseKLayer( const std::vector& points, // is the point inside cell bb? cvf::BoundingBox bb; - std::array hexCorners; - grid->cellCornerVertices( i, hexCorners ); + std::array hexCorners = grid->cellCornerVertices( i ); for ( const auto& corner : hexCorners ) { bb.add( corner ); diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureContainmentTools.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureContainmentTools.cpp index 6723269be6..1a058a670c 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureContainmentTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureContainmentTools.cpp @@ -87,8 +87,7 @@ void RimFractureContainmentTools::appendNeighborCellForFace( const std::set hexCorners; - mainGrid->cellCornerVertices( globalReservoirCellIndex, hexCorners ); + std::array hexCorners = mainGrid->cellCornerVertices( globalReservoirCellIndex ); double avgZ = 0.0; @@ -250,8 +249,7 @@ std::set RimFractureContainmentTools::getCellsIntersectingFracturePlane( for ( const auto& globalCellIndex : indicesToPotentiallyFracturedCells ) { - std::array hexCorners; - mainGrid->cellCornerVertices( globalCellIndex, hexCorners ); + std::array hexCorners = mainGrid->cellCornerVertices( globalCellIndex ); std::vector> planeCellPolygons; bool isPlanIntersected = diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechCase.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechCase.cpp index b965870760..f7a8515d7f 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechCase.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechCase.cpp @@ -514,8 +514,7 @@ cvf::BoundingBox RimGeoMechCase::reservoirBoundingBox() if ( validPorValue ) { - std::array hexCorners; - femPartGrid->cellCornerVertices( i, hexCorners ); + std::array hexCorners = femPartGrid->cellCornerVertices( i ); for ( size_t c = 0; c < 8; ++c ) { boundingBox.add( hexCorners[c] ); diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimGridCaseSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimGridCaseSurface.cpp index d8c9971608..beef6a80d5 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/RimGridCaseSurface.cpp +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimGridCaseSurface.cpp @@ -240,8 +240,7 @@ void RimGridCaseSurface::extractStructuredSurfaceFromGridData() size_t cellFaceIndex = 0; if ( !findValidCellIndex( grid, faceType, cellIndex, row, column, zeroBasedLayerIndex, cellFaceIndex ) ) return; - std::array cornerVerts; - grid->cellCornerVertices( cellIndex, cornerVerts ); + std::array cornerVerts = grid->cellCornerVertices( cellIndex ); cvf::ubyte faceConn[4]; RigMainGrid::cellFaceVertexIndices( faceType, faceConn ); @@ -317,11 +316,10 @@ void RimGridCaseSurface::extractGridDataUsingFourVerticesPerCell() if ( m_watertight ) skipInactiveCells = false; if ( skipInactiveCells && activeCells && !activeCells->isActive( currentCellIndex ) ) continue; - std::array currentCornerVerts; + std::array currentCornerVerts = grid->cellCornerVertices( currentCellIndex ); { cvf::ubyte currentFaceConn[4]; - grid->cellCornerVertices( currentCellIndex, currentCornerVerts ); RigMainGrid::cellFaceVertexIndices( extractionFace, currentFaceConn ); auto currentCellStartIndex = static_cast( vertices.size() ); @@ -382,9 +380,8 @@ void RimGridCaseSurface::addGeometryForFaultFaces( const RigMainGrid* auto nextCell = grid->cell( currentCellIndex ).neighborCell( faultFace ); if ( !nextCell.isInvalid() ) { - size_t nextCellIndex = nextCell.mainGridCellIndex(); - std::array nextCellCornerVerts; - grid->cellCornerVertices( nextCellIndex, nextCellCornerVerts ); + size_t nextCellIndex = nextCell.mainGridCellIndex(); + std::array nextCellCornerVerts = grid->cellCornerVertices( nextCellIndex ); auto startIndex = static_cast( vertices.size() ); { diff --git a/ApplicationLibCode/ReservoirDataModel/Completions/RigEclipseToStimPlanCellTransmissibilityCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/Completions/RigEclipseToStimPlanCellTransmissibilityCalculator.cpp index c24dd54700..3a28581e42 100644 --- a/ApplicationLibCode/ReservoirDataModel/Completions/RigEclipseToStimPlanCellTransmissibilityCalculator.cpp +++ b/ApplicationLibCode/ReservoirDataModel/Completions/RigEclipseToStimPlanCellTransmissibilityCalculator.cpp @@ -195,8 +195,7 @@ void RigEclipseToStimPlanCellTransmissibilityCalculator::calculateStimPlanCellsM const RigMainGrid* mainGrid = m_case->eclipseCaseData()->mainGrid(); if ( !m_fracture->isEclipseCellOpenForFlow( mainGrid, reservoirCellIndicesOpenForFlow, reservoirCellIndex ) ) continue; - std::array hexCorners; - mainGrid->cellCornerVertices( reservoirCellIndex, hexCorners ); + std::array hexCorners = mainGrid->cellCornerVertices( reservoirCellIndex ); std::vector> planeCellPolygons; bool isPlanIntersected = RigHexIntersectionTools::planeHexIntersectionPolygons( hexCorners, m_fractureTransform, planeCellPolygons ); diff --git a/ApplicationLibCode/ReservoirDataModel/ContourMap/RigEclipseContourMapProjection.cpp b/ApplicationLibCode/ReservoirDataModel/ContourMap/RigEclipseContourMapProjection.cpp index 6f1910dc5e..b6e5639784 100644 --- a/ApplicationLibCode/ReservoirDataModel/ContourMap/RigEclipseContourMapProjection.cpp +++ b/ApplicationLibCode/ReservoirDataModel/ContourMap/RigEclipseContourMapProjection.cpp @@ -257,14 +257,12 @@ size_t RigEclipseContourMapProjection::kLayers() const //-------------------------------------------------------------------------------------------------- double RigEclipseContourMapProjection::calculateOverlapVolume( size_t globalCellIdx, const cvf::BoundingBox& bbox ) const { - std::array hexCorners; - const RigCell& cell = m_mainGrid->cell( globalCellIdx ); size_t localCellIdx = cell.gridLocalCellIndex(); RigGridBase* localGrid = cell.hostGrid(); - localGrid->cellCornerVertices( localCellIdx, hexCorners ); + std::array hexCorners = localGrid->cellCornerVertices( localCellIdx ); cvf::BoundingBox overlapBBox; std::array overlapCorners; @@ -283,17 +281,15 @@ double RigEclipseContourMapProjection::calculateRayLengthInCell( size_t const cvf::Vec3d& highestPoint, const cvf::Vec3d& lowestPoint ) const { - std::array hexCorners; - const RigCell& cell = m_mainGrid->cell( globalCellIdx ); size_t localCellIdx = cell.gridLocalCellIndex(); RigGridBase* localGrid = cell.hostGrid(); - localGrid->cellCornerVertices( localCellIdx, hexCorners ); + std::array hexCorners = localGrid->cellCornerVertices( localCellIdx ); std::vector 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; diff --git a/ApplicationLibCode/ReservoirDataModel/ContourMap/RigGeoMechContourMapProjection.cpp b/ApplicationLibCode/ReservoirDataModel/ContourMap/RigGeoMechContourMapProjection.cpp index 114d09757c..c88da1142d 100644 --- a/ApplicationLibCode/ReservoirDataModel/ContourMap/RigGeoMechContourMapProjection.cpp +++ b/ApplicationLibCode/ReservoirDataModel/ContourMap/RigGeoMechContourMapProjection.cpp @@ -89,8 +89,7 @@ cvf::BoundingBox RigGeoMechContourMapProjection::calculateExpandedPorBarBBox( Ri if ( validPorValue ) { - std::array hexCorners; - femPartGrid->cellCornerVertices( i, hexCorners ); + std::array 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 hexCorners; - m_femPartGrid->cellCornerVertices( globalCellIdx, hexCorners ); + std::array hexCorners = m_femPartGrid->cellCornerVertices( globalCellIdx ); cvf::BoundingBox overlapBBox; std::array overlapCorners; @@ -307,23 +305,11 @@ double RigGeoMechContourMapProjection::calculateRayLengthInCell( size_t const cvf::Vec3d& highestPoint, const cvf::Vec3d& lowestPoint ) const { - std::array hexCorners; - - const std::vector& 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 hexCorners = m_femPartGrid->cellCornerVertices( globalCellIdx ); std::vector 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; diff --git a/ApplicationLibCode/ReservoirDataModel/RigCell.cpp b/ApplicationLibCode/ReservoirDataModel/RigCell.cpp index f1d6aba7de..d96dad7078 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCell.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCell.cpp @@ -417,17 +417,17 @@ void RigCell::faceIndices( cvf::StructGridInterface::FaceType face, std::array hexCorners; + cvf::BoundingBox bb; if ( m_hostGrid ) { - m_hostGrid->cellCornerVertices( m_gridLocalCellIndex, hexCorners ); + std::array hexCorners = m_hostGrid->cellCornerVertices( m_gridLocalCellIndex ); for ( const auto& corner : hexCorners ) { bb.add( corner ); } } + return bb; } diff --git a/ApplicationLibCode/ReservoirDataModel/RigEclipseCaseData.cpp b/ApplicationLibCode/ReservoirDataModel/RigEclipseCaseData.cpp index 910822ce7c..4f992b719d 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigEclipseCaseData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigEclipseCaseData.cpp @@ -663,12 +663,11 @@ void RigEclipseCaseData::computeActiveCellsGeometryBoundingBoxSlow() } else { - std::array hexCorners; for ( size_t i = 0; i < m_mainGrid->cellCount(); i++ ) { if ( activeInfos[acIdx]->isActive( i ) ) { - m_mainGrid->cellCornerVertices( i, hexCorners ); + std::array 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 hexCorners; - m_mainGrid->cellCornerVertices( cellIndex, hexCorners ); + std::array hexCorners = m_mainGrid->cellCornerVertices( cellIndex ); for ( const auto& corner : hexCorners ) { bb.add( corner ); diff --git a/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp index 4cf3442c00..c122dcb129 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp @@ -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& vertices ) const +std::array RigGridBase::cellCornerVertices( size_t cellIndex ) const { + std::array vertices; const std::array& indices = cell( cellIndex ).cornerIndices(); vertices[0].set( m_mainGrid->nodes()[indices[0]] ); @@ -179,6 +180,8 @@ void RigGridBase::cellCornerVertices( size_t cellIndex, std::arraynodes()[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 cornerVerts; - for ( size_t i = 0; i < cellCount(); i++ ) { - cellCornerVertices( i, cornerVerts ); - + std::array cornerVerts = cellCornerVertices( i ); for ( size_t j = 0; j < 8; j++ ) { m_boundingBox.add( cornerVerts[j] ); diff --git a/ApplicationLibCode/ReservoirDataModel/RigGridBase.h b/ApplicationLibCode/ReservoirDataModel/RigGridBase.h index c94e9c8809..3a62485fc9 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGridBase.h +++ b/ApplicationLibCode/ReservoirDataModel/RigGridBase.h @@ -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& vertices ) const override; - cvf::Vec3d cellCentroid( size_t cellIndex ) const override; + std::array 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; diff --git a/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.cpp b/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.cpp index 2134dd5eeb..9f6b69e91f 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.cpp @@ -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& hexCorners, const size_t hexIndex, std::vector* 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& 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& hexCorners ) +bool RigHexIntersectionTools::isPointInCell( const cvf::Vec3d& point, const std::array& 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& hexCorners, const cvf::Plane& fracturePlane, std::list>& intersectionLineSegments ) { @@ -196,7 +196,7 @@ bool RigHexIntersectionTools::planeHexCellIntersection( cvf::Vec3d* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RigHexIntersectionTools::planeHexIntersectionPolygons( std::array hexCorners, +bool RigHexIntersectionTools::planeHexIntersectionPolygons( const std::array& hexCorners, cvf::Mat4d transformMatrixForPlane, std::vector>& polygons ) { @@ -208,7 +208,7 @@ bool RigHexIntersectionTools::planeHexIntersectionPolygons( std::array> intersectionLineSegments; - isCellIntersected = planeHexCellIntersection( hexCorners.data(), fracturePlane, intersectionLineSegments ); + isCellIntersected = planeHexCellIntersection( hexCorners, fracturePlane, intersectionLineSegments ); RigCellGeometryTools::createPolygonFromLineSegments( intersectionLineSegments, polygons ); diff --git a/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.h b/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.h index 867ced34e0..67f2f4746c 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.h +++ b/ApplicationLibCode/ReservoirDataModel/RigHexIntersectionTools.h @@ -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& hexCorners, const size_t hexIndex, std::vector* 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& hexCorners ); - static bool isPointInCell( const cvf::Vec3d point, const std::array& hexCorners ); + static bool isPointInCell( const cvf::Vec3d& point, const std::array& hexCorners ); - static bool planeHexCellIntersection( cvf::Vec3d* hexCorners, + static bool planeHexCellIntersection( const std::array& hexCorners, const cvf::Plane& fracturePlane, std::list>& intersectionLineSegments ); - static bool planeHexIntersectionPolygons( std::array hexCorners, + static bool planeHexIntersectionPolygons( const std::array& hexCorners, cvf::Mat4d transformMatrixForPlane, std::vector>& polygons ); }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp b/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp index 5769a99ef5..dd2eac551c 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp @@ -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 cellIndices = m_mainGrid->findIntersectingCells( pointBBox ); - std::array hexCorners; for ( size_t cellIndex : cellIndices ) { - m_mainGrid->cellCornerVertices( cellIndex, hexCorners ); - + std::array hexCorners = m_mainGrid->cellCornerVertices( cellIndex ); if ( RigHexIntersectionTools::isPointInCell( point, hexCorners ) ) { - cellContainingPoint = cellIndex; - break; + return cellIndex; } } - return cellContainingPoint; + return cvf::UNDEFINED_SIZE_T; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ReservoirDataModel/Well/RigEclipseWellLogExtractor.cpp b/ApplicationLibCode/ReservoirDataModel/Well/RigEclipseWellLogExtractor.cpp index 45c4f9f886..d048c69171 100644 --- a/ApplicationLibCode/ReservoirDataModel/Well/RigEclipseWellLogExtractor.cpp +++ b/ApplicationLibCode/ReservoirDataModel/Well/RigEclipseWellLogExtractor.cpp @@ -75,16 +75,14 @@ void RigEclipseWellLogExtractor::calculateIntersection() std::vector closeCellIndices = findCloseCellIndices( bb ); - std::array 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 hexCorners = m_caseData->mainGrid()->cellCornerVertices( globalCellIndex ); + RigHexIntersectionTools::lineHexCellIntersection( p1, p2, hexCorners, globalCellIndex, &intersections ); } if ( !isCellFaceNormalsOut ) @@ -121,15 +119,13 @@ void RigEclipseWellLogExtractor::calculateIntersection() std::vector closeCellIndices = findCloseCellIndices( bb ); - std::array 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 hexCorners = m_caseData->mainGrid()->cellCornerVertices( globalCellIndex ); if ( RigHexIntersectionTools::isPointInCell( firstPoint, hexCorners ) ) { if ( RigHexIntersectionTools::isPointInCell( lastPoint, hexCorners ) ) @@ -202,8 +198,7 @@ std::vector RigEclipseWellLogExtractor::findCloseCellIndices( const cvf: //-------------------------------------------------------------------------------------------------- cvf::Vec3d RigEclipseWellLogExtractor::calculateLengthInCell( size_t cellIndex, const cvf::Vec3d& startPoint, const cvf::Vec3d& endPoint ) const { - std::array hexCorners; - m_caseData->mainGrid()->cellCornerVertices( cellIndex, hexCorners ); + std::array hexCorners = m_caseData->mainGrid()->cellCornerVertices( cellIndex ); return RigWellPathIntersectionTools::calculateLengthInCell( hexCorners, startPoint, endPoint ); } diff --git a/ApplicationLibCode/ReservoirDataModel/Well/RigGeoMechWellLogExtractor.cpp b/ApplicationLibCode/ReservoirDataModel/Well/RigGeoMechWellLogExtractor.cpp index 714ce59142..7189f59a76 100644 --- a/ApplicationLibCode/ReservoirDataModel/Well/RigGeoMechWellLogExtractor.cpp +++ b/ApplicationLibCode/ReservoirDataModel/Well/RigGeoMechWellLogExtractor.cpp @@ -1139,7 +1139,6 @@ void RigGeoMechWellLogExtractor::calculateIntersection() std::vector 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 hexCorners; + hexCorners[0] = cvf::Vec3d( nodeCoords[cornerIndices[0]] ); hexCorners[1] = cvf::Vec3d( nodeCoords[cornerIndices[1]] ); hexCorners[2] = cvf::Vec3d( nodeCoords[cornerIndices[2]] ); diff --git a/ApplicationLibCode/ReservoirDataModel/Well/RigWellPathIntersectionTools.cpp b/ApplicationLibCode/ReservoirDataModel/Well/RigWellPathIntersectionTools.cpp index f930136112..d1dde67011 100644 --- a/ApplicationLibCode/ReservoirDataModel/Well/RigWellPathIntersectionTools.cpp +++ b/ApplicationLibCode/ReservoirDataModel/Well/RigWellPathIntersectionTools.cpp @@ -142,8 +142,7 @@ cvf::Vec3d RigWellPathIntersectionTools::calculateLengthInCell( const RigMainGri const cvf::Vec3d& startPoint, const cvf::Vec3d& endPoint ) { - std::array hexCorners; - grid->cellCornerVertices( cellIndex, hexCorners ); + std::array hexCorners = grid->cellCornerVertices( cellIndex ); return calculateLengthInCell( hexCorners, startPoint, endPoint ); } diff --git a/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp index 66eb6cdff2..f50bad93ae 100644 --- a/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationLibCode/SocketInterface/RiaGeometryCommands.cpp @@ -279,9 +279,8 @@ public: // dv(3) = 8; // dv(4) = 3; - std::array cornerVerts; - size_t blockByteCount = cellCount * sizeof( double ); - std::vector doubleValues( blockByteCount ); + size_t blockByteCount = cellCount * sizeof( double ); + std::vector doubleValues( blockByteCount ); for ( int coordIdx = 0; coordIdx < 3; coordIdx++ ) { @@ -298,8 +297,8 @@ public: for ( size_t i = 0; i < cellCountI; i++ ) { size_t gridLocalCellIndex = rigGrid->cellIndexFromIJK( i, j, k ); - rigGrid->cellCornerVertices( gridLocalCellIndex, cornerVerts ); + std::array cornerVerts = rigGrid->cellCornerVertices( gridLocalCellIndex ); doubleValues[valueIndex++] = getCellCornerWithPositiveDepth( cornerVerts, cornerIndexMapping, coordIdx ); } } @@ -367,9 +366,8 @@ public: // dv(1) = 8; // dv(2) = 3; - std::array cornerVerts; - size_t blockByteCount = activeCellCount * sizeof( double ); - std::vector doubleValues( blockByteCount ); + size_t blockByteCount = activeCellCount * sizeof( double ); + std::vector doubleValues( blockByteCount ); for ( int coordIdx = 0; coordIdx < 3; coordIdx++ ) { @@ -383,9 +381,8 @@ public: { if ( !actCellInfo->isActive( reservoirCellIndex ) ) continue; - mainGrid->cellCornerVertices( reservoirCellIndex, cornerVerts ); - - doubleValues[valueIndex++] = getCellCornerWithPositiveDepth( cornerVerts, cornerIndexMapping, coordIdx ); + std::array cornerVerts = mainGrid->cellCornerVertices( reservoirCellIndex ); + doubleValues[valueIndex++] = getCellCornerWithPositiveDepth( cornerVerts, cornerIndexMapping, coordIdx ); } CVF_ASSERT( valueIndex == activeCellCount ); diff --git a/ApplicationLibCode/UnitTests/RigHexIntersectionTools-Test.cpp b/ApplicationLibCode/UnitTests/RigHexIntersectionTools-Test.cpp index f3f00b1093..15e0cd7e2d 100644 --- a/ApplicationLibCode/UnitTests/RigHexIntersectionTools-Test.cpp +++ b/ApplicationLibCode/UnitTests/RigHexIntersectionTools-Test.cpp @@ -29,7 +29,7 @@ //-------------------------------------------------------------------------------------------------- TEST( RigHexIntersectionTools, planeHexCellIntersectionTest ) { - cvf::Vec3d hexCorners[8]; + std::array hexCorners; hexCorners[0] = cvf::Vec3d( 0, 0, 0 ); hexCorners[1] = cvf::Vec3d( 1, 0, 0 ); hexCorners[2] = cvf::Vec3d( 0, 1, 0 ); @@ -57,7 +57,7 @@ TEST( RigHexIntersectionTools, planeHexCellIntersectionTest ) //-------------------------------------------------------------------------------------------------- TEST( RigHexIntersectionTools, DISABLED_planeHexCellIntersectionPerformanceTest ) { - cvf::Vec3d hexCorners[8]; + std::array hexCorners; hexCorners[0] = cvf::Vec3d( 0, 0, 0 ); hexCorners[1] = cvf::Vec3d( 1, 0, 0 ); hexCorners[2] = cvf::Vec3d( 0, 1, 0 ); diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp index 38305c6175..e6b44c7769 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.cpp @@ -373,8 +373,7 @@ void StructGridInterface::computeCharacteristicCellSize( const std::vector cornerVerts; - size_t evaluatedCellCount = 0; + size_t evaluatedCellCount = 0; // Evaluate N-th cells, compute the stride between each index size_t stride = std::max( size_t( 1 ), globalCellIndices.size() / 100 ); @@ -387,7 +386,7 @@ void StructGridInterface::computeCharacteristicCellSize( const std::vector cornerVerts = cellCornerVertices( cellIndex ); cvf::BoundingBox bb; for ( const auto& v : cornerVerts ) diff --git a/Fwk/AppFwk/CommonCode/cvfStructGrid.h b/Fwk/AppFwk/CommonCode/cvfStructGrid.h index 06b2bb7f4e..bf6de71773 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGrid.h +++ b/Fwk/AppFwk/CommonCode/cvfStructGrid.h @@ -101,8 +101,8 @@ public: virtual bool cellIJKFromCoordinate( const cvf::Vec3d& coord, size_t* i, size_t* j, size_t* k ) const = 0; - virtual void cellCornerVertices( size_t cellIndex, std::array& vertices ) const = 0; - virtual cvf::Vec3d cellCentroid( size_t cellIndex ) const = 0; + virtual std::array cellCornerVertices( size_t cellIndex ) const = 0; + virtual cvf::Vec3d cellCentroid( size_t cellIndex ) const = 0; virtual void cellMinMaxCordinates( size_t cellIndex, cvf::Vec3d* minCoordinate, cvf::Vec3d* maxCoordinate ) const = 0; virtual size_t gridPointIndexFromIJK( size_t i, size_t j, size_t k ) const = 0; diff --git a/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp b/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp index 36e805ab0d..037fa463c4 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp +++ b/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp @@ -276,8 +276,7 @@ ref StructGridGeometryGenerator::createMeshDrawableFromSingleCell( size_t cellIndex, const cvf::Vec3d& displayModelOffset ) { - std::array cornerVerts; - grid->cellCornerVertices( cellIndex, cornerVerts ); + std::array cornerVerts = grid->cellCornerVertices( cellIndex ); std::vector vertices; @@ -415,8 +414,7 @@ void StructGridGeometryGenerator::computeArrays() if ( !visibleFaces.empty() ) { - std::array cornerVerts; - m_grid->cellCornerVertices( cellIndex, cornerVerts ); + std::array cornerVerts = m_grid->cellCornerVertices( cellIndex ); size_t idx; for ( idx = 0; idx < visibleFaces.size(); idx++ ) diff --git a/GrpcInterface/RiaGrpcCaseService.cpp b/GrpcInterface/RiaGrpcCaseService.cpp index 4b869f8daf..fcf789d119 100644 --- a/GrpcInterface/RiaGrpcCaseService.cpp +++ b/GrpcInterface/RiaGrpcCaseService.cpp @@ -311,9 +311,8 @@ void RiaActiveCellInfoStateHandler::assignCellCorners( rips::CellCorners* const std::vector& reservoirCells, size_t cellIdx ) { - std::array cornerVerts; - RigGridBase* grid = m_eclipseCase->eclipseCaseData()->mainGrid(); - grid->cellCornerVertices( cellIdx, cornerVerts ); + RigGridBase* grid = m_eclipseCase->eclipseCaseData()->mainGrid(); + std::array cornerVerts = grid->cellCornerVertices( cellIdx ); for ( cvf::Vec3d& corner : cornerVerts ) { RiaGrpcHelper::convertVec3dToPositiveDepth( &corner ); diff --git a/GrpcInterface/RiaGrpcGridService.cpp b/GrpcInterface/RiaGrpcGridService.cpp index a8c965bbbf..df0aadcb5d 100644 --- a/GrpcInterface/RiaGrpcGridService.cpp +++ b/GrpcInterface/RiaGrpcGridService.cpp @@ -104,10 +104,9 @@ grpc::Status RiaCellCenterStateHandler::assignCornersReply( rips::CellCornersArr size_t indexInPackage = 0u; reply->mutable_cells()->Reserve( (int)packageSize ); - std::array cornerVerts; for ( ; indexInPackage < packageSize && m_currentCellIdx < m_grid->cellCount(); ++indexInPackage ) { - m_grid->cellCornerVertices( m_currentCellIdx, cornerVerts ); + std::array cornerVerts = m_grid->cellCornerVertices( m_currentCellIdx ); for ( cvf::Vec3d& corner : cornerVerts ) { RiaGrpcHelper::convertVec3dToPositiveDepth( &corner );