mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Slight restructuring/renaming for (possibly) improved clarity.
This commit is contained in:
@@ -406,9 +406,8 @@ namespace Opm {
|
||||
|
||||
SimulatorReportSingle last_report_{};
|
||||
|
||||
// solve to get a good network solution, group and well states might be updated during the process.
|
||||
// the reservoir should stay static during this solution procedure.
|
||||
void balanceNetwork(DeferredLogger& deferred_logger);
|
||||
// Pre-step network solve at static reservoir conditions (group and well states might be updated)
|
||||
void doPreStepNetworkRebalance(DeferredLogger& deferred_logger);
|
||||
|
||||
// used to better efficiency of calcuation
|
||||
mutable BVector scaleAddRes_{};
|
||||
|
||||
@@ -985,35 +985,46 @@ hasTHPConstraints() const
|
||||
return BlackoilWellModelConstraints(*this).hasTHPConstraints();
|
||||
}
|
||||
|
||||
std::pair<bool, bool>
|
||||
void
|
||||
BlackoilWellModelGeneric::
|
||||
needRebalanceNetwork(const int report_step) const
|
||||
{
|
||||
updateNetworkActiveState(const int report_step) {
|
||||
const auto& network = schedule()[report_step].network();
|
||||
if (!network.active()) {
|
||||
return {false, false};
|
||||
this->network_active_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
bool network_active = false;
|
||||
bool network_rebalance_necessary = false;
|
||||
for (const auto& well : well_container_generic_) {
|
||||
const bool is_partof_network = network.has_node(well->wellEcl().groupName());
|
||||
const bool prediction_mode = well->wellEcl().predictionMode();
|
||||
if (is_partof_network && prediction_mode) {
|
||||
network_active = true;
|
||||
break;
|
||||
}
|
||||
// TODO: we might find more relevant events to be included here
|
||||
}
|
||||
this->network_active_ = comm_.max(network_active);
|
||||
}
|
||||
|
||||
bool
|
||||
BlackoilWellModelGeneric::
|
||||
needPreStepNetworkRebalance(const int report_step) const
|
||||
{
|
||||
assert(this->networkActive());
|
||||
|
||||
const auto& network = schedule()[report_step].network();
|
||||
bool network_rebalance_necessary = false;
|
||||
for (const auto& well : well_container_generic_) {
|
||||
const bool is_partof_network = network.has_node(well->wellEcl().groupName());
|
||||
// TODO: we might find more relevant events to be included here (including network change events?)
|
||||
const auto& events = this->wellState().well(well->indexOfWell()).events;
|
||||
if (is_partof_network && events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE)) {
|
||||
network_rebalance_necessary = true;
|
||||
}
|
||||
if (network_active && network_rebalance_necessary)
|
||||
break;
|
||||
}
|
||||
}
|
||||
network_rebalance_necessary = comm_.max(network_rebalance_necessary);
|
||||
network_active = comm_.max(network_active);
|
||||
|
||||
return {network_active, network_rebalance_necessary};
|
||||
return network_rebalance_necessary;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1383,11 +1394,9 @@ bool
|
||||
BlackoilWellModelGeneric::
|
||||
shouldBalanceNetwork(const int reportStepIdx, const int iterationIdx) const
|
||||
{
|
||||
// if network is not active, we do not need to balance the network
|
||||
const auto& network = schedule()[reportStepIdx].network();
|
||||
if (!network.active()) {
|
||||
// If the network is not active now, we do not need to balance it.
|
||||
if (!this->networkActive())
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& balance = schedule()[reportStepIdx].network_balance();
|
||||
if (balance.mode() == Network::Balance::CalcMode::TimeStepStart) {
|
||||
|
||||
@@ -172,9 +172,13 @@ public:
|
||||
/// Return true if any well has a THP constraint.
|
||||
bool hasTHPConstraints() const;
|
||||
|
||||
/// Checks if network is active (at least one network well on prediction),
|
||||
/// and whether it is necessary to re-balance the network
|
||||
std::pair<bool,bool> needRebalanceNetwork(const int report_step) const;
|
||||
/// Checks if network is active (at least one network well on prediction).
|
||||
void updateNetworkActiveState(const int report_step);
|
||||
|
||||
/// Checks if there are reasons to perform a pre-step network re-balance.
|
||||
/// (Currently, the only reasons are network well status changes.)
|
||||
/// (TODO: Consider if adding network change events would be helpful.)
|
||||
bool needPreStepNetworkRebalance(const int report_step) const;
|
||||
|
||||
/// Shut down any single well
|
||||
/// Returns true if the well was actually found and shut.
|
||||
|
||||
@@ -1006,7 +1006,7 @@ namespace Opm {
|
||||
template<typename TypeTag>
|
||||
void
|
||||
BlackoilWellModel<TypeTag>::
|
||||
balanceNetwork(DeferredLogger& deferred_logger) {
|
||||
doPreStepNetworkRebalance(DeferredLogger& deferred_logger) {
|
||||
const double dt = this->ebosSimulator_.timeStepSize();
|
||||
// TODO: should we also have the group and network backed-up here in case the solution did not get converged?
|
||||
auto& well_state = this->wellState();
|
||||
@@ -2239,8 +2239,14 @@ namespace Opm {
|
||||
BlackoilWellModel<TypeTag>::
|
||||
prepareTimeStep(DeferredLogger& deferred_logger)
|
||||
{
|
||||
bool network_rebalance_necessary{false};
|
||||
std::tie(this->network_active_, network_rebalance_necessary) = this->needRebalanceNetwork(ebosSimulator_.episodeIndex());
|
||||
// Check if there is a network with active prediction wells at this time step.
|
||||
const auto episodeIdx = ebosSimulator_.episodeIndex();
|
||||
this->updateNetworkActiveState(episodeIdx);
|
||||
|
||||
// Rebalance the network initially if any wells in the network have status changes
|
||||
// (Need to check this before clearing events)
|
||||
bool do_prestep_network_rebalance{false};
|
||||
if (this->networkActive()) do_prestep_network_rebalance = this->needPreStepNetworkRebalance(episodeIdx);
|
||||
|
||||
for (const auto& well : well_container_) {
|
||||
auto& events = this->wellState().well(well->indexOfWell()).events;
|
||||
@@ -2258,7 +2264,7 @@ namespace Opm {
|
||||
try {
|
||||
well->solveWellEquation(ebosSimulator_, this->wellState(), this->groupState(), deferred_logger);
|
||||
} catch (const std::exception& e) {
|
||||
const std::string msg = "Compute initial well solution for " + well->name() + " initially failed. Continue with the privious rates";
|
||||
const std::string msg = "Compute initial well solution for " + well->name() + " initially failed. Continue with the previous rates";
|
||||
deferred_logger.warning("WELL_INITIAL_SOLVE_FAILED", msg);
|
||||
}
|
||||
}
|
||||
@@ -2268,10 +2274,8 @@ namespace Opm {
|
||||
}
|
||||
updatePrimaryVariables(deferred_logger);
|
||||
|
||||
if (network_rebalance_necessary) {
|
||||
// this is to obtain good network solution
|
||||
balanceNetwork(deferred_logger);
|
||||
}
|
||||
// Actually do the pre-step network rebalance, using the updated well states and initial solutions
|
||||
if (do_prestep_network_rebalance) doPreStepNetworkRebalance(deferred_logger);
|
||||
}
|
||||
|
||||
template<typename TypeTag>
|
||||
|
||||
Reference in New Issue
Block a user