#4254 Saturation Pressure Plots: Add command file command

This commit is contained in:
Magne Sjaastad 2019-04-09 12:43:15 +02:00
parent c0f3258f19
commit 6e88cecbb2
5 changed files with 206 additions and 68 deletions

View File

@ -27,6 +27,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportPropertyInViews.h
${CMAKE_CURRENT_LIST_DIR}/RicfExportLgrForCompletions.h
${CMAKE_CURRENT_LIST_DIR}/RicfCreateLgrForCompletions.h
${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.h
${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -57,6 +58,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportPropertyInViews.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfExportLgrForCompletions.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateLgrForCompletions.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,83 @@
#include "RicfCreateSaturationPressurePlots.h"
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfCreateSaturationPressurePlots.h"
#include "GridCrossPlotCommands/RicCreateSaturationPressurePlotsFeature.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimEclipseResultCase.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimSaturationPressurePlotCollection.h"
CAF_PDM_SOURCE_INIT(RicfCreateSaturationPressurePlots, "createSaturationPressurePlots");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCreateSaturationPressurePlots::RicfCreateSaturationPressurePlots()
{
RICF_InitField(&m_caseIds, "caseIds", std::vector<int>(), "Case IDs", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfCreateSaturationPressurePlots::execute()
{
std::vector<int> caseIds = m_caseIds();
if (caseIds.empty())
{
RimProject* project = RiaApplication::instance()->project();
if (project)
{
auto eclipeCases = project->eclipseCases();
for (auto c : eclipeCases)
{
caseIds.push_back(c->caseId());
}
}
}
RimProject* project = RiaApplication::instance()->project();
if (project)
{
auto eclipeCases = project->eclipseCases();
for (auto c : eclipeCases)
{
auto eclipseResultCase = dynamic_cast<RimEclipseResultCase*>(c);
if (!eclipseResultCase) continue;
for (auto caseId : caseIds)
{
if (c->caseId == caseId)
{
RicCreateSaturationPressurePlotsFeature::createPlots(eclipseResultCase);
}
}
}
}
RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();
collection->updateAllRequiredEditors();
RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
}

View File

@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RicfCommandObject.h"
#include "cafPdmField.h"
//==================================================================================================
//
//
//
//==================================================================================================
class RicfCreateSaturationPressurePlots : public RicfCommandObject
{
CAF_PDM_HEADER_INIT;
public:
RicfCreateSaturationPressurePlots();
void execute() override;
private:
caf::PdmField< std::vector<int> > m_caseIds;
};

View File

@ -45,6 +45,63 @@
CAF_CMD_SOURCE_INIT(RicCreateSaturationPressurePlotsFeature, "RicCreateSaturationPressurePlotsFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSaturationPressurePlot*>
RicCreateSaturationPressurePlotsFeature::createPlots(RimEclipseResultCase* eclipseResultCase)
{
std::vector<RimSaturationPressurePlot*> plots;
if (!eclipseResultCase)
{
RiaLogging::error(
"RicCreateSaturationPressurePlotsFeature:: No case specified for creation of saturation pressure plots");
return plots;
}
RimProject* project = RiaApplication::instance()->project();
RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();
if (eclipseResultCase && eclipseResultCase->ensureReservoirCaseIsOpen())
{
eclipseResultCase->ensureDeckIsParsedForEquilData();
RigEclipseCaseData* eclipseCaseData = eclipseResultCase->eclipseCaseData();
bool requiredInputDataPresent = false;
if (!eclipseCaseData->equilData().empty())
{
if (eclipseCaseData && eclipseCaseData->results(RiaDefines::MATRIX_MODEL))
{
RigCaseCellResultsData* resultData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);
if (resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PRESSURE")) &&
resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PDEW")) &&
resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PBUB")))
{
requiredInputDataPresent = true;
}
}
}
if (requiredInputDataPresent)
{
plots = collection->createSaturationPressurePlots(eclipseResultCase);
for (auto plot : plots)
{
plot->loadDataAndUpdate();
plot->zoomAll();
plot->updateConnectedEditors();
}
}
}
return plots;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -60,15 +117,7 @@ void RicCreateSaturationPressurePlotsFeature::onActionTriggered(bool isChecked)
{
RimProject* project = RiaApplication::instance()->project();
bool launchedFromPlotCollection = true;
RimSaturationPressurePlotCollection* collection =
caf::SelectionManager::instance()->selectedItemAncestorOfType<RimSaturationPressurePlotCollection>();
if (!collection)
{
collection = project->mainPlotCollection()->saturationPressurePlotCollection();
launchedFromPlotCollection = false;
}
RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();
std::vector<RimEclipseResultCase*> eclipseCases;
{
@ -112,58 +161,24 @@ void RicCreateSaturationPressurePlotsFeature::onActionTriggered(bool isChecked)
caf::PdmObject* objectToSelect = nullptr;
if (eclipseResultCase && eclipseResultCase->ensureReservoirCaseIsOpen())
std::vector<RimSaturationPressurePlot*> plots = createPlots(eclipseResultCase);
if (plots.empty())
{
eclipseResultCase->ensureDeckIsParsedForEquilData();
QString text = "No plots generated.\n\n";
text += "Data required to generate saturation/pressure plots:\n";
text += " - EQLNUM property defining at least one region\n";
text += " - Dynamic properties PRESSURE, PBUB and PDEW\n\n";
text += "Make sure to add 'PBPD' to the RPTRST keyword in the SOLUTION selection. ";
text += "If this is a two phase run (Oil/water or Gas/Water) or if both VAPOIL ";
text += "and DISGAS are disabled, saturation pressure are not valid.";
RigEclipseCaseData* eclipseCaseData = eclipseResultCase->eclipseCaseData();
QMessageBox::warning(nullptr, "Saturation Pressure Plots", text);
bool requiredInputDataPresent = false;
if (!eclipseCaseData->equilData().empty())
{
if (eclipseCaseData && eclipseCaseData->results(RiaDefines::MATRIX_MODEL))
{
RigCaseCellResultsData* resultData = eclipseCaseData->results(RiaDefines::MATRIX_MODEL);
if (resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PRESSURE")) &&
resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PDEW")) &&
resultData->hasResultEntry(RigEclipseResultAddress(RiaDefines::DYNAMIC_NATIVE, "PBUB")))
{
requiredInputDataPresent = true;
}
}
}
std::vector<RimSaturationPressurePlot*> plots;
if (requiredInputDataPresent)
{
plots = collection->createSaturationPressurePlots(eclipseResultCase);
for (auto plot : plots)
{
plot->loadDataAndUpdate();
plot->zoomAll();
plot->updateConnectedEditors();
}
}
if (plots.empty())
{
QString text = "No plots generated.\n\n";
text += "Data required to generate saturation/pressure plots:\n";
text += " - EQLNUM property defining at least one region\n";
text += " - Dynamic properties PRESSURE, PBUB and PDEW\n\n";
text += "Make sure to add 'PBPD' to the RPTRST keyword in the SOLUTION selection. ";
text += "If this is a two phase run (Oil/water or Gas/Water) or if both VAPOIL ";
text += "and DISGAS are disabled, saturation pressure are not valid.";
QMessageBox::warning(nullptr, "Saturation Pressure Plots", text);
RiaLogging::warning(text);
}
else
{
objectToSelect = plots.front();
}
RiaLogging::warning(text);
}
else
{
objectToSelect = plots.front();
}
collection->updateAllRequiredEditors();
@ -180,15 +195,6 @@ void RicCreateSaturationPressurePlotsFeature::onActionTriggered(bool isChecked)
//--------------------------------------------------------------------------------------------------
void RicCreateSaturationPressurePlotsFeature::setupActionLook(QAction* actionToSetup)
{
RimSaturationPressurePlotCollection* collection =
caf::SelectionManager::instance()->selectedItemAncestorOfType<RimSaturationPressurePlotCollection>();
if (!collection)
{
actionToSetup->setText("New Grid Cross Plot from 3d View");
}
else
{
actionToSetup->setText("Create Saturation Pressure Plots");
}
actionToSetup->setText("Create Saturation Pressure Plots");
actionToSetup->setIcon(QIcon(":/SummaryXPlotsLight16x16.png"));
}

View File

@ -20,6 +20,9 @@
#include "cafCmdFeature.h"
class RimEclipseResultCase;
class RimSaturationPressurePlot;
//==================================================================================================
///
//==================================================================================================
@ -27,6 +30,9 @@ class RicCreateSaturationPressurePlotsFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static std::vector<RimSaturationPressurePlot*> createPlots(RimEclipseResultCase* eclipseCase);
protected:
bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override;