From f20a83c710a8ff12b6bf8f347a9e8d9fa4b3294e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 7 Jul 2023 10:58:33 +0200 Subject: [PATCH] Add create_statistics_case Remove original implementation not working in gridcasegroup.py Add create_statistics_case object method --- .../RimIdenticalGridCaseGroup.cpp | 37 ++++++-- .../RimIdenticalGridCaseGroup.h | 3 + .../CMakeLists_files.cmake | 2 + .../RimcEclipseStatisticsCase.cpp | 88 +++++++++++++------ .../RimcEclipseStatisticsCase.h | 22 ++++- .../RimcIdenticalGridCaseGroup.cpp | 63 +++++++++++++ .../RimcIdenticalGridCaseGroup.h | 42 +++++++++ .../case_grid_group_generated_results.py | 20 +++-- GrpcInterface/Python/rips/gridcasegroup.py | 14 --- 9 files changed, 233 insertions(+), 58 deletions(-) create mode 100644 ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.cpp create mode 100644 ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.h diff --git a/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp b/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp index 58048a2389..face568ee2 100644 --- a/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp @@ -347,16 +347,17 @@ void RimIdenticalGridCaseGroup::computeUnionOfActiveCells() //-------------------------------------------------------------------------------------------------- RimEclipseStatisticsCase* RimIdenticalGridCaseGroup::createAndAppendStatisticsCase() { - RimEclipseStatisticsCase* newStatisticsCase = new RimEclipseStatisticsCase; + bool selectDefaultResults = true; + return createStatisticsCase( selectDefaultResults ); +} - newStatisticsCase->setCaseUserDescription( QString( "Statistics " ) + QString::number( statisticsCaseCollection()->reservoirs.size() + 1 ) ); - statisticsCaseCollection()->reservoirs.push_back( newStatisticsCase ); - - newStatisticsCase->populateResultSelectionAfterLoadingGrid(); - newStatisticsCase->openEclipseGridFile(); - newStatisticsCase->eclipseCaseData()->computeActiveCellBoundingBoxes(); - - return newStatisticsCase; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseStatisticsCase* RimIdenticalGridCaseGroup::createAndAppendEmptyStatisticsCase() +{ + bool selectDefaultResults = false; + return createStatisticsCase( selectDefaultResults ); } //-------------------------------------------------------------------------------------------------- @@ -418,6 +419,24 @@ void RimIdenticalGridCaseGroup::clearActiveCellUnions() m_unionOfFractureActiveCells->clear(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseStatisticsCase* RimIdenticalGridCaseGroup::createStatisticsCase( bool selectDefaultResults ) +{ + RimEclipseStatisticsCase* newStatisticsCase = new RimEclipseStatisticsCase; + + newStatisticsCase->setCaseUserDescription( QString( "Statistics " ) + QString::number( statisticsCaseCollection()->reservoirs.size() + 1 ) ); + statisticsCaseCollection()->reservoirs.push_back( newStatisticsCase ); + + if ( selectDefaultResults ) newStatisticsCase->populateResultSelectionAfterLoadingGrid(); + + newStatisticsCase->openEclipseGridFile(); + newStatisticsCase->eclipseCaseData()->computeActiveCellBoundingBoxes(); + + return newStatisticsCase; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.h b/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.h index 4fb3fe005f..e982a1bd8f 100644 --- a/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.h +++ b/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.h @@ -59,6 +59,7 @@ public: bool contains( RimEclipseCase* reservoir ) const; RimEclipseStatisticsCase* createAndAppendStatisticsCase(); + RimEclipseStatisticsCase* createAndAppendEmptyStatisticsCase(); RimEclipseCase* mainCase(); void loadMainCaseAndActiveCellInfo(); @@ -78,6 +79,8 @@ private: void clearStatisticsResults(); void clearActiveCellUnions(); + RimEclipseStatisticsCase* createStatisticsCase( bool selectDefaultResults ); + private: RigMainGrid* m_mainGrid; diff --git a/ApplicationLibCode/ProjectDataModelCommands/CMakeLists_files.cmake b/ApplicationLibCode/ProjectDataModelCommands/CMakeLists_files.cmake index cc717830d2..9cb5949276 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/ProjectDataModelCommands/CMakeLists_files.cmake @@ -25,6 +25,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RimcIntersection.h ${CMAKE_CURRENT_LIST_DIR}/RimcEclipseCase.h ${CMAKE_CURRENT_LIST_DIR}/RimcEclipseStatisticsCase.h + ${CMAKE_CURRENT_LIST_DIR}/RimcIdenticalGridCaseGroup.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -54,6 +55,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RimcIntersection.cpp ${CMAKE_CURRENT_LIST_DIR}/RimcEclipseCase.cpp ${CMAKE_CURRENT_LIST_DIR}/RimcEclipseStatisticsCase.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimcIdenticalGridCaseGroup.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.cpp index 2d1432fe9a..079edad08f 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2020- Equinor ASA +// Copyright (C) 2023- Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,36 +20,20 @@ #include "RiaApplication.h" #include "RiaGuiApplication.h" +#include "RiaLogging.h" #include "RicImportSummaryCasesFeature.h" -/* -#include "RimEclipseCase.h" -#include "RimFileSummaryCase.h" -#include "RimOilField.h" -#include "RimProject.h" -#include "RimSummaryCase.h" -#include "RimSurfaceCollection.h" -#include "RiuPlotMainWindow.h" -*/ - -#include "RiaLogging.h" #include "RimEclipseStatisticsCase.h" + #include "cafPdmFieldScriptingCapability.h" -/* -#include -#include - -#include -*/ - -CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseStatisticsCase, RimcEclipseStatisticsCase_defineSourceProperties, "set_source_result" ); +CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseStatisticsCase, RimcEclipseStatisticsCase_setSourceProperties, "set_source_properties" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimcEclipseStatisticsCase_defineSourceProperties::RimcEclipseStatisticsCase_defineSourceProperties( caf::PdmObjectHandle* self ) +RimcEclipseStatisticsCase_setSourceProperties::RimcEclipseStatisticsCase_setSourceProperties( caf::PdmObjectHandle* self ) : caf::PdmObjectMethod( self ) { CAF_PDM_InitObject( "Define Source Properties" ); @@ -60,7 +44,7 @@ RimcEclipseStatisticsCase_defineSourceProperties::RimcEclipseStatisticsCase_defi //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::PdmObjectHandle* RimcEclipseStatisticsCase_defineSourceProperties::execute() +caf::PdmObjectHandle* RimcEclipseStatisticsCase_setSourceProperties::execute() { RiaDefines::ResultCatType myEnum = caf::AppEnum::fromText( m_propertyType() ); @@ -81,7 +65,7 @@ caf::PdmObjectHandle* RimcEclipseStatisticsCase_defineSourceProperties::execute( //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimcEclipseStatisticsCase_defineSourceProperties::resultIsPersistent() const +bool RimcEclipseStatisticsCase_setSourceProperties::resultIsPersistent() const { return false; } @@ -89,7 +73,7 @@ bool RimcEclipseStatisticsCase_defineSourceProperties::resultIsPersistent() cons //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::unique_ptr RimcEclipseStatisticsCase_defineSourceProperties::defaultResult() const +std::unique_ptr RimcEclipseStatisticsCase_setSourceProperties::defaultResult() const { return nullptr; } @@ -97,7 +81,7 @@ std::unique_ptr RimcEclipseStatisticsCase_defineSourceProp //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimcEclipseStatisticsCase_defineSourceProperties::isNullptrValidResult() const +bool RimcEclipseStatisticsCase_setSourceProperties::isNullptrValidResult() const { return true; } @@ -146,3 +130,57 @@ bool RimcEclipseStatisticsCase_computeStatistics::isNullptrValidResult() const { return true; } + +CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseStatisticsCase, RimcEclipseStatisticsCase_clearSourceProperties, "clear_source_properties" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimcEclipseStatisticsCase_clearSourceProperties::RimcEclipseStatisticsCase_clearSourceProperties( caf::PdmObjectHandle* self ) + : caf::PdmObjectMethod( self ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmObjectHandle* RimcEclipseStatisticsCase_clearSourceProperties::execute() +{ + auto myEnums = { RiaDefines::ResultCatType::DYNAMIC_NATIVE, + RiaDefines::ResultCatType::STATIC_NATIVE, + RiaDefines::ResultCatType::INPUT_PROPERTY, + RiaDefines::ResultCatType::GENERATED }; + + auto eclipseCase = self(); + + for ( auto myEnum : myEnums ) + { + eclipseCase->setSourceProperties( myEnum, {} ); + } + + return nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimcEclipseStatisticsCase_clearSourceProperties::resultIsPersistent() const +{ + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::unique_ptr RimcEclipseStatisticsCase_clearSourceProperties::defaultResult() const +{ + return nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimcEclipseStatisticsCase_clearSourceProperties::isNullptrValidResult() const +{ + return true; +} diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.h b/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.h index dcc29a767f..a7bd0bcba4 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.h +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcEclipseStatisticsCase.h @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////////// // -// Copyright (C) 2020- Equinor ASA +// Copyright (C) 2023- Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -29,12 +29,12 @@ //================================================================================================== /// //================================================================================================== -class RimcEclipseStatisticsCase_defineSourceProperties : public caf::PdmObjectMethod +class RimcEclipseStatisticsCase_setSourceProperties : public caf::PdmObjectMethod { CAF_PDM_HEADER_INIT; public: - RimcEclipseStatisticsCase_defineSourceProperties( caf::PdmObjectHandle* self ); + RimcEclipseStatisticsCase_setSourceProperties( caf::PdmObjectHandle* self ); caf::PdmObjectHandle* execute() override; bool resultIsPersistent() const override; @@ -61,3 +61,19 @@ public: std::unique_ptr defaultResult() const override; bool isNullptrValidResult() const override; }; + +//================================================================================================== +/// +//================================================================================================== +class RimcEclipseStatisticsCase_clearSourceProperties : public caf::PdmObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimcEclipseStatisticsCase_clearSourceProperties( caf::PdmObjectHandle* self ); + + caf::PdmObjectHandle* execute() override; + bool resultIsPersistent() const override; + std::unique_ptr defaultResult() const override; + bool isNullptrValidResult() const override; +}; diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.cpp new file mode 100644 index 0000000000..ef4040cbcf --- /dev/null +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.cpp @@ -0,0 +1,63 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RimcIdenticalGridCaseGroup.h" + +#include "RimEclipseStatisticsCase.h" +#include "RimIdenticalGridCaseGroup.h" + +#include "cafPdmFieldScriptingCapability.h" + +CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimIdenticalGridCaseGroup, RimcIdenticalGridCaseGroup_createStatisticsCase, "create_statistics_case" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimcIdenticalGridCaseGroup_createStatisticsCase::RimcIdenticalGridCaseGroup_createStatisticsCase( caf::PdmObjectHandle* self ) + : caf::PdmObjectMethod( self ) +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmObjectHandle* RimcIdenticalGridCaseGroup_createStatisticsCase::execute() +{ + auto gridCaseGroup = self(); + auto statCase = gridCaseGroup->createAndAppendEmptyStatisticsCase(); + + gridCaseGroup->updateConnectedEditors(); + + return statCase; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimcIdenticalGridCaseGroup_createStatisticsCase::resultIsPersistent() const +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::unique_ptr RimcIdenticalGridCaseGroup_createStatisticsCase::defaultResult() const +{ + return std::unique_ptr( new RimEclipseStatisticsCase ); +} diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.h b/ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.h new file mode 100644 index 0000000000..ec7d5a93e6 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcIdenticalGridCaseGroup.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmField.h" +#include "cafPdmObjectHandle.h" +#include "cafPdmObjectMethod.h" + +#include + +#include + +//================================================================================================== +/// +//================================================================================================== +class RimcIdenticalGridCaseGroup_createStatisticsCase : public caf::PdmObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimcIdenticalGridCaseGroup_createStatisticsCase( caf::PdmObjectHandle* self ); + + caf::PdmObjectHandle* execute() override; + bool resultIsPersistent() const override; + std::unique_ptr defaultResult() const override; +}; diff --git a/GrpcInterface/Python/rips/PythonExamples/case_grid_group_generated_results.py b/GrpcInterface/Python/rips/PythonExamples/case_grid_group_generated_results.py index a89cf06436..05c018bf90 100644 --- a/GrpcInterface/Python/rips/PythonExamples/case_grid_group_generated_results.py +++ b/GrpcInterface/Python/rips/PythonExamples/case_grid_group_generated_results.py @@ -49,10 +49,16 @@ for case in cases: print("Transferred all results back to ResInsight") -# The API does not support configuration of a computation -# Suggested next steps -# - open ResInsight -# - select the statistics object -# - select the generated result(PRESSURE_PORV) as source for computations -# - compute statistics -# - create a view and investigate the statistics of the generated data (PRESSURE_PORV) +# one of "GENERATED", "DYNAMIC_NATIVE", "STATIC_NATIVE", "IMPORTED" +# https://api.resinsight.org/en/main/rips.html#result-definition +property_type = "GENERATED" + +property_name = "PRESSURE_PORV" + +statistics_case = case_group.create_statistics_case() +statistics_case.set_source_properties(property_type, [property_name]) +statistics_case.compute_statistics() + +view = statistics_case.create_view() +statistics_property_name = property_name + "_MEAN" +view.apply_cell_result(result_type=property_type, result_variable=statistics_property_name) diff --git a/GrpcInterface/Python/rips/gridcasegroup.py b/GrpcInterface/Python/rips/gridcasegroup.py index f90f8ed6a1..1caf8f00f8 100644 --- a/GrpcInterface/Python/rips/gridcasegroup.py +++ b/GrpcInterface/Python/rips/gridcasegroup.py @@ -11,20 +11,6 @@ from .resinsight_classes import GridCaseGroup from .resinsight_classes import EclipseView from .resinsight_classes import RimStatisticalCalculation -@add_method(GridCaseGroup) -def create_statistics_case(self): - """Create a Statistics case in the Grid Case Group - - Returns: - :class:`rips.generated.generated_classes.EclipseCase` - """ - command_reply = self._execute_command( - createStatisticsCase=Commands_pb2.CreateStatisticsCaseRequest( - caseGroupId=self.group_id - ) - ) - return Case(self.channel, command_reply.createStatisticsCaseResult.caseId) - @add_method(GridCaseGroup) def statistics_cases(self):