diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.cpp index 1d91c9ae4d..eccd4abd41 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.cpp @@ -278,6 +278,14 @@ std::unique_ptr RicMswSegment::removeCompletion( RicMswComplet return removedCompletion; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicMswSegment::deleteAllCompletions() +{ + m_completions.clear(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.h b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.h index 3d5897fc4f..68800b6d39 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.h +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswSegment.h @@ -76,6 +76,7 @@ public: void addCompletion( std::unique_ptr completion ); std::unique_ptr removeCompletion( RicMswCompletion* completion ); + void deleteAllCompletions(); void addIntersection( std::shared_ptr intersection ); diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp index c0456b1c81..c0dae61061 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp @@ -550,36 +550,29 @@ void RicMswTableFormatterTools::generateWsegvalvTableRecursively( gsl::not_null< { if ( RigCompletionData::isWsegValveTypes( completion->completionType() ) ) { - auto wsegValve = static_cast( completion ); - if ( !wsegValve->segments().empty() ) + // Related function RicWellPathExportMswCompletionsImpl::moveIntersectionsToSuperICDsOrAICDs + + auto wsegValve = static_cast( completion ); + int segmentNumber = -1; + for ( auto seg : wsegValve->segments() ) { - CVF_ASSERT( wsegValve->segments().size() == 1u ); + if ( seg->segmentNumber() > -1 ) segmentNumber = seg->segmentNumber(); + if ( seg->intersections().empty() ) continue; - auto firstSubSegment = wsegValve->segments().front(); + size_t cellIndex = seg->intersections().front()->globalCellIndex(); - // TODO: The following line was blocking export of valves for fishbones - // Unclear why this line was included. Remove when MSW export has ben verified correctly - // if ( !firstSubSegment->intersections().empty() ) + QString comment; + if ( wsegValve->completionType() == RigCompletionData::CompletionType::PERFORATION_ICD || + wsegValve->completionType() == RigCompletionData::CompletionType::PERFORATION_ICV ) { - QString comment; - if ( wsegValve->completionType() == RigCompletionData::CompletionType::PERFORATION_ICD || - wsegValve->completionType() == RigCompletionData::CompletionType::PERFORATION_ICV ) - { - comment = wsegValve->label(); - } - - size_t cellIndex = std::numeric_limits::max(); - if ( !firstSubSegment->intersections().empty() ) - { - cellIndex = firstSubSegment->intersections().front()->globalCellIndex(); - } - - wsegvalveData[cellIndex].push_back( WsegvalveData( wellNameForExport, - comment, - firstSubSegment->segmentNumber(), - wsegValve->flowCoefficient(), - wsegValve->area() ) ); + comment = wsegValve->label(); } + + wsegvalveData[cellIndex].push_back( WsegvalveData( wellNameForExport, + comment, + segmentNumber, + wsegValve->flowCoefficient(), + wsegValve->area() ) ); } } } @@ -739,22 +732,19 @@ void RicMswTableFormatterTools::generateWsegAicdTableRecursively( RicMswExportIn auto aicd = static_cast( completion ); if ( aicd->isValid() ) { - if ( !aicd->segments().empty() ) + int segmentNumber = -1; + for ( auto seg : aicd->segments() ) { - CVF_ASSERT( aicd->segments().size() == 1u ); - auto firstSegment = aicd->segments().front(); + if ( seg->segmentNumber() > -1 ) segmentNumber = seg->segmentNumber(); + if ( seg->intersections().empty() ) continue; - size_t cellIndex = std::numeric_limits::max(); - if ( !firstSegment->intersections().empty() ) - { - cellIndex = firstSegment->intersections().front()->globalCellIndex(); - } + size_t cellIndex = seg->intersections().front()->globalCellIndex(); auto wellName = exportInfo.mainBoreBranch()->wellPath()->completionSettings()->wellNameForExport(); auto comment = aicd->label(); aicdValveData[cellIndex].push_back( AicdWsegvalveData( wellName, comment, - firstSegment->segmentNumber(), + segmentNumber, aicd->flowScalingFactor(), aicd->isOpen(), aicd->values() ) ); diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp index af898c8bea..63b51db22e 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp @@ -1622,13 +1622,13 @@ void RicWellPathExportMswCompletionsImpl::moveIntersectionsToSuperICDsOrAICDs( g std::vector perforations; for ( auto completion : segment->completions() ) { - if ( RigCompletionData::isPerforationValve( completion->completionType() ) ) + if ( completion->completionType() == RigCompletionData::CompletionType::PERFORATION_ICD || + completion->completionType() == RigCompletionData::CompletionType::PERFORATION_AICD ) { superValve = completion; } - else + else if ( completion->completionType() == RigCompletionData::CompletionType::PERFORATION ) { - CVF_ASSERT( completion->completionType() == RigCompletionData::CompletionType::PERFORATION ); perforations.push_back( completion ); } } @@ -1636,21 +1636,55 @@ void RicWellPathExportMswCompletionsImpl::moveIntersectionsToSuperICDsOrAICDs( g if ( superValve == nullptr ) continue; CVF_ASSERT( superValve->segments().size() == 1u ); + + double aggregatedMinStartMD = std::numeric_limits::max(); + // Remove and take over ownership of the superValve completion auto completionPtr = segment->removeCompletion( superValve ); for ( auto perforation : perforations ) { for ( auto subSegment : perforation->segments() ) { + aggregatedMinStartMD = std::min( aggregatedMinStartMD, subSegment->startMD() ); + + // The valve completions on the main branch will be deleted. Create a segment with startMD and + // endMD representing the perforation along main well path to be connected to the valve. When COMPSEGS + // data is exported, the startMD and endMD of the segment is used to define the Start Length and End + // Length of the COMPSEGS keyword + // + // Example output + // + // COMPSEGS + // --Name + // Well - 1 / + // --I J K Branch no Start Length End Length + // 17 17 9 2 3030.71791 3034.01331 / + // 17 18 9 3 3034.01331 3125.47617 / + + auto valveInflowSegment = + std::make_unique( QString( "%1 real valve segment " ).arg( branch->label() ), + subSegment->startMD(), + subSegment->endMD(), + subSegment->startTVD(), + subSegment->endTVD() ); + for ( auto intersectionPtr : subSegment->intersections() ) { - completionPtr->segments()[0]->addIntersection( intersectionPtr ); + valveInflowSegment->addIntersection( intersectionPtr ); } + + completionPtr->addSegment( std::move( valveInflowSegment ) ); } } + // Remove all completions and re-add the super valve - segment->completions().clear(); - segment->addCompletion( std::move( completionPtr ) ); + segment->deleteAllCompletions(); + + auto segmentWithLowerMD = branch->findClosestSegmentWithLowerMD( aggregatedMinStartMD ); + if ( segmentWithLowerMD ) + { + segmentWithLowerMD->addCompletion( std::move( completionPtr ) ); + } } }