Merge pull request #3849 from hakonhagland/glift_debug_rank

Cleanup gaslift debugging output code
This commit is contained in:
Tor Harald Sandve 2022-03-24 14:13:33 +01:00 committed by GitHub
commit 2d6794f077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 105 additions and 53 deletions

View File

@ -2189,13 +2189,14 @@ BlackoilWellModelGeneric::
gliftDebug(const std::string& msg,
DeferredLogger& deferred_logger) const
{
if (this->glift_debug) {
if (this->glift_debug && this->terminal_output_) {
const std::string message = fmt::format(
" GLIFT (DEBUG) : BlackoilWellModel : {}", msg);
deferred_logger.info(message);
}
}
void
BlackoilWellModelGeneric::
gliftDebugShowALQ(DeferredLogger& deferred_logger)

View File

@ -909,8 +909,7 @@ namespace Opm {
if (this->glift_debug) gliftDebugShowALQ(deferred_logger);
num_wells_changed = glift_wells.size();
}
auto comm = ebosSimulator_.vanguard().grid().comm();
num_wells_changed = comm.sum(num_wells_changed);
num_wells_changed = this->comm_.sum(num_wells_changed);
return num_wells_changed > 0;
}
@ -1043,7 +1042,7 @@ namespace Opm {
= std::make_unique<GasLiftSingleWell>(
*well, ebosSimulator_, summary_state,
deferred_logger, this->wellState(), this->groupState(),
group_info, sync_groups, this->glift_debug);
group_info, sync_groups, this->comm_, this->glift_debug);
auto state = glift->runOptimize(
ebosSimulator_.model().newtonMethod().numIterations());
if (state) {

View File

@ -26,10 +26,12 @@ GasLiftCommon::
GasLiftCommon(
WellState &well_state,
DeferredLogger &deferred_logger,
const Parallel::Communication& comm,
bool glift_debug
) :
well_state_{well_state},
deferred_logger_{deferred_logger},
comm_{comm},
debug{glift_debug}
{
@ -49,6 +51,51 @@ debugUpdateGlobalCounter_() const
return count;
}
void
GasLiftCommon::
displayDebugMessageOnRank0_(const std::string &msg) const
{
// This output should be identical for all ranks.
if ( (!this->debug_output_only_on_rank0)
|| (this->debug_output_only_on_rank0 && this->comm_.rank() == 0) ) {
displayDebugMessage_(msg);
}
}
void
GasLiftCommon::
logMessage_(
const std::string& prefix, const std::string& msg, MessageType msg_type) const
{
std::string rank = "";
if (this->comm_.size() > 1) {
rank = fmt::format(" Rank #{} :", this->comm_.rank());
}
std::string type_str;
switch (msg_type) {
case MessageType::INFO:
type_str = "DEBUG";
break;
case MessageType::WARNING:
type_str = "WARNING";
break;
default:
throw std::runtime_error("This should not happen");
}
const std::string message = fmt::format(
" {} ({}) :{} {}", prefix, type_str, rank, msg);
switch (msg_type) {
case MessageType::INFO:
this->deferred_logger_.info(message);
break;
case MessageType::WARNING:
this->deferred_logger_.info(message);
break;
default:
throw std::runtime_error("This should not happen");
}
}
/****************************************
* Private methods in alphabetical order

View File

@ -37,14 +37,28 @@ protected:
GasLiftCommon(
WellState &well_state,
DeferredLogger &deferred_logger,
const Parallel::Communication& comm,
bool debug
);
enum class MessageType { INFO, WARNING };
int debugUpdateGlobalCounter_() const;
virtual void displayDebugMessage_(const std::string& msg) const = 0;
void displayDebugMessageOnRank0_(const std::string &msg) const;
void logMessage_(
const std::string& prefix,
const std::string& msg,
MessageType msg_type = MessageType::INFO) const;
WellState &well_state_;
DeferredLogger &deferred_logger_;
const Parallel::Communication& comm_;
bool debug;
// By setting this variable to true we restrict some debug output
// to only be printed for rank 0. By setting this variable to false we keep
// the output on all ranks. This can in some cases be helpful as a debugging
// aid to check that the output is in fact identical over all ranks
bool debug_output_only_on_rank0 = false;
};
} // namespace Opm

View File

@ -35,14 +35,13 @@ GasLiftGroupInfo(
const Communication &comm,
bool glift_debug
) :
GasLiftCommon(well_state, deferred_logger, glift_debug)
GasLiftCommon(well_state, deferred_logger, comm, glift_debug)
, ecl_wells_{ecl_wells}
, schedule_{schedule}
, summary_state_{summary_state}
, report_step_idx_{report_step_idx}
, iteration_idx_{iteration_idx}
, phase_usage_{phase_usage}
, comm_{comm}
, glo_{schedule_.glo(report_step_idx_)}
{
@ -294,7 +293,7 @@ checkDoGasLiftOptimization_(const std::string &well_name)
auto itr = this->ecl_wells_.find(well_name);
if (itr == this->ecl_wells_.end()) {
// well_name is not present in the well_model's well container
displayDebugMessage_("Could find well ecl_wells. Skipping.", well_name);
//displayDebugMessage_("Could not find well in ecl_wells. Skipping.", well_name);
return false;
}
const Well *well = (itr->second).first;
@ -368,6 +367,8 @@ checkNewtonIterationIdxOk_(const std::string &well_name)
}
}
// This is called by each rank, but the value of "well_name" should be unique
// across ranks
void
GasLiftGroupInfo::
debugDisplayWellContribution_(
@ -393,11 +394,10 @@ debugDisplayUpdatedGroupRates(
const std::string& name,
double oil_rate, double gas_rate, double water_rate, double alq) const
{
const std::string msg = fmt::format("Updated group info for {} : "
"oil_rate = {}, gas_rate = {}, water_rate = {}, alq = {}",
name, oil_rate, gas_rate, water_rate, alq);
displayDebugMessage_(msg);
displayDebugMessageOnRank0_(msg);
}
void
@ -405,7 +405,7 @@ GasLiftGroupInfo::
debugEndInitializeGroup(const std::string& name) const
{
const std::string msg = fmt::format("Finished with group {} ...", name);
displayDebugMessage_(msg);
displayDebugMessageOnRank0_(msg);
}
void
@ -413,7 +413,7 @@ GasLiftGroupInfo::
debugStartInitializeGroup(const std::string& name) const
{
const std::string msg = fmt::format("Initializing group {} ...", name);
displayDebugMessage_(msg);
displayDebugMessageOnRank0_(msg);
}
void
@ -421,9 +421,8 @@ GasLiftGroupInfo::
displayDebugMessage_(const std::string &msg) const
{
if (this->debug) {
const std::string message = fmt::format(
" GLIFT (DEBUG) : Init group info : {}", msg);
this->deferred_logger_.info(message);
const std::string message = fmt::format("Init group info : {}", msg);
logMessage_(/*prefix=*/"GLIFT", message);
}
}
@ -432,10 +431,8 @@ GasLiftGroupInfo::
displayDebugMessage_(const std::string &msg, const std::string &well_name)
{
if (this->debug) {
const std::string message = fmt::format(
" GLIFT (DEBUG) : Init group info : Well {} : {}",
well_name, msg);
this->deferred_logger_.info(message);
const std::string message = fmt::format("Well {} : {}", well_name, msg);
displayDebugMessage_(message);
}
}

