mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
*Control::mode(): Defer keyword look-up to std::find() algorithm.
This is simpler than implementing our own version of the same.
This commit is contained in:
parent
1795e6b1a7
commit
5ad262ec84
@ -29,6 +29,11 @@
|
||||
|
||||
#include <tr1/array>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
// Helper structs and functions for the implementation.
|
||||
@ -57,20 +62,27 @@ namespace
|
||||
enum Mode { ORAT, WRAT, GRAT,
|
||||
LRAT, CRAT, RESV,
|
||||
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") };
|
||||
|
||||
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<num_prod_control_modes; ++i) {
|
||||
if (control == prod_control_modes[i]) {
|
||||
m = i;
|
||||
break;
|
||||
}
|
||||
if (p != prod_control_modes + num_prod_control_modes) {
|
||||
m = int(p - prod_control_modes);
|
||||
}
|
||||
|
||||
if (m >= 0) {
|
||||
return static_cast<Mode>(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") };
|
||||
|
||||
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<num_inje_control_modes; ++i) {
|
||||
if (control == inje_control_modes[i]) {
|
||||
m = i;
|
||||
break;
|
||||
}
|
||||
if (p != inje_control_modes + num_inje_control_modes) {
|
||||
m = int(p - inje_control_modes);
|
||||
}
|
||||
|
||||
if (m >= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user