Refactor Group injection enum
This commit is contained in:
@@ -47,9 +47,21 @@ static const std::string ExceedAction2String( ExceedAction enumValue );
|
||||
static ExceedAction ExceedActionFromString( const std::string& stringValue );
|
||||
|
||||
|
||||
enum class InjectionCMode : int {
|
||||
NONE = 0,
|
||||
RATE = 1,
|
||||
RESV = 2,
|
||||
REIN = 4,
|
||||
VREP = 8,
|
||||
FLD = 16
|
||||
};
|
||||
static const std::string InjectionCMode2String( InjectionCMode enumValue );
|
||||
static InjectionCMode InjectionCModeFromString( const std::string& stringValue );
|
||||
|
||||
|
||||
struct GroupInjectionProperties {
|
||||
Phase phase = Phase::WATER;
|
||||
GroupInjection::ControlEnum cmode = GroupInjection::NONE;
|
||||
InjectionCMode cmode = InjectionCMode::NONE;
|
||||
UDAValue surface_max_rate;
|
||||
UDAValue resv_max_rate;
|
||||
UDAValue target_reinj_fraction;
|
||||
@@ -62,13 +74,13 @@ struct GroupInjectionProperties {
|
||||
|
||||
struct InjectionControls {
|
||||
Phase phase;
|
||||
GroupInjection::ControlEnum cmode;
|
||||
InjectionCMode cmode;
|
||||
double surface_max_rate;
|
||||
double resv_max_rate;
|
||||
double target_reinj_fraction;
|
||||
double target_void_fraction;
|
||||
int injection_controls = 0;
|
||||
bool has_control(GroupInjection::ControlEnum control) const;
|
||||
bool has_control(InjectionCMode control) const;
|
||||
};
|
||||
|
||||
struct GroupProductionProperties {
|
||||
@@ -136,10 +148,10 @@ struct ProductionControls {
|
||||
ProductionControls productionControls(const SummaryState& st) const;
|
||||
InjectionControls injectionControls(const SummaryState& st) const;
|
||||
GroupProduction::ControlEnum production_cmode() const;
|
||||
GroupInjection::ControlEnum injection_cmode() const;
|
||||
InjectionCMode injection_cmode() const;
|
||||
Phase injection_phase() const;
|
||||
bool has_control(GroupProduction::ControlEnum control) const;
|
||||
bool has_control(GroupInjection::ControlEnum control) const;
|
||||
bool has_control(InjectionCMode control) const;
|
||||
private:
|
||||
bool hasType(GroupType gtype) const;
|
||||
void addType(GroupType new_gtype);
|
||||
|
||||
@@ -27,22 +27,6 @@ namespace Opm {
|
||||
|
||||
|
||||
|
||||
namespace GroupInjection {
|
||||
|
||||
enum ControlEnum {
|
||||
NONE = 0,
|
||||
RATE = 1,
|
||||
RESV = 2,
|
||||
REIN = 4,
|
||||
VREP = 8,
|
||||
FLD = 16
|
||||
};
|
||||
|
||||
const std::string ControlEnum2String( ControlEnum enumValue );
|
||||
ControlEnum ControlEnumFromString( const std::string& stringValue );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// A group can have both injection controls and production controls set at
|
||||
// the same time, i.e. this enum is used as a bitmask.
|
||||
|
||||
@@ -295,7 +295,7 @@ GroupProduction::ControlEnum Group2::production_cmode() const {
|
||||
return this->production_properties.cmode;
|
||||
}
|
||||
|
||||
GroupInjection::ControlEnum Group2::injection_cmode() const {
|
||||
Group2::InjectionCMode Group2::injection_cmode() const {
|
||||
return this->injection_properties.cmode;
|
||||
}
|
||||
|
||||
@@ -309,16 +309,16 @@ bool Group2::ProductionControls::has_control(GroupProduction::ControlEnum contro
|
||||
}
|
||||
|
||||
|
||||
bool Group2::InjectionControls::has_control(GroupInjection::ControlEnum control) const {
|
||||
return (this->injection_controls & control) != 0;
|
||||
bool Group2::InjectionControls::has_control(InjectionCMode cmode_arg) const {
|
||||
return (this->injection_controls & static_cast<int>(cmode_arg)) != 0;
|
||||
}
|
||||
|
||||
bool Group2::has_control(GroupProduction::ControlEnum control) const {
|
||||
return (this->production_properties.production_controls & control) != 0;
|
||||
}
|
||||
|
||||
bool Group2::has_control(GroupInjection::ControlEnum control) const {
|
||||
return (this->injection_properties.injection_controls & control) != 0;
|
||||
bool Group2::has_control(InjectionCMode control) const {
|
||||
return (this->injection_properties.injection_controls & static_cast<int>(control)) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -361,5 +361,42 @@ Group2::ExceedAction Group2::ExceedActionFromString( const std::string& stringVa
|
||||
}
|
||||
|
||||
|
||||
const std::string Group2::InjectionCMode2String( InjectionCMode enumValue ) {
|
||||
switch( enumValue ) {
|
||||
case InjectionCMode::NONE:
|
||||
return "NONE";
|
||||
case InjectionCMode::RATE:
|
||||
return "RATE";
|
||||
case InjectionCMode::RESV:
|
||||
return "RESV";
|
||||
case InjectionCMode::REIN:
|
||||
return "REIN";
|
||||
case InjectionCMode::VREP:
|
||||
return "VREP";
|
||||
case InjectionCMode::FLD:
|
||||
return "FLD";
|
||||
default:
|
||||
throw std::invalid_argument("Unhandled enum value");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Group2::InjectionCMode Group2::InjectionCModeFromString( const std::string& stringValue ) {
|
||||
if (stringValue == "NONE")
|
||||
return InjectionCMode::NONE;
|
||||
else if (stringValue == "RATE")
|
||||
return InjectionCMode::RATE;
|
||||
else if (stringValue == "RESV")
|
||||
return InjectionCMode::RESV;
|
||||
else if (stringValue == "REIN")
|
||||
return InjectionCMode::REIN;
|
||||
else if (stringValue == "VREP")
|
||||
return InjectionCMode::VREP;
|
||||
else if (stringValue == "FLD")
|
||||
return InjectionCMode::FLD;
|
||||
else
|
||||
throw std::invalid_argument("Unknown enum state string: " + stringValue );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1448,7 +1448,7 @@ namespace {
|
||||
invalidNamePattern(groupNamePattern, parseContext, errors, keyword);
|
||||
|
||||
for (const auto& group_name : group_names){
|
||||
GroupInjection::ControlEnum controlMode = GroupInjection::ControlEnumFromString( record.getItem("CONTROL_MODE").getTrimmedString(0) );
|
||||
Group2::InjectionCMode controlMode = Group2::InjectionCModeFromString( record.getItem("CONTROL_MODE").getTrimmedString(0) );
|
||||
Phase phase = get_phase( record.getItem("PHASE").getTrimmedString(0));
|
||||
auto surfaceInjectionRate = record.getItem("SURFACE_TARGET").get< UDAValue >(0);
|
||||
auto reservoirInjectionRate = record.getItem("RESV_TARGET").get<UDAValue>(0);
|
||||
@@ -1468,16 +1468,16 @@ namespace {
|
||||
injection.injection_controls = 0;
|
||||
|
||||
if (!record.getItem("SURFACE_TARGET").defaultApplied(0))
|
||||
injection.injection_controls += GroupInjection::RATE;
|
||||
injection.injection_controls += static_cast<int>(Group2::InjectionCMode::RATE);
|
||||
|
||||
if (!record.getItem("RESV_TARGET").defaultApplied(0))
|
||||
injection.injection_controls += GroupInjection::RESV;
|
||||
injection.injection_controls += static_cast<int>(Group2::InjectionCMode::RESV);
|
||||
|
||||
if (!record.getItem("REINJ_TARGET").defaultApplied(0))
|
||||
injection.injection_controls += GroupInjection::REIN;
|
||||
injection.injection_controls += static_cast<int>(Group2::InjectionCMode::REIN);
|
||||
|
||||
if (!record.getItem("VOIDAGE_TARGET").defaultApplied(0))
|
||||
injection.injection_controls += GroupInjection::VREP;
|
||||
injection.injection_controls += static_cast<int>(Group2::InjectionCMode::VREP);
|
||||
|
||||
if (group_ptr->updateInjection(injection))
|
||||
this->updateGroup(std::move(group_ptr), currentStep);
|
||||
|
||||
@@ -26,46 +26,6 @@ namespace Opm {
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
namespace GroupInjection {
|
||||
|
||||
const std::string ControlEnum2String( ControlEnum enumValue ) {
|
||||
switch( enumValue ) {
|
||||
case NONE:
|
||||
return "NONE";
|
||||
case RATE:
|
||||
return "RATE";
|
||||
case RESV:
|
||||
return "RESV";
|
||||
case REIN:
|
||||
return "REIN";
|
||||
case VREP:
|
||||
return "VREP";
|
||||
case FLD:
|
||||
return "FLD";
|
||||
default:
|
||||
throw std::invalid_argument("Unhandled enum value");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ControlEnum ControlEnumFromString( const std::string& stringValue ) {
|
||||
if (stringValue == "NONE")
|
||||
return NONE;
|
||||
else if (stringValue == "RATE")
|
||||
return RATE;
|
||||
else if (stringValue == "RESV")
|
||||
return RESV;
|
||||
else if (stringValue == "REIN")
|
||||
return REIN;
|
||||
else if (stringValue == "VREP")
|
||||
return VREP;
|
||||
else if (stringValue == "FLD")
|
||||
return FLD;
|
||||
else
|
||||
throw std::invalid_argument("Unknown enum state string: " + stringValue );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ BOOST_AUTO_TEST_CASE(CreateGroup_SetInjectorProducer_CorrectStatusSet) {
|
||||
BOOST_AUTO_TEST_CASE(ControlModeOK) {
|
||||
Opm::Group2 group("G1" , 1, 0, 0, UnitSystem::newMETRIC());
|
||||
Opm::SummaryState st;
|
||||
const auto& prod = group.productionControls(st);
|
||||
BOOST_CHECK_EQUAL( Opm::GroupInjection::NONE , prod.cmode);
|
||||
const auto& inj = group.injectionControls(st);
|
||||
BOOST_CHECK( Opm::Group2::InjectionCMode::NONE == inj.cmode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2384,41 +2384,41 @@ BOOST_AUTO_TEST_CASE(TestCompletionConnectionDirectionLoop)
|
||||
/*****************************************************************/
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnum2String) {
|
||||
BOOST_CHECK_EQUAL( "NONE" , GroupInjection::ControlEnum2String(GroupInjection::NONE));
|
||||
BOOST_CHECK_EQUAL( "RATE" , GroupInjection::ControlEnum2String(GroupInjection::RATE));
|
||||
BOOST_CHECK_EQUAL( "RESV" , GroupInjection::ControlEnum2String(GroupInjection::RESV));
|
||||
BOOST_CHECK_EQUAL( "REIN" , GroupInjection::ControlEnum2String(GroupInjection::REIN));
|
||||
BOOST_CHECK_EQUAL( "VREP" , GroupInjection::ControlEnum2String(GroupInjection::VREP));
|
||||
BOOST_CHECK_EQUAL( "FLD" , GroupInjection::ControlEnum2String(GroupInjection::FLD));
|
||||
BOOST_CHECK_EQUAL( "NONE" , Group2::InjectionCMode2String(Group2::InjectionCMode::NONE));
|
||||
BOOST_CHECK_EQUAL( "RATE" , Group2::InjectionCMode2String(Group2::InjectionCMode::RATE));
|
||||
BOOST_CHECK_EQUAL( "RESV" , Group2::InjectionCMode2String(Group2::InjectionCMode::RESV));
|
||||
BOOST_CHECK_EQUAL( "REIN" , Group2::InjectionCMode2String(Group2::InjectionCMode::REIN));
|
||||
BOOST_CHECK_EQUAL( "VREP" , Group2::InjectionCMode2String(Group2::InjectionCMode::VREP));
|
||||
BOOST_CHECK_EQUAL( "FLD" , Group2::InjectionCMode2String(Group2::InjectionCMode::FLD));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnumFromString) {
|
||||
BOOST_CHECK_THROW( GroupInjection::ControlEnumFromString("XXX") , std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( GroupInjection::NONE , GroupInjection::ControlEnumFromString("NONE"));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::RATE , GroupInjection::ControlEnumFromString("RATE"));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::RESV , GroupInjection::ControlEnumFromString("RESV"));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::REIN , GroupInjection::ControlEnumFromString("REIN"));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::VREP , GroupInjection::ControlEnumFromString("VREP"));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::FLD , GroupInjection::ControlEnumFromString("FLD"));
|
||||
BOOST_CHECK_THROW( Group2::InjectionCModeFromString("XXX") , std::invalid_argument );
|
||||
BOOST_CHECK( Group2::InjectionCMode::NONE == Group2::InjectionCModeFromString("NONE"));
|
||||
BOOST_CHECK( Group2::InjectionCMode::RATE == Group2::InjectionCModeFromString("RATE"));
|
||||
BOOST_CHECK( Group2::InjectionCMode::RESV == Group2::InjectionCModeFromString("RESV"));
|
||||
BOOST_CHECK( Group2::InjectionCMode::REIN == Group2::InjectionCModeFromString("REIN"));
|
||||
BOOST_CHECK( Group2::InjectionCMode::VREP == Group2::InjectionCModeFromString("VREP"));
|
||||
BOOST_CHECK( Group2::InjectionCMode::FLD == Group2::InjectionCModeFromString("FLD"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestGroupInjectionControlEnumLoop) {
|
||||
BOOST_CHECK_EQUAL( GroupInjection::NONE , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::NONE ) ));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::RATE , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::RATE ) ));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::RESV , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::RESV ) ));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::REIN , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::REIN ) ));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::VREP , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::VREP ) ));
|
||||
BOOST_CHECK_EQUAL( GroupInjection::FLD , GroupInjection::ControlEnumFromString( GroupInjection::ControlEnum2String( GroupInjection::FLD ) ));
|
||||
BOOST_CHECK( Group2::InjectionCMode::NONE == Group2::InjectionCModeFromString( Group2::InjectionCMode2String( Group2::InjectionCMode::NONE ) ));
|
||||
BOOST_CHECK( Group2::InjectionCMode::RATE == Group2::InjectionCModeFromString( Group2::InjectionCMode2String( Group2::InjectionCMode::RATE ) ));
|
||||
BOOST_CHECK( Group2::InjectionCMode::RESV == Group2::InjectionCModeFromString( Group2::InjectionCMode2String( Group2::InjectionCMode::RESV ) ));
|
||||
BOOST_CHECK( Group2::InjectionCMode::REIN == Group2::InjectionCModeFromString( Group2::InjectionCMode2String( Group2::InjectionCMode::REIN ) ));
|
||||
BOOST_CHECK( Group2::InjectionCMode::VREP == Group2::InjectionCModeFromString( Group2::InjectionCMode2String( Group2::InjectionCMode::VREP ) ));
|
||||
BOOST_CHECK( Group2::InjectionCMode::FLD == Group2::InjectionCModeFromString( Group2::InjectionCMode2String( Group2::InjectionCMode::FLD ) ));
|
||||
|
||||
BOOST_CHECK_EQUAL( "NONE" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "NONE" ) ));
|
||||
BOOST_CHECK_EQUAL( "RATE" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "RATE" ) ));
|
||||
BOOST_CHECK_EQUAL( "RESV" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "RESV" ) ));
|
||||
BOOST_CHECK_EQUAL( "REIN" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "REIN" ) ));
|
||||
BOOST_CHECK_EQUAL( "VREP" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "VREP" ) ));
|
||||
BOOST_CHECK_EQUAL( "FLD" , GroupInjection::ControlEnum2String(GroupInjection::ControlEnumFromString( "FLD" ) ));
|
||||
BOOST_CHECK_EQUAL( "NONE" , Group2::InjectionCMode2String(Group2::InjectionCModeFromString( "NONE" ) ));
|
||||
BOOST_CHECK_EQUAL( "RATE" , Group2::InjectionCMode2String(Group2::InjectionCModeFromString( "RATE" ) ));
|
||||
BOOST_CHECK_EQUAL( "RESV" , Group2::InjectionCMode2String(Group2::InjectionCModeFromString( "RESV" ) ));
|
||||
BOOST_CHECK_EQUAL( "REIN" , Group2::InjectionCMode2String(Group2::InjectionCModeFromString( "REIN" ) ));
|
||||
BOOST_CHECK_EQUAL( "VREP" , Group2::InjectionCMode2String(Group2::InjectionCModeFromString( "VREP" ) ));
|
||||
BOOST_CHECK_EQUAL( "FLD" , Group2::InjectionCMode2String(Group2::InjectionCModeFromString( "FLD" ) ));
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
@@ -344,7 +344,7 @@ BOOST_AUTO_TEST_CASE( WellTestGroups ) {
|
||||
auto& group = sched.getGroup2("INJ", 3);
|
||||
const auto& injection = group.injectionControls(st);
|
||||
BOOST_CHECK_EQUAL( Phase::WATER , injection.phase);
|
||||
BOOST_CHECK_EQUAL( GroupInjection::VREP , injection.cmode);
|
||||
BOOST_CHECK( Group2::InjectionCMode::VREP == injection.cmode);
|
||||
BOOST_CHECK_CLOSE( 10/Metric::Time , injection.surface_max_rate, 0.001);
|
||||
BOOST_CHECK_CLOSE( 20/Metric::Time , injection.resv_max_rate, 0.001);
|
||||
BOOST_CHECK_EQUAL( 0.75 , injection.target_reinj_fraction);
|
||||
@@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE( WellTestGroups ) {
|
||||
auto& group = sched.getGroup2("INJ", 6);
|
||||
const auto& injection = group.injectionControls(st);
|
||||
BOOST_CHECK_EQUAL( Phase::OIL , injection.phase);
|
||||
BOOST_CHECK_EQUAL( GroupInjection::RATE , injection.cmode);
|
||||
BOOST_CHECK( Group2::InjectionCMode::RATE == injection.cmode);
|
||||
BOOST_CHECK_CLOSE( 1000/Metric::Time , injection.surface_max_rate, 0.0001);
|
||||
BOOST_CHECK(group.isInjectionGroup());
|
||||
}
|
||||
@@ -363,7 +363,7 @@ BOOST_AUTO_TEST_CASE( WellTestGroups ) {
|
||||
{
|
||||
auto& group = sched.getGroup2("OP", 3);
|
||||
const auto& production = group.productionControls(st);
|
||||
BOOST_CHECK_EQUAL( GroupProduction::ORAT , production.cmode);
|
||||
BOOST_CHECK( GroupProduction::ORAT == production.cmode);
|
||||
BOOST_CHECK_CLOSE( 10/Metric::Time , production.oil_target , 0.001);
|
||||
BOOST_CHECK_CLOSE( 20/Metric::Time , production.water_target , 0.001);
|
||||
BOOST_CHECK_CLOSE( 30/Metric::Time , production.gas_target , 0.001);
|
||||
|
||||
Reference in New Issue
Block a user