View File

@ -202,7 +202,6 @@ protected:
const int report_step_idx_;
const int iteration_idx_;
const PhaseUsage &phase_usage_;
const Parallel::Communication &comm_;
const GasLiftOpt& glo_;
GroupRateMap group_rate_map_;
Well2GroupMap well_group_map_;

View File

@ -50,6 +50,7 @@ namespace Opm
const GroupState& group_state,
GasLiftGroupInfo &group_info,
GLiftSyncGroups &sync_groups,
const Parallel::Communication& comm,
bool glift_debug
);
const WellInterfaceGeneric &getWell() const override { return well_; }

View File

@ -48,9 +48,10 @@ GasLiftSingleWellGeneric::GasLiftSingleWellGeneric(
const Schedule& schedule,
const int report_step_idx,
GLiftSyncGroups& sync_groups,
const Parallel::Communication& comm,
bool glift_debug
) :
GasLiftCommon(well_state, deferred_logger, glift_debug)
GasLiftCommon(well_state, deferred_logger, comm, glift_debug)
, group_state_{group_state}
, ecl_well_{ecl_well}
, summary_state_{summary_state}
@ -495,9 +496,8 @@ displayDebugMessage_(const std::string& msg) const
{
if (this->debug) {
const std::string message = fmt::format(
" GLIFT (DEBUG) : Well {} : {}", this->well_name_, msg);
this->deferred_logger_.info(message);
const std::string message = fmt::format("Well {} : {}", this->well_name_, msg);
logMessage_(/*prefix=*/"GLIFT", message);
}
}
@ -505,9 +505,8 @@ void
GasLiftSingleWellGeneric::
displayWarning_(const std::string& msg)
{
const std::string message = fmt::format(
"GAS LIFT OPTIMIZATION, WELL {} : {}", this->well_name_, msg);
this->deferred_logger_.warning("WARNING", message);
const std::string message = fmt::format("WELL {} : {}", this->well_name_, msg);
logMessage_(/*prefix=*/"GLIFT", msg, MessageType::WARNING);
}
std::pair<double, bool>

