From ffa117e736cfba3fb540ecb9db7899abc5817f13 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 3 Jan 2024 09:00:32 +0100 Subject: [PATCH] Refactor: Extract getPartIndexFromPoint to avoid duplication. --- .../GeoMechDataModel/RigFemPartCollection.cpp | 37 +++++++++++++++++ .../GeoMechDataModel/RigFemPartCollection.h | 2 + ...RimFaultReactivationDataAccessorStress.cpp | 40 ++----------------- .../RimFaultReactivationDataAccessorStress.h | 1 - .../RimGeoMechFaultReactivationResult.cpp | 40 ++----------------- .../RimGeoMechFaultReactivationResult.h | 2 - 6 files changed, 46 insertions(+), 76 deletions(-) diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.cpp b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.cpp index 6a932d88c9..bff4ff5b2e 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.cpp +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.cpp @@ -18,6 +18,9 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RigFemPartCollection.h" + +#include "RigHexIntersectionTools.h" + #include "cvfBoundingBox.h" //-------------------------------------------------------------------------------------------------- @@ -181,6 +184,40 @@ void RigFemPartCollection::findIntersectingGlobalElementIndices( const cvf::Boun } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RigFemPartCollection::getPartIndexFromPoint( const cvf::Vec3d& point ) const +{ + const int idx = -1; + + // Find candidates for intersected global elements + const cvf::BoundingBox intersectingBb( point, point ); + std::vector intersectedGlobalElementIndexCandidates; + findIntersectingGlobalElementIndices( intersectingBb, &intersectedGlobalElementIndexCandidates ); + + if ( intersectedGlobalElementIndexCandidates.empty() ) return idx; + + // Iterate through global element candidates and check if point is in hexCorners + for ( const auto& globalElementIndex : intersectedGlobalElementIndexCandidates ) + { + const auto [part, elementIndex] = partAndElementIndex( globalElementIndex ); + + // Find nodes from element + std::array coordinates; + if ( part->fillElementCoordinates( elementIndex, coordinates ) ) + { + if ( RigHexIntersectionTools::isPointInCell( point, coordinates.data() ) ) + { + return part->elementPartId(); + } + } + } + + // Utilize first part to have an id + return idx; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.h b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.h index 8c4dfd9fb7..694d72d301 100644 --- a/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.h +++ b/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemPartCollection.h @@ -49,6 +49,8 @@ public: size_t globalElementNodeResultIdx( int part, int elementIdx, int elmLocalNodeIdx ) const; + int getPartIndexFromPoint( const cvf::Vec3d& point ) const; + private: cvf::Collection m_femParts; std::vector m_partElementOffset; diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.cpp index 5c4a633e60..15f11388ce 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.cpp +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.cpp @@ -99,50 +99,18 @@ void RimFaultReactivationDataAccessorStress::updateResultAccessor() { std::vector wellPoints = generateWellPoints( faultTopPosition, faultBottomPosition, faultNormal * distanceFromFault ); m_faceAWellPath = new RigWellPath( wellPoints, generateMds( wellPoints ) ); - m_partIndexA = getPartIndexFromPoint( *geoMechPartCollection, wellPoints[1] ); + m_partIndexA = geoMechPartCollection->getPartIndexFromPoint( wellPoints[1] ); m_extractorA = new RigGeoMechWellLogExtractor( m_geoMechCaseData, partIndex, m_faceAWellPath.p(), errorName ); } { std::vector wellPoints = generateWellPoints( faultTopPosition, faultBottomPosition, -faultNormal * distanceFromFault ); m_faceBWellPath = new RigWellPath( wellPoints, generateMds( wellPoints ) ); - m_partIndexB = getPartIndexFromPoint( *geoMechPartCollection, wellPoints[1] ); + m_partIndexB = geoMechPartCollection->getPartIndexFromPoint( wellPoints[1] ); m_extractorB = new RigGeoMechWellLogExtractor( m_geoMechCaseData, partIndex, m_faceBWellPath.p(), errorName ); } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int RimFaultReactivationDataAccessorStress::getPartIndexFromPoint( const RigFemPartCollection& partCollection, const cvf::Vec3d& point ) -{ - const int idx = 0; - - // Find candidates for intersected global elements - const cvf::BoundingBox intersectingBb( point, point ); - std::vector intersectedGlobalElementIndexCandidates; - partCollection.findIntersectingGlobalElementIndices( intersectingBb, &intersectedGlobalElementIndexCandidates ); - - if ( intersectedGlobalElementIndexCandidates.empty() ) return idx; - - // Iterate through global element candidates and check if point is in hexCorners - for ( const auto& globalElementIndex : intersectedGlobalElementIndexCandidates ) - { - const auto [part, elementIndex] = partCollection.partAndElementIndex( globalElementIndex ); - - // Find nodes from element - std::array coordinates; - const bool isSuccess = part->fillElementCoordinates( elementIndex, coordinates ); - if ( !isSuccess ) continue; - - const bool isPointInCell = RigHexIntersectionTools::isPointInCell( point, coordinates.data() ); - if ( isPointInCell ) return part->elementPartId(); - } - - // Utilize first part to have an id - return idx; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -255,8 +223,8 @@ std::pair RimFaultReactivationDataAccessorStress::getPorBar( int frameIndex ) const { RigFemPartCollection* partCollection = m_geoMechCaseData->femParts(); - cvf::ref extractor = m_partIndexA == getPartIndexFromPoint( *partCollection, position ) ? m_extractorA - : m_extractorB; + cvf::ref extractor = m_partIndexA == partCollection->getPartIndexFromPoint( position ) ? m_extractorA + : m_extractorB; if ( !extractor->valid() ) { RiaLogging::error( "Invalid extractor when extracting PorBar" ); diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.h index cf667f14e2..b50f128df2 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.h +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultReactivationDataAccessorStress.h @@ -82,7 +82,6 @@ private: findElementSetContainingElement( const std::map>& elementSets, unsigned int elmIdx ); - static int getPartIndexFromPoint( const RigFemPartCollection& partCollection, const cvf::Vec3d& point ); static std::pair findIntersectionsForTvd( const std::vector& intersections, double tvd ); static std::pair findOverburdenAndUnderburdenIndex( const std::vector& values ); static double computePorBarWithGradient( const std::vector& intersections, diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.cpp index 7097456810..2e0ceb1e32 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.cpp @@ -29,7 +29,6 @@ #include "RigFemPartCollection.h" #include "RigGeoMechCaseData.h" -#include "RigHexIntersectionTools.h" #include "RigReservoirGridTools.h" #include "RimFaultReactivationTools.h" @@ -253,8 +252,8 @@ void RimGeoMechFaultReactivationResult::createWellGeometry() m_faceBWellPath->createWellPathGeometry(); // Detect which part well path centers are in - m_faceAWellPathPartIndex = getPartIndexFromPoint( geoMechPartCollection, partATop ); - m_faceBWellPathPartIndex = getPartIndexFromPoint( geoMechPartCollection, partBTop ); + m_faceAWellPathPartIndex = geoMechPartCollection->getPartIndexFromPoint( partATop ); + m_faceBWellPathPartIndex = geoMechPartCollection->getPartIndexFromPoint( partBTop ); // Update UI wellPathCollection->uiCapability()->updateConnectedEditors(); @@ -328,40 +327,7 @@ void RimGeoMechFaultReactivationResult::createWellLogCurves() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -int RimGeoMechFaultReactivationResult::getPartIndexFromPoint( const RigFemPartCollection* const partCollection, const cvf::Vec3d& point ) const -{ - const int idx = 0; - if ( !partCollection ) return idx; - - // Find candidates for intersected global elements - const cvf::BoundingBox intersectingBb( point, point ); - std::vector intersectedGlobalElementIndexCandidates; - partCollection->findIntersectingGlobalElementIndices( intersectingBb, &intersectedGlobalElementIndexCandidates ); - - if ( intersectedGlobalElementIndexCandidates.empty() ) return idx; - - // Iterate through global element candidates and check if point is in hexCorners - for ( const auto& globalElementIndex : intersectedGlobalElementIndexCandidates ) - { - const auto [part, elementIndex] = partCollection->partAndElementIndex( globalElementIndex ); - - // Find nodes from element - std::array coordinates; - const bool isSuccess = part->fillElementCoordinates( elementIndex, coordinates ); - if ( !isSuccess ) continue; - - const bool isPointInCell = RigHexIntersectionTools::isPointInCell( point, coordinates.data() ); - if ( isPointInCell ) return part->elementPartId(); - } - - // Utilize first part to have an id - return idx; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimWellLogExtractionCurve* RimGeoMechFaultReactivationResult::createWellLogExtractionCurveAndAddToTrack( RimWellLogTrack* track, +RimWellLogExtractionCurve* RimGeoMechFaultReactivationResult::createWellLogExtractionCurveAndAddToTrack( RimWellLogTrack* track, const RigFemResultAddress& resultAddress, RimModeledWellPath* wellPath, int partId ) diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.h b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.h index 13fa6b1555..f3f01845d3 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.h +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechFaultReactivationResult.h @@ -58,8 +58,6 @@ private: void createWellGeometry(); void createWellLogCurves(); - int getPartIndexFromPoint( const RigFemPartCollection* const partCollection, const cvf::Vec3d& point ) const; - RimWellLogExtractionCurve* createWellLogExtractionCurveAndAddToTrack( RimWellLogTrack* track, const RigFemResultAddress& resultAddress, RimModeledWellPath* wellPath,