Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP update group target reduction during local solve #5924

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion opm/simulators/wells/BlackoilWellModel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ namespace Opm {
local_deferredLogger);

prepareWellsBeforeAssembling(dt, local_deferredLogger);
}
}
OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
"updateWellControlsAndNetworkIteration() failed: ",
this->terminal_output_, grid().comm());
Expand Down Expand Up @@ -1530,6 +1530,12 @@ namespace Opm {
for (auto& well : well_container_) {
well->prepareWellBeforeAssembling(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
}
const int reportStepIdx = simulator_.episodeIndex();
const int iterationIdx = simulator_.model().newtonMethod().numIterations();
this->updateAndCommunicateGroupData(reportStepIdx,
iterationIdx,
param_.nupcol_group_rate_tolerance_,
deferred_logger);
}


Expand Down
2 changes: 1 addition & 1 deletion opm/simulators/wells/MultisegmentWell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ namespace Opm {
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger,
const bool fixed_control = false,
const bool fixed_status = false) override;
Expand Down
4 changes: 2 additions & 2 deletions opm/simulators/wells/MultisegmentWell_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ namespace Opm

// store a copy of the well state, we don't want to update the real well state
WellState<Scalar> well_state_copy = simulator.problem().wellModel().wellState();
const auto& group_state = simulator.problem().wellModel().groupState();
auto group_state = simulator.problem().wellModel().groupState();
auto& ws = well_state_copy.well(this->index_of_well_);

// get current controls
Expand Down Expand Up @@ -1622,7 +1622,7 @@ namespace Opm
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger,
const bool fixed_control /*false*/,
const bool fixed_status /*false*/)
Expand Down
2 changes: 1 addition & 1 deletion opm/simulators/wells/StandardWell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ namespace Opm
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger,
const bool fixed_control = false,
const bool fixed_status = false) override;
Expand Down
4 changes: 2 additions & 2 deletions opm/simulators/wells/StandardWell_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ namespace Opm

// store a copy of the well state, we don't want to update the real well state
WellState<Scalar> well_state_copy = simulator.problem().wellModel().wellState();
const auto& group_state = simulator.problem().wellModel().groupState();
auto group_state = simulator.problem().wellModel().groupState();
auto& ws = well_state_copy.well(this->index_of_well_);

// get current controls
Expand Down Expand Up @@ -2396,7 +2396,7 @@ namespace Opm
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger,
const bool fixed_control /*false*/,
const bool fixed_status /*false*/)
Expand Down
18 changes: 9 additions & 9 deletions opm/simulators/wells/WellInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie
void assembleWellEq(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);

void assembleWellEqWithoutIteration(const Simulator& simulator,
Expand All @@ -175,7 +175,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie
void prepareWellBeforeAssembling(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);


Expand Down Expand Up @@ -246,7 +246,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie

bool updateWellControlAndStatusLocalIteration(const Simulator& simulator,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
const Scalar WQTotal,
Expand Down Expand Up @@ -305,7 +305,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie
bool gliftBeginTimeStepWellTestIterateWellEquations(const Simulator& ebos_simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);

void gliftBeginTimeStepWellTestUpdateALQ(const Simulator& simulator,
Expand Down Expand Up @@ -344,7 +344,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie

void solveWellEquation(const Simulator& simulator,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);

const std::vector<RateVector>& connectionRates() const
Expand All @@ -368,7 +368,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie
const WellInjectionControls& inj_controls,
const WellProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger,
const bool fixed_control = false,
const bool fixed_status = false) = 0;
Expand Down Expand Up @@ -432,15 +432,15 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie
bool iterateWellEquations(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);

bool solveWellWithTHPConstraint(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);

std::optional<Scalar>
Expand All @@ -463,7 +463,7 @@ class WellInterface : public WellInterfaceIndices<GetPropType<TypeTag, Propertie

bool solveWellForTesting(const Simulator& simulator,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger);


Expand Down
49 changes: 37 additions & 12 deletions opm/simulators/wells/WellInterface_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <opm/input/eclipse/Schedule/Well/WDFAC.hpp>

#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>

#include <opm/simulators/wells/WellGroupHelpers.hpp>
#include <opm/simulators/wells/GroupState.hpp>
#include <opm/simulators/wells/TargetCalculator.hpp>
#include <opm/simulators/wells/WellBhpThpCalculator.hpp>
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace Opm
WellInterface<TypeTag>::
updateWellControlAndStatusLocalIteration(const Simulator& simulator,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
const Scalar wqTotal,
Expand Down Expand Up @@ -320,7 +320,7 @@ namespace Opm
if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
changed = changed || this->checkGroupConstraints(well_state, group_state, schedule, summary_state,deferred_logger);
}

if (changed) {
const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
ws.production_cmode == Well::ProducerCMode::THP;
Expand All @@ -332,6 +332,29 @@ namespace Opm
}
updatePrimaryVariables(simulator, well_state, deferred_logger);
}

bool isNowGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
if (isGroupControl != isNowGroupControl) {
well_state.updateGlobalIsGrup();
int reportStepIdx = simulator.episodeIndex();
const Group& fieldGroup = schedule.getGroup("FIELD", reportStepIdx);
std::vector<Scalar> groupTargetReduction(well_state.numPhases(), 0.0);
WellGroupHelpers<Scalar>::updateGroupTargetReduction(fieldGroup,
schedule,
reportStepIdx,
this->isInjector(),
well_state.phaseUsage(),
*this->guideRate(),
well_state,
summary_state,
group_state,
groupTargetReduction);

if (isNowGroupControl) {
updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
updatePrimaryVariables(simulator, well_state, deferred_logger);
}
}
}
return changed;
}
Expand Down Expand Up @@ -395,6 +418,8 @@ namespace Opm
deferred_logger.info(" well " + this->name() + " is being tested");

