Simplified using fmt::format()

Simplified debug output formatting by using fmt::format(). Also switched
off glift debug output by default.
This commit is contained in:
Håkon Hægland 2020-10-01 18:27:57 +02:00
parent a01ae8a64c
commit 52f6f819ee
6 changed files with 65 additions and 101 deletions

View File

@ -306,7 +306,7 @@ namespace Opm {
std::vector<double> depth_;
bool initial_step_;
bool report_step_starts_;
bool glift_debug = true;
bool glift_debug = false;
std::unique_ptr<RateConverterType> rateConverter_;
std::unique_ptr<VFPProperties<VFPInjProperties,VFPProdProperties>> vfp_properties_;
@ -331,10 +331,6 @@ namespace Opm {
const std::string &msg,
Opm::DeferredLogger& deferred_logger) const;
void gliftDebug(
std::ostringstream &ss,
Opm::DeferredLogger& deferred_logger) const;
// compute the well fluxes and assemble them in to the reservoir equations as source terms
// and in the well equations.
void assemble(const int iterationIdx,

View File

@ -26,6 +26,7 @@
#include <utility>
#include <algorithm>
#include <fmt/format.h>
namespace Opm {
template<typename TypeTag>
@ -402,23 +403,11 @@ namespace Opm {
void
BlackoilWellModel<TypeTag>::gliftDebug(
const std::string &msg, Opm::DeferredLogger &deferred_logger) const
{
std::ostringstream ss;
ss << msg;
gliftDebug(ss, deferred_logger);
}
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::gliftDebug(
std::ostringstream &ss, Opm::DeferredLogger &deferred_logger) const
{
if (this->glift_debug) {
std::string message = ss.str();
if (message.empty()) return;
std::ostringstream ss2;
ss2 << " GLIFT (DEBUG) : BlackoilWellModel : " << message;
deferred_logger.info(ss2.str());
const std::string message = fmt::format(
" GLIFT (DEBUG) : BlackoilWellModel : {}", msg);
deferred_logger.info(message);
}
}
@ -841,9 +830,9 @@ namespace Opm {
Opm::DeferredLogger local_deferredLogger;
if (this->glift_debug) {
std::ostringstream os;
os << "assemble() : iteration = " << iterationIdx;
gliftDebug(os, local_deferredLogger);
const std::string msg = fmt::format(
"assemble() : iteration {}" , iterationIdx);
gliftDebug(msg, local_deferredLogger);
}
last_report_ = SimulatorReportSingle();
Dune::Timer perfTimer;

View File

@ -45,6 +45,7 @@ namespace Opm {
#include <optional>
#include <string>
#include <vector>
#include <fmt/format.h>
namespace Opm
{
@ -76,7 +77,7 @@ namespace Opm
void computeWellRates_(double bhp, std::vector<double> &potentials);
void debugShowIterationInfo_(OptimizeState &state, double alq);
void debugShowStartIteration_(double alq, bool increase);
void displayDebugMessage_(std::ostringstream &ss);
void displayDebugMessage_(const std::string &msg);
void displayWarning_();
void displayWarning_(std::string warning);
double getGasRateWithLimit_(std::vector<double> &potentials);
@ -100,7 +101,6 @@ namespace Opm
const WellState &well_state_;
std::string well_name_;
bool debug; // extra debug output
bool debug_disable; // act as glift optimization is disabled
double alpha_w_;
double alpha_g_;

View File

@ -46,8 +46,7 @@ GasLiftRuntime(
std_well_{std_well},
summary_state_{summary_state},
well_state_{well_state},
debug{true}, // extra debugging output
debug_disable{false} // act as glift optimization is disabled
debug{false} // extra debugging output
{
int well_index = this->std_well_.indexOfWell();
const Well::ProducerCMode& control_mode
@ -77,10 +76,7 @@ GasLiftRuntime(
this->eco_grad_ = glo.min_eco_gradient();
auto& gl_well = glo.well(this->well_name_);
if (this->debug_disable) {
this->optimize_ = false;
}
else if(useFixedAlq_(gl_well)) {
if(useFixedAlq_(gl_well)) {
updateWellStateAlqFixedValue_(gl_well);
this->optimize_ = false; // lift gas supply is fixed
}
@ -155,9 +151,8 @@ void
Opm::GasLiftRuntime<TypeTag>::
debugShowIterationInfo_(OptimizeState &state, double alq)
{
std::ostringstream ss;
ss << "iteration " << state.it << ", ALQ = " << alq;
this->displayDebugMessage_(ss);
const std::string msg = fmt::format("iteration {}, ALQ = {}", state.it, alq);
this->displayDebugMessage_(msg);
}
template<typename TypeTag>
@ -165,25 +160,23 @@ void
Opm::GasLiftRuntime<TypeTag>::
debugShowStartIteration_(double alq, bool increase)
{
std::ostringstream ss;
auto oil_rate = -this->potentials_[this->oil_pos_];
std::string dir = increase ? "increase" : "decrease";
ss << "starting " << dir << " iteration, ALQ = " << alq
<< ", oilrate = " << oil_rate;
this->displayDebugMessage_(ss);
const std::string msg =
fmt::format("starting {} iteration, ALQ = {}, oilrate = {}",
(increase ? "increase" : "decrease"),
alq,
-this->potentials_[this->oil_pos_]);
this->displayDebugMessage_(msg);
}
template<typename TypeTag>
void
Opm::GasLiftRuntime<TypeTag>::
displayDebugMessage_(std::ostringstream &ss)
displayDebugMessage_(const std::string &msg)
{
std::string message = ss.str();
if (message.empty()) return;
std::ostringstream ss2;
ss2 << " GLIFT (DEBUG) : Well " << this->well_name_ << " : " << message;
this->deferred_logger_.info(ss2.str());
const std::string message = fmt::format(
" GLIFT (DEBUG) : Well {} : {}", this->well_name_, msg);
this->deferred_logger_.info(message);
}
template<typename TypeTag>
@ -191,9 +184,9 @@ void
Opm::GasLiftRuntime<TypeTag>::
displayWarning_(std::string msg)
{
std::ostringstream ss;
ss << "GAS LIFT OPTIMIZATION, WELL: " << this->well_name_ << " : " << msg;
this->deferred_logger_.warning("WARNING", ss.str());
const std::string message = fmt::format(
"GAS LIFT OPTIMIZATION, WELL {} : {}", this->well_name_, msg);
this->deferred_logger_.warning("WARNING", message);
}
// TODO: what if the gas_rate_target_ has been defaulted
@ -252,12 +245,13 @@ Opm::GasLiftRuntime<TypeTag>::
logSuccess_()
{
std::ostringstream ss;
std::string dir;
dir = (this->new_alq_ > this->orig_alq_) ? "increased" : "decreased";
ss << "GLIFT, WELL " << this->well_name_ << " " << dir << " ALQ from "
<< this->orig_alq_ << " to " << this->new_alq_;
this->deferred_logger_.info(ss.str());
const std::string message = fmt::format(
"GLIFT, WELL {} {} ALQ from {} to {}",
this->well_name_,
((this->new_alq_ > this->orig_alq_) ? "increased" : "decreased"),
this->orig_alq_,
this->new_alq_);
this->deferred_logger_.info(message);
}
/* - At this point we know that this is a production well, and that its current
@ -648,7 +642,7 @@ checkAlqOutsideLimits(double alq, double oil_rate)
}
}
}
if (this->parent.debug) this->parent.displayDebugMessage_(ss);
if (this->parent.debug) this->parent.displayDebugMessage_(ss.str());
return result;
}
@ -683,7 +677,7 @@ checkEcoGradient(double gradient)
if (this->parent.debug) ss << "false";
}
}
if (this->parent.debug) this->parent.displayDebugMessage_(ss);
if (this->parent.debug) this->parent.displayDebugMessage_(ss.str());
return result;
}
@ -695,11 +689,10 @@ checkRate(double rate, double limit, const std::string rate_str)
if (limit < rate ) {
if (this->parent.debug) {
std::ostringstream ss;
ss << "iteration " << this->it << " : " << rate_str << " rate "
<< rate << " exceeds target rate "
<< limit << ". Stopping iteration";
this->parent.displayDebugMessage_(ss);
const std::string msg = fmt::format(
"iteration {} : rate {} exceeds target rate {}. Stopping iteration",
this->it, rate_str, rate, limit);
this->parent.displayDebugMessage_(msg);
}
return true;
}
@ -753,11 +746,11 @@ computeBhpAtThpLimit(double alq)
this->parent.deferred_logger_,
alq);
if (!bhp_at_thp_limit) {
std::ostringstream ss;
ss << "Failed in getting converged bhp potential for well "
<< this->parent.well_name_;
const std::string msg = fmt::format(
"Failed in getting converged bhp potential for well {}",
this->parent.well_name_);
this->parent.deferred_logger_.warning(
"FAILURE_GETTING_CONVERGED_POTENTIAL", ss.str());
"FAILURE_GETTING_CONVERGED_POTENTIAL", msg);
return false;
}
this->bhp = *bhp_at_thp_limit;

View File

@ -43,6 +43,7 @@
#include <dune/common/dynmatrix.hh>
#include <optional>
#include <fmt/format.h>
namespace Opm
{
@ -256,10 +257,6 @@ namespace Opm
const std::string &msg,
Opm::DeferredLogger& deferred_logger) const;
void gliftDebug(
std::ostringstream &ss,
Opm::DeferredLogger& deferred_logger) const;
void gasLiftOptimizeProduction(
const Simulator& ebosSimulator,
const SummaryState& summaryState,
@ -378,7 +375,7 @@ namespace Opm
bool changed_to_stopped_this_step_ = false;
// Enable GLIFT debug mode. This will enable output of logging messages.
bool glift_debug = true;
bool glift_debug = false;
const EvalWell& getBhp() const;

View File

@ -2589,10 +2589,10 @@ namespace Opm
// turned off by entering a zero or negative number."
if (increment <= 0) {
if (this->glift_debug) {
std::ostringstream ss;
ss << "Gas Lift switched off in LIFTOPT item 1 due to non-positive "
<< "value: " << increment;
gliftDebug(ss, deferred_logger);
const std::string msg = fmt::format(
"Gas Lift switched off in LIFTOPT item 1 due to non-positive "
"value: {}", increment);
gliftDebug(msg, deferred_logger);
}
return false;
}
@ -2615,21 +2615,21 @@ namespace Opm
if (glo.all_newton()) {
const int nupcol = schedule.getNupcol(report_step_idx);
if (this->glift_debug) {
std::ostringstream ss;
ss << "LIFTOPT item4 == YES, it = " << iteration_idx
<< ", nupcol = " << nupcol << " -> " << " --> GLIFT optimize = "
<< ((iteration_idx <= nupcol) ? "TRUE" : "FALSE");
gliftDebug(ss, deferred_logger);
const std::string msg = fmt::format(
"LIFTOPT item4 == YES, it = {}, nupcol = {} --> GLIFT optimize = {}",
iteration_idx,
nupcol,
((iteration_idx <= nupcol) ? "TRUE" : "FALSE"));
gliftDebug(msg, deferred_logger);
}
return iteration_idx <= nupcol;
}
else {
if (this->glift_debug) {
std::ostringstream ss;
ss << "LIFTOPT item4 == NO, it = " << iteration_idx
<< " --> GLIFT optimize = "
<< ((iteration_idx == 1) ? "TRUE" : "FALSE");
gliftDebug(ss, deferred_logger);
const std::string msg = fmt::format(
"LIFTOPT item4 == NO, it = {} --> GLIFT optimize = {}",
iteration_idx, ((iteration_idx == 1) ? "TRUE" : "FALSE"));
gliftDebug(msg, deferred_logger);
}
return iteration_idx == 1;
}
@ -2641,22 +2641,11 @@ namespace Opm
gliftDebug(
const std::string &msg, DeferredLogger& deferred_logger) const
{
std::ostringstream ss;
ss << msg;
gliftDebug(ss, deferred_logger);
}
template<typename TypeTag>
void
StandardWell<TypeTag>::
gliftDebug(
std::ostringstream &ss, DeferredLogger& deferred_logger) const
{
std::string message = ss.str();
if (message.empty()) return;
std::ostringstream ss2;
ss2 << " GLIFT (DEBUG) : Well " << this->name() << " : " << message;
deferred_logger.info(ss2.str());
if (this->glift_debug) {
const std::string message = fmt::format(
" GLIFT (DEBUG) : Well {} : {}", this->name(), msg);
deferred_logger.info(message);
}
}
template<typename TypeTag>