From 5ad262ec845077e7cced8ffcaebd6affec08aab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 18 Jun 2012 15:21:27 +0200 Subject: [PATCH] *Control::mode(): Defer keyword look-up to std::find() algorithm. This is simpler than implementing our own version of the same. --- opm/core/wells/WellsManager.cpp | 55 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index d883f0367..a35c8fab0 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -29,6 +29,11 @@ #include #include +#include +#include + +#include +#include // Helper structs and functions for the implementation. @@ -56,21 +61,28 @@ namespace { enum Mode { ORAT, WRAT, GRAT, LRAT, CRAT, RESV, - BHP, THP, GRUP }; + BHP , THP , GRUP }; + Mode mode(const std::string& control) { - const int num_prod_control_modes = 9; - static std::string prod_control_modes[num_prod_control_modes] = + static std::string prod_control_modes[] = {std::string("ORAT"), std::string("WRAT"), std::string("GRAT"), std::string("LRAT"), std::string("CRAT"), std::string("RESV"), - std::string("BHP"), std::string("THP"), std::string("GRUP") }; + std::string("BHP") , std::string("THP") , std::string("GRUP") }; + + static const std::size_t num_prod_control_modes = + sizeof(prod_control_modes) / sizeof(prod_control_modes[0]); + + const std::string* p = + std::find(prod_control_modes, + prod_control_modes + num_prod_control_modes, + control); + int m = -1; - for (int i=0; i= 0) { return static_cast(m); } else { @@ -84,18 +96,23 @@ namespace { enum Mode { RATE, RESV, BHP, THP, GRUP }; + Mode mode(const std::string& control) { - const int num_inje_control_modes = 5; - static std::string inje_control_modes[num_inje_control_modes] = + static std::string inje_control_modes[] = {std::string("RATE"), std::string("RESV"), std::string("BHP"), - std::string("THP"), std::string("GRUP") }; + std::string("THP") , std::string("GRUP") }; + + static const std::size_t num_inje_control_modes = + sizeof(inje_control_modes) / sizeof(inje_control_modes[0]); + + const std::string* p = + std::find(inje_control_modes, + inje_control_modes + num_inje_control_modes, + control); int m = -1; - for (int i=0; i= 0) { @@ -408,10 +425,10 @@ namespace Opm } else { THROW("Unseen well name: " << lines[i].well_ << " first seen in WCONPROD"); } - + } } - + // Add wells. for (int w = 0; w < num_wells; ++w) { const int w_num_perf = wellperf_data[w].size();