Merge pull request #4219 from akva2/use_fmt

BlackoilWellModel: use fmt::format
This commit is contained in:
Markus Blatt 2022-10-31 11:54:57 +01:00 committed by GitHub
commit 50eff23710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 28 deletions

View File

@ -29,7 +29,8 @@
#include <opm/simulators/wells/WellGroupHelpers.hpp> #include <opm/simulators/wells/WellGroupHelpers.hpp>
#include <opm/simulators/wells/WellInterfaceGeneric.hpp> #include <opm/simulators/wells/WellInterfaceGeneric.hpp>
#include <sstream> #include <fmt/format.h>
#include <stdexcept> #include <stdexcept>
namespace Opm { namespace Opm {
@ -384,17 +385,17 @@ actionOnBrokenConstraints(const Group& group,
{ {
auto oldControl = wellModel_.groupState().injection_control(group.name(), controlPhase); auto oldControl = wellModel_.groupState().injection_control(group.name(), controlPhase);
std::ostringstream ss;
if (oldControl != newControl) { if (oldControl != newControl) {
const std::string from = Group::InjectionCMode2String(oldControl); const std::string from = Group::InjectionCMode2String(oldControl);
ss << "Switching injection control mode for group "<< group.name()
<< " from " << Group::InjectionCMode2String(oldControl)
<< " to " << Group::InjectionCMode2String(newControl);
group_state.injection_control(group.name(), controlPhase, newControl); group_state.injection_control(group.name(), controlPhase, newControl);
if (wellModel_.comm().rank() == 0) {
auto msg = fmt::format("Switching injection control mode for group {} from {} to {}",
group.name(),
Group::InjectionCMode2String(oldControl),
Group::InjectionCMode2String(newControl));
deferred_logger.info(msg);
}
} }
if (!ss.str().empty() && wellModel_.comm().rank() == 0)
deferred_logger.info(ss.str());
} }
void BlackoilWellModelConstraints:: void BlackoilWellModelConstraints::
@ -406,12 +407,12 @@ actionOnBrokenConstraints(const Group& group,
{ {
const Group::ProductionCMode oldControl = wellModel_.groupState().production_control(group.name()); const Group::ProductionCMode oldControl = wellModel_.groupState().production_control(group.name());
std::ostringstream ss; std::string ss;
switch(exceed_action) { switch(exceed_action) {
case Group::ExceedAction::NONE: { case Group::ExceedAction::NONE: {
if (oldControl != newControl && oldControl != Group::ProductionCMode::NONE) { if (oldControl != newControl && oldControl != Group::ProductionCMode::NONE) {
ss << "Group production exceed action is NONE for group " + group.name() + ". Nothing happens."; ss = fmt::format("Group production exceed action is NONE for group {}. Nothing happens.",
group.name());
} }
break; break;
} }
@ -434,9 +435,10 @@ actionOnBrokenConstraints(const Group& group,
case Group::ExceedAction::RATE: { case Group::ExceedAction::RATE: {
if (oldControl != newControl) { if (oldControl != newControl) {
group_state.production_control(group.name(), newControl); group_state.production_control(group.name(), newControl);
ss << "Switching production control mode for group "<< group.name() ss = fmt::format("Switching production control mode for group {} from {} to {}",
<< " from " << Group::ProductionCMode2String(oldControl) group.name(),
<< " to " << Group::ProductionCMode2String(newControl); Group::ProductionCMode2String(oldControl),
Group::ProductionCMode2String(newControl));
} }
break; break;
} }
@ -444,8 +446,8 @@ actionOnBrokenConstraints(const Group& group,
throw("Invalid procedure for maximum rate limit selected for group" + group.name()); throw("Invalid procedure for maximum rate limit selected for group" + group.name());
} }
if (!ss.str().empty() && wellModel_.comm().rank() == 0) if (!ss.empty() && wellModel_.comm().rank() == 0)
deferred_logger.debug(ss.str()); deferred_logger.debug(ss);
} }
bool BlackoilWellModelConstraints:: bool BlackoilWellModelConstraints::

View File

@ -328,7 +328,7 @@ checkGconsaleLimits(const Group& group,
if (!schedule()[reportStepIdx].gconsale().has(group.name())) if (!schedule()[reportStepIdx].gconsale().has(group.name()))
return; return;
std::ostringstream ss; std::string ss;
const auto& gconsale = schedule()[reportStepIdx].gconsale().get(group.name(), summaryState_); const auto& gconsale = schedule()[reportStepIdx].gconsale().get(group.name(), summaryState_);
const Group::ProductionCMode& oldProductionControl = this->groupState().production_control(group.name()); const Group::ProductionCMode& oldProductionControl = this->groupState().production_control(group.name());
@ -359,7 +359,8 @@ checkGconsaleLimits(const Group& group,
switch(gconsale.max_proc) { switch(gconsale.max_proc) {
case GConSale::MaxProcedure::NONE: { case GConSale::MaxProcedure::NONE: {
if (oldProductionControl != Group::ProductionCMode::GRAT && oldProductionControl != Group::ProductionCMode::NONE) { if (oldProductionControl != Group::ProductionCMode::GRAT && oldProductionControl != Group::ProductionCMode::NONE) {
ss << "Group sales exceed maximum limit, but the action is NONE for " + group.name() + ". Nothing happens"; ss = fmt::format("Group sales exceed maximum limit, but the action is NONE for {}. Nothing happens",
group.name());
} }
break; break;
} }
@ -389,9 +390,13 @@ checkGconsaleLimits(const Group& group,
} }
case GConSale::MaxProcedure::RATE: { case GConSale::MaxProcedure::RATE: {
this->groupState().production_control(group.name(), Group::ProductionCMode::GRAT); this->groupState().production_control(group.name(), Group::ProductionCMode::GRAT);
ss << "Maximum GCONSALE limit violated for " << group.name() << ". The group is switched from "; ss = fmt::format("Maximum GCONSALE limit violated for {}. "
ss << Group::ProductionCMode2String(oldProductionControl) << " to " << Group::ProductionCMode2String(Group::ProductionCMode::GRAT); "The group is switched from {} to {} "
ss << " and limited by the maximum sales rate after consumption and import are considered" ; "and limited by the maximum sales rate after "
"consumption and import are considered",
group.name(),
Group::ProductionCMode2String(oldProductionControl),
Group::ProductionCMode2String(Group::ProductionCMode::GRAT));
this->groupState().update_grat_sales_target(group.name(), production_target); this->groupState().update_grat_sales_target(group.name(), production_target);
break; break;
} }
@ -402,23 +407,25 @@ checkGconsaleLimits(const Group& group,
if (sales_rate < gconsale.min_sales_rate) { if (sales_rate < gconsale.min_sales_rate) {
const Group::ProductionCMode& currentProductionControl = this->groupState().production_control(group.name()); const Group::ProductionCMode& currentProductionControl = this->groupState().production_control(group.name());
if ( currentProductionControl == Group::ProductionCMode::GRAT ) { if ( currentProductionControl == Group::ProductionCMode::GRAT ) {
ss << "Group " + group.name() + " has sale rate less then minimum permitted value and is under GRAT control. \n"; ss = fmt::format("Group {} has sale rate less then minimum permitted value and is under GRAT control.\n"
ss << "The GRAT is increased to meet the sales minimum rate. \n"; "The GRAT is increased to meet the sales minimum rate.",
group.name());
this->groupState().update_grat_sales_target(group.name(), production_target); this->groupState().update_grat_sales_target(group.name(), production_target);
//} else if () {//TODO add action for WGASPROD //} else if () {//TODO add action for WGASPROD
//} else if () {//TODO add action for drilling queue //} else if () {//TODO add action for drilling queue
} else { } else {
ss << "Group " + group.name() + " has sale rate less then minimum permitted value but cannot increase the group production rate \n"; ss = fmt::format("Group {} has sale rate less then minimum permitted value but cannot increase the group production rate \n"
ss << "or adjust gas production using WGASPROD or drill new wells to meet the sales target. \n"; "or adjust gas production using WGASPROD or drill new wells to meet the sales target. \n"
ss << "Note that WGASPROD and drilling queues are not implemented in Flow. No action is taken. \n "; "Note that WGASPROD and drilling queues are not implemented in Flow. No action is taken.",
group.name());
} }
} }
if (gconsale.sales_target < 0.0) { if (gconsale.sales_target < 0.0) {
OPM_DEFLOG_THROW(std::runtime_error, "Group " + group.name() + " has sale rate target less then zero. Not implemented in Flow" , deferred_logger); OPM_DEFLOG_THROW(std::runtime_error, "Group " + group.name() + " has sale rate target less then zero. Not implemented in Flow" , deferred_logger);
} }
if (!ss.str().empty() && comm_.rank() == 0) if (!ss.empty() && comm_.rank() == 0)
deferred_logger.info(ss.str()); deferred_logger.info(ss);
} }
bool bool