From c4e6bf0dd8d78c9ff9bdccd5f6fd223dae92929a Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 25 Jan 2021 12:20:45 +0100 Subject: [PATCH] Add optional methods to get VFP tables --- .../EclipseState/Schedule/ScheduleState.hpp | 2 ++ .../EclipseState/Schedule/ScheduleState.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp index 4e91977fc..e4f8ab99e 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp @@ -124,10 +124,12 @@ namespace Opm { std::vector> vfpprod() const; const VFPProdTable& vfpprod(int table_id) const; void update_vfpprod(VFPProdTable vfpprod); + std::optional> try_vfpprod(int table_id) const; std::vector> vfpinj() const; const VFPInjTable& vfpinj(int table_id) const; void update_vfpinj(VFPInjTable vfpinj); + std::optional> try_vfpinj(int table_id) const; const Action::Actions& actions() const; void update_actions(Action::Actions actions); diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp index a890304ca..dd72c654f 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/ScheduleState.cpp @@ -318,6 +318,14 @@ void ScheduleState::update_vfpprod(VFPProdTable vfpprod) { this->m_vfpprod[table_id] = std::make_shared( std::move(vfpprod) ); } +std::optional> ScheduleState::try_vfpprod(int table_id) const { + auto vfp_iter = this->m_vfpprod.find(table_id); + if (vfp_iter != this->m_vfpprod.end()) + return std::cref(*vfp_iter->second); + return {}; +} + + std::vector> ScheduleState::vfpinj() const { std::vector> tables; for (const auto& [_, table] : this->m_vfpinj) { @@ -327,6 +335,13 @@ std::vector> ScheduleState::vfpinj() c return tables; } +std::optional> ScheduleState::try_vfpinj(int table_id) const { + auto vfp_iter = this->m_vfpinj.find(table_id); + if (vfp_iter != this->m_vfpinj.end()) + return std::cref(*vfp_iter->second); + return {}; +} + const VFPInjTable& ScheduleState::vfpinj(int table_id) const { auto vfp_iter = this->m_vfpinj.find(table_id); if (vfp_iter == this->m_vfpinj.end())