mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Code improvment for the group control switching
Pass the controls as enums not strings Avoid pair as key in map
This commit is contained in:
@@ -628,29 +628,31 @@ checkGroupHigherConstraints(const Group& group,
|
||||
const Phase all[] = { Phase::WATER, Phase::OIL, Phase::GAS };
|
||||
for (Phase phase : all) {
|
||||
bool group_is_oscillating = false;
|
||||
if (switched_inj_groups_.count({group.name(), phase}) > 0) {
|
||||
for (const auto& key : switched_inj_groups_[{group.name(), phase}]) {
|
||||
if (std::count(switched_inj_groups_[{group.name(), phase}].begin(), switched_inj_groups_[{group.name(), phase}].end(), key) >= max_number_of_group_switch) {
|
||||
const size_t sz = switched_inj_groups_[{group.name(), phase}].size();
|
||||
// only output if the two last keys are not the same.
|
||||
if (key != switched_inj_groups_[{group.name(), phase}][sz-2]) {
|
||||
if (comm_.rank() == 0 ) {
|
||||
std::ostringstream os;
|
||||
os << phase;
|
||||
const std::string msg =
|
||||
fmt::format("Group control for {} injector group {} is oscillating. Group control kept at {}.",
|
||||
std::move(os).str(),
|
||||
group.name(),
|
||||
key);
|
||||
deferred_logger.info(msg);
|
||||
}
|
||||
switched_inj_groups_[{group.name(), phase}].push_back(key);
|
||||
}
|
||||
group_is_oscillating = true;
|
||||
break;
|
||||
if (auto groupPos = switched_inj_groups_.find(group.name()); groupPos != switched_inj_groups_.end()) {
|
||||
auto& ctrls = groupPos->second[static_cast<std::underlying_type_t<Phase>>(phase)];
|
||||
for (const auto& ctrl : ctrls) {
|
||||
if (std::count(ctrls.begin(), ctrls.end(), ctrl) < max_number_of_group_switch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctrls.back() != *(ctrls.end() - 2)) {
|
||||
if (comm_.rank() == 0 ) {
|
||||
std::ostringstream os;
|
||||
os << phase;
|
||||
const std::string msg =
|
||||
fmt::format("Group control for {} injector group {} is oscillating. Group control kept at {}.",
|
||||
std::move(os).str(),
|
||||
group.name(),
|
||||
Group::InjectionCMode2String(ctrl));
|
||||
deferred_logger.info(msg);
|
||||
}
|
||||
ctrls.push_back(ctrl);
|
||||
}
|
||||
group_is_oscillating = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (group_is_oscillating) {
|
||||
continue;
|
||||
}
|
||||
@@ -676,7 +678,7 @@ checkGroupHigherConstraints(const Group& group,
|
||||
resv_coeff_inj,
|
||||
deferred_logger);
|
||||
if (is_changed) {
|
||||
switched_inj_groups_[{group.name(), phase}].push_back(Group::InjectionCMode2String(Group::InjectionCMode::FLD));
|
||||
switched_inj_groups_[group.name()][static_cast<std::underlying_type_t<Phase>>(phase)].push_back(Group::InjectionCMode::FLD);
|
||||
BlackoilWellModelConstraints(*this).
|
||||
actionOnBrokenConstraints(group, Group::InjectionCMode::FLD,
|
||||
phase, this->groupState(),
|
||||
@@ -700,23 +702,24 @@ checkGroupHigherConstraints(const Group& group,
|
||||
// So when checking constraints, current groups rate must also be subtracted it's reduction rate
|
||||
const std::vector<Scalar> reduction_rates = this->groupState().production_reduction_rates(group.name());
|
||||
|
||||
if (switched_prod_groups_.count(group.name()) > 0) {
|
||||
for (const auto& key : switched_prod_groups_[group.name()]) {
|
||||
if (std::count(switched_prod_groups_[group.name()].begin(), switched_prod_groups_[group.name()].end(), key) >= max_number_of_group_switch) {
|
||||
const size_t sz = switched_prod_groups_[group.name()].size();
|
||||
// only output on rank 0 and if the two last keys are not the same.
|
||||
if (key != switched_prod_groups_[group.name()][sz-2]) {
|
||||
if (comm_.rank() == 0) {
|
||||
const std::string msg =
|
||||
fmt::format("Group control for production group {} is oscillating. Group control kept at {}.",
|
||||
group.name(),
|
||||
key);
|
||||
deferred_logger.info(msg);
|
||||
}
|
||||
switched_prod_groups_[group.name()].push_back(key);
|
||||
}
|
||||
return false;
|
||||
if (auto groupPos = switched_prod_groups_.find(group.name()); groupPos != switched_prod_groups_.end()) {
|
||||
auto& ctrls = groupPos->second;
|
||||
for (const auto& ctrl : ctrls) {
|
||||
if (std::count(ctrls.begin(), ctrls.end(), ctrl) < max_number_of_group_switch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ctrls.back() != *(ctrls.end() - 2)) {
|
||||
if (comm_.rank() == 0) {
|
||||
const std::string msg =
|
||||
fmt::format("Group control for production group {} is oscillating. Group control kept at {}.",
|
||||
group.name(),
|
||||
Group::ProductionCMode2String(ctrl));
|
||||
deferred_logger.info(msg);
|
||||
}
|
||||
ctrls.push_back(ctrl);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int phasePos = 0; phasePos < phase_usage_.num_phases; ++phasePos) {
|
||||
@@ -762,7 +765,7 @@ checkGroupHigherConstraints(const Group& group,
|
||||
deferred_logger);
|
||||
|
||||
if (changed) {
|
||||
switched_prod_groups_[group.name()].push_back(Group::ProductionCMode2String(Group::ProductionCMode::FLD));
|
||||
switched_prod_groups_[group.name()].push_back(Group::ProductionCMode::FLD);
|
||||
WellGroupHelpers<Scalar>::updateWellRatesFromGroupTargetScale(scaling_factor,
|
||||
group,
|
||||
schedule(),
|
||||
|
||||
Reference in New Issue
Block a user