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 <tr1/array>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
// Helper structs and functions for the implementation.
|
// Helper structs and functions for the implementation.
|
||||||
@ -56,21 +61,28 @@ namespace
|
|||||||
{
|
{
|
||||||
enum Mode { ORAT, WRAT, GRAT,
|
enum Mode { ORAT, WRAT, GRAT,
|
||||||
LRAT, CRAT, RESV,
|
LRAT, CRAT, RESV,
|
||||||
BHP, THP, GRUP };
|
BHP , THP , GRUP };
|
||||||
|
|
||||||
Mode mode(const std::string& control)
|
Mode mode(const std::string& control)
|
||||||
{
|
{
|
||||||
const int num_prod_control_modes = 9;
|
static std::string prod_control_modes[] =
|
||||||
static std::string prod_control_modes[num_prod_control_modes] =
|
|
||||||
{std::string("ORAT"), std::string("WRAT"), std::string("GRAT"),
|
{std::string("ORAT"), std::string("WRAT"), std::string("GRAT"),
|
||||||
std::string("LRAT"), std::string("CRAT"), std::string("RESV"),
|
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;
|
int m = -1;
|
||||||
for (int i=0; i<num_prod_control_modes; ++i) {
|
if (p != prod_control_modes + num_prod_control_modes) {
|
||||||
if (control == prod_control_modes[i]) {
|
m = int(p - prod_control_modes);
|
||||||
m = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m >= 0) {
|
if (m >= 0) {
|
||||||
return static_cast<Mode>(m);
|
return static_cast<Mode>(m);
|
||||||
} else {
|
} else {
|
||||||
@ -84,18 +96,23 @@ namespace
|
|||||||
{
|
{
|
||||||
enum Mode { RATE, RESV, BHP,
|
enum Mode { RATE, RESV, BHP,
|
||||||
THP, GRUP };
|
THP, GRUP };
|
||||||
|
|
||||||
Mode mode(const std::string& control)
|
Mode mode(const std::string& control)
|
||||||
{
|
{
|
||||||
const int num_inje_control_modes = 5;
|
static std::string inje_control_modes[] =
|
||||||
static std::string inje_control_modes[num_inje_control_modes] =
|
|
||||||
{std::string("RATE"), std::string("RESV"), std::string("BHP"),
|
{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;
|
int m = -1;
|
||||||
for (int i=0; i<num_inje_control_modes; ++i) {
|
if (p != inje_control_modes + num_inje_control_modes) {
|
||||||
if (control == inje_control_modes[i]) {
|
m = int(p - inje_control_modes);
|
||||||
m = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m >= 0) {
|
if (m >= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user