diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewPltPlotFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewPltPlotFeature.cpp index 4fd4374fcd..3ac8b5d5c6 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewPltPlotFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewPltPlotFeature.cpp @@ -66,12 +66,12 @@ bool RicNewPltPlotFeature::isCommandEnabled() RimEclipseResultCase* eclCase = caf::firstAncestorOfTypeFromSelectedObject(); if (simWell != nullptr) { - enable &= RimWellPltPlot::hasFlowData(eclCase); + enable &= RimWellPlotTools::hasFlowData(eclCase); } } else if (rimWellPath) { - enable &= RimWellPltPlot::hasFlowData(rimWellPath); + enable &= RimWellPlotTools::hasFlowData(rimWellPath); } return enable; } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp index 873e4c0888..5ccb9122db 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp @@ -19,11 +19,13 @@ #include "RimWellPlotTools.h" #include "RiaApplication.h" +#include "RiaWellNameComparer.h" #include "RifReaderEclipseRft.h" #include "RigCaseCellResultsData.h" #include "RigEclipseCaseData.h" +#include "RigSimWellData.h" #include "RimEclipseCase.h" #include "RimEclipseResultCase.h" @@ -38,11 +40,35 @@ #include "RimWellPathCollection.h" +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class StaticFieldsInitializer +{ +public: + StaticFieldsInitializer() + { + // Init static list + RimWellPlotTools::FLOW_DATA_NAMES.insert(RimWellPlotTools::OIL_CHANNEL_NAMES.begin(), RimWellPlotTools::OIL_CHANNEL_NAMES.end()); + RimWellPlotTools::FLOW_DATA_NAMES.insert(RimWellPlotTools::GAS_CHANNEL_NAMES.begin(), RimWellPlotTools::GAS_CHANNEL_NAMES.end()); + RimWellPlotTools::FLOW_DATA_NAMES.insert(RimWellPlotTools::WATER_CHANNEL_NAMES.begin(), RimWellPlotTools::WATER_CHANNEL_NAMES.end()); + RimWellPlotTools::FLOW_DATA_NAMES.insert(RimWellPlotTools::TOTAL_CHANNEL_NAMES.begin(), RimWellPlotTools::TOTAL_CHANNEL_NAMES.end()); + } +}; + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const std::set RimWellPlotTools::PRESSURE_DATA_NAMES = { "PRESSURE", "PRES_FORM" }; +const std::set RimWellPlotTools::OIL_CHANNEL_NAMES = { "QOZT", "QOIL" }; +const std::set RimWellPlotTools::GAS_CHANNEL_NAMES = { "QGZT", "QGAS" }; +const std::set RimWellPlotTools::WATER_CHANNEL_NAMES = { "QWZT", "QWAT" }; +const std::set RimWellPlotTools::TOTAL_CHANNEL_NAMES = { "QTZT", "QTOT" }; + +std::set RimWellPlotTools::FLOW_DATA_NAMES = {}; + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -109,6 +135,93 @@ bool RimWellPlotTools::hasPressureData(RimEclipseResultCase* gridCase) { return pressureResultDataInfo(gridCase->eclipseCaseData()).first != cvf::UNDEFINED_SIZE_T; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::hasFlowData(const RimWellLogFile* wellLogFile) +{ + for (RimWellLogFileChannel* const wellLogChannel : wellLogFile->wellLogChannels()) + { + if (isFlowChannel(wellLogChannel)) return true; + } + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::hasFlowData(RimWellPath* wellPath) +{ + for (RimWellLogFile* const wellLogFile : wellPath->wellLogFiles()) + { + if (hasFlowData(wellLogFile)) + { + return true; + } + } + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::isFlowChannel(RimWellLogFileChannel* channel) +{ + return FLOW_DATA_NAMES.count(channel->name()) > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::isOilFlowChannel(const QString& channelName) +{ + return OIL_CHANNEL_NAMES.count(channelName) > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::isGasFlowChannel(const QString& channelName) +{ + return GAS_CHANNEL_NAMES.count(channelName) > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::isWaterFlowChannel(const QString& channelName) +{ + return WATER_CHANNEL_NAMES.count(channelName) > 0; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::hasFlowData(RimEclipseResultCase* gridCase) +{ + const RigEclipseCaseData* const eclipseCaseData = gridCase->eclipseCaseData(); + + for (const QString& channelName : FLOW_DATA_NAMES) + { + size_t resultIndex = eclipseCaseData->results(RiaDefines::MATRIX_MODEL)-> + findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, channelName); + + if (resultIndex != cvf::UNDEFINED_SIZE_T) return true; + } + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +FlowPhase RimWellPlotTools::flowPhaseFromChannelName(const QString& channelName) +{ + if (tryMatchChannelName(OIL_CHANNEL_NAMES, channelName)) return FLOW_PHASE_OIL; + if (tryMatchChannelName(GAS_CHANNEL_NAMES, channelName)) return FLOW_PHASE_GAS; + if (tryMatchChannelName(WATER_CHANNEL_NAMES, channelName)) return FLOW_PHASE_WATER; + if (tryMatchChannelName(TOTAL_CHANNEL_NAMES, channelName)) return FLOW_PHASE_TOTAL; + return FLOW_PHASE_NONE; +} //-------------------------------------------------------------------------------------------------- /// @@ -143,7 +256,7 @@ void RimWellPlotTools::addTimeStepsToMap(std::map RimWellPlotTools::wellLogFilesContainingPressure(const QString& wellName) +std::vector RimWellPlotTools::wellLogFilesContainingPressure(const QString& wellPathName) { std::vector wellLogFiles; const RimProject* const project = RiaApplication::instance()->project(); @@ -159,10 +272,10 @@ std::vector RimWellPlotTools::wellLogFilesContainingPressure(co for (RimWellLogFile* const file : files) { - size_t timeStepCount = timeStepsMapFromWellLogFile(file).size(); + size_t timeStepCount = timeStepsMapFromWellLogFile(file).size(); // todo: only one timestep if (timeStepCount == 0) continue; - if (QString::compare(file->wellName(), wellName) != 0) continue; + if (RiaWellNameComparer::tryFindMatchingWellPath(wellPathName).isEmpty()) continue; if (hasPressureData(file)) { @@ -192,6 +305,54 @@ RimWellLogFileChannel* RimWellPlotTools::getPressureChannelFromWellFile(const Ri return nullptr; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimWellPlotTools::wellLogFilesContainingFlow(const QString& wellPathName) +{ + std::vector wellLogFiles; + const RimProject* const project = RiaApplication::instance()->project(); + + for (const auto& wellPath : project->allWellPaths()) + { + bool hasPressure = false; + const std::vector files = wellPath->wellLogFiles(); + + for (RimWellLogFile* const file : files) + { + size_t timeStepCount = timeStepsMapFromWellLogFile(file).size(); // todo: only one timestep + + if (timeStepCount == 0) continue; + if (RiaWellNameComparer::tryFindMatchingWellPath(wellPathName).isEmpty()) continue; + + if (hasFlowData(file)) + { + wellLogFiles.push_back(file); + } + } + } + return wellLogFiles; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimWellPlotTools::getFlowChannelsFromWellFile(const RimWellLogFile* wellLogFile) +{ + std::vector channels; + if (wellLogFile != nullptr) + { + for (RimWellLogFileChannel* const channel : wellLogFile->wellLogChannels()) + { + if (isFlowChannel(channel)) + { + channels.push_back(channel); + } + } + } + return channels; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -220,7 +381,7 @@ RimWellPath* RimWellPlotTools::wellPathFromWellLogFile(const RimWellLogFile* wel //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimWellPlotTools::gridCasesForWell(const QString& wellName) +std::vector RimWellPlotTools::gridCasesForWell(const QString& simWellName) { std::vector cases; const RimProject* const project = RiaApplication::instance()->project(); @@ -230,7 +391,15 @@ std::vector RimWellPlotTools::gridCasesForWell(const QStr RimEclipseResultCase* resultCase = dynamic_cast(eclCase); if (resultCase != nullptr) { - cases.push_back(resultCase); + RigEclipseCaseData* const eclipseCaseData = eclCase->eclipseCaseData(); + for (const cvf::ref& wellResult : eclipseCaseData->wellResults()) + { + if (wellResult->m_wellName == simWellName) + { + cases.push_back(resultCase); + break; + } + } } } return cases; @@ -239,7 +408,7 @@ std::vector RimWellPlotTools::gridCasesForWell(const QStr //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimWellPlotTools::rftCasesForWell(const QString& wellName) +std::vector RimWellPlotTools::rftCasesForWell(const QString& simWellName) { std::vector cases; const RimProject* const project = RiaApplication::instance()->project(); @@ -249,7 +418,15 @@ std::vector RimWellPlotTools::rftCasesForWell(const QStri RimEclipseResultCase* resultCase = dynamic_cast(eclCase); if (resultCase != nullptr && resultCase->rftReader() != nullptr) { - cases.push_back(resultCase); + RigEclipseCaseData* const eclipseCaseData = eclCase->eclipseCaseData(); + for (const cvf::ref& wellResult : eclipseCaseData->wellResults()) + { + if (wellResult->m_wellName == simWellName) + { + cases.push_back(resultCase); + break; + } + } } } return cases; @@ -258,13 +435,14 @@ std::vector RimWellPlotTools::rftCasesForWell(const QStri //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::set RimWellPlotTools::timeStepsFromRftCase(RimEclipseResultCase* rftCase, const QString& wellName) +std::set RimWellPlotTools::timeStepsFromRftCase(RimEclipseResultCase* rftCase, + const QString& simWellName) { std::set timeSteps; RifReaderEclipseRft* const reader = rftCase->rftReader(); if (reader != nullptr) { - for (const QDateTime& timeStep : reader->availableTimeSteps(wellName, RifEclipseRftAddress::PRESSURE)) + for (const QDateTime& timeStep : reader->availableTimeSteps(simWellName, RifEclipseRftAddress::PRESSURE)) { timeSteps.insert(timeStep); } @@ -303,13 +481,13 @@ QDateTime RimWellPlotTools::timeStepFromWellLogFile(RimWellLogFile* wellLogFile) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::map> RimWellPlotTools::timeStepsMapFromRftCase(RimEclipseResultCase* rftCase, const QString& wellName) +std::map> RimWellPlotTools::timeStepsMapFromRftCase(RimEclipseResultCase* rftCase, const QString& simWellName) { std::map> timeStepsMap; RifReaderEclipseRft* const reader = rftCase->rftReader(); if (reader != nullptr) { - for (const QDateTime& timeStep : reader->availableTimeSteps(wellName, RifEclipseRftAddress::PRESSURE)) + for (const QDateTime& timeStep : reader->availableTimeSteps(simWellName, RifEclipseRftAddress::PRESSURE)) { if (timeStepsMap.count(timeStep) == 0) { @@ -456,3 +634,35 @@ RiaRftPltCurveDefinition RimWellPlotTools::curveDefFromCurve(const RimWellLogCur } return RiaRftPltCurveDefinition(RifWellRftAddress(), QDateTime()); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellPath* RimWellPlotTools::wellPathByWellPathNameOrSimWellName(const QString& wellPathNameOrSimwellName) +{ + RimProject* proj = RiaApplication::instance()->project(); + RimWellPath* wellPath = proj->wellPathByName(wellPathNameOrSimwellName); + + return wellPath != nullptr ? wellPath : proj->wellPathFromSimulationWell(wellPathNameOrSimwellName); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimWellPlotTools::simWellName(const QString& wellPathNameOrSimWellName) +{ + RimWellPath* wellPath = wellPathByWellPathNameOrSimWellName(wellPathNameOrSimWellName); + return wellPath != nullptr ? wellPath->associatedSimulationWell() : wellPathNameOrSimWellName; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimWellPlotTools::tryMatchChannelName(const std::set& channelNames, const QString& channelNameToMatch) +{ + auto itr = std::find_if(channelNames.begin(), channelNames.end(), [&](const QString& channelName) + { + return channelName.contains(channelNameToMatch, Qt::CaseInsensitive); + }); + return itr != channelNames.end(); +} diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.h b/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.h index 03b0aaaac6..98d8a58083 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.h @@ -39,12 +39,24 @@ class RigEclipseCaseData; //================================================================================================== /// +//================================================================================================== +enum FlowType { FLOW_TYPE_TOTAL, FLOW_TYPE_PHASE_SPLIT }; +enum FlowPhase { FLOW_PHASE_NONE, FLOW_PHASE_OIL, FLOW_PHASE_GAS, FLOW_PHASE_WATER, FLOW_PHASE_TOTAL }; + +//================================================================================================== /// //================================================================================================== class RimWellPlotTools { static const std::set PRESSURE_DATA_NAMES; + static const std::set OIL_CHANNEL_NAMES; + static const std::set GAS_CHANNEL_NAMES; + static const std::set WATER_CHANNEL_NAMES; + static const std::set TOTAL_CHANNEL_NAMES; + + static std::set FLOW_DATA_NAMES; + public: static bool hasPressureData(const RimWellLogFile* wellLogFile); static bool isPressureChannel(RimWellLogFileChannel* channel); @@ -52,24 +64,36 @@ public: static bool hasPressureData(RimWellPath* wellPath); static std::pair pressureResultDataInfo(const RigEclipseCaseData* eclipseCaseData); + static bool hasFlowData(const RimWellLogFile* wellLogFile); + static bool isFlowChannel(RimWellLogFileChannel* channel); + static bool isOilFlowChannel(const QString& channelName); + static bool isGasFlowChannel(const QString& channelName); + static bool isWaterFlowChannel(const QString& channelName); + static bool hasFlowData(RimEclipseResultCase* gridCase); + static bool hasFlowData(RimWellPath* wellPath); + static FlowPhase flowPhaseFromChannelName(const QString& channelName); + static void addTimeStepToMap(std::map>& destMap, const std::pair>& timeStepToAdd); static void addTimeStepsToMap(std::map>& destMap, const std::map>& timeStepsToAdd); - static std::vector wellLogFilesContainingPressure(const QString& wellName); + static std::vector wellLogFilesContainingPressure(const QString& simWellName); static RimWellLogFileChannel* getPressureChannelFromWellFile(const RimWellLogFile* wellLogFile); + static std::vector wellLogFilesContainingFlow(const QString& wellName); + static std::vector getFlowChannelsFromWellFile(const RimWellLogFile* wellLogFile); + static RimWellPath* wellPathFromWellLogFile(const RimWellLogFile* wellLogFile); - static std::vector gridCasesForWell(const QString& wellName); - static std::vector rftCasesForWell(const QString& wellName); + static std::vector gridCasesForWell(const QString& simWellName); + static std::vector rftCasesForWell(const QString& simWellName); - static std::set timeStepsFromRftCase(RimEclipseResultCase* rftCase, const QString& wellName); + static std::set timeStepsFromRftCase(RimEclipseResultCase* rftCase, const QString& simWellName); static std::set timeStepsFromGridCase(RimEclipseCase* gridCase); static QDateTime timeStepFromWellLogFile(RimWellLogFile* wellLogFile); - static std::map> timeStepsMapFromRftCase(RimEclipseResultCase* rftCase, const QString& wellName); + static std::map> timeStepsMapFromRftCase(RimEclipseResultCase* rftCase, const QString& simWellName); static std::map> timeStepsMapFromGridCase(RimEclipseCase* gridCase); static std::map> timeStepsMapFromWellLogFile(RimWellLogFile* wellLogFile); static std::map> adjacentTimeSteps(const std::vector>>& allTimeSteps, @@ -78,8 +102,17 @@ public: static RiaRftPltCurveDefinition curveDefFromCurve(const RimWellLogCurve* curve); + static RimWellPath* wellPathByWellPathNameOrSimWellName(const QString& wellPathNameOrSimwellName); + static QString simWellName(const QString& wellPathNameOrSimWellName); + static bool tryMatchChannelName(const std::set& channelNames, const QString& channelNameToMatch); + template static void appendSet(std::set& destSet, const std::set& setToAppend); + +private: + friend class StaticFieldsInitializer; + + static StaticFieldsInitializer ms_staticFieldInitializer; }; //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp index a3cecc5708..2f4ee0fb01 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp @@ -43,6 +43,7 @@ #include "RimWellLogTrack.h" #include "RimWellPath.h" #include "RimWellPathCollection.h" +#include "RimWellPlotTools.h" #include "RimWellFlowRateCurve.h" #include "RiuWellPltPlot.h" #include "cafPdmUiTreeSelectionEditor.h" @@ -59,70 +60,29 @@ #include "RimSummaryCurveAppearanceCalculator.h" - -//-------------------------------------------------------------------------------------------------- -/// Move to tools class -//-------------------------------------------------------------------------------------------------- -RimWellPath* wellPathByWellPathNameOrSimWellName(const QString& wellPathNameOrSimwellName) -{ - RimProject* proj = RiaApplication::instance()->project(); - RimWellPath* wellPath = proj->wellPathByName(wellPathNameOrSimwellName); - - return wellPath != nullptr ? wellPath : proj->wellPathFromSimulationWell(wellPathNameOrSimwellName); -} - -//-------------------------------------------------------------------------------------------------- -/// Move to tools class -//-------------------------------------------------------------------------------------------------- -QString simWellName(const QString& wellPathNameOrSimWellName) -{ - RimWellPath* wellPath = wellPathByWellPathNameOrSimWellName(wellPathNameOrSimWellName); - return wellPath != nullptr ? wellPath->associatedSimulationWell() : wellPathNameOrSimWellName; -} - -//-------------------------------------------------------------------------------------------------- -/// Move to tools class -//-------------------------------------------------------------------------------------------------- -bool tryMatchChannelName(const std::set& channelNames, const QString& channelNameToMatch) -{ - auto itr = std::find_if(channelNames.begin(), channelNames.end(), [&](const QString& channelName) - { - return channelName.contains(channelNameToMatch, Qt::CaseInsensitive); - }); - return itr != channelNames.end(); -} - - - CAF_PDM_SOURCE_INIT(RimWellPltPlot, "WellPltPlot"); namespace caf { template<> -void caf::AppEnum< RimWellPltPlot::FlowType>::setUp() +void caf::AppEnum< FlowType>::setUp() { - addItem(RimWellPltPlot::FLOW_TYPE_TOTAL, "TOTAL", "Total Flow"); - addItem(RimWellPltPlot::FLOW_TYPE_PHASE_SPLIT, "PHASE_SPLIT", "Phase Split"); + addItem(FLOW_TYPE_TOTAL, "TOTAL", "Total Flow"); + addItem(FLOW_TYPE_PHASE_SPLIT, "PHASE_SPLIT", "Phase Split"); } template<> -void caf::AppEnum< RimWellPltPlot::FlowPhase>::setUp() +void caf::AppEnum< FlowPhase>::setUp() { - addItem(RimWellPltPlot::PHASE_OIL, "PHASE_OIL", "Oil"); - addItem(RimWellPltPlot::PHASE_GAS, "PHASE_GAS", "Gas"); - addItem(RimWellPltPlot::PHASE_WATER, "PHASE_WATER", "Water"); + addItem(FLOW_PHASE_OIL, "PHASE_OIL", "Oil"); + addItem(FLOW_PHASE_GAS, "PHASE_GAS", "Gas"); + addItem(FLOW_PHASE_WATER, "PHASE_WATER", "Water"); } } -const std::set RimWellPltPlot::OIL_CHANNEL_NAMES = { "QOZT", "QOIL" }; -const std::set RimWellPltPlot::GAS_CHANNEL_NAMES = { "QGZT", "QGAS" }; -const std::set RimWellPltPlot::WATER_CHANNEL_NAMES = { "QWZT", "QWAT" }; -const std::set RimWellPltPlot::TOTAL_CHANNEL_NAMES = { "QTZT", "QTOT" }; - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::set RimWellPltPlot::FLOW_DATA_NAMES = { }; const char RimWellPltPlot::PLOT_NAME_QFORMAT_STRING[] = "PLT: %1"; //-------------------------------------------------------------------------------------------------- @@ -130,12 +90,6 @@ const char RimWellPltPlot::PLOT_NAME_QFORMAT_STRING[] = "PLT: %1"; //-------------------------------------------------------------------------------------------------- RimWellPltPlot::RimWellPltPlot() { - // Init static list - FLOW_DATA_NAMES.insert(OIL_CHANNEL_NAMES.begin(), OIL_CHANNEL_NAMES.end()); - FLOW_DATA_NAMES.insert(GAS_CHANNEL_NAMES.begin(), GAS_CHANNEL_NAMES.end()); - FLOW_DATA_NAMES.insert(WATER_CHANNEL_NAMES.begin(), WATER_CHANNEL_NAMES.end()); - FLOW_DATA_NAMES.insert(TOTAL_CHANNEL_NAMES.begin(), TOTAL_CHANNEL_NAMES.end()); - CAF_PDM_InitObject("Well Allocation Plot", ":/WellAllocPlot16x16.png", "", ""); CAF_PDM_InitField(&m_userName, "PlotDescription", QString("PLT Plot"), "Name", "", "", ""); @@ -171,7 +125,7 @@ RimWellPltPlot::RimWellPltPlot() CAF_PDM_InitFieldNoDefault(&m_phases, "Phases", "Phases", "", "", ""); m_phases.uiCapability()->setUiEditorTypeName(caf::PdmUiTreeSelectionEditor::uiEditorTypeName()); - m_phases = std::vector>({ FlowPhase::PHASE_OIL, FlowPhase::PHASE_GAS, FlowPhase::PHASE_WATER }); + m_phases = std::vector>({ FLOW_PHASE_OIL, FLOW_PHASE_GAS, FLOW_PHASE_WATER }); this->setAsPlotMdiWindow(); m_doInitAfterLoad = false; @@ -328,18 +282,6 @@ void RimWellPltPlot::updateSelectedTimeStepsFromSelectedSources() m_selectedTimeSteps = newTimeStepsSelections; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimWellPltPlot::FlowPhase RimWellPltPlot::flowPhaseFromChannelName(const QString& channelName) -{ - if (tryMatchChannelName(OIL_CHANNEL_NAMES, channelName)) return PHASE_OIL; - if (tryMatchChannelName(GAS_CHANNEL_NAMES, channelName)) return PHASE_GAS; - if (tryMatchChannelName(WATER_CHANNEL_NAMES, channelName)) return PHASE_WATER; - if (tryMatchChannelName(TOTAL_CHANNEL_NAMES, channelName)) return PHASE_TOTAL; - return PHASE_NONE; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -429,7 +371,7 @@ void RimWellPltPlot::updateFormationsOnPlot() const if (m_wellLogPlot->trackCount() > 0) { - m_wellLogPlot->trackByIndex(0)->updateFormationNamesData(rimCase, trajectoryType, wellPath, simWellName(m_wellPathName), m_branchIndex); + m_wellLogPlot->trackByIndex(0)->updateFormationNamesData(rimCase, trajectoryType, wellPath, RimWellPlotTools::simWellName(m_wellPathName), m_branchIndex); } } @@ -506,261 +448,15 @@ void RimWellPltPlot::updateWidgetTitleWindowTitle() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RimWellPltPlot::wellLogFilesContainingFlow(const QString& wellPathName) const -{ - std::vector wellLogFiles; - const RimProject* const project = RiaApplication::instance()->project(); - - for (const auto& wellPath : project->allWellPaths()) - { - bool hasPressure = false; - const std::vector files = wellPath->wellLogFiles(); - - for (RimWellLogFile* const file : files) - { - size_t timeStepCount = timeStepsFromWellLogFile(file).size(); - - if (timeStepCount == 0) continue; - if(RiaWellNameComparer::tryFindMatchingWellPath(wellPathName).isEmpty()) continue; - - if (hasFlowData(file)) - { - wellLogFiles.push_back(file); - } - } - } - return wellLogFiles; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RimWellPltPlot::getFlowChannelsFromWellFile(const RimWellLogFile* wellLogFile) const -{ - std::vector channels; - if(wellLogFile != nullptr) - { - for (RimWellLogFileChannel* const channel : wellLogFile->wellLogChannels()) - { - if (isFlowChannel(channel)) - { - channels.push_back(channel); - } - } - } - return channels; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimWellPath* RimWellPltPlot::wellPathFromWellLogFile(const RimWellLogFile* wellLogFile) const -{ - RimProject* const project = RiaApplication::instance()->project(); - for (const auto& oilField : project->oilFields) - { - auto wellPaths = std::vector(oilField->wellPathCollection()->wellPaths.begin(), oilField->wellPathCollection()->wellPaths.end()); - - for (const auto& wellPath : wellPaths) - { - for (RimWellLogFile* const file : wellPath->wellLogFiles()) - { - if (file == wellLogFile) - { - return wellPath; - } - } - } - } - - return nullptr; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector> -RimWellPltPlot::eclipseCasesForWell(const QString& wellName) const -{ - std::vector> cases; - const RimProject* const project = RiaApplication::instance()->project(); - - for (const auto& oilField : project->oilFields) - { - const RimEclipseCaseCollection* const eclCaseColl = oilField->analysisModels(); - for (RimEclipseCase* eCase : eclCaseColl->cases()) - { - auto eclCase = dynamic_cast(eCase); - if (eclCase != nullptr) - { - RigEclipseCaseData* const eclipseCaseData = eclCase->eclipseCaseData(); - for (const cvf::ref& wellResult : eclipseCaseData->wellResults()) - { - if (QString::compare(wellResult->m_wellName, wellName) == 0) - { - bool hasRftData = eclCase->rftReader() != nullptr; - cases.push_back(std::make_tuple(eclCase, true, hasRftData)); - break; - } - } - } - } - } - return cases; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector -RimWellPltPlot::gridCasesFromEclipseCases(const std::vector>& eclipseCasesTuple) const -{ - std::vector cases; - for (const std::tuple& eclCaseTuple : eclipseCasesTuple) - { - bool hasPressureData = std::get<1>(eclCaseTuple); - size_t timeStepCount = timeStepsFromGridCase(std::get<0>(eclCaseTuple)).size(); - if (hasPressureData && timeStepCount > 0) - { - cases.push_back(std::get<0>(eclCaseTuple)); - } - } - return cases; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector -RimWellPltPlot::rftCasesFromEclipseCases(const std::vector>& eclipseCasesTuple) const -{ - std::vector cases; - for (const std::tuple& eclCaseTuple : eclipseCasesTuple) - { - bool hasRftData = std::get<2>(eclCaseTuple); - size_t timeStepCount = timeStepsFromRftCase(std::get<0>(eclCaseTuple)).size(); - if (hasRftData && timeStepCount > 0) - { - cases.push_back(std::get<0>(eclCaseTuple)); - } - } - return cases; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::map> RimWellPltPlot::timeStepsFromRftCase(RimEclipseResultCase* rftCase) const -{ - std::map> timeStepsMap; - RifReaderEclipseRft* const reader = rftCase->rftReader(); - if (reader != nullptr) - { - for (const QDateTime& timeStep : reader->availableTimeSteps(simWellName(m_wellPathName), RifEclipseRftAddress::PRESSURE)) - { - if (timeStepsMap.count(timeStep) == 0) - { - timeStepsMap.insert(std::make_pair(timeStep, std::set())); - } - timeStepsMap[timeStep].insert(RifWellRftAddress(RifWellRftAddress::RFT, rftCase)); - } - } - return timeStepsMap; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::map> RimWellPltPlot::timeStepsFromGridCase(RimEclipseCase* gridCase) const -{ - const RigEclipseCaseData* const eclipseCaseData = gridCase->eclipseCaseData(); - - std::map > timeStepsMap; - { - for (const QDateTime& timeStep : eclipseCaseData->results(RiaDefines::MATRIX_MODEL)->timeStepDates()) - { - if (timeStepsMap.count(timeStep) == 0) - { - timeStepsMap.insert(std::make_pair(timeStep, std::set())); - } - timeStepsMap[timeStep].insert(RifWellRftAddress(RifWellRftAddress::GRID, gridCase)); - } - } - return timeStepsMap; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::map > RimWellPltPlot::timeStepsFromWellLogFile(RimWellLogFile* wellLogFile) const -{ - std::map > timeStepsMap; - - QDateTime timeStep = wellLogFile->date(); - - if (timeStepsMap.count(timeStep) == 0) - { - timeStepsMap.insert(std::make_pair(timeStep, std::set())); - } - timeStepsMap[timeStep].insert(RifWellRftAddress(RifWellRftAddress::OBSERVED, wellLogFile)); - - return timeStepsMap; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::map> -RimWellPltPlot::adjacentTimeSteps(const std::vector>>& allTimeSteps, - const std::pair>& searchTimeStepPair) -{ - std::map> timeStepsMap; - - if (allTimeSteps.size() > 0) - { - auto itr = std::find_if(allTimeSteps.begin(), allTimeSteps.end(), - [searchTimeStepPair](const std::pair>& dt) - { - return dt.first > searchTimeStepPair.first; - }); - - auto itrEnd = itr != allTimeSteps.end() ? itr + 1 : itr; - - for (itr = itrEnd - 1; itr != allTimeSteps.begin() && (*itr).first >= searchTimeStepPair.first; itr--); - auto itrFirst = itr; - - timeStepsMap.insert(itrFirst, itrEnd); - } - - // Add searched time step in case it is not included - addTimeStepToMap(timeStepsMap, searchTimeStepPair); - - return timeStepsMap; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimWellPltPlot::mapContainsTimeStep(const std::map>& map, const QDateTime& timeStep) -{ - return std::find_if(map.begin(), map.end(), [timeStep](const std::pair>& pair) - { - return pair.first == timeStep; - }) != map.end(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::set < std::pair> RimWellPltPlot::selectedCurveDefs() const { std::set> curveDefs; - const std::vector>& eclipseCases = eclipseCasesForWell(simWellName(m_wellPathName)); - const std::vector rftCases = rftCasesFromEclipseCases(eclipseCases); - const std::vector gridCases = gridCasesFromEclipseCases(eclipseCases); + const std::vector rftCases = RimWellPlotTools::rftCasesForWell(RimWellPlotTools::simWellName(m_wellPathName)); + const std::vector gridCases = RimWellPlotTools::gridCasesForWell(RimWellPlotTools::simWellName(m_wellPathName)); + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathName); for (const QDateTime& timeStep : m_selectedTimeSteps()) { @@ -770,8 +466,8 @@ std::set < std::pair> RimWellPltPlot::selectedCurv { for (RimEclipseResultCase* const rftCase : rftCases) { - const std::map>& timeStepsMap = timeStepsFromRftCase(rftCase); - if (mapContainsTimeStep(timeStepsMap , timeStep)) + const std::set& timeSteps = RimWellPlotTools::timeStepsFromRftCase(rftCase, simWellName); + if (timeSteps.count(timeStep) > 0) { curveDefs.insert(std::make_pair(addr, timeStep)); } @@ -781,8 +477,8 @@ std::set < std::pair> RimWellPltPlot::selectedCurv { for (RimEclipseResultCase* const gridCase : gridCases) { - const std::map>& timeStepsMap = timeStepsFromGridCase(gridCase); - if (mapContainsTimeStep(timeStepsMap, timeStep)) + const std::set& timeSteps = RimWellPlotTools::timeStepsFromGridCase(gridCase); + if (timeSteps.count(timeStep) > 0) { curveDefs.insert(std::make_pair(addr, timeStep)); } @@ -793,8 +489,8 @@ std::set < std::pair> RimWellPltPlot::selectedCurv { if (addr.wellLogFile() != nullptr) { - const std::map>& timeStepsMap = timeStepsFromWellLogFile(addr.wellLogFile()); - if (mapContainsTimeStep(timeStepsMap, timeStep)) + const QDateTime& wellLogFileTimeStep = RimWellPlotTools::timeStepFromWellLogFile(addr.wellLogFile()); + if (wellLogFileTimeStep == timeStep) { curveDefs.insert(std::make_pair(RifWellRftAddress(RifWellRftAddress::OBSERVED, addr.wellLogFile()), timeStep)); } @@ -919,9 +615,9 @@ public: QDateTime m_timeStep) { - RifEclipseRftAddress gasRateAddress(simWellName(wellPathName), m_timeStep, RifEclipseRftAddress::GRAT); - RifEclipseRftAddress oilRateAddress(simWellName(wellPathName), m_timeStep, RifEclipseRftAddress::ORAT); - RifEclipseRftAddress watRateAddress(simWellName(wellPathName), m_timeStep, RifEclipseRftAddress::WRAT); + RifEclipseRftAddress gasRateAddress(RimWellPlotTools::simWellName(wellPathName), m_timeStep, RifEclipseRftAddress::GRAT); + RifEclipseRftAddress oilRateAddress(RimWellPlotTools::simWellName(wellPathName), m_timeStep, RifEclipseRftAddress::ORAT); + RifEclipseRftAddress watRateAddress(RimWellPlotTools::simWellName(wellPathName), m_timeStep, RifEclipseRftAddress::WRAT); std::vector rftIndices; eclCase->rftReader()->cellIndices(gasRateAddress, &rftIndices); @@ -1014,7 +710,7 @@ public: std::map > globCellIdxToIdxInSimWellBranch; - const RimWellPath* wellPath = wellPathByWellPathNameOrSimWellName(wellPathName); + const RimWellPath* wellPath = RimWellPlotTools::wellPathByWellPathNameOrSimWellName(wellPathName); const RigSimWellData* simWell = wellPath != nullptr ? eclCase->eclipseCaseData()->findSimWellData(wellPath->associatedSimulationWell()) : nullptr; if (!simWell) return; @@ -1095,7 +791,7 @@ void RimWellPltPlot::syncCurvesFromUiSelection() int curveGroupId = 0; RimProject* proj = RiaApplication::instance()->project(); - RimWellPath* wellPath = wellPathByWellPathNameOrSimWellName(m_wellPathName); + RimWellPath* wellPath = RimWellPlotTools::wellPathByWellPathNameOrSimWellName(m_wellPathName); RimWellLogPlotCollection* wellLogCollection = proj->mainPlotCollection()->wellLogPlotCollection(); @@ -1104,7 +800,7 @@ void RimWellPltPlot::syncCurvesFromUiSelection() { std::set selectedPhases = m_phaseSelectionMode == FLOW_TYPE_PHASE_SPLIT ? std::set(m_phases().begin(), m_phases().end()) : - std::set({ PHASE_TOTAL }); + std::set({ FLOW_PHASE_TOTAL }); RifWellRftAddress sourceDef = curveDefToAdd.first; QDateTime timeStep = curveDefToAdd.second; @@ -1149,9 +845,9 @@ void RimWellPltPlot::syncCurvesFromUiSelection() tracerName == RIG_FLOW_WATER_NAME ? cvf::Color3f::BLUE : cvf::Color3f::DARK_GRAY; - if ( tracerName == RIG_FLOW_OIL_NAME && selectedPhases.count(PHASE_OIL) - || tracerName == RIG_FLOW_GAS_NAME && selectedPhases.count(PHASE_GAS) - || tracerName == RIG_FLOW_WATER_NAME && selectedPhases.count(PHASE_WATER) ) + if ( tracerName == RIG_FLOW_OIL_NAME && selectedPhases.count(FLOW_PHASE_OIL) + || tracerName == RIG_FLOW_GAS_NAME && selectedPhases.count(FLOW_PHASE_GAS) + || tracerName == RIG_FLOW_WATER_NAME && selectedPhases.count(FLOW_PHASE_WATER) ) { const std::vector accFlow = wfAccumulator.accumulatedTracerFlowPrPseudoLength(tracerName, 0); addStackedCurve(curveName + ", " + tracerName, @@ -1174,14 +870,14 @@ void RimWellPltPlot::syncCurvesFromUiSelection() if (rigWellLogFile != nullptr) { - for (RimWellLogFileChannel* channel : getFlowChannelsFromWellFile(wellLogFile)) + for (RimWellLogFileChannel* channel : RimWellPlotTools::getFlowChannelsFromWellFile(wellLogFile)) { const auto& channelName = channel->name(); - if (selectedPhases.count(flowPhaseFromChannelName(channelName)) > 0) + if (selectedPhases.count(RimWellPlotTools::flowPhaseFromChannelName(channelName)) > 0) { - auto color = OIL_CHANNEL_NAMES.count(channelName) > 0 ? cvf::Color3f::DARK_GREEN : - GAS_CHANNEL_NAMES.count(channelName) > 0 ? cvf::Color3f::DARK_RED : - WATER_CHANNEL_NAMES.count(channelName) > 0 ? cvf::Color3f::BLUE : + auto color = RimWellPlotTools::isOilFlowChannel(channelName) ? cvf::Color3f::DARK_GREEN : + RimWellPlotTools::isGasFlowChannel(channelName) ? cvf::Color3f::DARK_RED : + RimWellPlotTools::isWaterFlowChannel(channelName) ? cvf::Color3f::BLUE : cvf::Color3f::DARK_GRAY; addStackedCurve(curveName + ", " + channelName, @@ -1260,7 +956,7 @@ std::vector RimWellPltPlot::selectedSources() const { if (addr.sourceType() == RifWellRftAddress::OBSERVED) { - for (RimWellLogFile* const wellLogFile : wellLogFilesContainingFlow(m_wellPathName)) + for (RimWellLogFile* const wellLogFile : RimWellPlotTools::wellLogFilesContainingFlow(m_wellPathName)) { sources.push_back(RifWellRftAddress(RifWellRftAddress::OBSERVED, wellLogFile)); } @@ -1343,58 +1039,6 @@ int RimWellPltPlot::branchIndex() const return m_branchIndex; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimWellPltPlot::hasFlowData(const RimWellLogFile* wellLogFile) -{ - for (RimWellLogFileChannel* const wellLogChannel : wellLogFile->wellLogChannels()) - { - if (isFlowChannel(wellLogChannel)) return true; - } - return false; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimWellPltPlot::hasFlowData(RimWellPath* wellPath) -{ - for (RimWellLogFile* const wellLogFile : wellPath->wellLogFiles()) - { - if (hasFlowData(wellLogFile)) - { - return true; - } - } - return false; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimWellPltPlot::isFlowChannel(RimWellLogFileChannel* channel) -{ - return FLOW_DATA_NAMES.count(channel->name()) > 0; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RimWellPltPlot::hasFlowData(RimEclipseResultCase* gridCase) -{ - const RigEclipseCaseData* const eclipseCaseData = gridCase->eclipseCaseData(); - - for (const QString& channelName : FLOW_DATA_NAMES) - { - size_t resultIndex = eclipseCaseData->results(RiaDefines::MATRIX_MODEL)-> - findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, channelName); - - if (resultIndex != cvf::UNDEFINED_SIZE_T) return true; - } - return false; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1409,6 +1053,7 @@ const char* RimWellPltPlot::plotNameFormatString() QList RimWellPltPlot::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) { QList options; + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathName); if (fieldNeedingOptions == &m_wellPathName) { @@ -1418,9 +1063,7 @@ QList RimWellPltPlot::calculateValueOptions(const caf::P { std::set optionAddresses; - const std::vector>& eclipseCases = eclipseCasesForWell(simWellName(m_wellPathName)); - - const std::vector rftCases = rftCasesFromEclipseCases(eclipseCases); + const std::vector rftCases = RimWellPlotTools::rftCasesForWell(simWellName); if (rftCases.size() > 0) { options.push_back(caf::PdmOptionItemInfo::createHeader(RifWellRftAddress::sourceTypeUiText(RifWellRftAddress::RFT), true)); @@ -1434,7 +1077,7 @@ QList RimWellPltPlot::calculateValueOptions(const caf::P options.push_back(item); } - const std::vector gridCases = gridCasesFromEclipseCases(eclipseCases); + const std::vector gridCases = RimWellPlotTools::gridCasesForWell(simWellName); if (gridCases.size() > 0) { options.push_back(caf::PdmOptionItemInfo::createHeader(RifWellRftAddress::sourceTypeUiText(RifWellRftAddress::GRID), true)); @@ -1448,7 +1091,7 @@ QList RimWellPltPlot::calculateValueOptions(const caf::P options.push_back(item); } - if (wellLogFilesContainingFlow(m_wellPathName).size() > 0) + if (RimWellPlotTools::wellLogFilesContainingFlow(m_wellPathName).size() > 0) { options.push_back(caf::PdmOptionItemInfo::createHeader(RifWellRftAddress::sourceTypeUiText(RifWellRftAddress::OBSERVED), true)); @@ -1467,7 +1110,7 @@ QList RimWellPltPlot::calculateValueOptions(const caf::P { RimProject* proj = RiaApplication::instance()->project(); - size_t branchCount = proj->simulationWellBranches(simWellName(m_wellPathName)).size(); + size_t branchCount = proj->simulationWellBranches(simWellName).size(); for (int bIdx = 0; bIdx < static_cast(branchCount); ++bIdx) { @@ -1485,9 +1128,9 @@ QList RimWellPltPlot::calculateValueOptions(const caf::P } else if (fieldNeedingOptions == &m_phases) { - options.push_back(caf::PdmOptionItemInfo("Oil", PHASE_OIL)); - options.push_back(caf::PdmOptionItemInfo("Gas", PHASE_GAS)); - options.push_back(caf::PdmOptionItemInfo("Water", PHASE_WATER)); + options.push_back(caf::PdmOptionItemInfo("Oil", FLOW_PHASE_OIL)); + options.push_back(caf::PdmOptionItemInfo("Gas", FLOW_PHASE_GAS)); + options.push_back(caf::PdmOptionItemInfo("Water", FLOW_PHASE_WATER)); } return options; @@ -1559,11 +1202,13 @@ QImage RimWellPltPlot::snapshotWindowContent() //-------------------------------------------------------------------------------------------------- void RimWellPltPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) { + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathName); + uiOrdering.add(&m_userName); uiOrdering.add(&m_wellPathName); RimProject* proj = RiaApplication::instance()->project(); - if (proj->simulationWellBranches(simWellName(m_wellPathName)).size() > 1) + if (proj->simulationWellBranches(simWellName).size() > 1) { uiOrdering.add(&m_branchIndex); } @@ -1667,37 +1312,6 @@ void RimWellPltPlot::syncSourcesIoFieldFromGuiField() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellPltPlot::addTimeStepToMap(std::map>& destMap, - const std::pair>& timeStepToAdd) -{ - auto timeStepMapToAdd = std::map> { timeStepToAdd }; - addTimeStepsToMap(destMap, timeStepMapToAdd); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimWellPltPlot::addTimeStepsToMap(std::map>& destMap, - const std::map>& timeStepsToAdd) -{ - for (const auto& timeStepPair : timeStepsToAdd) - { - if (timeStepPair.first.isValid()) - { - if (destMap.count(timeStepPair.first) == 0) - { - destMap.insert(std::make_pair(timeStepPair.first, std::set())); - } - auto addresses = timeStepPair.second; - destMap[timeStepPair.first].insert(addresses.begin(), addresses.end()); - } - } -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1754,10 +1368,10 @@ void RimWellPltPlot::calculateValueOptionsForWells(QList //-------------------------------------------------------------------------------------------------- void RimWellPltPlot::calculateValueOptionsForTimeSteps(const QString& wellPathNameOrSimWellName, QList& options) { + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathName); std::map> displayTimeStepsMap, obsAndRftTimeStepsMap, gridTimeStepsMap; - const std::vector>& eclipseCases = eclipseCasesForWell(simWellName(wellPathNameOrSimWellName)); - const std::vector rftCases = rftCasesFromEclipseCases(eclipseCases); - const std::vector gridCases = gridCasesFromEclipseCases(eclipseCases); + const std::vector rftCases = RimWellPlotTools::rftCasesForWell(simWellName); + const std::vector gridCases = RimWellPlotTools::gridCasesForWell(simWellName); // First update timeSteps to Address 'cache' std::vector selSources = selectedSources(); @@ -1769,22 +1383,21 @@ void RimWellPltPlot::calculateValueOptionsForTimeSteps(const QString& wellPathNa { for (RimEclipseResultCase* const rftCase : rftCases) { - addTimeStepsToMap(obsAndRftTimeStepsMap, timeStepsFromRftCase(rftCase)); + RimWellPlotTools::addTimeStepsToMap(obsAndRftTimeStepsMap, RimWellPlotTools::timeStepsMapFromRftCase(rftCase, simWellName)); } } else if (selection.sourceType() == RifWellRftAddress::GRID) { for (RimEclipseResultCase* const gridCase : gridCases) { - addTimeStepsToMap(gridTimeStepsMap, timeStepsFromGridCase(gridCase)); + RimWellPlotTools::addTimeStepsToMap(gridTimeStepsMap, RimWellPlotTools::timeStepsMapFromGridCase(gridCase)); } } - else - if (selection.sourceType() == RifWellRftAddress::OBSERVED) + else if (selection.sourceType() == RifWellRftAddress::OBSERVED) { if (selection.wellLogFile() != nullptr) { - addTimeStepsToMap(obsAndRftTimeStepsMap, timeStepsFromWellLogFile(selection.wellLogFile())); + RimWellPlotTools::addTimeStepsToMap(obsAndRftTimeStepsMap, RimWellPlotTools::timeStepsMapFromWellLogFile(selection.wellLogFile())); } } } @@ -1799,14 +1412,14 @@ void RimWellPltPlot::calculateValueOptionsForTimeSteps(const QString& wellPathNa for (const std::pair>& timeStepPair : obsAndRftTimeStepsMap) { - const std::map>& adjTimeSteps = adjacentTimeSteps(gridTimeStepsVector, timeStepPair); - addTimeStepsToMap(displayTimeStepsMap, adjTimeSteps); + const std::map>& adjTimeSteps = RimWellPlotTools::adjacentTimeSteps(gridTimeStepsVector, timeStepPair); + RimWellPlotTools::addTimeStepsToMap(displayTimeStepsMap, adjTimeSteps); } // Add the first grid time step (from the total grid time steps list) if (gridTimeStepsVector.size() > 0) { - addTimeStepToMap(displayTimeStepsMap, gridTimeStepsVector.front()); + RimWellPlotTools::addTimeStepToMap(displayTimeStepsMap, gridTimeStepsVector.front()); } // Add already selected time steps @@ -1817,13 +1430,13 @@ void RimWellPltPlot::calculateValueOptionsForTimeSteps(const QString& wellPathNa const std::set sourceAddresses = m_timeStepsToAddresses[timeStep]; if (isAnySourceAddressSelected(sourceAddresses)) { - addTimeStepToMap(displayTimeStepsMap, std::make_pair(timeStep, m_timeStepsToAddresses[timeStep])); + RimWellPlotTools::addTimeStepToMap(displayTimeStepsMap, std::make_pair(timeStep, m_timeStepsToAddresses[timeStep])); } } } } - addTimeStepsToMap(m_timeStepsToAddresses, displayTimeStepsMap); + RimWellPlotTools::addTimeStepsToMap(m_timeStepsToAddresses, displayTimeStepsMap); // Create vector of all time steps std::vector allTimeSteps; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.h index 94a3d267f3..a61d7fe9c0 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.h @@ -23,6 +23,7 @@ #include "RimRftAddress.h" #include "RifWellRftAddressQMetaType.h" #include "RimPlotCurve.h" +#include "RimWellPlotTools.h" #include "cafPdmField.h" #include "cafPdmObject.h" @@ -62,15 +63,6 @@ class RimWellPltPlot : public RimViewWindow { CAF_PDM_HEADER_INIT; - enum FlowType { FLOW_TYPE_TOTAL, FLOW_TYPE_PHASE_SPLIT }; - enum FlowPhase { PHASE_NONE, PHASE_OIL, PHASE_GAS, PHASE_WATER, PHASE_TOTAL }; - - static const std::set OIL_CHANNEL_NAMES; - static const std::set GAS_CHANNEL_NAMES; - static const std::set WATER_CHANNEL_NAMES; - static const std::set TOTAL_CHANNEL_NAMES; - - static std::set FLOW_DATA_NAMES; static const char PLOT_NAME_QFORMAT_STRING[]; public: @@ -89,10 +81,6 @@ public: QString currentWellName() const; int branchIndex() const; - static bool hasFlowData(const RimWellLogFile* wellLogFile); - static bool isFlowChannel(RimWellLogFileChannel* channel); - static bool hasFlowData(RimEclipseResultCase* gridCase); - static bool hasFlowData(RimWellPath* wellPath); static const char* plotNameFormatString(); //void applyInitialSelections(); @@ -117,10 +105,6 @@ protected: void syncSourcesIoFieldFromGuiField(); private: - static void addTimeStepToMap(std::map>& destMap, - const std::pair>& timeStepToAdd); - static void addTimeStepsToMap(std::map>& destMap, - const std::map>& timeStepsToAdd); void updateTimeStepsToAddresses(const std::vector& addressesToKeep); void calculateValueOptionsForWells(QList& options); void calculateValueOptionsForTimeSteps(const QString& wellPathNameOrSimWellName, QList& options); @@ -129,21 +113,6 @@ private: void syncCurvesFromUiSelection(); - std::vector wellLogFilesContainingFlow(const QString& wellName) const; - std::vector getFlowChannelsFromWellFile(const RimWellLogFile* wellLogFile) const; - - RimWellPath* wellPathFromWellLogFile(const RimWellLogFile* wellLogFile) const; - - std::vector> eclipseCasesForWell(const QString& wellName) const; - std::vector gridCasesFromEclipseCases(const std::vector>& eclipseCasesTuple) const; - std::vector rftCasesFromEclipseCases(const std::vector>& eclipseCasesTuple) const; - std::map> timeStepsFromRftCase(RimEclipseResultCase* gridCase) const; - std::map> timeStepsFromGridCase(RimEclipseCase* gridCase) const; - std::map> timeStepsFromWellLogFile(RimWellLogFile* wellLogFile) const; - std::map> adjacentTimeSteps(const std::vector>>& allTimeSteps, - const std::pair>& searchTimeStepPair); - static bool mapContainsTimeStep(const std::map>& map, const QDateTime& timeStep); - std::set> selectedCurveDefs() const; std::set> curveDefsFromCurves() const; std::pair curveDefFromCurve(const RimWellLogCurve* curve) const; @@ -167,7 +136,6 @@ private: //void applyCurveAppearance(RimWellLogCurve* newCurve); void updateSelectedTimeStepsFromSelectedSources(); - static FlowPhase flowPhaseFromChannelName(const QString& channelName); void setPlotXAxisTitles(RimWellLogTrack* plotTrack); std::vector eclipseCases() const; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp index b4f54fc324..f575edaeb2 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellRftPlot.cpp @@ -81,7 +81,7 @@ RimWellRftPlot::RimWellRftPlot() m_wellLogPlot.uiCapability()->setUiTreeHidden(true); m_wellLogPlot.uiCapability()->setUiTreeChildrenHidden(true); - CAF_PDM_InitFieldNoDefault(&m_wellName, "WellName", "WellName", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_wellPathNameOrSimWellName, "WellName", "WellName", "", "", ""); CAF_PDM_InitField(&m_branchIndex, "BranchIndex", 0, "BranchIndex", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_selectedSources, "Sources", "Sources", "", "", ""); @@ -269,7 +269,7 @@ void RimWellRftPlot::updateFormationsOnPlot() const RimOilField* oilField = proj->activeOilField(); RimWellPathCollection* wellPathCollection = oilField->wellPathCollection(); - RimWellPath* wellPath = wellPathCollection->wellPathByName(m_wellName); + RimWellPath* wellPath = wellPathCollection->wellPathByName(m_wellPathNameOrSimWellName); RimWellLogTrack::TrajectoryType trajectoryType; @@ -292,7 +292,7 @@ void RimWellRftPlot::updateFormationsOnPlot() const if (m_wellLogPlot->trackCount() > 0) { - m_wellLogPlot->trackByIndex(0)->updateFormationNamesData(rimCase, trajectoryType, wellPath, m_wellName, m_branchIndex); + m_wellLogPlot->trackByIndex(0)->updateFormationNamesData(rimCase, trajectoryType, wellPath, m_wellPathNameOrSimWellName, m_branchIndex); } } @@ -305,20 +305,21 @@ void RimWellRftPlot::applyInitialSelections() std::set rftTimeSteps; std::set observedTimeSteps; std::set gridTimeSteps; + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathNameOrSimWellName); - for(RimEclipseResultCase* const rftCase : RimWellPlotTools::rftCasesForWell(m_wellName)) + for(RimEclipseResultCase* const rftCase : RimWellPlotTools::rftCasesForWell(m_wellPathNameOrSimWellName)) { sourcesToSelect.push_back(RifWellRftAddress(RifWellRftAddress::RFT, rftCase)); - RimWellPlotTools::appendSet(rftTimeSteps, RimWellPlotTools::timeStepsFromRftCase(rftCase, m_wellName)); + RimWellPlotTools::appendSet(rftTimeSteps, RimWellPlotTools::timeStepsFromRftCase(rftCase, simWellName)); } - for (RimEclipseResultCase* const gridCase : RimWellPlotTools::gridCasesForWell(m_wellName)) + for (RimEclipseResultCase* const gridCase : RimWellPlotTools::gridCasesForWell(m_wellPathNameOrSimWellName)) { sourcesToSelect.push_back(RifWellRftAddress(RifWellRftAddress::GRID, gridCase)); RimWellPlotTools::appendSet(gridTimeSteps, RimWellPlotTools::timeStepsFromGridCase(gridCase)); } - std::vector wellLogFiles = RimWellPlotTools::wellLogFilesContainingPressure(m_wellName); + std::vector wellLogFiles = RimWellPlotTools::wellLogFilesContainingPressure(m_wellPathNameOrSimWellName); if(wellLogFiles.size() > 0) { sourcesToSelect.push_back(RifWellRftAddress(RifWellRftAddress::OBSERVED)); @@ -438,8 +439,9 @@ void RimWellRftPlot::syncCurvesFromUiSelection() std::set < RiaRftPltCurveDefinition> RimWellRftPlot::selectedCurveDefs() const { std::set curveDefs; - const std::vector rftCases = RimWellPlotTools::rftCasesForWell(m_wellName); - const std::vector gridCases = RimWellPlotTools::gridCasesForWell(m_wellName); + const std::vector rftCases = RimWellPlotTools::rftCasesForWell(m_wellPathNameOrSimWellName); + const std::vector gridCases = RimWellPlotTools::gridCasesForWell(m_wellPathNameOrSimWellName); + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathNameOrSimWellName); for (const QDateTime& timeStep : m_selectedTimeSteps()) { @@ -449,7 +451,7 @@ std::set < RiaRftPltCurveDefinition> RimWellRftPlot::selectedCurveDefs() const { for (RimEclipseResultCase* const rftCase : rftCases) { - const std::set& timeSteps = RimWellPlotTools::timeStepsFromRftCase(rftCase, m_wellName); + const std::set& timeSteps = RimWellPlotTools::timeStepsFromRftCase(rftCase, simWellName); if (timeSteps.count(timeStep) > 0) { curveDefs.insert(RiaRftPltCurveDefinition(addr, timeStep)); @@ -471,8 +473,8 @@ std::set < RiaRftPltCurveDefinition> RimWellRftPlot::selectedCurveDefs() const { if (addr.wellLogFile() != nullptr) { - const QDateTime wlfTimeStep = RimWellPlotTools::timeStepFromWellLogFile(addr.wellLogFile()); - if (wlfTimeStep == timeStep) + const QDateTime wellLogFileTimeStep = RimWellPlotTools::timeStepFromWellLogFile(addr.wellLogFile()); + if (wellLogFileTimeStep == timeStep) { curveDefs.insert(RiaRftPltCurveDefinition(RifWellRftAddress(RifWellRftAddress::OBSERVED, addr.wellLogFile()), timeStep)); } @@ -524,7 +526,7 @@ void RimWellRftPlot::updateCurvesInPlot(const std::set auto rftCase = curveDefToAdd.address().eclCase(); curve->setEclipseResultCase(dynamic_cast(rftCase)); - RifEclipseRftAddress address(m_wellName, curveDefToAdd.timeStep(), RifEclipseRftAddress::PRESSURE); + RifEclipseRftAddress address(m_wellPathNameOrSimWellName, curveDefToAdd.timeStep(), RifEclipseRftAddress::PRESSURE); curve->setRftAddress(address); curve->setZOrder(1); @@ -538,7 +540,7 @@ void RimWellRftPlot::updateCurvesInPlot(const std::set cvf::Color3f curveColor = RiaColorTables::wellLogPlotPaletteColors().cycledColor3f(plotTrack->curveCount()); curve->setColor(curveColor); - curve->setFromSimulationWellName(m_wellName, m_branchIndex); + curve->setFromSimulationWellName(m_wellPathNameOrSimWellName, m_branchIndex); // Fetch cases and time steps auto gridCase = curveDefToAdd.address().eclCase(); @@ -555,9 +557,9 @@ void RimWellRftPlot::updateCurvesInPlot(const std::set curve->setEclipseResultDefinition(resultDef); // Time step - const std::map>& timeSteps = RimWellPlotTools::timeStepsMapFromGridCase(gridCase); + const std::set& timeSteps = RimWellPlotTools::timeStepsFromGridCase(gridCase); auto currentTimeStepItr = std::find_if(timeSteps.begin(), timeSteps.end(), - [curveDefToAdd](std::pair> pair) {return pair.first == curveDefToAdd.timeStep(); }); + [curveDefToAdd](const QDateTime& timeStep) {return timeStep == curveDefToAdd.timeStep(); }); auto currentTimeStepIndex = std::distance(timeSteps.begin(), currentTimeStepItr); curve->setCurrentTimeStep(currentTimeStepIndex); curve->setZOrder(0); @@ -623,7 +625,7 @@ std::vector RimWellRftPlot::selectedSources() const { if (addr.sourceType() == RifWellRftAddress::OBSERVED) { - for (RimWellLogFile* const wellLogFile : RimWellPlotTools::wellLogFilesContainingPressure(m_wellName)) + for (RimWellLogFile* const wellLogFile : RimWellPlotTools::wellLogFilesContainingPressure(m_wellPathNameOrSimWellName)) { sources.push_back(RifWellRftAddress(RifWellRftAddress::OBSERVED, wellLogFile)); } @@ -663,7 +665,7 @@ RimWellLogPlot* RimWellRftPlot::wellLogPlot() const //-------------------------------------------------------------------------------------------------- void RimWellRftPlot::setCurrentWellName(const QString& currWellName) { - m_wellName = currWellName; + m_wellPathNameOrSimWellName = currWellName; } //-------------------------------------------------------------------------------------------------- @@ -671,7 +673,7 @@ void RimWellRftPlot::setCurrentWellName(const QString& currWellName) //-------------------------------------------------------------------------------------------------- QString RimWellRftPlot::currentWellName() const { - return m_wellName; + return m_wellPathNameOrSimWellName; } //-------------------------------------------------------------------------------------------------- @@ -695,15 +697,16 @@ const char* RimWellRftPlot::plotNameFormatString() //-------------------------------------------------------------------------------------------------- QList RimWellRftPlot::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) { + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathNameOrSimWellName); QList options; - if (fieldNeedingOptions == &m_wellName) + if (fieldNeedingOptions == &m_wellPathNameOrSimWellName) { calculateValueOptionsForWells(options); } else if (fieldNeedingOptions == &m_selectedSources) { - const std::vector rftCases = RimWellPlotTools::rftCasesForWell(m_wellName); + const std::vector rftCases = RimWellPlotTools::rftCasesForWell(simWellName); if (rftCases.size() > 0) { options.push_back(caf::PdmOptionItemInfo::createHeader(RifWellRftAddress::sourceTypeUiText(RifWellRftAddress::RFT), true)); @@ -716,7 +719,7 @@ QList RimWellRftPlot::calculateValueOptions(const caf::P options.push_back(item); } - const std::vector gridCases = RimWellPlotTools::gridCasesForWell(m_wellName); + const std::vector gridCases = RimWellPlotTools::gridCasesForWell(simWellName); if (gridCases.size() > 0) { options.push_back(caf::PdmOptionItemInfo::createHeader(RifWellRftAddress::sourceTypeUiText(RifWellRftAddress::GRID), true)); @@ -729,7 +732,7 @@ QList RimWellRftPlot::calculateValueOptions(const caf::P options.push_back(item); } - if (RimWellPlotTools::wellLogFilesContainingPressure(m_wellName).size() > 0) + if (RimWellPlotTools::wellLogFilesContainingPressure(m_wellPathNameOrSimWellName).size() > 0) { options.push_back(caf::PdmOptionItemInfo::createHeader(RifWellRftAddress::sourceTypeUiText(RifWellRftAddress::OBSERVED), true)); @@ -747,7 +750,7 @@ QList RimWellRftPlot::calculateValueOptions(const caf::P { RimProject* proj = RiaApplication::instance()->project(); - size_t branchCount = proj->simulationWellBranches(m_wellName).size(); + size_t branchCount = proj->simulationWellBranches(m_wellPathNameOrSimWellName).size(); for (int bIdx = 0; bIdx < static_cast(branchCount); ++bIdx) { @@ -770,12 +773,12 @@ void RimWellRftPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c { RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); - if (changedField == &m_wellName) + if (changedField == &m_wellPathNameOrSimWellName) { - setDescription(QString(plotNameFormatString()).arg(m_wellName)); + setDescription(QString(plotNameFormatString()).arg(m_wellPathNameOrSimWellName)); } - if (changedField == &m_wellName || changedField == &m_branchIndex) + if (changedField == &m_wellPathNameOrSimWellName || changedField == &m_branchIndex) { RimWellLogTrack* const plotTrack = m_wellLogPlot->trackByIndex(0); for (RimWellLogCurve* const curve : plotTrack->curvesVector()) @@ -833,10 +836,10 @@ void RimWellRftPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& m_selectedSourcesOrTimeStepsFieldsChanged = false; uiOrdering.add(&m_userName); - uiOrdering.add(&m_wellName); + uiOrdering.add(&m_wellPathNameOrSimWellName); RimProject* proj = RiaApplication::instance()->project(); - if (proj->simulationWellBranches(m_wellName).size() > 1) + if (proj->simulationWellBranches(m_wellPathNameOrSimWellName).size() > 1) { uiOrdering.add(&m_branchIndex); } @@ -918,9 +921,10 @@ void RimWellRftPlot::calculateValueOptionsForWells(QList //-------------------------------------------------------------------------------------------------- void RimWellRftPlot::calculateValueOptionsForTimeSteps(QList& options) { + const QString simWellName = RimWellPlotTools::simWellName(m_wellPathNameOrSimWellName); std::map> displayTimeStepsMap, obsAndRftTimeStepsMap, gridTimeStepsMap; - const std::vector rftCases = RimWellPlotTools::rftCasesForWell(m_wellName); - const std::vector gridCases = RimWellPlotTools::gridCasesForWell(m_wellName); + const std::vector rftCases = RimWellPlotTools::rftCasesForWell(simWellName); + const std::vector gridCases = RimWellPlotTools::gridCasesForWell(simWellName); for (const RifWellRftAddress& selection : selectedSources()) { @@ -928,7 +932,7 @@ void RimWellRftPlot::calculateValueOptionsForTimeSteps(QList m_showPlotTitle; caf::PdmField m_userName; - caf::PdmField m_wellName; + caf::PdmField m_wellPathNameOrSimWellName; caf::PdmField m_branchIndex; caf::PdmField> m_selectedSources; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp b/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp index 4a634f5b19..e248520a14 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogFile.cpp @@ -22,7 +22,9 @@ #include "RimWellPath.h" #include "RimWellPathCollection.h" #include "RimTools.h" -#include "RimWellPltPlot.h" +//#include "RimWellPltPlot.h" +#include "RimWellPlotTools.h" + #include "RiaDateStringParser.h" #include "RigWellLogFile.h" @@ -238,7 +240,7 @@ std::vector RimWellLogFile::wellLogChannels() const //-------------------------------------------------------------------------------------------------- bool RimWellLogFile::hasFlowData() const { - return RimWellPltPlot::hasFlowData(this); + return RimWellPlotTools::hasFlowData(this); } //--------------------------------------------------------------------------------------------------