Files
ResInsight/ApplicationLibCode/ProjectDataModel/Completions/RimPerforationInterval.cpp
T
Magne Sjaastad 91fed8e48c #14020 Use perforation interval cell filter to limit COMPDAT and MSW export
* Completions: Apply perforation cell filter to COMPDAT and MSW export
* PerforationInterval: Limit Cell Filter dropdown to case-level filters
* PerforationInterval: Prefix Cell Filter entries with case name when multiple cases
* Completions: Use std::format for cell filter suppression log messages
2026-05-20 16:04:40 +02:00

511 lines
20 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
//
// 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 "RimPerforationInterval.h"
#include "RiaColorTables.h"
#include "RiaEclipseUnitTools.h"
#include "RiaQDateTimeTools.h"
#include "RigCaseCellResultsData.h"
#include "Well/RigWellPath.h"
#include "RimCellFilter.h"
#include "RimDataFilterCollection.h"
#include "RimEclipseCase.h"
#include "RimPerforationCollection.h"
#include "RimProject.h"
#include "RimWellLogTrack.h"
#include "RimWellPath.h"
#include "RimWellPathValve.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObjectScriptingCapability.h"
#include "cafPdmUiDateEditor.h"
#include "cafPdmUiDoubleSliderEditor.h"
CAF_PDM_SOURCE_INIT( RimPerforationInterval, "Perforation" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPerforationInterval::RimPerforationInterval()
{
CAF_PDM_InitScriptableObject( "Perforation", ":/PerforationInterval16x16.png" );
CAF_PDM_InitScriptableField( &m_startMD, "StartMeasuredDepth", 0.0, "Start MD" );
CAF_PDM_InitScriptableField( &m_endMD, "EndMeasuredDepth", 0.0, "End MD" );
CAF_PDM_InitScriptableField( &m_diameter, "Diameter", 0.216, "Diameter" );
CAF_PDM_InitScriptableField( &m_skinFactor, "SkinFactor", 0.0, "Skin Factor" );
CAF_PDM_InitScriptableField( &m_completionNumber, "CompletionNumber", 0, "Completion Number" );
CAF_PDM_InitField( &m_startOfHistory_OBSOLETE, "StartOfHistory", true, "All Timesteps" );
m_startOfHistory_OBSOLETE.xmlCapability()->setIOWritable( false );
CAF_PDM_InitField( &m_useCustomStartDate, "UseCustomStartDate", false, "Custom Start Date" );
CAF_PDM_InitField( &m_startDate, "StartDate", QDateTime::currentDateTime(), "Start Date" );
CAF_PDM_InitField( &m_useCustomEndDate, "UseCustomEndDate", false, "Custom End Date" );
CAF_PDM_InitField( &m_endDate, "EndDate", QDateTime::currentDateTime(), "End Date" );
CAF_PDM_InitScriptableFieldNoDefault( &m_valves, "Valves", "Valves" );
// Non-scriptable: a scriptable PdmPtrField surfaces in Python as an opaque address string.
// Keeping the field non-scriptable makes the generator emit a `cell_filter()` accessor that
// resolves to a CellFilter object (same pattern as `valve.template()`). The setter goes
// through RimcPerforationInterval_addFilter ("AddFilter").
CAF_PDM_InitFieldNoDefault( &m_cellFilter, "CellFilter", "Cell Filter" );
nameField()->uiCapability()->setUiReadOnly( true );
m_startMD.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
m_endMD.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
setDeletable( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPerforationInterval::~RimPerforationInterval()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setStartAndEndMD( double startMD, double endMD )
{
m_startMD = startMD;
m_endMD = endMD;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::enableCustomStartDate( bool enable )
{
m_useCustomStartDate = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setCustomStartDate( const QDate& date )
{
if ( date.isValid() )
{
m_startDate = RiaQDateTimeTools::createDateTime( date );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setCustomEndDate( const QDate& date )
{
if ( date.isValid() )
{
m_endDate = RiaQDateTimeTools::createDateTime( date );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setDiameter( double diameter )
{
m_diameter = diameter;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setSkinFactor( double skinFactor )
{
m_skinFactor = skinFactor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimPerforationInterval::diameter( RiaDefines::EclipseUnitSystem unitSystem ) const
{
auto wellPath = firstAncestorOrThisOfTypeAsserted<RimWellPath>();
if ( unitSystem == RiaDefines::EclipseUnitSystem::UNITS_METRIC && wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_FIELD )
{
return RiaEclipseUnitTools::feetToMeter( m_diameter() );
}
else if ( unitSystem == RiaDefines::EclipseUnitSystem::UNITS_FIELD && wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_METRIC )
{
return RiaEclipseUnitTools::meterToFeet( m_diameter() );
}
return m_diameter();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimPerforationInterval::skinFactor() const
{
return m_skinFactor();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setCompletionNumber( int number )
{
m_completionNumber = number;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimPerforationInterval::completionNumber() const
{
return m_completionNumber();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPerforationInterval::isActiveOnDate( const QDateTime& date ) const
{
if ( m_useCustomStartDate() && date < m_startDate() ) return false;
if ( m_useCustomEndDate() && date > m_endDate() ) return false;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox RimPerforationInterval::boundingBoxInDomainCoords() const
{
cvf::BoundingBox bb;
auto wellPath = firstAncestorOrThisOfTypeAsserted<RimWellPath>();
RigWellPath* rigWellPath = wellPath->wellPathGeometry();
if ( rigWellPath )
{
bb.add( rigWellPath->interpolatedPointAlongWellPath( startMD() ) );
bb.add( rigWellPath->interpolatedPointAlongWellPath( endMD() ) );
}
return bb;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setUnitSystemSpecificDefaults()
{
auto wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( wellPath )
{
if ( wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_METRIC )
{
m_diameter = 0.216;
}
else if ( wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_FIELD )
{
m_diameter = 0.709;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::addValve( RimWellPathValve* valve )
{
m_valves.push_back( valve );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPathValve*> RimPerforationInterval::valves() const
{
std::vector<RimWellPathValve*> allValves;
for ( RimWellPathValve* valve : m_valves() )
{
allValves.push_back( valve );
}
return allValves;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCellFilter* RimPerforationInterval::cellFilter() const
{
return m_cellFilter();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::setCellFilter( RimCellFilter* filter )
{
m_cellFilter = filter;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::updateAllReferringTracks()
{
std::vector<RimWellLogTrack*> wellLogTracks = objectsWithReferringPtrFieldsOfType<RimWellLogTrack>();
for ( RimWellLogTrack* track : wellLogTracks )
{
track->loadDataAndUpdate();
}
updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPerforationInterval::isEnabled() const
{
auto perforationCollection = firstAncestorOrThisOfTypeAsserted<RimPerforationCollection>();
return perforationCollection->isChecked() && isChecked();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaDefines::WellPathComponentType RimPerforationInterval::componentType() const
{
return RiaDefines::WellPathComponentType::PERFORATION_INTERVAL;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPerforationInterval::componentLabel() const
{
return QString( "Perforation Interval\n%1" ).arg( name() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPerforationInterval::componentTypeLabel() const
{
return "Perforations";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimPerforationInterval::defaultComponentColor() const
{
return RiaColorTables::wellPathComponentColors()[componentType()];
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimPerforationInterval::startMD() const
{
return m_startMD();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimPerforationInterval::endMD() const
{
return m_endMD();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::applyOffset( double offsetMD )
{
m_startMD = m_startMD + offsetMD;
m_endMD = m_endMD + offsetMD;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
if ( changedField == &m_startMD || changedField == &m_endMD )
{
for ( RimWellPathValve* valve : m_valves() )
{
valve->perforationIntervalUpdated();
}
}
updateAllReferringTracks();
RimProject* proj = RimProject::current();
proj->reloadCompletionTypeResultsInAllViews();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ )
{
setName( QString( "%1 - %2" ).arg( m_startMD() ).arg( m_endMD() ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
{
auto wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( wellPath )
{
if ( wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_METRIC )
{
m_startMD.uiCapability()->setUiName( "Start MD [m]" );
m_endMD.uiCapability()->setUiName( "End MD [m]" );
m_diameter.uiCapability()->setUiName( "Diameter [m]" );
}
else if ( wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_FIELD )
{
m_startMD.uiCapability()->setUiName( "Start MD [ft]" );
m_endMD.uiCapability()->setUiName( "End MD [ft]" );
m_diameter.uiCapability()->setUiName( "Diameter [ft]" );
}
}
}
uiOrdering.add( &m_startMD );
uiOrdering.add( &m_endMD );
uiOrdering.add( &m_diameter );
uiOrdering.add( &m_skinFactor );
uiOrdering.add( &m_completionNumber );
auto filterGrp = uiOrdering.addNewGroup( "Cell Filter" );
filterGrp->add( &m_cellFilter );
auto dateGrp = uiOrdering.addNewGroup( "Date Settings" );
dateGrp->setCollapsedByDefault();
dateGrp->add( &m_useCustomStartDate );
dateGrp->add( &m_startDate );
m_startDate.uiCapability()->setUiReadOnly( !m_useCustomStartDate );
dateGrp->add( &m_useCustomEndDate );
dateGrp->add( &m_endDate );
m_endDate.uiCapability()->setUiReadOnly( !m_useCustomEndDate );
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
/// Populate the "Cell Filter" dropdown with case-level data filters only. View-owned filters
/// (under RimGridView's RimCellFilterCollection) are excluded — completion export operates on a
/// case, not a view, so per-view filters are not applicable here.
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimPerforationInterval::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
{
QList<caf::PdmOptionItemInfo> options;
if ( fieldNeedingOptions == &m_cellFilter )
{
options.push_back( caf::PdmOptionItemInfo( "None", static_cast<RimCellFilter*>( nullptr ) ) );
if ( auto* project = RimProject::current() )
{
std::vector<std::pair<RimEclipseCase*, std::vector<RimCellFilter*>>> filtersByCase;
for ( RimCase* rimCase : project->allGridCases() )
{
auto* eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase );
if ( !eclipseCase ) continue;
RimDataFilterCollection* dataFilters = eclipseCase->dataFilterCollection();
if ( !dataFilters ) continue;
std::vector<RimCellFilter*> caseFilters;
for ( RimCellFilter* filter : dataFilters->filters() )
{
if ( filter ) caseFilters.push_back( filter );
}
if ( !caseFilters.empty() ) filtersByCase.emplace_back( eclipseCase, caseFilters );
}
const bool prefixWithCaseName = filtersByCase.size() > 1;
for ( const auto& [eclipseCase, caseFilters] : filtersByCase )
{
for ( RimCellFilter* filter : caseFilters )
{
QString label = prefixWithCaseName ? QString( "%1 : %2" ).arg( eclipseCase->caseUserDescription(), filter->name() )
: filter->name();
options.push_back( caf::PdmOptionItemInfo( label, filter ) );
}
}
}
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
if ( field == &m_startDate || field == &m_endDate )
{
caf::PdmUiDateEditorAttribute* myAttr = dynamic_cast<caf::PdmUiDateEditorAttribute*>( attribute );
if ( myAttr )
{
myAttr->dateFormat = "dd MMM yyyy";
}
}
else if ( field == &m_startMD || field == &m_endMD )
{
caf::PdmUiDoubleSliderEditorAttribute* myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute );
if ( myAttr )
{
auto wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( !wellPath ) return;
myAttr->m_minimum = wellPath->uniqueStartMD();
myAttr->m_maximum = wellPath->uniqueEndMD();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPerforationInterval::initAfterRead()
{
if ( !m_startOfHistory_OBSOLETE )
{
m_useCustomStartDate = true;
}
}