///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RimWellPathTieIn.h" #include "Well/RigWellPath.h" #include "RimFileWellPath.h" #include "RimModeledWellPath.h" #include "RimTools.h" #include "RimWellPathCollection.h" #include "RimWellPathGeometryDef.h" #include "RimWellPathTarget.h" #include "RimWellPathValve.h" #include "RiuMainWindow.h" #include "cafPdmFieldScriptingCapability.h" #include "cafPdmObjectScriptingCapability.h" #include "cafPdmUiDoubleSliderEditor.h" #include "cafPdmUiLabelEditor.h" CAF_PDM_SOURCE_INIT( RimWellPathTieIn, "RimWellPathTieIn" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimWellPathTieIn::RimWellPathTieIn() { CAF_PDM_InitScriptableObjectWithNameAndComment( "Well Path Tie In", ":/NotDefined.png", "", "Well Path Tie In description", "WellPathTimeIn", "A ResInsight Well Tie-in" ); CAF_PDM_InitFieldNoDefault( &m_infoLabel, "InfoLabel", "Use right-click menu of well to set parent well." ); m_infoLabel.uiCapability()->setUiEditorTypeName( caf::PdmUiLabelEditor::uiEditorTypeName() ); m_infoLabel.xmlCapability()->disableIO(); m_infoLabel.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::LabelPosition::TOP ); CAF_PDM_InitFieldNoDefault( &m_parentWell, "ParentWellPath", "Parent Well Path" ); m_parentWell.uiCapability()->setUiReadOnly( true ); CAF_PDM_InitFieldNoDefault( &m_childWell, "ChildWellPath", "ChildWellPath" ); CAF_PDM_InitScriptableFieldNoDefault( &m_tieInMeasuredDepth, "TieInMeasuredDepth", "Tie In Measured Depth" ); m_tieInMeasuredDepth.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() ); CAF_PDM_InitScriptableField( &m_addValveAtConnection, "AddValveAtConnection", false, "Add Outlet Valve for Branch" ); CAF_PDM_InitScriptableFieldNoDefault( &m_valve, "Valve", "Branch Outlet Valve" ); CAF_PDM_InitScriptableField( &m_customOutletValveMD, "CustomOutletValveMd", std::make_pair( false, 0.0 ), "Outlet Valve Custom MD" ); m_valve = new RimWellPathValve(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::connectWellPaths( RimWellPath* parentWell, RimWellPath* childWell, double tieInMeasuredDepth ) { m_parentWell = parentWell; m_childWell = childWell; m_tieInMeasuredDepth = tieInMeasuredDepth; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimWellPath* RimWellPathTieIn::parentWell() const { return m_parentWell(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- double RimWellPathTieIn::tieInMeasuredDepth() const { return m_tieInMeasuredDepth(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::setTieInMeasuredDepth( double measuredDepth ) { m_tieInMeasuredDepth = measuredDepth; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- double RimWellPathTieIn::branchValveMeasuredDepth() const { if ( m_customOutletValveMD().first ) { return m_customOutletValveMD().second; } return m_tieInMeasuredDepth(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::setBranchValveMeasuredDepth( double measuredDepth ) { m_customOutletValveMD = std::make_pair( true, measuredDepth ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::useDefaultBranchValveMeasuredDepth() { m_customOutletValveMD = std::make_pair( false, m_tieInMeasuredDepth() ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::setBranchValveTemplate( RimValveTemplate* valveTemplate ) { if ( m_valve() ) { m_valve()->setValveTemplate( valveTemplate ); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::setEnableBranchValveAtConnection( bool enable ) { m_addValveAtConnection = enable; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimWellPath* RimWellPathTieIn::childWell() const { return m_childWell(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::updateChildWellGeometry() { auto modeledWellPath = dynamic_cast( m_childWell() ); if ( modeledWellPath ) { modeledWellPath->updateTieInLocationFromParentWell(); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::updateFirstTargetFromParentWell() { auto parentWellPath = m_parentWell(); if ( !parentWellPath ) return; auto modeledWellPath = dynamic_cast( m_childWell() ); if ( modeledWellPath && modeledWellPath->geometryDefinition() && parentWellPath->wellPathGeometry() && parentWellPath->wellPathGeometry()->measuredDepths().size() > 2 ) { auto [pointVector, measuredDepths] = parentWellPath->wellPathGeometry()->clippedPointSubset( parentWellPath->wellPathGeometry()->measuredDepths().front(), m_tieInMeasuredDepth ); if ( pointVector.size() < 2u ) return; RimWellPathTarget* newTarget = nullptr; if ( modeledWellPath->geometryDefinition()->activeWellTargets().empty() ) { newTarget = modeledWellPath->geometryDefinition()->appendTarget(); } else { newTarget = modeledWellPath->geometryDefinition()->activeWellTargets().front(); } auto lastPointXYZ = pointVector.back(); auto tangent = lastPointXYZ - pointVector[pointVector.size() - 2]; modeledWellPath->updateReferencePoint(); cvf::Vec3d referencePointXYZ = modeledWellPath->geometryDefinition()->anchorPointXyz(); cvf::Vec3d relativePointXYZ = lastPointXYZ - referencePointXYZ; newTarget->setAsPointXYZAndTangentTarget( { relativePointXYZ[0], relativePointXYZ[1], relativePointXYZ[2] }, tangent ); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimWellPathValve* RimWellPathTieIn::outletValve() const { auto retVal = m_addValveAtConnection() && m_valve() && m_valve->valveTemplate() ? m_valve() : nullptr; if ( retVal != nullptr ) { retVal->setMeasuredDepthAndCount( branchValveMeasuredDepth(), 0.0, 1 ); } return retVal; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { auto tieInGroup = uiOrdering.addNewGroup( "Tie In Settings" ); tieInGroup->add( &m_infoLabel ); tieInGroup->add( &m_parentWell ); if ( m_parentWell() != nullptr ) { tieInGroup->add( &m_tieInMeasuredDepth ); if ( parentWell() ) { auto wellPathGeo = parentWell()->wellPathGeometry(); if ( wellPathGeo && wellPathGeo->measuredDepths().size() > 0 ) { m_tieInMeasuredDepth.uiCapability()->setAttribute( caf::PdmUiDoubleSliderEditor::Keys::MINIMUM, wellPathGeo->measuredDepths().front() ); m_tieInMeasuredDepth.uiCapability()->setAttribute( caf::PdmUiDoubleSliderEditor::Keys::MAXIMUM, wellPathGeo->measuredDepths().back() ); } } tieInGroup->add( &m_addValveAtConnection ); bool isFileWellPath = dynamic_cast( m_childWell() ); m_tieInMeasuredDepth.uiCapability()->setUiReadOnly( isFileWellPath ); // Display only ICV valves m_valve->setComponentTypeFilter( { RiaDefines::WellPathComponentType::ICV } ); if ( m_addValveAtConnection ) { auto valveGrp = tieInGroup->addNewGroup( "Valve Options" ); valveGrp->add( &m_customOutletValveMD ); m_valve->uiOrdering( "TemplateOnly", *valveGrp ); } } uiOrdering.skipRemainingFields(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimWellPathTieIn::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) { // TODO: It is not possible to change the parent well from the UI as the field is set to read only. Refactor and possibly delete this // method. // https://github.com/OPM/ResInsight/issues/11312 // https://github.com/OPM/ResInsight/issues/11313 if ( changedField == &m_parentWell ) { updateFirstTargetFromParentWell(); RimWellPathCollection::instance()->rebuildWellPathNodes(); } updateChildWellGeometry(); // Update all well paths to make sure the visibility of completion settings is updated // Completions settings is only visible for top-level wells, not for tie-in wells RimWellPathCollection::instance()->updateAllRequiredEditors(); if ( changedField == &m_parentWell && m_childWell ) { RiuMainWindow::instance()->setExpanded( m_childWell ); RiuMainWindow::instance()->selectAsCurrentItem( m_childWell ); } if ( ( changedField == &m_customOutletValveMD ) && ( m_customOutletValveMD().first ) ) { if ( m_customOutletValveMD().second == 0.0 ) { m_customOutletValveMD.setValue( std::make_pair( true, m_tieInMeasuredDepth() ) ); } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QList RimWellPathTieIn::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) { QList options; if ( fieldNeedingOptions == &m_parentWell ) { std::vector wellPathsToExclude = { m_childWell() }; RimTools::wellPathOptionItemsSubset( wellPathsToExclude, &options ); options.push_front( caf::PdmOptionItemInfo( "None", nullptr ) ); } return options; }