Files
ResInsight/ApplicationLibCode/Commands/CompletionExportCommands/RicMswValveAccumulators.cpp
T
JJ 24be78f105 Tie-in valve improvements (#13661)
Support (bool, something) pairs as tuples on python side.
Support custom outlet valve md
Add python test for custom outlet valve md
Use tie-in depth as default for custom valve md
Standalone valve creation and display updates
Update MSW valve export
Add valve open/shut flag.
Add python examples
2026-03-06 12:01:14 +01:00

312 lines
13 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicMswValveAccumulators.h"
#include "RigStatisticsTools.h"
#include "RicMswCompletions.h"
#include "RimPerforationInterval.h"
#include "RimWellPathValve.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicMswICDAccumulator::RicMswICDAccumulator( RicMswValve* valve, RiaDefines::EclipseUnitSystem unitSystem )
: RicMswValveAccumulator( valve, unitSystem )
, m_areaSum( 0.0 )
{
}
//--------------------------------------------------------------------------------------------------
/// Accumulates weighted ICD valve parameters based on the overlap between valve locations and
/// perforation segments. Calculates area contributions weighted by overlap length for later
/// aggregation into a "super" ICD valve.
///
/// overlapLength Length of overlap between valve and perforation segment
/// perforationCompsegsLength Total length of perforation COMPSEGS for weighting
//--------------------------------------------------------------------------------------------------
bool RicMswICDAccumulator::accumulateValveParameters( const RimWellPathValve* wellPathValve, double overlapLength, double perforationCompsegsLength )
{
const double eps = 1.0e-8;
CVF_ASSERT( wellPathValve );
if ( wellPathValve->componentType() == RiaDefines::WellPathComponentType::ICV ||
wellPathValve->componentType() == RiaDefines::WellPathComponentType::ICD )
{
size_t nICDs = wellPathValve->valveLocations().size();
double icdArea = wellPathValve->area( m_unitSystem );
double totalIcdArea = static_cast<double>( nICDs ) * icdArea;
double icdAreaFactor = totalIcdArea * overlapLength / perforationCompsegsLength;
if ( icdAreaFactor > eps )
{
m_valid = true;
m_areaSum += icdAreaFactor;
m_coefficientCalculator.addValueAndWeight( wellPathValve->flowCoefficient(), icdAreaFactor );
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicMswICDAccumulator::applyToSuperValve()
{
auto icd = dynamic_cast<RicMswWsegValve*>( m_valve );
CVF_ASSERT( icd );
if ( m_coefficientCalculator.validAggregatedWeight() && m_valid )
{
icd->setIsValid( m_valid );
icd->setArea( m_areaSum );
icd->setFlowCoefficient( m_coefficientCalculator.weightedMean() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicMswAICDAccumulator::RicMswAICDAccumulator( RicMswValve* valve, RiaDefines::EclipseUnitSystem unitSystem )
: RicMswValveAccumulator( valve, unitSystem )
, m_deviceOpen( valve->isOpen() )
, m_accumulatedLength( 0.0 )
, m_accumulatedFlowScalingFactorDivisor( 0.0 )
{
}
//--------------------------------------------------------------------------------------------------
/// Accumulates weighted AICD (Autonomous Inflow Control Device) valve parameters based on the
/// overlap between valve locations and perforation segments. Calculates length-weighted means
/// of AICD parameters and flow scaling factors for later aggregation into a "super" AICD valve.
///
/// Only processes open AICD devices with valid parameters. All AICD parameters (strength,
/// exponents, viscosity function parameters, etc.) are accumulated using weighted means based
/// on overlap length. Flow scaling factor is computed according to issue #6126:
/// flowScalingFactor = 1 / (lengthFraction * aicdCount).
///
/// wellPathValve The valve to process (must be AICD type with valid parameters)
/// overlapLength Length of overlap between valve and perforation segment
/// perforationCompsegsLength Total length of perforation COMPSEGS for weighting
//--------------------------------------------------------------------------------------------------
bool RicMswAICDAccumulator::accumulateValveParameters( const RimWellPathValve* wellPathValve, double overlapLength, double perforationCompsegsLength )
{
const double eps = 1.0e-8;
CVF_ASSERT( wellPathValve );
if ( wellPathValve->componentType() == RiaDefines::WellPathComponentType::AICD && overlapLength > eps )
{
const RimWellPathAicdParameters* params = wellPathValve->aicdParameters();
if ( params->isValid() )
{
m_valid = true;
m_deviceOpen = m_deviceOpen || params->isOpen();
if ( params->isOpen() )
{
std::array<double, AICD_NUM_PARAMS> values = params->doubleValues();
for ( size_t i = 0; i < (size_t)AICD_NUM_PARAMS; ++i )
{
if ( RigStatisticsTools::isValidNumber( values[i] ) )
{
m_meanCalculators[i].addValueAndWeight( values[i], overlapLength );
}
}
m_accumulatedLength += overlapLength / perforationCompsegsLength;
// https://github.com/OPM/ResInsight/issues/6126
//
// flowScalingFactor = 1 / (lengthFraction * aicdCount)
// where:
// lengthFraction = length_COMPSEGS / Sum_length_COMPSEGS_for_valve
// N_AICDs = number of AICDs in perforation interval
size_t aicdCount = wellPathValve->valveLocations().size();
double lengthFraction = overlapLength / perforationCompsegsLength;
double divisor = lengthFraction * aicdCount;
m_accumulatedFlowScalingFactorDivisor += divisor;
return true;
}
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicMswAICDAccumulator::applyToSuperValve()
{
const double eps = 1.0e-8;
auto aicd = dynamic_cast<RicMswPerforationAICD*>( m_valve );
if ( aicd && m_valid && m_accumulatedLength > eps )
{
std::array<double, AICD_NUM_PARAMS> values;
for ( size_t i = 0; i < (size_t)AICD_NUM_PARAMS; ++i )
{
if ( m_meanCalculators[i].validAggregatedWeight() )
{
values[i] = m_meanCalculators[i].weightedMean();
}
else
{
values[i] = std::numeric_limits<double>::infinity();
}
}
aicd->setIsValid( m_valid );
aicd->setIsOpen( m_deviceOpen );
aicd->setLength( m_accumulatedLength );
// See https://github.com/OPM/ResInsight/issues/6126
double flowScalingFactor = 0.0;
if ( m_accumulatedFlowScalingFactorDivisor > eps )
{
flowScalingFactor = 1.0 / m_accumulatedFlowScalingFactorDivisor;
}
aicd->setflowScalingFactor( flowScalingFactor );
aicd->values() = values;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RicMswAICDAccumulator::accumulatedLength() const
{
return m_accumulatedLength;
}
//////////////////////////////////////////////////////////////
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicMswSICDAccumulator::RicMswSICDAccumulator( RicMswValve* valve, RiaDefines::EclipseUnitSystem unitSystem )
: RicMswValveAccumulator( valve, unitSystem )
, m_deviceOpen( valve->isOpen() )
, m_accumulatedLength( 0.0 )
, m_accumulatedFlowScalingFactorDivisor( 0.0 )
{
}
//--------------------------------------------------------------------------------------------------
/// Accumulates weighted SICD (Spiral Inflow Control Device) valve parameters based on the
/// overlap between valve locations and perforation segments. Calculates length-weighted means
/// of SICD parameters and flow scaling factors for later aggregation into a "super" SICD valve.
///
/// Only processes open SICD devices with valid parameters. All SICD parameters (strength,
/// exponents, viscosity function parameters, etc.) are accumulated using weighted means based
/// on overlap length. Flow scaling factor is computed according to issue #6126:
/// flowScalingFactor = 1 / (lengthFraction * aicdCount).
///
/// wellPathValve The valve to process (must be AICD type with valid parameters)
/// overlapLength Length of overlap between valve and perforation segment
/// perforationCompsegsLength Total length of perforation COMPSEGS for weighting
//--------------------------------------------------------------------------------------------------
bool RicMswSICDAccumulator::accumulateValveParameters( const RimWellPathValve* wellPathValve, double overlapLength, double perforationCompsegsLength )
{
const double eps = 1.0e-8;
CVF_ASSERT( wellPathValve );
if ( wellPathValve->componentType() == RiaDefines::WellPathComponentType::SICD && overlapLength > eps )
{
const RimWellPathSicdParameters* params = wellPathValve->sicdParameters();
if ( params->isValid() )
{
m_valid = true;
m_deviceOpen = m_deviceOpen || params->isOpen();
if ( params->isOpen() )
{
std::array<double, SICD_NUM_PARAMS> values = params->doubleValues();
for ( size_t i = 0; i < (size_t)SICD_NUM_PARAMS; ++i )
{
if ( RigStatisticsTools::isValidNumber( values[i] ) )
{
m_meanCalculators[i].addValueAndWeight( values[i], overlapLength );
}
}
m_accumulatedLength += overlapLength / perforationCompsegsLength;
size_t sicdCount = wellPathValve->valveLocations().size();
double lengthFraction = overlapLength / perforationCompsegsLength;
double divisor = lengthFraction * sicdCount;
m_accumulatedFlowScalingFactorDivisor += divisor;
return true;
}
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicMswSICDAccumulator::applyToSuperValve()
{
const double eps = 1.0e-8;
auto sicd = dynamic_cast<RicMswPerforationSICD*>( m_valve );
if ( sicd && m_valid && m_accumulatedLength > eps )
{
std::array<double, SICD_NUM_PARAMS> values;
for ( size_t i = 0; i < (size_t)SICD_NUM_PARAMS; i++ )
{
if ( m_meanCalculators[i].validAggregatedWeight() )
{
values[i] = m_meanCalculators[i].weightedMean();
}
else
{
values[i] = std::numeric_limits<double>::infinity();
}
}
sicd->setIsValid( m_valid );
sicd->setIsOpen( m_deviceOpen );
sicd->setLength( m_accumulatedLength );
double flowScalingFactor = 0.0;
if ( m_accumulatedFlowScalingFactorDivisor > eps )
{
flowScalingFactor = 1.0 / m_accumulatedFlowScalingFactorDivisor;
}
sicd->setflowScalingFactor( flowScalingFactor );
sicd->values() = values;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RicMswSICDAccumulator::accumulatedLength() const
{
return m_accumulatedLength;
}