Use optional - and default to self - for reinj and voidage groups

This commit is contained in:
Joakim Hove 2020-10-19 17:06:04 +02:00
parent fd1cc74f74
commit d545359395
3 changed files with 10 additions and 17 deletions

View File

@ -121,8 +121,8 @@ struct GroupInjectionProperties {
UDAValue resv_max_rate;
UDAValue target_reinj_fraction;
UDAValue target_void_fraction;
std::string reinj_group;
std::string voidage_group;
std::optional<std::string> reinj_group;
std::optional<std::string> voidage_group;
bool available_group_control = true;
static GroupInjectionProperties serializeObject();

View File

@ -465,8 +465,8 @@ Group::InjectionControls Group::injectionControls(Phase phase, const SummaryStat
ic.resv_max_rate = UDA::eval_group_uda(inj.resv_max_rate, this->m_name, st, this->udq_undefined);
ic.target_reinj_fraction = UDA::eval_group_uda(inj.target_reinj_fraction, this->m_name, st, this->udq_undefined);
ic.target_void_fraction = UDA::eval_group_uda(inj.target_void_fraction, this->m_name, st, this->udq_undefined);
ic.reinj_group = inj.reinj_group;
ic.voidage_group = inj.voidage_group;
ic.reinj_group = inj.reinj_group.value_or(this->m_name);
ic.voidage_group = inj.voidage_group.value_or(this->m_name);
return ic;
}

View File

@ -270,19 +270,8 @@ namespace {
const auto voidage_target = record.getItem("VOIDAGE_TARGET").get<UDAValue>(0);
const bool is_free = DeckItem::to_bool(record.getItem("FREE").getTrimmedString(0));
const std::optional<std::string> reinj_group_name = record.getItem("REINJECT_GROUP").defaultApplied(0)
? std::nullopt
: std::optional<std::string>(record.getItem("REINJECT_GROUP").getTrimmedString(0));
const std::optional<std::string> voidage_group_name = record.getItem("VOIDAGE_GROUP").defaultApplied(0)
? std::nullopt
: std::optional<std::string>(record.getItem("VOIDAGE_GROUP").getTrimmedString(0));
for (const auto& group_name : group_names) {
const bool availableForGroupControl = is_free && (group_name != "FIELD");
const std::string reinj_group = reinj_group_name.value_or(group_name);
const std::string voidage_group = voidage_group_name.value_or(group_name);
auto group_ptr = std::make_shared<Group>(this->getGroup(group_name, handlerContext.currentStep));
Group::GroupInjectionProperties injection;
injection.phase = phase;
@ -292,8 +281,6 @@ namespace {
injection.target_reinj_fraction = reinj_target;
injection.target_void_fraction = voidage_target;
injection.injection_controls = 0;
injection.reinj_group = reinj_group;
injection.voidage_group = voidage_group;
injection.available_group_control = availableForGroupControl;
if (!record.getItem("SURFACE_TARGET").defaultApplied(0))
@ -308,6 +295,12 @@ namespace {
if (!record.getItem("VOIDAGE_TARGET").defaultApplied(0))
injection.injection_controls += static_cast<int>(Group::InjectionCMode::VREP);
if (record.getItem("REINJECT_GROUP").hasValue(0))
injection.reinj_group = record.getItem("REINJECT_GROUP").getTrimmedString(0);
if (record.getItem("VOIDAGE_GROUP").hasValue(0))
injection.voidage_group = record.getItem("VOIDAGE_GROUP").getTrimmedString(0);
if (group_ptr->updateInjection(injection)) {
this->updateGroup(std::move(group_ptr), handlerContext.currentStep);
m_events.addEvent( ScheduleEvents::GROUP_INJECTION_UPDATE , handlerContext.currentStep);