From ab63d14bcdfe7a7fc8e1aa7b52153b7229190d7b Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 27 Oct 2021 12:53:56 +0200 Subject: [PATCH 1/2] Remove debugging aid GroupState::dump --- opm/simulators/wells/GroupState.cpp | 66 ----------------------------- opm/simulators/wells/GroupState.hpp | 2 - tests/test_GroupState.cpp | 12 ------ 3 files changed, 80 deletions(-) diff --git a/opm/simulators/wells/GroupState.cpp b/opm/simulators/wells/GroupState.cpp index 702a08589..0102b0b40 100644 --- a/opm/simulators/wells/GroupState.cpp +++ b/opm/simulators/wells/GroupState.cpp @@ -268,70 +268,4 @@ bool GroupState::has_gpmaint_target(const std::string& gname) const { return (this->m_gpmaint_target.count(gname) > 0); } -//------------------------------------------------------------------------- - -namespace { - -template -void dump_vector(Json::JsonObject& root, const std::string& key, const std::vector& data) { - auto data_obj = root.add_array(key); - for (const auto& rate : data) - data_obj.add(rate); -} - - -template -void dump_groupmap(Json::JsonObject& root, const std::string& key, const std::map>& group_data) { - auto map_obj = root.add_object(key); - for (const auto& [gname, data] : group_data) - dump_vector(map_obj, gname, data); -} - - -template -void dump_groupmap(Json::JsonObject& root, const std::string& key, const std::map& group_data) { - auto map_obj = root.add_object(key); - for (const auto& [gname, value] : group_data) - map_obj.add_item(gname, value); -} - -} - -std::string GroupState::dump() const -{ - Json::JsonObject root; - dump_groupmap(root, "production_rates", this->m_production_rates); - dump_groupmap(root, "prod_red_rates", this->prod_red_rates); - dump_groupmap(root, "inj_red_rates", this->inj_red_rates); - dump_groupmap(root, "inj_resv_rates", this->inj_resv_rates); - dump_groupmap(root, "inj_rein_rates", this->inj_rein_rates); - dump_groupmap(root, "vrep_rate", this->inj_vrep_rate); - dump_groupmap(root, "grat_sales_target", this->m_grat_sales_target); - { - std::map int_controls; - for (const auto& [gname, control] : this->production_controls) - int_controls.insert({gname, static_cast(control)}); - dump_groupmap(root, "production_controls", int_controls); - } - { - std::map>> inj_cntrl; - for (const auto& [phase_name, cmode] : this->injection_controls) { - const auto& [phase, gname] = phase_name; - inj_cntrl[gname].emplace_back(phase, cmode); - } - - auto map_obj = root.add_object("injection_controls"); - for (const auto& [gname, phase_cmode] : inj_cntrl) { - auto group_array = map_obj.add_array(gname); - for (const auto& [phase, cmode] : phase_cmode) { - auto control_pair = group_array.add_array(); - control_pair.add(static_cast(phase)); - control_pair.add(static_cast(cmode)); - } - } - } - return root.to_string(); -} - - } diff --git a/opm/simulators/wells/GroupState.hpp b/opm/simulators/wells/GroupState.hpp index 98ee3994f..674ddf4fd 100644 --- a/opm/simulators/wells/GroupState.hpp +++ b/opm/simulators/wells/GroupState.hpp @@ -159,8 +159,6 @@ public: throw std::logic_error("Internal size mismatch when distributing groupData"); } - std::string dump() const; - private: std::size_t num_phases; diff --git a/tests/test_GroupState.cpp b/tests/test_GroupState.cpp index f549d6b8a..2538bbca4 100644 --- a/tests/test_GroupState.cpp +++ b/tests/test_GroupState.cpp @@ -70,15 +70,3 @@ BOOST_AUTO_TEST_CASE(GroupStateCreate) { } -BOOST_AUTO_TEST_CASE(GroupStateDump) { - std::size_t num_phases{3}; - GroupState gs(num_phases); - std::vector rates{0,1,2}; - gs.update_production_rates("AGROUP", rates); - gs.update_injection_rein_rates("CGROUP", rates); - gs.injection_control("AGROUP", Phase::WATER, Group::InjectionCMode::RATE); - gs.injection_control("AGROUP", Phase::GAS, Group::InjectionCMode::RATE); - - auto json_string = gs.dump(); - Json::JsonObject json_gs(json_string); -} From 129288b2bd4e740bd6a095ef9391a6d09744e637 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 28 Oct 2021 14:30:20 +0200 Subject: [PATCH 2/2] Add operator[] to WellState --- opm/simulators/wells/WellState.hpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index 362c3abaf..d006109d7 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -237,20 +237,36 @@ public: return this->wells_.well_index(well_name); } - const SingleWellState& well(std::size_t well_index) const { + const SingleWellState& operator[](std::size_t well_index) const { return this->wells_[well_index]; } + const SingleWellState& operator[](const std::string& well_name) const { + return this->wells_[well_name]; + } + + SingleWellState& operator[](std::size_t well_index) { + return this->wells_[well_index]; + } + + SingleWellState& operator[](const std::string& well_name) { + return this->wells_[well_name]; + } + + const SingleWellState& well(std::size_t well_index) const { + return this->operator[](well_index); + } + const SingleWellState& well(const std::string& well_name) const { - return this->wells_[well_name]; + return this->operator[](well_name); } SingleWellState& well(std::size_t well_index) { - return this->wells_[well_index]; + return this->operator[](well_index); } SingleWellState& well(const std::string& well_name) { - return this->wells_[well_name]; + return this->operator[](well_name); } bool has(const std::string& well_name) const {