diff --git a/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake index 0aadafdc3e..4869ad0c8d 100644 --- a/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/EclipseCommands/CMakeLists_files.cmake @@ -18,6 +18,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicEclipsePropertyFilterNewInViewFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicEclipseHideFaultFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicEclipseShowOnlyFaultFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicNewFaultDistanceResultFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicRenameCaseFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicAddGridCalculationFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCaseEnsemblesFromFilesFeature.cpp diff --git a/ApplicationLibCode/Commands/EclipseCommands/RicNewFaultDistanceResultFeature.cpp b/ApplicationLibCode/Commands/EclipseCommands/RicNewFaultDistanceResultFeature.cpp new file mode 100644 index 0000000000..70112f1563 --- /dev/null +++ b/ApplicationLibCode/Commands/EclipseCommands/RicNewFaultDistanceResultFeature.cpp @@ -0,0 +1,109 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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 "RicNewFaultDistanceResultFeature.h" + +#include "RimFaultDistanceResult.h" +#include "RimFaultDistanceResultCollection.h" +#include "RimFaultInView.h" +#include "RimFaultInViewCollection.h" + +#include "Riu3DMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicNewFaultDistanceResultFeature, "RicNewFaultDistanceResultFeature" ); + +namespace +{ +RimFaultInViewCollection* findHostCollection() +{ + const auto faultCollections = caf::SelectionManager::instance()->objectsByType(); + if ( !faultCollections.empty() ) return faultCollections.front(); + + const auto distanceCollections = caf::SelectionManager::instance()->objectsByType(); + if ( !distanceCollections.empty() ) + { + return distanceCollections.front()->firstAncestorOrThisOfType(); + } + + const auto distanceResults = caf::SelectionManager::instance()->objectsByType(); + if ( !distanceResults.empty() ) + { + return distanceResults.front()->firstAncestorOrThisOfType(); + } + + const auto faults = caf::SelectionManager::instance()->objectsByType(); + if ( !faults.empty() ) + { + return faults.front()->firstAncestorOrThisOfType(); + } + + return nullptr; +} +} // namespace + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicNewFaultDistanceResultFeature::isCommandEnabled() const +{ + return findHostCollection() != nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewFaultDistanceResultFeature::onActionTriggered( bool isChecked ) +{ + RimFaultInViewCollection* hostCollection = findHostCollection(); + if ( !hostCollection ) return; + + RimFaultDistanceResultCollection* distanceCollection = hostCollection->faultDistanceResults(); + if ( !distanceCollection ) return; + + const auto selectedFaultPointers = caf::SelectionManager::instance()->objectsByType(); + std::vector selectedFaults( selectedFaultPointers.begin(), selectedFaultPointers.end() ); + + RimFaultDistanceResult* newResult = distanceCollection->addResult(); + if ( !newResult ) return; + + if ( !selectedFaults.empty() ) + { + newResult->setSelectedFaults( selectedFaults ); + } + else + { + newResult->setSelectedFaults( hostCollection->faults() ); + } + + hostCollection->updateConnectedEditors(); + distanceCollection->updateConnectedEditors(); + Riu3DMainWindowTools::selectAsCurrentItem( newResult ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicNewFaultDistanceResultFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "New Fault Distance Result" ); + actionToSetup->setIcon( QIcon( ":/draw_style_faults_24x24.png" ) ); +} diff --git a/ApplicationLibCode/Commands/EclipseCommands/RicNewFaultDistanceResultFeature.h b/ApplicationLibCode/Commands/EclipseCommands/RicNewFaultDistanceResultFeature.h new file mode 100644 index 0000000000..f4e25a3f8e --- /dev/null +++ b/ApplicationLibCode/Commands/EclipseCommands/RicNewFaultDistanceResultFeature.h @@ -0,0 +1,34 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicNewFaultDistanceResultFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() const override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; diff --git a/ApplicationLibCode/ProjectDataModel/Faults/CMakeLists_files.cmake b/ApplicationLibCode/ProjectDataModel/Faults/CMakeLists_files.cmake index 735ff2aa04..89ce932cff 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/CMakeLists_files.cmake +++ b/ApplicationLibCode/ProjectDataModel/Faults/CMakeLists_files.cmake @@ -1,4 +1,6 @@ set(SOURCE_GROUP_SOURCE_FILES + ${CMAKE_CURRENT_LIST_DIR}/RimFaultDistanceResult.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimFaultDistanceResultCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimFaultInView.cpp ${CMAKE_CURRENT_LIST_DIR}/RimFaultInViewCollection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimFaultReactivationModel.cpp diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.cpp new file mode 100644 index 0000000000..1ce953fef2 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.cpp @@ -0,0 +1,190 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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 "RimFaultDistanceResult.h" + +#include "RiaDefines.h" + +#include "RigCaseCellResultsData.h" +#include "RigEclipseCaseData.h" +#include "RigEclipseResultAddress.h" +#include "RigFault.h" +#include "RigSelectedFaultDistanceResultCalculator.h" + +#include "RimEclipseCase.h" +#include "RimEclipseView.h" +#include "RimFaultInView.h" +#include "RimFaultInViewCollection.h" + +#include "cafPdmUiTreeSelectionEditor.h" + +CAF_PDM_SOURCE_INIT( RimFaultDistanceResult, "RimFaultDistanceResult" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaultDistanceResult::RimFaultDistanceResult() +{ + CAF_PDM_InitObject( "Fault Distance Result", ":/draw_style_faults_24x24.png" ); + + CAF_PDM_InitFieldNoDefault( &m_resultName, "ResultName", "Name" ); + + CAF_PDM_InitFieldNoDefault( &m_faults, "SelectedFaults", "Faults" ); + m_faults.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFaultDistanceResult::resultName() const +{ + return m_resultName(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResult::setResultName( const QString& name ) +{ + m_resultName = name; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResult::setSelectedFaults( const std::vector& faults ) +{ + m_faults.setValue( faults ); + compute(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimFaultDistanceResult::selectedRigFaults() const +{ + std::vector rigFaults; + for ( RimFaultInView* fault : m_faults ) + { + if ( fault && fault->faultGeometry() ) rigFaults.push_back( fault->faultGeometry() ); + } + return rigFaults; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResult::compute() +{ + if ( m_resultName().isEmpty() ) return; + + auto eclipseView = firstAncestorOrThisOfType(); + if ( !eclipseView ) return; + + RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); + if ( !eclipseCase ) return; + + RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData(); + if ( !caseData ) return; + + RigSelectedFaultDistanceResultCalculator::compute( caseData, m_resultName(), selectedRigFaults() ); + + eclipseView->scheduleCreateDisplayModelAndRedraw(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResult::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) +{ + if ( changedField == &m_resultName ) + { + const QString previousName = oldValue.toString(); + if ( !previousName.isEmpty() && previousName != m_resultName() ) + { + removeGeneratedResult( previousName ); + } + compute(); + } + else if ( changedField == &m_faults ) + { + compute(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RimFaultDistanceResult::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) +{ + QList options; + + if ( fieldNeedingOptions == &m_faults ) + { + auto faultCollection = firstAncestorOrThisOfType(); + if ( faultCollection ) + { + for ( RimFaultInView* fault : faultCollection->faults() ) + { + if ( fault ) options.push_back( caf::PdmOptionItemInfo( fault->name(), fault ) ); + } + } + } + + return options; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmFieldHandle* RimFaultDistanceResult::userDescriptionField() +{ + return &m_resultName; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResult::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) +{ + uiOrdering.add( &m_resultName ); + uiOrdering.add( &m_faults ); + uiOrdering.skipRemainingFields( true ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResult::removeGeneratedResult( const QString& name ) +{ + if ( name.isEmpty() ) return; + + auto eclipseView = firstAncestorOrThisOfType(); + if ( !eclipseView ) return; + + RimEclipseCase* eclipseCase = eclipseView->eclipseCase(); + if ( !eclipseCase ) return; + + RigEclipseCaseData* caseData = eclipseCase->eclipseCaseData(); + if ( !caseData ) return; + + RigCaseCellResultsData* resultsData = caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); + if ( !resultsData ) return; + + resultsData->clearScalarResult( RiaDefines::ResultCatType::GENERATED, name ); +} diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.h new file mode 100644 index 0000000000..df4821f5f1 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResult.h @@ -0,0 +1,61 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmPtrArrayField.h" + +#include + +#include + +class RigFault; +class RimFaultInView; + +//================================================================================================== +/// +//================================================================================================== +class RimFaultDistanceResult : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + RimFaultDistanceResult(); + + QString resultName() const; + void setResultName( const QString& name ); + + void setSelectedFaults( const std::vector& faults ); + std::vector selectedRigFaults() const; + + void compute(); + +protected: + void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; + QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; + caf::PdmFieldHandle* userDescriptionField() override; + void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; + +private: + void removeGeneratedResult( const QString& name ); + + caf::PdmPtrArrayField m_faults; + caf::PdmField m_resultName; +}; diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResultCollection.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResultCollection.cpp new file mode 100644 index 0000000000..3167afc7e3 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResultCollection.cpp @@ -0,0 +1,79 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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 "RimFaultDistanceResultCollection.h" + +#include "RimFaultDistanceResult.h" + +#include "cafPdmUiTreeOrdering.h" + +#include + +CAF_PDM_SOURCE_INIT( RimFaultDistanceResultCollection, "RimFaultDistanceResultCollection" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaultDistanceResultCollection::RimFaultDistanceResultCollection() +{ + CAF_PDM_InitObject( "Fault Distance Results", ":/draw_style_faults_24x24.png" ); + + CAF_PDM_InitFieldNoDefault( &m_items, "FaultDistanceResults", "" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaultDistanceResult* RimFaultDistanceResultCollection::addResult() +{ + auto* newResult = new RimFaultDistanceResult(); + newResult->setResultName( nextDefaultName() ); + addItem( newResult ); + return newResult; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFaultDistanceResultCollection::nextDefaultName() const +{ + QRegularExpression pattern( "^FAULTDIST(\\d+)$" ); + int maxIndex = 0; + for ( RimFaultDistanceResult* result : items() ) + { + if ( !result ) continue; + const QRegularExpressionMatch match = pattern.match( result->resultName() ); + if ( match.hasMatch() ) + { + maxIndex = std::max( maxIndex, match.captured( 1 ).toInt() ); + } + } + return QString( "FAULTDIST%1" ).arg( maxIndex + 1 ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFaultDistanceResultCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName ) +{ + for ( RimFaultDistanceResult* result : items() ) + { + uiTreeOrdering.add( result ); + } + uiTreeOrdering.skipRemainingChildren( true ); +} diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResultCollection.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResultCollection.h new file mode 100644 index 0000000000..f5faa811fd --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultDistanceResultCollection.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmObjectCollection.h" + +#include + +class RimFaultDistanceResult; + +//================================================================================================== +/// +//================================================================================================== +class RimFaultDistanceResultCollection : public caf::PdmObjectCollection +{ + CAF_PDM_HEADER_INIT; + +public: + RimFaultDistanceResultCollection(); + + RimFaultDistanceResult* addResult(); + QString nextDefaultName() const; + +private: + void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName ) override; +}; diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.cpp index 43c774ee34..5d9242647b 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.cpp @@ -27,6 +27,7 @@ #include "RimEclipseFaultColors.h" #include "RimEclipseView.h" +#include "RimFaultDistanceResultCollection.h" #include "RimFaultInView.h" #include "RimIntersectionCollection.h" #include "RimProject.h" @@ -98,6 +99,9 @@ RimFaultInViewCollection::RimFaultInViewCollection() CAF_PDM_InitFieldNoDefault( &m_faults, "Faults", "Faults" ); + CAF_PDM_InitFieldNoDefault( &m_distanceResults, "FaultDistanceResults", "" ); + m_distanceResults = new RimFaultDistanceResultCollection; + CAF_PDM_InitField( &m_showFaultsOutsideFilters_obsolete, "ShowFaultsOutsideFilters", true, "Show Faults Outside Filters" ); m_showFaultsOutsideFilters_obsolete.xmlCapability()->setIOWritable( false ); m_showFaultsOutsideFilters_obsolete.uiCapability()->setUiHidden( true ); @@ -391,6 +395,11 @@ void RimFaultInViewCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiT uiTreeOrdering.appendChild( uiTree ); } + if ( m_distanceResults() && !m_distanceResults()->isEmpty() ) + { + uiTreeOrdering.add( m_distanceResults() ); + } + for ( const auto& fault : m_faults ) { uiTreeOrdering.add( fault ); @@ -407,6 +416,14 @@ RimEclipseView* RimFaultInViewCollection::parentView() const return firstAncestorOrThisOfTypeAsserted(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFaultDistanceResultCollection* RimFaultInViewCollection::faultDistanceResults() const +{ + return m_distanceResults(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.h b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.h index 0514b1da69..1c61f2d875 100644 --- a/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.h +++ b/ApplicationLibCode/ProjectDataModel/Faults/RimFaultInViewCollection.h @@ -21,6 +21,7 @@ #include "cafAppEnum.h" #include "cafPdmChildArrayField.h" +#include "cafPdmChildField.h" #include "cafPdmField.h" #include "cafPdmObject.h" @@ -32,6 +33,7 @@ #include class RimEclipseView; +class RimFaultDistanceResultCollection; class RimFaultInView; //================================================================================================== @@ -57,6 +59,7 @@ public: void setActive( bool bActive ); std::vector faults() const; + RimFaultDistanceResultCollection* faultDistanceResults() const; cvf::Color3f faultLabelColor() const; caf::AppEnum faultResult() const; bool showFaultFaces() const; @@ -105,7 +108,8 @@ private: caf::PdmField> m_faultResult; - caf::PdmChildArrayField m_faults; + caf::PdmChildArrayField m_faults; + caf::PdmChildField m_distanceResults; caf::PdmField m_showFaultsOutsideFilters_obsolete; }; diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 83d87b57b7..77ce60dd4b 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -68,7 +68,10 @@ #include "RimEnsembleCurveSetCollection.h" #include "RimEnsembleFractureStatisticsCollection.h" #include "RimExtrudedCurveIntersection.h" +#include "RimFaultDistanceResult.h" +#include "RimFaultDistanceResultCollection.h" #include "RimFaultInView.h" +#include "RimFaultInViewCollection.h" #include "RimFaultReactivationModel.h" #include "RimFileWellPath.h" #include "RimFishbones.h" @@ -846,6 +849,12 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicExportFaultsFeature"; + menuBuilder << "RicNewFaultDistanceResultFeature"; + } + else if ( dynamic_cast( firstUiItem ) || + dynamic_cast( firstUiItem ) || dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicNewFaultDistanceResultFeature"; } else if ( dynamic_cast( firstUiItem ) ) { @@ -1186,6 +1195,12 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicExportFaultsFeature"; + menuBuilder << "RicNewFaultDistanceResultFeature"; + } + else if ( dynamic_cast( firstUiItem ) || + dynamic_cast( firstUiItem ) || dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicNewFaultDistanceResultFeature"; } else if ( dynamic_cast( firstUiItem ) ) { diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake index 5951329c40..e128fe78eb 100644 --- a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/CMakeLists_files.cmake @@ -2,7 +2,9 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigSoilResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigSwatResultCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/RigFaultDistanceCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigFaultDistanceResultCalculator.cpp + ${CMAKE_CURRENT_LIST_DIR}/RigSelectedFaultDistanceResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigMobilePoreVolumeResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigIndexIjkResultCalculator.cpp ${CMAKE_CURRENT_LIST_DIR}/RigOilVolumeResultCalculator.cpp diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceCalculator.cpp new file mode 100644 index 0000000000..4a8e46f36f --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceCalculator.cpp @@ -0,0 +1,134 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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 "RigFaultDistanceCalculator.h" + +#include "RigActiveCellInfo.h" +#include "RigCell.h" +#include "RigFault.h" +#include "RigMainGrid.h" + +#include "cvfBoundingBoxTree.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigFaultDistanceCalculator::computeFaultDistances( const RigMainGrid* mainGrid, + const RigActiveCellInfo* activeCellInfo, + const std::vector& faultsToInclude, + std::vector& resultValues ) +{ + if ( !mainGrid || !activeCellInfo ) return; + + const auto activeCells = activeCellInfo->activeReservoirCellIndices(); + if ( activeCells.empty() ) return; + + if ( resultValues.size() < activeCells.size() ) + { + resultValues.resize( activeCells.size(), std::numeric_limits::infinity() ); + } + + // Collect fault face centers from the requested subset of faults. + std::vector faultFaceCenters; + for ( const RigFault* fault : faultsToInclude ) + { + if ( !fault ) continue; + for ( const RigFault::FaultFace& faultFace : fault->faultFaces() ) + { + if ( faultFace.m_nativeReservoirCellIndex >= mainGrid->cellCount() ) continue; + const RigCell& cell = mainGrid->cell( faultFace.m_nativeReservoirCellIndex ); + if ( cell.isInvalid() ) continue; + faultFaceCenters.push_back( cell.faceCenter( faultFace.m_nativeFace ) ); + } + } + + if ( faultFaceCenters.empty() ) return; + + // Create bounding box tree for all face centers + cvf::BoundingBoxTree searchTree; + { + std::vector faceIndicesForBoundingBoxes; + std::vector faceBBs; + + size_t faceCenterIndex = 0; + for ( const auto& faultFaceCenter : faultFaceCenters ) + { + cvf::BoundingBox bb; + bb.add( faultFaceCenter ); + faceBBs.push_back( bb ); + faceIndicesForBoundingBoxes.push_back( faceCenterIndex++ ); + } + searchTree.buildTreeFromBoundingBoxes( faceBBs, &faceIndicesForBoundingBoxes ); + } + + const auto nodes = mainGrid->nodes(); + const auto mainGridBB = mainGrid->boundingBox(); + +#pragma omp parallel for + for ( int activeIndex = 0; activeIndex < static_cast( activeCells.size() ); activeIndex++ ) + { + auto cellIdx = activeCells[activeIndex]; + if ( cellIdx.value() == cvf::UNDEFINED_SIZE_T ) continue; + + const RigCell& cell = mainGrid->cell( cellIdx.value() ); + if ( cell.isInvalid() ) continue; + + std::vector candidateFaceIndices; + { + cvf::BoundingBox bb; + const auto& cellIndices = cell.cornerIndices(); + for ( const auto& i : cellIndices ) + { + bb.add( nodes[i] ); + } + + searchTree.findIntersections( bb, &candidateFaceIndices ); + + bool bbIsBelowThreshold = true; + while ( candidateFaceIndices.empty() && bbIsBelowThreshold ) + { + if ( bb.extent().x() > mainGridBB.extent().x() * 2 ) + { + bbIsBelowThreshold = false; + break; + } + if ( bb.extent().y() > mainGridBB.extent().y() * 2 ) + { + bbIsBelowThreshold = false; + break; + } + + bb.expand( bb.extent().x() ); + searchTree.findIntersections( bb, &candidateFaceIndices ); + } + } + + // Find closest fault face + double shortestDistance = std::numeric_limits::infinity(); + + for ( const auto& faultFaceIndex : candidateFaceIndices ) + { + const cvf::Vec3d& faultFaceCenter = faultFaceCenters[faultFaceIndex]; + shortestDistance = std::min( cell.center().pointDistance( faultFaceCenter ), shortestDistance ); + } + + resultValues[activeIndex] = shortestDistance; + } +} diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceCalculator.h b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceCalculator.h new file mode 100644 index 0000000000..e8d65695f8 --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceCalculator.h @@ -0,0 +1,36 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +class RigActiveCellInfo; +class RigFault; +class RigMainGrid; + +//================================================================================================== +/// +//================================================================================================== +namespace RigFaultDistanceCalculator +{ +void computeFaultDistances( const RigMainGrid* mainGrid, + const RigActiveCellInfo* activeCellInfo, + const std::vector& faultsToInclude, + std::vector& resultValues ); +} diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceResultCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceResultCalculator.cpp index fbceff6591..5c4a177bcd 100644 --- a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceResultCalculator.cpp +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigFaultDistanceResultCalculator.cpp @@ -22,12 +22,11 @@ #include "RiaResultNames.h" #include "RigActiveCellInfo.h" #include "RigCaseCellResultsData.h" -#include "RigCell.h" #include "RigEclipseResultInfo.h" +#include "RigFault.h" +#include "RigFaultDistanceCalculator.h" #include "RigMainGrid.h" -#include "cvfBoundingBoxTree.h" - //================================================================================================== /// //================================================================================================== @@ -80,92 +79,11 @@ void RigFaultDistanceResultCalculator::calculate( const RigEclipseResultAddress& const auto mainGrid = m_resultsData->m_ownerMainGrid; - std::vector faceTypes = cvf::StructGridInterface::validFaceTypes(); - - // Preprocessing: create vector of all fault face centers. - std::vector faultFaceCenters; - const auto activeCells = m_resultsData->activeCellInfo()->activeReservoirCellIndices(); - for ( auto cellIdx : activeCells ) + std::vector allFaults; + for ( size_t i = 0; i < mainGrid->faults().size(); ++i ) { - const RigCell& cell = mainGrid->cell( cellIdx.value() ); - if ( cell.isInvalid() ) continue; - for ( auto faceType : faceTypes ) - { - if ( m_resultsData->m_ownerMainGrid->findFaultFromCellIndexAndCellFace( cellIdx.value(), faceType ) ) - faultFaceCenters.push_back( cell.faceCenter( faceType ) ); - } + allFaults.push_back( mainGrid->faults().at( i ) ); } - if ( faultFaceCenters.empty() ) return; - - // Create bounding box tree for all face centers - auto searchTree = new cvf::BoundingBoxTree; - { - std::vector faceIndicesForBoundingBoxes; - std::vector faceBBs; - - size_t faceCenterIndex = 0; - for ( const auto& faultFaceCenter : faultFaceCenters ) - { - cvf::BoundingBox bb; - bb.add( faultFaceCenter ); - faceBBs.push_back( bb ); - faceIndicesForBoundingBoxes.push_back( faceCenterIndex++ ); - } - searchTree->buildTreeFromBoundingBoxes( faceBBs, &faceIndicesForBoundingBoxes ); - } - - const auto nodes = m_resultsData->m_ownerMainGrid->nodes(); - const auto mainGridBB = m_resultsData->m_ownerMainGrid->boundingBox(); - -#pragma omp parallel for - for ( int activeIndex = 0; activeIndex < static_cast( activeCells.size() ); activeIndex++ ) - { - auto cellIdx = activeCells[activeIndex]; - if ( cellIdx.value() == cvf::UNDEFINED_SIZE_T ) continue; - - const RigCell& cell = mainGrid->cell( cellIdx.value() ); - if ( cell.isInvalid() ) continue; - - std::vector candidateFaceIndices; - { - cvf::BoundingBox bb; - const auto& cellIndices = cell.cornerIndices(); - for ( const auto& i : cellIndices ) - { - bb.add( nodes[i] ); - } - - searchTree->findIntersections( bb, &candidateFaceIndices ); - - bool bbIsBelowThreshold = true; - while ( candidateFaceIndices.empty() && bbIsBelowThreshold ) - { - if ( bb.extent().x() > mainGridBB.extent().x() * 2 ) - { - bbIsBelowThreshold = false; - break; - } - if ( bb.extent().y() > mainGridBB.extent().y() * 2 ) - { - bbIsBelowThreshold = false; - break; - } - - bb.expand( bb.extent().x() ); - searchTree->findIntersections( bb, &candidateFaceIndices ); - } - } - - // Find closest fault face - double shortestDistance = std::numeric_limits::infinity(); - - for ( const auto& faultFaceIndex : candidateFaceIndices ) - { - const cvf::Vec3d& faultFaceCenter = faultFaceCenters[faultFaceIndex]; - shortestDistance = std::min( cell.center().pointDistance( faultFaceCenter ), shortestDistance ); - } - - result[0][activeIndex] = shortestDistance; - } + RigFaultDistanceCalculator::computeFaultDistances( mainGrid, m_resultsData->activeCellInfo(), allFaults, result[0] ); } diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigSelectedFaultDistanceResultCalculator.cpp b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigSelectedFaultDistanceResultCalculator.cpp new file mode 100644 index 0000000000..a0696f3c17 --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigSelectedFaultDistanceResultCalculator.cpp @@ -0,0 +1,65 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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 "RigSelectedFaultDistanceResultCalculator.h" + +#include "RiaDefines.h" + +#include "RigActiveCellInfo.h" +#include "RigCaseCellResultsData.h" +#include "RigEclipseCaseData.h" +#include "RigEclipseResultAddress.h" +#include "RigFaultDistanceCalculator.h" +#include "RigMainGrid.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSelectedFaultDistanceResultCalculator::compute( RigEclipseCaseData* caseData, + const QString& resultName, + const std::vector& selectedFaults ) +{ + if ( !caseData || resultName.isEmpty() ) return; + + RigCaseCellResultsData* resultsData = caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); + if ( !resultsData ) return; + + const RigActiveCellInfo* activeCellInfo = resultsData->activeCellInfo(); + if ( !activeCellInfo ) return; + + const size_t activeCellCount = activeCellInfo->reservoirActiveCellCount(); + if ( activeCellCount == 0 ) return; + + RigEclipseResultAddress resultAddress( RiaDefines::ResultCatType::GENERATED, resultName ); + + if ( !resultsData->hasResultEntry( resultAddress ) ) + { + resultsData->addStaticScalarResult( RiaDefines::ResultCatType::GENERATED, resultName, false, activeCellCount ); + } + + std::vector* resultVector = resultsData->modifiableCellScalarResult( resultAddress, 0 ); + if ( !resultVector ) return; + + resultVector->assign( activeCellCount, std::numeric_limits::infinity() ); + + RigFaultDistanceCalculator::computeFaultDistances( caseData->mainGrid(), activeCellInfo, selectedFaults, *resultVector ); + + resultsData->recalculateStatistics( resultAddress ); +} diff --git a/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigSelectedFaultDistanceResultCalculator.h b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigSelectedFaultDistanceResultCalculator.h new file mode 100644 index 0000000000..f207a6ed30 --- /dev/null +++ b/ApplicationLibCode/ReservoirDataModel/ResultCalculators/RigSelectedFaultDistanceResultCalculator.h @@ -0,0 +1,35 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026- 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. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +#include + +class RigEclipseCaseData; +class RigFault; + +//================================================================================================== +/// +//================================================================================================== +class RigSelectedFaultDistanceResultCalculator +{ +public: + static void compute( RigEclipseCaseData* caseData, const QString& resultName, const std::vector& selectedFaults ); +};