Implement UDQ::*_control in Terms of UDQ::keyword

This replaces the cost of maintaining sets of switch/case statements
with some additional runtime cost of looking up the corresponding
keyword in a std::map<>, but these functions are not called in inner
loops so the extra cost is justified.
This commit is contained in:
Bård Skaflestad 2022-04-22 14:50:46 +02:00
parent f4fde15e67
commit 25ede43bf7

View File

@ -495,56 +495,53 @@ int udaCode(const UDAControl control)
return lookup_control_map_value(c2uda, control);
}
bool group_control(UDAControl control) {
if (control == UDAControl::GCONPROD_OIL_TARGET)
return true;
if (control == UDAControl::GCONPROD_WATER_TARGET)
return true;
if (control == UDAControl::GCONPROD_GAS_TARGET)
return true;
if (control == UDAControl::GCONPROD_LIQUID_TARGET)
return true;
if (control == UDAControl::GCONINJE_SURFACE_MAX_RATE)
return true;
if (control == UDAControl::GCONINJE_RESV_MAX_RATE)
return true;
if (control == UDAControl::GCONINJE_TARGET_REINJ_FRACTION)
return true;
if (control == UDAControl::GCONINJE_TARGET_VOID_FRACTION)
return true;
return false;
}
bool well_control(UDAControl control) {
return !group_control(control);
}
bool injection_control(UDAControl control) {
switch (control) {
case UDAControl::WCONINJE_RATE:
case UDAControl::WCONINJE_RESV:
case UDAControl::WCONINJE_BHP:
case UDAControl::WCONINJE_THP:
case UDAControl::GCONINJE_SURFACE_MAX_RATE:
case UDAControl::GCONINJE_RESV_MAX_RATE:
case UDAControl::GCONINJE_TARGET_REINJ_FRACTION:
case UDAControl::GCONINJE_TARGET_VOID_FRACTION:
return true;
default:
bool group_control(const UDAControl control)
{
try {
const auto kw = keyword(control);
return (kw == UDAKeyword::GCONPROD)
|| (kw == UDAKeyword::GCONINJE);
}
catch (const std::logic_error&) {
return false;
}
}
bool production_control(UDAControl control) {
return !injection_control(control);
bool well_control(const UDAControl control)
{
try {
const auto kw = keyword(control);
return (kw == UDAKeyword::WCONPROD)
|| (kw == UDAKeyword::WCONINJE)
|| (kw == UDAKeyword::WELTARG);
}
catch (const std::logic_error&) {
return false;
}
}
bool injection_control(const UDAControl control)
{
try {
const auto kw = keyword(control);
return (kw == UDAKeyword::WCONINJE)
|| (kw == UDAKeyword::GCONINJE);
}
catch (const std::logic_error&) {
return false;
}
}
bool production_control(const UDAControl control)
{
try {
const auto kw = keyword(control);
return (kw == UDAKeyword::WCONPROD)
|| (kw == UDAKeyword::GCONPROD);
}
catch (const std::logic_error&) {
return false;
}
}
UDAControl udaControl(const int uda_code)