#14496 MSW export: Order COMPSEGS by branch number

The COMPSEGS rows were emitted in the order the branches are listed in, so they followed the WELSEGS order where the completion branches come before the laterals with a lower branch number.

The rows are now collected while the segments are visited and sorted by branch number before they are added. The sort is stable, so the rows of a branch keep their order along the well path.
This commit is contained in:
Magne Sjaastad committed 2026-08-10 09:42:17 +02:00
1 parent f796801a7a
commit c0ebe1a331
2 files changed
+45 -1

No files matched your search

@@ -503,6 +503,9 @@ RigMswTableData collectTableData( const RigMswWellExportData& exportData, RiaDef
RigMswTableData tableData( exportData.header.well, unitSystem );
tableData.setWelsegsHeader( exportData.header );
// Collected while the segments are visited, and added to the table data ordered by branch number.
std::vector<CompsegsRow> compsegsRows;
auto emitSegment = [&]( const RigMswBranch& branch, const RigMswSegment& seg )
{
// WELSEGS row
@@ -530,7 +533,7 @@ RigMswTableData collectTableData( const RigMswWellExportData& exportData, RiaDef
compRow.distanceStart = inter.distanceStart;
compRow.distanceEnd = inter.distanceEnd;
compRow.gridName = inter.gridName;
tableData.addCompsegsRow( compRow );
compsegsRows.push_back( compRow );
}
// WSEGVALV row
@@ -550,6 +553,19 @@ RigMswTableData collectTableData( const RigMswWellExportData& exportData, RiaDef
emitSegment( branch, seg );
tableData.addMswBranch( branch );
}
// COMPSEGS is ordered by branch number. WELSEGS keeps the order the branches are listed in, where
// the completion branches follow the lateral they are connected to and thus are not sorted by
// branch number. The sort is stable, so the rows of a branch keep their order along the well path.
std::stable_sort( compsegsRows.begin(),
compsegsRows.end(),
[]( const CompsegsRow& lhs, const CompsegsRow& rhs ) { return lhs.branch < rhs.branch; } );
for ( const auto& compsegsRow : compsegsRows )
{
tableData.addCompsegsRow( compsegsRow );
}
return tableData;
}
@@ -36,6 +36,7 @@
#include <QDir>
#include <QFile>
#include <algorithm>
#include <map>
namespace
@@ -538,3 +539,30 @@ TEST( RicWellPathExportMswGeometryPath, MultipleLaterals_CompletionBranchesListe
const std::vector<int> expected = { 1, 4, 5, 6, 2, 3 };
EXPECT_EQ( expected, branchNumbersInListedOrder );
}
//--------------------------------------------------------------------------------------------------
/// COMPSEGS is ordered by branch number, unlike WELSEGS.
//--------------------------------------------------------------------------------------------------
TEST( RicWellPathExportMswGeometryPath, MultipleLaterals_CompsegsOrderedByBranchNumber )
{
auto input = loadMultipleLateralsProject( "Well-A Y1" );
ASSERT_TRUE( input.eclipseCase != nullptr );
ASSERT_TRUE( input.wellPath != nullptr );
auto tableData = RicWellPathExportMswTableData::extractSingleWellMswData( input.eclipseCase, input.wellPath );
ASSERT_TRUE( tableData.has_value() );
ASSERT_FALSE( tableData->compsegsData().empty() );
std::vector<int> branchNumbers;
for ( const auto& row : tableData->compsegsData() )
{
branchNumbers.push_back( row.branch );
}
EXPECT_TRUE( std::is_sorted( branchNumbers.begin(), branchNumbers.end() ) );
// The lateral Y2 rows come before the ICD rows of the main bore, even though the ICD segments are
// listed first in WELSEGS.
EXPECT_LT( branchNumbers.front(), branchNumbers.back() );
}