From 1841379e647250ed379a086d20ef8a873620f78a Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Dec 2017 14:51:58 +0100 Subject: [PATCH] #2127 Sim Well Branches : Major refactor of sim well branch computation Remove local branch geometry caches Add checkbox to control if branch detection should be used Add RiaSimWllBranchTools and move helper functions from RimProject --- .../Application/Tools/CMakeLists_files.cmake | 2 + .../Tools/RiaSimWellBranchTools.cpp | 68 +++++++++ .../Application/Tools/RiaSimWellBranchTools.h | 42 ++++++ ApplicationCode/Commands/RicWellLogTools.cpp | 4 +- ApplicationCode/Commands/RicWellLogTools.h | 47 ++++--- .../RicNewWellLogCurveExtractionFeature.cpp | 17 ++- .../RicNewWellLogPlotFeature.cpp | 2 +- .../RicNewWellLogPlotTrackFeature.cpp | 2 +- .../Flow/RimWellAllocationPlot.cpp | 2 +- .../ProjectDataModel/Flow/RimWellRftPlot.cpp | 79 ++++++----- .../ProjectDataModel/Flow/RimWellRftPlot.h | 2 + .../ProjectDataModel/RimProject.cpp | 19 --- ApplicationCode/ProjectDataModel/RimProject.h | 2 +- .../RimWellLogExtractionCurve.cpp | 112 ++++++--------- .../RimWellLogExtractionCurve.h | 11 +- .../ProjectDataModel/RimWellLogRftCurve.cpp | 3 +- .../ProjectDataModel/RimWellLogRftCurve.h | 2 - .../ProjectDataModel/RimWellLogTrack.cpp | 133 ++++-------------- .../ProjectDataModel/RimWellLogTrack.h | 20 +-- .../ProjectDataModel/RimWellPath.cpp | 27 +++- .../ProjectDataModel/RimWellPath.h | 3 + .../ReservoirDataModel/RigEclipseCaseData.cpp | 51 +++---- .../ReservoirDataModel/RigEclipseCaseData.h | 7 +- 23 files changed, 345 insertions(+), 312 deletions(-) create mode 100644 ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp create mode 100644 ApplicationCode/Application/Tools/RiaSimWellBranchTools.h diff --git a/ApplicationCode/Application/Tools/CMakeLists_files.cmake b/ApplicationCode/Application/Tools/CMakeLists_files.cmake index ed51f2172e..2d7e96a859 100644 --- a/ApplicationCode/Application/Tools/CMakeLists_files.cmake +++ b/ApplicationCode/Application/Tools/CMakeLists_files.cmake @@ -22,6 +22,7 @@ ${CEE_CURRENT_LIST_DIR}RiaSummaryTools.h ${CEE_CURRENT_LIST_DIR}RiaWellNameComparer.h ${CEE_CURRENT_LIST_DIR}RiaStdStringTools.h ${CEE_CURRENT_LIST_DIR}RiaSummaryCurveAnalyzer.h +${CEE_CURRENT_LIST_DIR}RiaSimWellBranchTools.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -41,6 +42,7 @@ ${CEE_CURRENT_LIST_DIR}RiaSummaryTools.cpp ${CEE_CURRENT_LIST_DIR}RiaWellNameComparer.cpp ${CEE_CURRENT_LIST_DIR}RiaStdStringTools.cpp ${CEE_CURRENT_LIST_DIR}RiaSummaryCurveAnalyzer.cpp +${CEE_CURRENT_LIST_DIR}RiaSimWellBranchTools.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp new file mode 100644 index 0000000000..9d96b54f7f --- /dev/null +++ b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.cpp @@ -0,0 +1,68 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017 Statoil 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 "RiaSimWellBranchTools.h" + +#include "RiaApplication.h" +#include "RigEclipseCaseData.h" +#include "RimEclipseCase.h" +#include "RimProject.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RiaSimWellBranchTools::simulationWellBranches(const QString& simWellName, bool useAutoDetectionOfBranches) +{ + RiaApplication* app = RiaApplication::instance(); + RimProject* proj = app->project(); + + // Find first case containing the specified simulation well + auto simCases = proj->eclipseCases(); + auto caseItr = std::find_if(simCases.begin(), simCases.end(), [&simWellName](const RimEclipseCase* eclCase) { + const auto& eclData = eclCase->eclipseCaseData(); + return eclData != nullptr && eclData->hasSimulationWell(simWellName); + }); + RimEclipseCase* eclipseCase = caseItr != simCases.end() ? *caseItr : nullptr; + RigEclipseCaseData* eclCaseData = eclipseCase != nullptr ? eclipseCase->eclipseCaseData() : nullptr; + return eclCaseData != nullptr ? + eclCaseData->simulationWellBranches(simWellName, false, useAutoDetectionOfBranches) : + std::vector(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RiaSimWellBranchTools::valueOptionsForBranchIndexField(const std::vector& simulationWellPaths) +{ + QList options; + + size_t branchCount = simulationWellPaths.size(); + if (simulationWellPaths.size() == 0) + { + options.push_front(caf::PdmOptionItemInfo("None", -1)); + } + else + { + for (int bIdx = 0; bIdx < static_cast(branchCount); ++bIdx) + { + options.push_back(caf::PdmOptionItemInfo("Branch " + QString::number(bIdx + 1), QVariant::fromValue(bIdx))); + } + } + + return options; +} diff --git a/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h new file mode 100644 index 0000000000..1fa2a78b4e --- /dev/null +++ b/ApplicationCode/Application/Tools/RiaSimWellBranchTools.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017 Statoil 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 + +#include + +class RigWellPath; + +namespace caf +{ +class PdmOptionItemInfo; +} + +//================================================================================================== +// +//================================================================================================== +class RiaSimWellBranchTools +{ +public: + static std::vector simulationWellBranches(const QString& simWellName, bool useAutoDetectionOfBranches); + + static QList valueOptionsForBranchIndexField(const std::vector& simulationWellPaths); +}; diff --git a/ApplicationCode/Commands/RicWellLogTools.cpp b/ApplicationCode/Commands/RicWellLogTools.cpp index 57a3cfe116..db08b72621 100644 --- a/ApplicationCode/Commands/RicWellLogTools.cpp +++ b/ApplicationCode/Commands/RicWellLogTools.cpp @@ -167,7 +167,7 @@ RimWellPath* RicWellLogTools::selectedWellPathWithLogFile() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimWellLogExtractionCurve* RicWellLogTools::addExtractionCurve(RimWellLogTrack* plotTrack, RimView* view, RimWellPath* wellPath, const RimSimWellInView* simWell, int branchIndex) +RimWellLogExtractionCurve* RicWellLogTools::addExtractionCurve(RimWellLogTrack* plotTrack, RimView* view, RimWellPath* wellPath, const RimSimWellInView* simWell, int branchIndex, bool useBranchDetection) { CVF_ASSERT(plotTrack); RimWellLogExtractionCurve* curve = new RimWellLogExtractionCurve(); @@ -182,7 +182,7 @@ RimWellLogExtractionCurve* RicWellLogTools::addExtractionCurve(RimWellLogTrack* } if (simWell) { - curve->setFromSimulationWellName(simWell->name(), branchIndex); + curve->setFromSimulationWellName(simWell->name(), branchIndex, useBranchDetection); plotTrack->setFormationSimWellName(simWell->name()); plotTrack->setFormationBranchIndex(branchIndex); plotTrack->setFormationTrajectoryType(RimWellLogTrack::SIMULATION_WELL); diff --git a/ApplicationCode/Commands/RicWellLogTools.h b/ApplicationCode/Commands/RicWellLogTools.h index 6c8c580a19..e3b3ea0fd6 100644 --- a/ApplicationCode/Commands/RicWellLogTools.h +++ b/ApplicationCode/Commands/RicWellLogTools.h @@ -1,23 +1,27 @@ ///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017- Statoil 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 +// +// See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once +#include + +#include + class RimSimWellInView; class RimView; class RimWellLogExtractionCurve; @@ -27,24 +31,23 @@ class RimWellLogRftCurve; class RimWellLogTrack; class RimWellPath; -#include - -#include - +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- class RicWellLogTools { public: - static RimWellLogTrack* selectedWellLogPlotTrack(); - static RimSimWellInView* selectedSimulationWell(int *branchIndex); - static RimWellPath* selectedWellPath(); - static bool wellHasRftData(const QString& wellName); - - static bool isWellPathOrSimWellSelectedInView(); - - static void addWellLogChannelsToPlotTrack(RimWellLogTrack* plotTrack, const std::vector& wellLogFileChannels); - static RimWellPath* selectedWellPathWithLogFile(); - - static RimWellLogExtractionCurve* addExtractionCurve(RimWellLogTrack* plotTrack, RimView* view, RimWellPath* wellPath, const RimSimWellInView* simWell, int branchIndex); - static RimWellLogRftCurve* addRftCurve(RimWellLogTrack* plotTrack, const RimSimWellInView* simWell); - static RimWellLogFileCurve* addFileCurve(RimWellLogTrack* plotTrack); -}; \ No newline at end of file + static RimWellLogTrack* selectedWellLogPlotTrack(); + static RimSimWellInView* selectedSimulationWell(int* branchIndex); + static RimWellPath* selectedWellPath(); + static bool wellHasRftData(const QString& wellName); + static bool isWellPathOrSimWellSelectedInView(); + static void addWellLogChannelsToPlotTrack(RimWellLogTrack* plotTrack, + const std::vector& wellLogFileChannels); + static RimWellPath* selectedWellPathWithLogFile(); + static RimWellLogExtractionCurve* addExtractionCurve(RimWellLogTrack* plotTrack, RimView* view, RimWellPath* wellPath, + const RimSimWellInView* simWell, int branchIndex, + bool useBranchDetection); + static RimWellLogRftCurve* addRftCurve(RimWellLogTrack* plotTrack, const RimSimWellInView* simWell); + static RimWellLogFileCurve* addFileCurve(RimWellLogTrack* plotTrack); +}; diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogCurveExtractionFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogCurveExtractionFeature.cpp index 6f3693cb37..df328acf3e 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogCurveExtractionFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogCurveExtractionFeature.cpp @@ -44,6 +44,7 @@ #include #include +#include "RimSimWellInViewCollection.h" CAF_CMD_SOURCE_INIT(RicNewWellLogCurveExtractionFeature, "RicNewWellLogCurveExtractionFeature"); @@ -69,17 +70,29 @@ void RicNewWellLogCurveExtractionFeature::onActionTriggered(bool isChecked) RimWellLogTrack* wellLogPlotTrack = RicWellLogTools::selectedWellLogPlotTrack(); if (wellLogPlotTrack) { - RicWellLogTools::addExtractionCurve(wellLogPlotTrack, nullptr, nullptr, nullptr, -1); + RicWellLogTools::addExtractionCurve(wellLogPlotTrack, nullptr, nullptr, nullptr, -1, true); } else { RimWellPath* wellPath = RicWellLogTools::selectedWellPath(); int branchIndex = -1; RimSimWellInView* simWell = RicWellLogTools::selectedSimulationWell(&branchIndex); + + bool useBranchDetection = true; + RimSimWellInViewCollection* simWellColl = nullptr; + if (simWell) + { + simWell->firstAncestorOrThisOfTypeAsserted(simWellColl); + useBranchDetection = simWellColl->isAutoDetectingBranches; + } + if (wellPath || simWell) { RimWellLogTrack* wellLogPlotTrack = RicNewWellLogPlotFeatureImpl::createWellLogPlotTrack(); - RimWellLogExtractionCurve* plotCurve = RicWellLogTools::addExtractionCurve(wellLogPlotTrack, RiaApplication::instance()->activeReservoirView(), wellPath, simWell, branchIndex); + + RimWellLogExtractionCurve* plotCurve = + RicWellLogTools::addExtractionCurve(wellLogPlotTrack, RiaApplication::instance()->activeReservoirView(), wellPath, + simWell, branchIndex, useBranchDetection); plotCurve->loadDataAndUpdate(true); diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeature.cpp index 8911caafc9..a3ba2821c5 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotFeature.cpp @@ -53,7 +53,7 @@ bool RicNewWellLogPlotFeature::isCommandEnabled() void RicNewWellLogPlotFeature::onActionTriggered(bool isChecked) { RimWellLogTrack* plotTrack = RicNewWellLogPlotFeatureImpl::createWellLogPlotTrack(); - RicWellLogTools::addExtractionCurve(plotTrack, nullptr, nullptr, nullptr, -1); + RicWellLogTools::addExtractionCurve(plotTrack, nullptr, nullptr, nullptr, -1, true); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotTrackFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotTrackFeature.cpp index 95e6447ae2..eb2b9f4e87 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotTrackFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogPlotTrackFeature.cpp @@ -62,7 +62,7 @@ void RicNewWellLogPlotTrackFeature::onActionTriggered(bool isChecked) plotTrack->setDescription(QString("Track %1").arg(wellLogPlot->trackCount())); wellLogPlot->updateConnectedEditors(); - RicWellLogTools::addExtractionCurve(plotTrack, nullptr, nullptr, nullptr, -1); + RicWellLogTools::addExtractionCurve(plotTrack, nullptr, nullptr, nullptr, -1, true); } } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 9afcbc956b..f6dba3da3d 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -835,7 +835,7 @@ void RimWellAllocationPlot::updateFormationNamesData() const for (size_t i = 0; i < m_accumulatedWellFlowPlot->trackCount(); ++i) { RimWellLogTrack* track = m_accumulatedWellFlowPlot->trackByIndex(i); - track->setAndUpdateSimWellFormationNamesData(m_case, m_wellName, track->formationBranchIndex()); + track->setAndUpdateSimWellFormationNamesData(m_case, m_wellName); } } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp index 0146888290..893a5caef0 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp @@ -21,6 +21,7 @@ #include "RiaApplication.h" #include "RiaColorTables.h" #include "RiaDateStringParser.h" +#include "RiaSimWellBranchTools.h" #include "RifReaderEclipseRft.h" @@ -46,6 +47,7 @@ #include "RimWellLogTrack.h" #include "RimWellPath.h" #include "RimWellPathCollection.h" +#include "RimWellPltPlot.h" #include "RiuWellRftPlot.h" @@ -55,7 +57,6 @@ #include #include #include -#include "RimWellPltPlot.h" CAF_PDM_SOURCE_INIT(RimWellRftPlot, "WellRftPlot"); @@ -83,6 +84,8 @@ RimWellRftPlot::RimWellRftPlot() CAF_PDM_InitFieldNoDefault(&m_wellPathNameOrSimWellName, "WellName", "Well Name", "", "", ""); CAF_PDM_InitField(&m_branchIndex, "BranchIndex", 0, "Branch Index", "", "", ""); + CAF_PDM_InitField(&m_branchDetection, "BranchDetection", true, "Branch Detection", "", + "Compute branches based on how simulation well cells are organized", ""); CAF_PDM_InitFieldNoDefault(&m_selectedSources, "Sources", "Sources", "", "", ""); m_selectedSources.uiCapability()->setUiEditorTypeName(caf::PdmUiTreeSelectionEditor::uiEditorTypeName()); @@ -102,7 +105,25 @@ RimWellRftPlot::RimWellRftPlot() } //-------------------------------------------------------------------------------------------------- -/// +/// +//-------------------------------------------------------------------------------------------------- +RimWellLogTrack::TrajectoryType trajectoryTypeFromWellName(const QString& wellPathOrSimWellName) +{ + RimWellLogTrack::TrajectoryType trajectoryType = RimWellLogTrack::SIMULATION_WELL; + + RimProject* proj = RiaApplication::instance()->project(); + RimWellPath* wellPath = proj->wellPathByName(wellPathOrSimWellName); + + if (wellPath) + { + trajectoryType = RimWellLogTrack::WELL_PATH; + } + + return trajectoryType; +} + +//-------------------------------------------------------------------------------------------------- +/// //-------------------------------------------------------------------------------------------------- RimWellRftPlot::~RimWellRftPlot() { @@ -234,20 +255,11 @@ void RimWellRftPlot::updateFormationsOnPlot() const { if (m_wellLogPlot->trackCount() > 0) { + RimWellLogTrack::TrajectoryType trajectoryType = trajectoryTypeFromWellName(m_wellPathNameOrSimWellName); + RimProject* proj = RiaApplication::instance()->project(); RimWellPath* wellPath = proj->wellPathByName(m_wellPathNameOrSimWellName); - RimWellLogTrack::TrajectoryType trajectoryType; - - if ( wellPath ) - { - trajectoryType = RimWellLogTrack::WELL_PATH; - } - else - { - trajectoryType = RimWellLogTrack::SIMULATION_WELL; - } - RimCase* formationNamesCase = m_wellLogPlot->trackByIndex(0)->formationNamesCase(); if ( !formationNamesCase ) @@ -264,7 +276,7 @@ void RimWellRftPlot::updateFormationsOnPlot() const if (trajectoryType == RimWellLogTrack::SIMULATION_WELL) { - m_wellLogPlot->trackByIndex(0)->setAndUpdateSimWellFormationNamesData(formationNamesCase, associatedSimWellName(), m_branchIndex); + m_wellLogPlot->trackByIndex(0)->setAndUpdateSimWellFormationNamesAndBranchData(formationNamesCase, associatedSimWellName(), m_branchIndex, m_branchDetection); } else if (trajectoryType == RimWellLogTrack::WELL_PATH) { @@ -487,7 +499,7 @@ void RimWellRftPlot::updateCurvesInPlot(const std::set cvf::Color3f curveColor = RiaColorTables::wellLogPlotPaletteColors().cycledColor3f(plotTrack->curveCount()); curve->setColor(curveColor); - curve->setFromSimulationWellName(simWellName, m_branchIndex); + curve->setFromSimulationWellName(simWellName, m_branchIndex, m_branchDetection); // Fetch cases and time steps auto gridCase = curveDefToAdd.address().eclCase(); @@ -676,19 +688,9 @@ QList RimWellRftPlot::calculateValueOptions(const caf::P } else if (fieldNeedingOptions == &m_branchIndex) { - RimProject* proj = RiaApplication::instance()->project(); + auto simulationWellBranches = RiaSimWellBranchTools::simulationWellBranches(simWellName, m_branchDetection); - size_t branchCount = proj->simulationWellBranches(simWellName).size(); - - for (int bIdx = 0; bIdx < static_cast(branchCount); ++bIdx) - { - options.push_back(caf::PdmOptionItemInfo("Branch " + QString::number(bIdx + 1), QVariant::fromValue(bIdx))); - } - - if (options.size() == 0) - { - options.push_front(caf::PdmOptionItemInfo("None", -1)); - } + options = RiaSimWellBranchTools::valueOptionsForBranchIndexField(simulationWellBranches); } return options; @@ -706,7 +708,7 @@ void RimWellRftPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c setDescription(QString(plotNameFormatString()).arg(m_wellPathNameOrSimWellName)); } - if (changedField == &m_wellPathNameOrSimWellName || changedField == &m_branchIndex) + if (changedField == &m_wellPathNameOrSimWellName) { if (changedField == &m_wellPathNameOrSimWellName) { @@ -719,11 +721,14 @@ void RimWellRftPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c updateEditorsFromCurves(); updateFormationsOnPlot(); } - else if (changedField == &m_selectedSources) + else if (changedField == &m_branchIndex || + changedField == &m_branchDetection) { - } + updateFormationsOnPlot(); + syncCurvesFromUiSelection(); - if (changedField == &m_selectedSources || + } + else if (changedField == &m_selectedSources || changedField == &m_selectedTimeSteps) { updateFormationsOnPlot(); @@ -773,11 +778,15 @@ void RimWellRftPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering.add(&m_userName); uiOrdering.add(&m_wellPathNameOrSimWellName); - - RimProject* proj = RiaApplication::instance()->project(); - if (proj->simulationWellBranches(associatedSimWellName()).size() > 1) + + if (trajectoryTypeFromWellName(m_wellPathNameOrSimWellName) == RimWellLogTrack::SIMULATION_WELL) { - uiOrdering.add(&m_branchIndex); + uiOrdering.add(&m_branchDetection); + + if (RiaSimWellBranchTools::simulationWellBranches(associatedSimWellName(), m_branchDetection).size() > 1) + { + uiOrdering.add(&m_branchIndex); + } } caf::PdmUiGroup* sourcesGroup = uiOrdering.addNewGroupWithKeyword("Sources", "Sources"); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.h index 24bcbef911..f1995a020c 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.h @@ -135,6 +135,8 @@ private: caf::PdmField m_wellPathNameOrSimWellName; caf::PdmField m_branchIndex; + caf::PdmField m_branchDetection; + caf::PdmField> m_selectedSources; caf::PdmField> m_selectedTimeSteps; diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index 517b1e2b18..7972783114 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -217,7 +217,6 @@ void RimProject::close() plotWindowTreeViewState = ""; } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -813,24 +812,6 @@ std::vector RimProject::simulationWellNames() const return std::vector(wellNames.begin(), wellNames.end()); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RimProject::simulationWellBranches(const QString& simWellName) -{ - // Find first case containing the specified simulation well - auto simCases = eclipseCases(); - auto caseItr = std::find_if(simCases.begin(), simCases.end(), [&simWellName](const RimEclipseCase* eclCase) { - const auto& eclData = eclCase->eclipseCaseData(); - return eclData != nullptr && eclData->hasSimulationWell(simWellName); - }); - RimEclipseCase* eclipseCase = caseItr != simCases.end() ? *caseItr : nullptr; - RigEclipseCaseData* eclCaseData = eclipseCase != nullptr ? eclipseCase->eclipseCaseData() : nullptr; - return eclCaseData != nullptr ? - eclCaseData->simulationWellBranches(simWellName) : - std::vector(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index bb71149621..be82cfa27d 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -126,7 +126,7 @@ public: std::vector eclipseCases() const; std::vector simulationWellNames() const; - std::vector simulationWellBranches(const QString& simWellName); + RimWellPath* wellPathFromSimWellName(const QString& simWellName, int branchIndex = -1); RimWellPath* wellPathByName(const QString& wellPathName) const; std::vector allWellPaths() const; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp index 66cfc8885e..85e8c5683e 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.cpp @@ -20,6 +20,7 @@ #include "RimWellLogExtractionCurve.h" #include "RiaApplication.h" +#include "RiaSimWellBranchTools.h" #include "RigCaseCellResultsData.h" #include "RigEclipseCaseData.h" @@ -93,7 +94,9 @@ RimWellLogExtractionCurve::RimWellLogExtractionCurve() m_wellPath.uiCapability()->setUiTreeChildrenHidden(true); CAF_PDM_InitField(&m_simWellName, "SimulationWellName", QString("None"), " ", "", "", ""); - CAF_PDM_InitField(&m_branchIndex, "Branch", 0, " ", "", "", ""); + CAF_PDM_InitField(&m_branchDetection, "BranchDetection", true, "Branch Detection", "", + "Compute branches based on how simulation well cells are organized", ""); + CAF_PDM_InitField(&m_branchIndex, "Branch", 0, "Branch Index", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_case, "CurveCase", "Case", "", "", ""); m_case.uiCapability()->setUiTreeChildrenHidden(true); @@ -150,11 +153,12 @@ RimWellPath* RimWellLogExtractionCurve::wellPath() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellLogExtractionCurve::setFromSimulationWellName(const QString& simWellName, int branchIndex) +void RimWellLogExtractionCurve::setFromSimulationWellName(const QString& simWellName, int branchIndex, bool branchDetection) { m_trajectoryType = SIMULATION_WELL; m_simWellName = simWellName; m_branchIndex = branchIndex; + m_branchDetection = branchDetection; clearGeneratedSimWellPaths(); } @@ -225,7 +229,7 @@ void RimWellLogExtractionCurve::clampTimestep() //-------------------------------------------------------------------------------------------------- void RimWellLogExtractionCurve::clampBranchIndex() { - int branchCount = static_cast(m_generatedSimulationWellPathBranches.size()); + int branchCount = static_cast(simulationWellBranches().size()); if ( branchCount > 0 ) { if ( m_branchIndex >= branchCount ) m_branchIndex = branchCount - 1; @@ -265,9 +269,16 @@ void RimWellLogExtractionCurve::fieldChangedByUi(const caf::PdmFieldHandle* chan this->loadDataAndUpdate(true); } - else if (changedField == &m_trajectoryType || + else if (changedField == &m_trajectoryType) + { + this->loadDataAndUpdate(true); + } + else if (changedField == &m_branchDetection || + changedField == &m_branchIndex || changedField == &m_branchIndex) { + clearGeneratedSimWellPaths(); + this->loadDataAndUpdate(true); } else if (changedField == &m_timeStep) @@ -303,7 +314,6 @@ void RimWellLogExtractionCurve::onLoadDataAndUpdate(bool updateParentPlot) m_eclipseResultDefinition->setEclipseCase(eclipseCase); m_geomResultDefinition->setGeoMechCase(geomCase); - updateGeneratedSimulationWellpath(); clampBranchIndex(); RimMainPlotCollection* mainPlotCollection; @@ -321,12 +331,19 @@ void RimWellLogExtractionCurve::onLoadDataAndUpdate(bool updateParentPlot) } else { - if (m_branchIndex >= 0 && m_branchIndex < static_cast(m_generatedSimulationWellPathBranches.size())) + std::vector simWellBranches = simulationWellBranches(); + if (m_branchIndex >= 0 && m_branchIndex < static_cast(simWellBranches.size())) { + auto wellBranch = simWellBranches[m_branchIndex]; eclExtractor = wellLogCollection->findOrCreateSimWellExtractor(m_simWellName, eclipseCase->caseUserDescription(), - m_generatedSimulationWellPathBranches[m_branchIndex].p(), + wellBranch, eclipseCase->eclipseCaseData()); + if (eclExtractor.notNull()) + { + m_wellPathsWithExtractors.push_back(wellBranch); + } + isUsingPseudoLength = true; } } @@ -451,51 +468,6 @@ std::set RimWellLogExtractionCurve::findSortedWellNames() return sortedWellNames; } - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellLogExtractionCurve::updateGeneratedSimulationWellpath() -{ - if (m_generatedSimulationWellPathBranches.size()) return; // Already created. Nothing to do - - RimEclipseCase* eclipseCase = dynamic_cast(m_case.value()); - - if (!(!m_simWellName().isEmpty() && m_simWellName() != "None" && eclipseCase && eclipseCase->eclipseCaseData())) - { - return ; - } - - RigEclipseCaseData* eclCaseData = eclipseCase->eclipseCaseData(); - const RigSimWellData* simWellData = eclCaseData->findSimWellData(m_simWellName()); - - if (!simWellData) return; - - std::vector< std::vector > pipeBranchesCLCoords; - std::vector< std::vector > pipeBranchesCellIds; - - RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(eclCaseData, - simWellData, - -1, - true, - true, - pipeBranchesCLCoords, - pipeBranchesCellIds); - - - for ( size_t brIdx = 0; brIdx < pipeBranchesCLCoords.size(); ++brIdx ) - { - auto wellMdCalculator = RigSimulationWellCoordsAndMD(pipeBranchesCLCoords[brIdx]); // Todo, branch index - - cvf::ref newWellPath = new RigWellPath(); - newWellPath->m_measuredDepths = wellMdCalculator.measuredDepths(); - newWellPath->m_wellPathPoints = wellMdCalculator.wellPathPoints(); - - m_generatedSimulationWellPathBranches.push_back(newWellPath.p() ); - } -} - //-------------------------------------------------------------------------------------------------- /// Clean up existing generated well paths //-------------------------------------------------------------------------------------------------- @@ -510,12 +482,20 @@ void RimWellLogExtractionCurve::clearGeneratedSimWellPaths() if (!wellLogCollection) return; - for ( size_t wpIdx = 0; wpIdx < m_generatedSimulationWellPathBranches.size(); ++wpIdx ) + for (auto wellPath : m_wellPathsWithExtractors) { - wellLogCollection->removeExtractors(m_generatedSimulationWellPathBranches[wpIdx].p()); + wellLogCollection->removeExtractors(wellPath); } - m_generatedSimulationWellPathBranches.clear(); + m_wellPathsWithExtractors.clear(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimWellLogExtractionCurve::simulationWellBranches() const +{ + return RiaSimWellBranchTools::simulationWellBranches(m_simWellName, m_branchDetection); } //-------------------------------------------------------------------------------------------------- @@ -571,24 +551,14 @@ QList RimWellLogExtractionCurve::calculateValueOptions(c } else if (fieldNeedingOptions == &m_branchIndex) { - updateGeneratedSimulationWellpath(); + auto branches = simulationWellBranches(); - size_t branchCount = m_generatedSimulationWellPathBranches.size(); - - for ( int bIdx = 0; bIdx < static_cast(branchCount); ++bIdx) - { - options.push_back(caf::PdmOptionItemInfo("Branch " + QString::number(bIdx + 1), QVariant::fromValue(bIdx) )); - } - - if (options.size() == 0) - { - options.push_front(caf::PdmOptionItemInfo("None", -1)); - } + options = RiaSimWellBranchTools::valueOptionsForBranchIndexField(branches); } + return options; } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -611,7 +581,9 @@ void RimWellLogExtractionCurve::defineUiOrdering(QString uiConfigName, caf::PdmU else { curveDataGroup->add(&m_simWellName); - if ( m_generatedSimulationWellPathBranches.size() > 1 ) + curveDataGroup->add(&m_branchDetection); + + if ( simulationWellBranches().size() > 1 ) { curveDataGroup->add(&m_branchIndex); } @@ -713,7 +685,7 @@ QString RimWellLogExtractionCurve::createCurveAutoName() if (!wellName().isEmpty()) { generatedCurveName += wellName(); - if (m_trajectoryType == SIMULATION_WELL && m_generatedSimulationWellPathBranches.size() > 1) + if (m_trajectoryType == SIMULATION_WELL && simulationWellBranches().size() > 1) { generatedCurveName.push_back(" Br" + QString::number(m_branchIndex + 1)); } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.h b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.h index 34d825952b..27578ebe5a 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogExtractionCurve.h @@ -23,14 +23,13 @@ #include "cafPdmPtrField.h" #include "cafPdmChildField.h" -#include "cvfCollection.h" +class RigWellPath; class RimCase; class RimEclipseResultDefinition; class RimGeoMechResultDefinition; class RimView; class RimWellPath; -class RigWellPath; //================================================================================================== /// @@ -48,7 +47,7 @@ public: void setWellPath(RimWellPath* wellPath); RimWellPath* wellPath() const; - void setFromSimulationWellName(const QString& simWellName, int branchIndex); + void setFromSimulationWellName(const QString& simWellName, int branchIndex, bool branchDetection); void setCase(RimCase* rimCase); RimCase* rimCase() const; @@ -83,8 +82,8 @@ private: void clampTimestep(); void clampBranchIndex(); std::set findSortedWellNames(); - void updateGeneratedSimulationWellpath(); void clearGeneratedSimWellPaths(); + std::vector simulationWellBranches() const; private: caf::PdmPtrField m_case; @@ -92,6 +91,7 @@ private: caf::PdmPtrField m_wellPath; caf::PdmField m_simWellName; caf::PdmField m_branchIndex; + caf::PdmField m_branchDetection; caf::PdmChildField m_eclipseResultDefinition; caf::PdmChildField m_geomResultDefinition; @@ -103,6 +103,5 @@ private: caf::PdmField m_addTimestepToCurveName; caf::PdmField m_addDateToCurveName; - cvf::Collection m_generatedSimulationWellPathBranches; + std::vector m_wellPathsWithExtractors; }; - diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp index 144ab10123..62c4939b2d 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp @@ -21,6 +21,7 @@ #include "RiaApplication.h" #include "RiaEclipseUnitTools.h" +#include "RiaSimWellBranchTools.h" #include "RimEclipseResultCase.h" #include "RimMainPlotCollection.h" @@ -484,7 +485,7 @@ RigEclipseWellLogExtractor* RimWellLogRftCurve::extractor() if (!eclExtractor) { - std::vector wellPaths = proj->simulationWellBranches(m_wellName()); + std::vector wellPaths = RiaSimWellBranchTools::simulationWellBranches(m_wellName(), true); if (wellPaths.size() == 0) return nullptr; eclExtractor = wellLogCollection->findOrCreateSimWellExtractor(m_wellName(), QString("Find or create sim well extractor"), wellPaths[0], m_eclipseResultCase->eclipseCaseData()); diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h index 4096379f0e..fdf384d035 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h @@ -93,5 +93,3 @@ private: bool m_isUsingPseudoLength; }; - - diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp index ab449af1ad..a75f81ed7c 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp @@ -58,6 +58,7 @@ #include "cvfAssert.h" #include "qwt_scale_engine.h" +#include "RiaSimWellBranchTools.h" #define RI_LOGPLOTTRACK_MINX_DEFAULT -10.0 #define RI_LOGPLOTTRACK_MAXX_DEFAULT 100.0 @@ -119,10 +120,11 @@ RimWellLogTrack::RimWellLogTrack() CAF_PDM_InitField(&m_formationSimWellName, "FormationSimulationWellName", QString("None"), "Simulation Well", "", "", ""); CAF_PDM_InitField(&m_formationBranchIndex, "FormationBranchIndex", 0, " ", "", "", ""); + CAF_PDM_InitField(&m_formationBranchDetection, "FormationBranchDetection", true, "Branch Detection", "", + "Compute branches based on how simulation well cells are organized", ""); CAF_PDM_InitFieldNoDefault(&m_formationCase, "FormationCase", "Formation Case", "", "", ""); m_formationCase.uiCapability()->setUiTreeChildrenHidden(true); - } //-------------------------------------------------------------------------------------------------- @@ -137,8 +139,6 @@ RimWellLogTrack::~RimWellLogTrack() m_wellLogTrackPlotWidget->deleteLater(); m_wellLogTrackPlotWidget = nullptr; } - - clearGeneratedSimWellPaths(&m_generatedSimulationWellPathBranches); } //-------------------------------------------------------------------------------------------------- @@ -178,28 +178,6 @@ void RimWellLogTrack::simWellOptionItems(QList* options, } } -//-------------------------------------------------------------------------------------------------- -/// Clean up existing generated well paths -//-------------------------------------------------------------------------------------------------- -void RimWellLogTrack::clearGeneratedSimWellPaths(cvf::Collection* generatedSimulationWellPathBranches) -{ - RimWellLogPlotCollection* wellLogCollection = nullptr; - - // Need to use this approach, and not firstAnchestor because the curve might not be inside the hierarchy when deleted. - - RimProject * proj = RiaApplication::instance()->project(); - if (proj && proj->mainPlotCollection()) wellLogCollection = proj->mainPlotCollection()->wellLogPlotCollection(); - - if (!wellLogCollection) return; - - for (size_t wpIdx = 0; wpIdx < generatedSimulationWellPathBranches->size(); ++wpIdx) - { - wellLogCollection->removeExtractors(generatedSimulationWellPathBranches->at(wpIdx)); - } - - generatedSimulationWellPathBranches->clear(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -286,8 +264,6 @@ void RimWellLogTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedField, m_formationSimWellName = QString("None"); } - clearGeneratedSimWellPaths(&m_generatedSimulationWellPathBranches); - loadDataAndUpdate(); } else if (changedField == &m_formationWellPath) @@ -296,17 +272,14 @@ void RimWellLogTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedField, } else if (changedField == &m_formationSimWellName) { - clearGeneratedSimWellPaths(&m_generatedSimulationWellPathBranches); - loadDataAndUpdate(); } else if (changedField == &m_formationTrajectoryType) { - clearGeneratedSimWellPaths(&m_generatedSimulationWellPathBranches); - loadDataAndUpdate(); } - else if (changedField == &m_formationBranchIndex) + else if (changedField == &m_formationBranchIndex || + changedField == &m_formationBranchDetection) { loadDataAndUpdate(); } @@ -346,19 +319,8 @@ QList RimWellLogTrack::calculateValueOptions(const caf:: } else if (fieldNeedingOptions == &m_formationBranchIndex) { - updateGeneratedSimulationWellpath(&m_generatedSimulationWellPathBranches, m_formationSimWellName(), m_formationCase); - - size_t branchCount = m_generatedSimulationWellPathBranches.size(); - - for (int bIdx = 0; bIdx < static_cast(branchCount); ++bIdx) - { - options.push_back(caf::PdmOptionItemInfo("Branch " + QString::number(bIdx + 1), QVariant::fromValue(bIdx))); - } - - if (options.size() == 0) - { - options.push_front(caf::PdmOptionItemInfo("None", -1)); - } + auto simulationWellBranches = RiaSimWellBranchTools::simulationWellBranches(m_formationSimWellName(), m_formationBranchDetection); + options = RiaSimWellBranchTools::valueOptionsForBranchIndexField(simulationWellBranches); } return options; @@ -528,13 +490,23 @@ void RimWellLogTrack::setAndUpdateWellPathFormationNamesData(RimCase* rimCase, R //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellLogTrack::setAndUpdateSimWellFormationNamesData(RimCase* rimCase, QString simWellName, int branchIndex) +void RimWellLogTrack::setAndUpdateSimWellFormationNamesAndBranchData(RimCase* rimCase, const QString& simWellName, int branchIndex, bool useBranchDetection) +{ + m_formationBranchIndex = branchIndex; + m_formationBranchDetection = useBranchDetection; + + setAndUpdateSimWellFormationNamesData(rimCase, simWellName); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellLogTrack::setAndUpdateSimWellFormationNamesData(RimCase* rimCase, const QString& simWellName) { m_formationCase = rimCase; m_formationTrajectoryType = RimWellLogTrack::SIMULATION_WELL; m_formationWellPath = nullptr; m_formationSimWellName = simWellName; - m_formationBranchIndex = branchIndex; updateConnectedEditors(); @@ -592,14 +564,6 @@ void RimWellLogTrack::setFormationTrajectoryType(TrajectoryType trajectoryType) m_formationTrajectoryType = trajectoryType; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -int RimWellLogTrack::formationBranchIndex() const -{ - return m_formationBranchIndex; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -738,49 +702,6 @@ RimWellLogCurve* RimWellLogTrack::curveDefinitionFromCurve(const QwtPlotCurve* c return nullptr; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellLogTrack::updateGeneratedSimulationWellpath(cvf::Collection* generatedSimulationWellPathBranches, const QString& simWellName, RimCase* rimCase) -{ - if (generatedSimulationWellPathBranches->size()) return; // Already created. Nothing to do - - RimEclipseCase* eclipseCase = dynamic_cast(rimCase); - - if (!(!simWellName.isEmpty() && simWellName != QString("None") && eclipseCase && eclipseCase->eclipseCaseData())) - { - return; - } - - RigEclipseCaseData* eclCaseData = eclipseCase->eclipseCaseData(); - const RigSimWellData* simWellData = eclCaseData->findSimWellData(simWellName); - - if (!simWellData) return; - - std::vector< std::vector > pipeBranchesCLCoords; - std::vector< std::vector > pipeBranchesCellIds; - - RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(eclCaseData, - simWellData, - -1, - true, - true, - pipeBranchesCLCoords, - pipeBranchesCellIds); - - for (size_t brIdx = 0; brIdx < pipeBranchesCLCoords.size(); ++brIdx) - { - auto wellMdCalculator = RigSimulationWellCoordsAndMD(pipeBranchesCLCoords[brIdx]); // Todo, branch index - - cvf::ref newWellPath = new RigWellPath(); - newWellPath->m_measuredDepths = wellMdCalculator.measuredDepths(); - newWellPath->m_wellPathPoints = wellMdCalculator.wellPathPoints(); - - generatedSimulationWellPathBranches->push_back(newWellPath.p()); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -805,10 +726,11 @@ void RimWellLogTrack::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& } else { - updateGeneratedSimulationWellpath(&m_generatedSimulationWellPathBranches, m_formationSimWellName(), m_formationCase); - formationGroup->add(&m_formationSimWellName); - if (m_generatedSimulationWellPathBranches.size() > 1) + formationGroup->add(&m_formationBranchDetection); + + auto simulationWellBranches = RiaSimWellBranchTools::simulationWellBranches(m_formationSimWellName(), m_formationBranchDetection); + if (simulationWellBranches.size() > 1) { formationGroup->add(&m_formationBranchIndex); } @@ -819,7 +741,6 @@ void RimWellLogTrack::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& formationGroup->add(&m_formationWellPath); } - uiOrderingForVisibleXRange(uiOrdering); uiOrdering.skipRemainingFields(true); @@ -973,15 +894,14 @@ void RimWellLogTrack::uiOrderingForVisibleXRange(caf::PdmUiOrdering& uiOrdering) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigEclipseWellLogExtractor* RimWellLogTrack::createSimWellExtractor(RimWellLogPlotCollection* wellLogCollection, RimCase* rimCase, const QString& simWellName, int branchIndex) +RigEclipseWellLogExtractor* RimWellLogTrack::createSimWellExtractor(RimWellLogPlotCollection* wellLogCollection, RimCase* rimCase, const QString& simWellName, int branchIndex, bool useBranchDetection) { if (!wellLogCollection) return nullptr; RimEclipseCase* eclipseCase = dynamic_cast(rimCase); if (!eclipseCase) return nullptr; - RimProject* proj = RiaApplication::instance()->project(); - std::vector wellPaths = proj->simulationWellBranches(simWellName); + std::vector wellPaths = RiaSimWellBranchTools::simulationWellBranches(simWellName, useBranchDetection); if (wellPaths.size() == 0) return nullptr; @@ -1196,7 +1116,8 @@ void RimWellLogTrack::updateFormationNamesOnPlot() eclWellLogExtractor = RimWellLogTrack::createSimWellExtractor(wellLogCollection, m_formationCase, m_formationSimWellName, - m_formationBranchIndex); + m_formationBranchIndex, + m_formationBranchDetection); } else { diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.h b/ApplicationCode/ProjectDataModel/RimWellLogTrack.h index fbf69e5ea5..2ae5254191 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.h @@ -19,14 +19,13 @@ #pragma once +#include "RimWellLogPlot.h" + #include "cafPdmObject.h" #include "cafPdmField.h" #include "cafPdmChildArrayField.h" -#include "cvfCollection.h" #include "cafPdmPtrField.h" -#include "RimWellLogPlot.h" - #include #include @@ -86,15 +85,18 @@ public: void setFormationBranchIndex(int branchIndex); void setFormationCase(RimCase* rimCase); void setFormationTrajectoryType(TrajectoryType trajectoryType); - int formationBranchIndex() const; RimCase* formationNamesCase() const; void recreateViewer(); void detachAllCurves(); void loadDataAndUpdate(); + void setAndUpdateWellPathFormationNamesData(RimCase* rimCase, RimWellPath* wellPath); - void setAndUpdateSimWellFormationNamesData(RimCase* rimCase, QString simWellName, int branchIndex); + + void setAndUpdateSimWellFormationNamesAndBranchData(RimCase* rimCase, const QString& simWellName, int branchIndex, bool useBranchDetection); + void setAndUpdateSimWellFormationNamesData(RimCase* rimCase, const QString& simWellName); + void availableDepthRange(double* minimumDepth, double* maximumDepth); void updateXZoomAndParentPlotDepthZoom(); void updateXZoom(); @@ -125,11 +127,9 @@ private: void computeAndSetXRangeMinForLogarithmicScale(); - static void updateGeneratedSimulationWellpath(cvf::Collection* generatedSimulationWellPathBranches, const QString& simWellName, RimCase* rimCase); static void simWellOptionItems(QList* options, RimCase* eclCase); - static void clearGeneratedSimWellPaths(cvf::Collection* generatedSimulationWellPathBranches); - static RigEclipseWellLogExtractor* createSimWellExtractor(RimWellLogPlotCollection* wellLogCollection, RimCase* rimCase, const QString& simWellName, int branchIndex); + static RigEclipseWellLogExtractor* createSimWellExtractor(RimWellLogPlotCollection* wellLogCollection, RimCase* rimCase, const QString& simWellName, int branchIndex, bool useBranchDetection); static RigEclipseWellLogExtractor* createWellPathExtractor(RimWellLogPlotCollection* wellLogCollection, RimCase* rimCase, RimWellPath* wellPath); static RigGeoMechWellLogExtractor* createGeoMechExtractor(RimWellLogPlotCollection* wellLogCollection, RimCase* rimCase, RimWellPath* wellPath); @@ -168,10 +168,10 @@ private: caf::PdmPtrField m_formationCase; caf::PdmField > m_formationTrajectoryType; caf::PdmPtrField m_formationWellPath; + caf::PdmField m_formationSimWellName; caf::PdmField m_formationBranchIndex; - - cvf::Collection m_generatedSimulationWellPathBranches; + caf::PdmField m_formationBranchDetection; QPointer m_wellLogTrackPlotWidget; diff --git a/ApplicationCode/ProjectDataModel/RimWellPath.cpp b/ApplicationCode/ProjectDataModel/RimWellPath.cpp index a8a2ac7540..712e520eb8 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPath.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPath.cpp @@ -20,6 +20,10 @@ #include "RimWellPath.h" +#include "RiaApplication.h" +#include "RiaSimWellBranchTools.h" +#include "RiaWellNameComparer.h" + #include "RifWellPathFormationsImporter.h" #include "RifWellPathImporter.h" @@ -40,9 +44,6 @@ #include "RivWellPathPartMgr.h" -#include "RiaApplication.h" -#include "RiaWellNameComparer.h" - #include "cafPdmUiTreeOrdering.h" #include "cafUtils.h" @@ -345,9 +346,8 @@ QList RimWellPath::calculateValueOptions(const caf::PdmF } else if (fieldNeedingOptions == &m_branchIndex) { - RimProject* proj = RiaApplication::instance()->project(); + size_t branchCount = RimWellPath::simulationWellBranchCount(m_simWellName); - size_t branchCount = proj->simulationWellBranches(m_simWellName).size(); if (branchCount == 0) branchCount = 1; @@ -471,9 +471,10 @@ void RimWellPath::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiO caf::PdmUiGroup* simWellGroup = uiOrdering.addNewGroup("Simulation Well"); simWellGroup->add(&m_simWellName); - RimProject* proj = RiaApplication::instance()->project(); - if(proj->simulationWellBranches(m_simWellName).size() > 1) + if (simulationWellBranchCount(m_simWellName) > 1) + { simWellGroup->add(&m_branchIndex); + } caf::PdmUiGroup* ssihubGroup = uiOrdering.addNewGroup("Well Info"); ssihubGroup->add(&id); @@ -581,6 +582,18 @@ void RimWellPath::setupBeforeSave() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimWellPath::simulationWellBranchCount(const QString& simWellName) +{ + bool detectBranches = true; + + auto branches = RiaSimWellBranchTools::simulationWellBranches(simWellName, detectBranches); + + return branches.size(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellPath.h b/ApplicationCode/ProjectDataModel/RimWellPath.h index d1bccc00ae..e858141232 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPath.h +++ b/ApplicationCode/ProjectDataModel/RimWellPath.h @@ -151,6 +151,9 @@ private: virtual void setupBeforeSave() override; + static size_t simulationWellBranchCount(const QString& simWellName); + +private: caf::PdmField id; caf::PdmField sourceSystem; caf::PdmField utmZone; diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp index 50f645438b..d43a682046 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.cpp @@ -281,7 +281,10 @@ const RigSimWellData* RigEclipseCaseData::findSimWellData(QString wellName) cons { for (size_t wIdx = 0; wIdx < m_simWellData.size(); ++wIdx) { - if (m_simWellData[wIdx]->m_wellName == wellName) return m_simWellData[wIdx].p(); + if (m_simWellData[wIdx]->m_wellName == wellName) + { + return m_simWellData[wIdx].p(); + } } return nullptr; @@ -467,52 +470,52 @@ bool RigEclipseCaseData::hasSimulationWell(const QString& simWellName) const } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -std::vector RigEclipseCaseData::simulationWellBranches(const QString& simWellName) +std::vector RigEclipseCaseData::simulationWellBranches(const QString& simWellName, + bool includeAllCellCenters, + bool useAutoDetectionOfBranches) { std::vector branches; - if (m_branchCache.find(simWellName) == m_branchCache.end()) + if (simWellName.isEmpty() || simWellName.toUpper() == "NONE") { - if (!(!simWellName.isEmpty() && simWellName != "None")) - { - return branches; - } + return branches; + } - const RigSimWellData* simWellData = findSimWellData(simWellName); + const RigSimWellData* simWellData = findSimWellData(simWellName); + if (!simWellData) return branches; - if (!simWellData) return branches; + std::tuple simWellSeachItem = + std::make_tuple(simWellName, includeAllCellCenters, useAutoDetectionOfBranches); - std::vector< std::vector > pipeBranchesCLCoords; - std::vector< std::vector > pipeBranchesCellIds; + if (m_simWellBranchCache.find(simWellSeachItem) == m_simWellBranchCache.end()) + { + std::vector> pipeBranchesCLCoords; + std::vector> pipeBranchesCellIds; - RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame(this, - simWellData, - -1, - true, - true, - pipeBranchesCLCoords, - pipeBranchesCellIds); + RigSimulationWellCenterLineCalculator::calculateWellPipeCenterlineFromWellFrame( + this, simWellData, -1, useAutoDetectionOfBranches, includeAllCellCenters, pipeBranchesCLCoords, pipeBranchesCellIds); - m_branchCache.insert(std::make_pair(simWellName, cvf::Collection())); + m_simWellBranchCache.insert(std::make_pair(simWellSeachItem, cvf::Collection())); for (size_t brIdx = 0; brIdx < pipeBranchesCLCoords.size(); ++brIdx) { auto wellMdCalculator = RigSimulationWellCoordsAndMD(pipeBranchesCLCoords[brIdx]); cvf::ref newWellPath = new RigWellPath(); - newWellPath->m_measuredDepths = wellMdCalculator.measuredDepths(); - newWellPath->m_wellPathPoints = wellMdCalculator.wellPathPoints(); + newWellPath->m_measuredDepths = wellMdCalculator.measuredDepths(); + newWellPath->m_wellPathPoints = wellMdCalculator.wellPathPoints(); - m_branchCache[simWellName].push_back(newWellPath.p()); + m_simWellBranchCache[simWellSeachItem].push_back(newWellPath.p()); } } - for (const auto& branch : m_branchCache[simWellName]) + for (const auto& branch : m_simWellBranchCache[simWellSeachItem]) { branches.push_back(branch.p()); } + return branches; } diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h index a1f021b3aa..f70db893b4 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCaseData.h @@ -99,7 +99,10 @@ public: std::vector simulationWellNames() const; bool hasSimulationWell(const QString& simWellName) const; - std::vector simulationWellBranches(const QString& simWellName); + + std::vector simulationWellBranches(const QString& simWellName, + bool includeAllCellCenters, + bool useAutoDetectionOfBranches); private: void computeActiveCellIJKBBox(); @@ -124,5 +127,5 @@ private: RiaEclipseUnitTools::UnitSystem m_unitsType; - std::map> m_branchCache; + std::map, cvf::Collection> m_simWellBranchCache; };