WellState<Scalar> well_state_copy = well_state;
GroupState<Scalar> group_state_copy = group_state;

auto& ws = well_state_copy.well(this->indexOfWell());

updateWellStateWithTarget(simulator, group_state, well_state_copy, deferred_logger);
Expand Down Expand Up @@ -424,7 +449,7 @@ namespace Opm
// untill the number of closed completions do not increase anymore.
while (testWell) {
const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
bool converged = solveWellForTesting(simulator, well_state_copy, group_state, deferred_logger);
bool converged = solveWellForTesting(simulator, well_state_copy, group_state_copy, deferred_logger);
if (!converged) {
const auto msg = fmt::format("WTEST: Well {} is not solvable (physical)", this->name());
deferred_logger.debug(msg);
Expand Down Expand Up @@ -499,7 +524,7 @@ namespace Opm
iterateWellEquations(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -535,7 +560,7 @@ namespace Opm
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -712,7 +737,7 @@ namespace Opm
WellInterface<TypeTag>::
solveWellForTesting(const Simulator& simulator,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -746,7 +771,7 @@ namespace Opm
WellInterface<TypeTag>::
solveWellEquation(const Simulator& simulator,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -805,7 +830,7 @@ namespace Opm
assembleWellEq(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -841,7 +866,7 @@ namespace Opm
prepareWellBeforeAssembling(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -993,7 +1018,7 @@ namespace Opm
gliftBeginTimeStepWellTestIterateWellEquations(const Simulator& simulator,
const double dt,
WellState<Scalar>& well_state,
const GroupState<Scalar>& group_state,
GroupState<Scalar>& group_state,
DeferredLogger& deferred_logger)
{
OPM_TIMEFUNCTION();
Expand Down Expand Up @@ -1135,7 +1160,7 @@ namespace Opm
assert(this->param_.local_well_solver_control_switching_);
this->operability_status_.resetOperability();
WellState<Scalar> well_state_copy = well_state;
const auto& group_state = simulator.problem().wellModel().groupState();
auto group_state = simulator.problem().wellModel().groupState();
const double dt = simulator.timeStepSize();
// equations should be converged at this stage, so only one it is needed
bool converged = iterateWellEquations(simulator, dt, well_state_copy, group_state, deferred_logger);
Expand Down
14 changes: 14 additions & 0 deletions opm/simulators/wells/WellState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,20 @@ void WellState<Scalar>::updateGlobalIsGrup(const Parallel::Communication& comm)
this->global_well_info.value().communicate(comm);
}

template<class Scalar>
void WellState<Scalar>::updateGlobalIsGrup()
{
this->global_well_info.value().clear();
for (std::size_t well_index = 0; well_index < this->size(); well_index++) {
const auto& ws = this->well(well_index);
this->global_well_info.value().update_efficiency_scaling_factor(well_index, ws.efficiency_scaling_factor);
if (ws.producer)
this->global_well_info.value().update_producer(well_index, ws.status, ws.production_cmode);
else
this->global_well_info.value().update_injector(well_index, ws.status, ws.injection_cmode);
}
}

template<class Scalar>
void WellState<Scalar>::
updateEfficiencyScalingFactor(const std::string& wellName,
Expand Down
1 change: 1 addition & 0 deletions opm/simulators/wells/WellState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class WellState
void communicateGroupRates(const Parallel::Communication& comm);

void updateGlobalIsGrup(const Parallel::Communication& comm);
void updateGlobalIsGrup();
void updateEfficiencyScalingFactor(const std::string& wellName,
const Scalar value);

Expand Down