View File

@ -111,6 +111,7 @@ protected:
const Schedule& schedule,
const int report_step_idx,
GLiftSyncGroups& sync_groups,
const Parallel::Communication& comm,
bool glift_debug
);

View File

@ -29,6 +29,7 @@ GasLiftSingleWell(const WellInterface<TypeTag> &well,
const GroupState &group_state,
GasLiftGroupInfo &group_info,
GLiftSyncGroups &sync_groups,
const Parallel::Communication& comm,
bool glift_debug
)
// The parent class GasLiftSingleWellGeneric contains all stuff
@ -44,6 +45,7 @@ GasLiftSingleWell(const WellInterface<TypeTag> &well,
ebos_simulator.vanguard().schedule(),
ebos_simulator.episodeIndex(),
sync_groups,
comm,
glift_debug
)
, ebos_simulator_{ebos_simulator}

View File

@ -49,7 +49,7 @@ GasLiftStage2::GasLiftStage2(
GLiftWellStateMap &state_map,
bool glift_debug
) :
GasLiftCommon(well_state, deferred_logger, glift_debug)
GasLiftCommon(well_state, deferred_logger, comm, glift_debug)
, prod_wells_{prod_wells}
, stage1_wells_{glift_wells}
, well_state_map_{state_map}
@ -57,7 +57,6 @@ GasLiftStage2::GasLiftStage2(
, summary_state_{summary_state}
, schedule_{schedule}
, glo_{schedule_.glo(report_step_idx_)}
, comm_{comm}
{
// this->time_step_idx_
// = this->ebos_simulator_.model().newtonMethod().currentTimeStep();
@ -233,18 +232,15 @@ void
GasLiftStage2::
displayWarning_(const std::string &msg, const std::string &group_name)
{
const std::string message = fmt::format(
"GAS LIFT OPTIMIZATION (STAGE2), GROUP: {} : {}", group_name, msg);
this->deferred_logger_.warning("WARNING", message);
const std::string message = fmt::format("GROUP: {} : {}", group_name, msg);
displayWarning_(message);
}
void
GasLiftStage2::
displayWarning_(const std::string &msg)
{
const std::string message = fmt::format(
"GAS LIFT OPTIMIZATION (STAGE2) : {}", msg);
this->deferred_logger_.warning("WARNING", message);
logMessage_(/*prefix=*/"GLIFT2", msg, MessageType::WARNING);
}
void
@ -252,9 +248,7 @@ GasLiftStage2::
displayDebugMessage_(const std::string &msg) const
{
if (this->debug) {
const std::string message = fmt::format(
" GLIFT2 (DEBUG) : {}", msg);
this->deferred_logger_.info(message);
logMessage_(/*prefix=*/"GLIFT2", msg);
}
}
@ -263,9 +257,7 @@ GasLiftStage2::
displayDebugMessage2B_(const std::string &msg)
{
if (this->debug) {
const std::string message = fmt::format(
"Stage 2B : {}", msg);
displayDebugMessage_(message);
logMessage_(/*prefix=*/"GLIFT2B", msg);
}
}
@ -291,7 +283,7 @@ getCurrentGroupRates_(const Group &group)
const std::string msg = fmt::format(
"Current group rates for {} : oil: {}, gas: {}, alq: {}",
group.name(), oil_rate, gas_rate, alq);
displayDebugMessage2B_(msg);
displayDebugMessageOnRank0_(msg);
}
return {oil_rate, gas_rate, alq};
@ -722,7 +714,7 @@ removeSurplusALQ_(const Group &group,
std::vector<GradPair> &inc_grads, std::vector<GradPair> &dec_grads)
{
if (dec_grads.empty()) {
displayDebugMessage2B_("no wells to remove ALQ from. Skipping");
displayDebugMessage_("no wells to remove ALQ from. Skipping");
return;
}
assert(!dec_grads.empty());
@ -740,7 +732,7 @@ removeSurplusALQ_(const Group &group,
"oil_rate = {}, oil_target = {}, gas_rate = {}, gas_target = {}, "
"alq = {}, max_alq = {}", group.name(), oil_rate, controls.oil_target,
gas_rate, controls.gas_target, alq, max_glift_str);
displayDebugMessage2B_(msg);
displayDebugMessage_(msg);
}
SurplusState state {*this, group, oil_rate, gas_rate, alq,
min_eco_grad, controls.oil_target, controls.gas_target, max_glift };
@ -790,11 +782,11 @@ removeSurplusALQ_(const Group &group,
"Finished after {} iterations for group: {}."
" oil_rate = {}, gas_rate = {}, alq = {}", state.it,
group.name(), oil_rate2, gas_rate2, alq2);
displayDebugMessage2B_(msg);
displayDebugMessage_(msg);
}
}
else {
displayDebugMessage2B_("Finished after 0 iterations");
displayDebugMessage_("Finished after 0 iterations");
}
}
@ -1022,7 +1014,7 @@ addOrRemoveALQincrement(GradMap &grad_map, const std::string& well_name, bool ad
if (this->parent.debug) {
const std::string msg = fmt::format("group: {} : well {} : {} ALQ increment",
this->group.name(), well_name, (add ? "adding" : "subtracting"));
this->parent.displayDebugMessage2B_(msg);
this->parent.displayDebugMessage_(msg);
}
this->parent.addOrRemoveALQincrement_(grad_map, well_name, add);
}
@ -1040,7 +1032,7 @@ checkALQlimit()
const std::string msg = fmt::format("group: {} : "
"ALQ rate {} is greater than ALQ limit {}", this->group.name(),
this->alq, max_alq);
this->parent.displayDebugMessage2B_(msg);
this->parent.displayDebugMessage_(msg);
}
return true;
}
@ -1057,7 +1049,7 @@ checkEcoGradient(const std::string &well_name, double eco_grad)
const std::string msg = fmt::format("group: {}, well: {} : "
"economic gradient {} less than minimum ({})", this->group.name(),
well_name, eco_grad, this->min_eco_grad);
this->parent.displayDebugMessage2B_(msg);
this->parent.displayDebugMessage_(msg);
}
return true;
}
@ -1076,7 +1068,7 @@ checkGasTarget()
const std::string msg = fmt::format("group: {} : "
"gas rate {} is greater than gas target {}", this->group.name(),
this->gas_rate, this->gas_target);
this->parent.displayDebugMessage2B_(msg);
this->parent.displayDebugMessage_(msg);
}
return true;
}
@ -1094,7 +1086,7 @@ checkOilTarget()
const std::string msg = fmt::format("group: {} : "
"oil rate {} is greater than oil target {}", this->group.name(),
this->oil_rate, this->oil_target);
this->parent.displayDebugMessage2B_(msg);
this->parent.displayDebugMessage_(msg);
}
return true;
}

View File

@ -130,7 +130,6 @@ protected:
const SummaryState& summary_state_;
const Schedule& schedule_;
const GasLiftOpt& glo_;
const Parallel::Communication& comm_;
GradMap inc_grads_;
GradMap dec_grads_;
int max_iterations_ = 1000;

View File

@ -172,6 +172,7 @@ BOOST_AUTO_TEST_CASE(G1)
GLiftEclWells ecl_well_map;
well_model.initGliftEclWellMap(ecl_well_map);
const int iteration_idx = simulator->model().newtonMethod().numIterations();
const auto& comm = simulator->vanguard().grid().comm();
GasLiftGroupInfo group_info {
ecl_well_map,
schedule,
@ -181,13 +182,13 @@ BOOST_AUTO_TEST_CASE(G1)
well_model.phaseUsage(),
deferred_logger,
well_state,
simulator->vanguard().grid().comm(),
comm,
/*glift_debug=*/false
};
GLiftSyncGroups sync_groups;
GasLiftSingleWell glift {*std_well, *(simulator.get()), summary_state,
deferred_logger, well_state, group_state, group_info, sync_groups,
/*glift_debug=*/false
comm, /*glift_debug=*/false
};
group_info.initialize();
auto state = glift.runOptimize(iteration_idx);