Adjust wsegdims values based on MSW data

This commit is contained in:
jonjenssen
2025-11-14 23:19:41 +01:00
committed by JJ
parent eb08ceeedc
commit df8fbfe458
3 changed files with 25 additions and 12 deletions
@@ -46,6 +46,8 @@
#include "opm/input/eclipse/Parser/ParserKeywords/O.hpp"
#include "opm/input/eclipse/Parser/ParserKeywords/W.hpp"
#include <algorithm>
//==================================================================================================
///
///
@@ -154,8 +156,11 @@ Opm::DeckKeyword compdatKeyword( RimEclipseCase* eCase, RimWellPath* wellPath )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Opm::DeckKeyword welsegsKeyword( const RigMswTableData& mswData )
Opm::DeckKeyword welsegsKeyword( const RigMswTableData& mswData, int& maxSegments, int& maxBranches )
{
maxSegments = 0;
maxBranches = 0;
if ( !mswData.hasWelsegsData() ) return Opm::DeckKeyword();
using W = Opm::ParserKeywords::WELSEGS;
@@ -178,6 +183,10 @@ Opm::DeckKeyword welsegsKeyword( const RigMswTableData& mswData )
// welsegs data rows
for ( auto& wsRow : mswData.welsegsData() )
{
maxSegments = std::max( maxSegments, wsRow.segment1 );
maxSegments = std::max( maxSegments, wsRow.segment2 );
maxBranches = std::max( maxBranches, wsRow.branch );
std::vector<Opm::DeckItem> items;
items.push_back( RifOpmDeckTools::item( Opm::ParserKeywords::WELSEGS::SEGMENT1::itemName, wsRow.segment1 ) );
items.push_back( RifOpmDeckTools::item( Opm::ParserKeywords::WELSEGS::SEGMENT2::itemName, wsRow.segment2 ) );
@@ -50,7 +50,7 @@ namespace RimKeywordFactory
Opm::DeckKeyword welspecsKeyword( const std::string wellGrpName, RimEclipseCase* eCase, RimWellPath* wellPath );
Opm::DeckKeyword compdatKeyword( RimEclipseCase* eCase, RimWellPath* wellPath );
Opm::DeckKeyword welsegsKeyword( const RigMswTableData& mswData );
Opm::DeckKeyword welsegsKeyword( const RigMswTableData& mswData, int& maxSegments, int& maxBranches );
Opm::DeckKeyword compsegsKeyword( const RigMswTableData& mswData );
Opm::DeckKeyword wsegvalvKeyword( const RigMswTableData& mswData );
Opm::DeckKeyword wsegaicdKeyword( const RigMswTableData& mswData );
@@ -1050,10 +1050,12 @@ int RimOpmFlowJob::mergeMswData( int mergePosition )
return failure;
}
auto welsegsKw = RimKeywordFactory::welsegsKeyword( mswDataResult.value() );
auto compsegsKw = RimKeywordFactory::compsegsKeyword( mswDataResult.value() );
auto wsegvalvKw = RimKeywordFactory::wsegvalvKeyword( mswDataResult.value() );
auto wsegaicdKw = RimKeywordFactory::wsegaicdKeyword( mswDataResult.value() );
int maxSegNum = 0;
int maxBranches = 0;
auto welsegsKw = RimKeywordFactory::welsegsKeyword( mswDataResult.value(), maxSegNum, maxBranches );
auto compsegsKw = RimKeywordFactory::compsegsKeyword( mswDataResult.value() );
auto wsegvalvKw = RimKeywordFactory::wsegvalvKeyword( mswDataResult.value() );
auto wsegaicdKw = RimKeywordFactory::wsegaicdKeyword( mswDataResult.value() );
if ( welsegsKw.empty() || compsegsKw.empty() )
{
@@ -1099,13 +1101,15 @@ int RimOpmFlowJob::mergeMswData( int mergePosition )
}
}
int branches = (int)m_wellPath->allWellPathLaterals().size();
int branches = (int)m_wellPath->allWellPathLaterals().size() + 1;
// increase wells and connections in welldims to make sure they are big enough
auto additionalSegments = (int)welsegsKw.size() - 1;
auto wsegdims = m_deckFile->wsegdims();
auto maxBranches = std::max( branches, wsegdims[2] );
if ( ( wsegdims.size() < 3 ) || !m_deckFile->setWsegdims( wsegdims[0] + 1, wsegdims[1] + additionalSegments, maxBranches + 1 ) )
// wsegdims contains: max segmented wells, max segments, max branches
auto wsegdims = m_deckFile->wsegdims();
int maxSegWells = wsegdims[0] + 1; // we have added one well
maxSegNum = std::max( wsegdims[1], maxSegNum );
maxBranches = std::max( branches, maxBranches );
maxBranches = std::max( wsegdims[2], maxBranches );
if ( !m_deckFile->setWsegdims( maxSegWells, maxSegNum, maxBranches ) )
{
RiaLogging::error( "Failed to update WSEGDIMS keyword in DATA file." );
return failure;