diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableDataTools.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableDataTools.cpp index cdb0818daa..30b29de1e5 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableDataTools.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableDataTools.cpp @@ -185,7 +185,11 @@ void RicMswTableDataTools::collectWelsegsSegment( RigMswTableData& double endMD = segment->endMD(); std::vector> segments = - RicMswTableFormatterTools::createSubSegmentMDPairs( startMD, endMD, std::nullopt, maxSegmentLength, customSegmentIntervals ); + RicMswTableFormatterTools::createSubSegmentMDPairs( startMD, + endMD, + std::nullopt, + std::optional( maxSegmentLength ), + customSegmentIntervals ); CVF_ASSERT( branch->wellPath() ); @@ -314,8 +318,11 @@ void RicMswTableDataTools::collectValveWelsegsSegment( RigMswTableData& endMD = subSegment->endMD(); } - auto splitSegments = - RicMswTableFormatterTools::createSubSegmentMDPairs( startMD, endMD, std::nullopt, maxSegmentLength, customSegmentIntervals ); + auto splitSegments = RicMswTableFormatterTools::createSubSegmentMDPairs( startMD, + endMD, + std::nullopt, + std::optional( maxSegmentLength ), + customSegmentIntervals ); int outletSegmentNumber = outletSegment ? outletSegment->segmentNumber() : 1; const auto linerDiameter = valve->wellPath()->mswCompletionParameters()->linerDiameter( exportInfo.unitSystem() ); diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp index 3261c664e1..b192842285 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.cpp @@ -610,7 +610,8 @@ void RicMswTableFormatterTools::writeWelsegsSegment( RicMswSegment* double startMD = segment->startMD(); double endMD = segment->endMD(); - std::vector> segments = createSubSegmentMDPairs( startMD, endMD, std::nullopt, maxSegmentLength ); + std::vector> segments = + createSubSegmentMDPairs( startMD, endMD, std::nullopt, std::optional( maxSegmentLength ) ); CVF_ASSERT( branch->wellPath() ); @@ -731,7 +732,8 @@ void RicMswTableFormatterTools::writeValveWelsegsSegment( const RicMswSegment* subSegment->setOutputTVD( midPointTVD ); } - std::vector> splitSegments = createSubSegmentMDPairs( startMD, endMD, std::nullopt, maxSegmentLength ); + std::vector> splitSegments = + createSubSegmentMDPairs( startMD, endMD, std::nullopt, std::optional( maxSegmentLength ) ); const auto linerDiameter = valve->wellPath()->mswCompletionParameters()->linerDiameter( exportInfo.unitSystem() ); const auto roughnessFactor = valve->wellPath()->mswCompletionParameters()->roughnessFactor( exportInfo.unitSystem() ); @@ -803,7 +805,8 @@ void RicMswTableFormatterTools::writeCompletionWelsegsSegments( gsl::not_nullstartTVD(); double endTVD = segment->endTVD(); - std::vector> splitSegments = createSubSegmentMDPairs( startMD, endMD, std::nullopt, maxSegmentLength ); + std::vector> splitSegments = + createSubSegmentMDPairs( startMD, endMD, std::nullopt, std::optional( maxSegmentLength ) ); for ( const auto& [subStartMD, subEndMD] : splitSegments ) { @@ -918,21 +921,23 @@ std::vector> RicMswTableFormatterTools::createSubSegmentMDPairs( double startMD, double endMD, std::optional minSegmentLength, - double maxSegmentLength, + std::optional maxSegmentLength, const std::vector>& customSegmentIntervals ) { - // Validate minSegmentLength < maxSegmentLength when both are specified and maxSegmentLength is active - if ( minSegmentLength.has_value() && minSegmentLength.value() > 0.0 && maxSegmentLength > 0.0 ) + // Validate minSegmentLength < maxSegmentLength when both are specified + if ( minSegmentLength.has_value() && minSegmentLength.value() > 0.0 && maxSegmentLength.has_value() && maxSegmentLength.value() > 0.0 ) { - CVF_ASSERT( minSegmentLength.value() < maxSegmentLength ); + CVF_ASSERT( minSegmentLength.value() < maxSegmentLength.value() ); } std::vector> subSegmentMDPairs; - // If no custom intervals, use original logic with maxSegmentLength subdivision - if ( customSegmentIntervals.empty() || maxSegmentLength <= 0.0 ) + // If no custom intervals, use simple subdivision logic + if ( customSegmentIntervals.empty() ) { - int subSegmentCount = maxSegmentLength > 0.0 ? static_cast( std::ceil( ( endMD - startMD ) / maxSegmentLength ) ) : 1; + int subSegmentCount = ( maxSegmentLength.has_value() && maxSegmentLength.value() > 0.0 ) + ? static_cast( std::ceil( ( endMD - startMD ) / maxSegmentLength.value() ) ) + : 1; double subSegmentLength = ( endMD - startMD ) / subSegmentCount; // If minSegmentLength is specified and segments would be too small, reduce segment count @@ -1007,10 +1012,10 @@ std::vector> } // If not covered by custom interval, subdivide using maxSegmentLength - if ( !coveredByCustomInterval && maxSegmentLength > 0.0 ) + if ( !coveredByCustomInterval && maxSegmentLength.has_value() && maxSegmentLength.value() > 0.0 ) { double gapLength = gapEnd - gapStart; - int subCount = static_cast( std::ceil( gapLength / maxSegmentLength ) ); + int subCount = static_cast( std::ceil( gapLength / maxSegmentLength.value() ) ); double subLength = gapLength / subCount; // If minSegmentLength is specified and segments would be too small, reduce segment count diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.h b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.h index 12abbdf37a..fd4dfb280e 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.h +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicMswTableFormatterTools.h @@ -125,7 +125,7 @@ void generateWsegAicdTable( RifTextDataTableFormatter& formatter, RicMswExportIn std::vector> createSubSegmentMDPairs( double startMD, double endMD, std::optional minSegmentLength, - double maxSegmentLength, + std::optional maxSegmentLength, const std::vector>& customSegmentIntervals = {} ); double tvdFromMeasuredDepth( gsl::not_null wellPath, double measuredDepth );