diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp index d655a3f2ea..621ed60346 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp @@ -530,7 +530,8 @@ void RicWellPathExportMswCompletionsImpl::generateFishbonesMswExportInfo( } // Find cell intersections closest to each sub location - std::map> subAndCellIntersectionIndices; + std::map> closestSubForCellIntersections; + std::map cellIntersectionContainingSubIndex; { auto fishboneSectionStart = subs->startMD(); auto fishboneSectionEnd = subs->endMD(); @@ -549,6 +550,11 @@ void RicWellPathExportMswCompletionsImpl::generateFishbonesMswExportInfo( { double subMD = subs->measuredDepth( sub.first ); + if ( ( cellIntersection.startMD <= subMD ) && ( subMD <= cellIntersection.endMD ) ) + { + cellIntersectionContainingSubIndex[sub.first] = intersectionIndex; + } + auto distanceCandicate = std::abs( subMD - intersectionMidpoint ); if ( distanceCandicate < closestDistance ) { @@ -557,7 +563,7 @@ void RicWellPathExportMswCompletionsImpl::generateFishbonesMswExportInfo( } } - subAndCellIntersectionIndices[closestSubIndex].push_back( intersectionIndex ); + closestSubForCellIntersections[closestSubIndex].push_back( intersectionIndex ); } } } @@ -597,7 +603,15 @@ void RicWellPathExportMswCompletionsImpl::generateFishbonesMswExportInfo( { const RigMainGrid* mainGrid = eclipseCase->mainGrid(); - for ( auto intersectionIndex : subAndCellIntersectionIndices[sub.first] ) + std::set indices; + for ( auto intersectionIndex : closestSubForCellIntersections[sub.first] ) + { + indices.insert( intersectionIndex ); + } + + indices.insert( cellIntersectionContainingSubIndex[sub.first] ); + + for ( auto intersectionIndex : indices ) { auto intersection = filteredIntersections[intersectionIndex]; if ( intersection.globCellIndex >= mainGrid->globalCellArray().size() ) continue;