From b2857676c8f4349840dcb540575a61546aee739b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 25 Jun 2019 17:49:38 +0200 Subject: [PATCH] #4136 Command File : Export of flow characteristics --- .../CMakeLists_files.cmake | 2 + .../RicfExportFlowCharacteristics.cpp | 116 ++++++++++++++++++ .../RicfExportFlowCharacteristics.h | 51 ++++++++ .../Flow/RimFlowCharacteristicsPlot.cpp | 53 ++++++++ .../Flow/RimFlowCharacteristicsPlot.h | 5 + 5 files changed, 227 insertions(+) create mode 100644 ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.cpp create mode 100644 ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.h diff --git a/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake b/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake index 91b91819de..8fd95c86d6 100644 --- a/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake +++ b/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake @@ -28,6 +28,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportLgrForCompletions.h ${CMAKE_CURRENT_LIST_DIR}/RicfCreateLgrForCompletions.h ${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.h ${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.h +${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -59,6 +60,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportLgrForCompletions.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfCreateLgrForCompletions.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfApplicationTools.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfCreateSaturationPressurePlots.cpp +${CMAKE_CURRENT_LIST_DIR}/RicfExportFlowCharacteristics.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.cpp b/ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.cpp new file mode 100644 index 0000000000..602d5f0417 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.cpp @@ -0,0 +1,116 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicfExportFlowCharacteristics.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RicfApplicationTools.h" + +#include "RimEclipseResultCase.h" +#include "RimFlowCharacteristicsPlot.h" +#include "RimFlowPlotCollection.h" +#include "RimMainPlotCollection.h" +#include "RimProject.h" + +#include +#include +#include + +CAF_PDM_SOURCE_INIT(RicfExportFlowCharacteristics, "exportFlowCharacteristics"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfExportFlowCharacteristics::RicfExportFlowCharacteristics() +{ + RICF_InitField(&m_caseId, "caseId", -1, "Case ID", "", "", ""); + RICF_InitField(&m_selectedTimeSteps, "timeSteps", std::vector(), "Selected Time Steps", "", "", ""); + RICF_InitField(&m_injectors, "injectors", std::vector(), "Injectors", "", "", ""); + RICF_InitField(&m_producers, "producers", std::vector(), "Producers", "", "", ""); + RICF_InitField(&m_fileName, "fileName", QString(), "Export File Name", "", "", ""); + RICF_InitField(&m_minCommunication, "minimumCommunication", 0.0, "Minimum Communication", "", "", ""); + RICF_InitField(&m_maxPvFraction, "aquiferCellThreshold", 0.1, "Aquifer Cell Threshold", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfCommandResponse RicfExportFlowCharacteristics::execute() +{ + using TOOLS = RicfApplicationTools; + + auto eclipseCase = dynamic_cast(TOOLS::caseFromId(m_caseId())); + if (!eclipseCase) + { + QString error = QString("exportFlowCharacteristics: Could not find case with ID %1.").arg(m_caseId()); + RiaLogging::error(error); + return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, error); + } + + { + QString exportFileName = m_fileName(); + if (exportFileName.isEmpty()) + { + QString exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath("flow_characteristics"); + + QDir exportDir(exportFolder); + if (!exportDir.exists()) + { + if (!exportDir.mkpath(".")) + { + QString msg = QString("Failed to create folder - %1").arg(exportFolder); + return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, msg); + } + } + + exportFileName = exportFolder + QString("/flow_characteristics_data.txt"); + } + + RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection(); + if (flowPlotColl) + { + RimFlowCharacteristicsPlot* plot = flowPlotColl->defaultFlowCharacteristicsPlot(); + plot->setFromFlowSolution(eclipseCase->defaultFlowDiagSolution()); + plot->setTimeSteps(m_selectedTimeSteps); + plot->setInjectorsAndProducers(m_injectors, m_producers); + plot->setAquiferCellThreshold(m_maxPvFraction); + plot->setMinimumCommunication(m_minCommunication); + + plot->loadDataAndUpdate(); + + { + QString content = plot->curveDataAsText(); + + QFile file(exportFileName); + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream textstream(&file); + textstream << content; + } + else + { + QString msg = QString("Failed to export file - %1").arg(exportFileName); + return RicfCommandResponse(RicfCommandResponse::COMMAND_ERROR, msg); + } + } + } + } + return RicfCommandResponse(); +} diff --git a/ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.h b/ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.h new file mode 100644 index 0000000000..37a510d0e2 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfExportFlowCharacteristics.h @@ -0,0 +1,51 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RiaDefines.h" + +#include "RicfCommandObject.h" + +#include + +#include "cafPdmField.h" + +//================================================================================================== +// +// +// +//================================================================================================== +class RicfExportFlowCharacteristics : public RicfCommandObject +{ + CAF_PDM_HEADER_INIT; + +public: + RicfExportFlowCharacteristics(); + + RicfCommandResponse execute() override; + +private: + caf::PdmField m_caseId; + caf::PdmField> m_selectedTimeSteps; + caf::PdmField> m_injectors; + caf::PdmField> m_producers; + caf::PdmField m_fileName; + caf::PdmField m_minCommunication; + caf::PdmField m_maxPvFraction; +}; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp index eb11b10c0f..97d6772b33 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp @@ -141,6 +141,8 @@ void RimFlowCharacteristicsPlot::setFromFlowSolution(RimFlowDiagSolution* flowSo m_flowDiagSolution = flowSolution; m_showWindow = true; + m_timeStepToFlowResultMap.clear(); + m_currentlyPlottedTimeSteps.clear(); onLoadDataAndUpdate(); } @@ -173,6 +175,57 @@ void RimFlowCharacteristicsPlot::updateCurrentTimeStep() this->onLoadDataAndUpdate(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFlowCharacteristicsPlot::setTimeSteps(const std::vector& timeSteps) +{ + m_selectedTimeSteps = timeSteps; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFlowCharacteristicsPlot::setInjectorsAndProducers(const std::vector& injectors, + const std::vector& producers) +{ + std::vector allTracers; + + allTracers = producers; + allTracers.insert(allTracers.end(), injectors.begin(), injectors.end()); + + if (producers.empty() && !injectors.empty()) + { + m_cellFilter = RigFlowDiagResults::CELLS_FLOODED; + } + else if (!producers.empty() && injectors.empty()) + { + m_cellFilter = RigFlowDiagResults::CELLS_DRAINED; + } + else if (!producers.empty() && !injectors.empty()) + { + m_cellFilter = RigFlowDiagResults::CELLS_COMMUNICATION; + } + + m_selectedTracerNames = allTracers; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFlowCharacteristicsPlot::setMinimumCommunication(double minimumCommunication) +{ + m_minCommunication = minimumCommunication; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFlowCharacteristicsPlot::setAquiferCellThreshold(double aquiferCellThreshold) +{ + m_maxPvFraction = aquiferCellThreshold; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.h index 78fc196a87..831bb2bcbc 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.h @@ -74,6 +74,11 @@ public: ALL_AVAILABLE, SELECTED, }; + + void setTimeSteps(const std::vector& timeSteps); + void setInjectorsAndProducers(const std::vector& injectors, const std::vector& producers); + void setMinimumCommunication(double minimumCommunication); + void setAquiferCellThreshold(double aquiferCellThreshold); protected: // RimViewWindow overrides