Merge pull request #5988 from atgeirr/remove-unneeded-evaluation-updaters

Remove explicit updating of well AD vars.
This commit is contained in:
Atgeirr Flø Rasmussen
2025-02-14 20:40:31 +01:00
committed by GitHub
15 changed files with 16 additions and 86 deletions

View File

@@ -257,8 +257,8 @@ template<class Scalar> class WellContributions;
// called at the beginning of a report step // called at the beginning of a report step
void beginReportStep(const int time_step); void beginReportStep(const int time_step);
// it should be able to go to prepareTimeStep(), however, the updateWellControls() and initPrimaryVariablesEvaluation() // it should be able to go to prepareTimeStep(), however, the updateWellControls()
// makes it a little more difficult. unless we introduce if (iterationIdx != 0) to avoid doing the above functions // makes it a little more difficult. unless we introduce if (iterationIdx != 0) to avoid doing the above function
// twice at the beginning of the time step // twice at the beginning of the time step
/// Calculating the explict quantities used in the well calculation. By explicit, we mean they are cacluated /// Calculating the explict quantities used in the well calculation. By explicit, we mean they are cacluated
/// at the beginning of the time step and no derivatives are included in these quantities /// at the beginning of the time step and no derivatives are included in these quantities
@@ -266,7 +266,6 @@ template<class Scalar> class WellContributions;
// some preparation work, mostly related to group control and RESV, // some preparation work, mostly related to group control and RESV,
// at the beginning of each time step (Not report step) // at the beginning of each time step (Not report step)
void prepareTimeStep(DeferredLogger& deferred_logger); void prepareTimeStep(DeferredLogger& deferred_logger);
void initPrimaryVariablesEvaluation() const;
std::pair<bool, bool> std::pair<bool, bool>
updateWellControls(const bool mandatory_network_balance, DeferredLogger& deferred_logger, const bool relax_network_tolerance = false); updateWellControls(const bool mandatory_network_balance, DeferredLogger& deferred_logger, const bool relax_network_tolerance = false);

View File

@@ -91,8 +91,6 @@ public:
, wellModel_(model) , wellModel_(model)
{} {}
void initPrimaryVariablesEvaluation(const Domain& domain) const;
void addWellPressureEquations(PressureMatrix& jacobian, void addWellPressureEquations(PressureMatrix& jacobian,
const BVector& weights, const BVector& weights,
const bool use_well_weights, const bool use_well_weights,

View File

@@ -47,7 +47,6 @@ assemble(const int /*iterationIdx*/,
DeferredLogger local_deferredLogger; DeferredLogger local_deferredLogger;
this->updateWellControls(local_deferredLogger, domain); this->updateWellControls(local_deferredLogger, domain);
this->initPrimaryVariablesEvaluation(domain);
this->assembleWellEq(dt, domain, local_deferredLogger); this->assembleWellEq(dt, domain, local_deferredLogger);
} }
@@ -125,18 +124,6 @@ recoverWellSolutionAndUpdateWellState(const BVector& x,
} }
} }
template<typename TypeTag>
void
BlackoilWellModelNldd<TypeTag>::
initPrimaryVariablesEvaluation(const Domain& domain) const
{
for (auto& well : wellModel_.localNonshutWells()) {
if (this->well_domain().at(well->name()) == domain.index) {
well->initPrimaryVariablesEvaluation();
}
}
}
template<typename TypeTag> template<typename TypeTag>
ConvergenceReport ConvergenceReport
BlackoilWellModelNldd<TypeTag>:: BlackoilWellModelNldd<TypeTag>::

View File

@@ -1103,7 +1103,6 @@ namespace Opm {
} }
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::doPreStepNetworkRebalance() failed: ", OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::doPreStepNetworkRebalance() failed: ",
this->simulator_.vanguard().grid().comm()); this->simulator_.vanguard().grid().comm());
this->initPrimaryVariablesEvaluation();
} while (iter < max_iter); } while (iter < max_iter);
if (!converged) { if (!converged) {
@@ -1239,9 +1238,6 @@ namespace Opm {
bool alq_updated = false; bool alq_updated = false;
OPM_BEGIN_PARALLEL_TRY_CATCH(); OPM_BEGIN_PARALLEL_TRY_CATCH();
{ {
// Set the well primary variables based on the value of well solutions
initPrimaryVariablesEvaluation();
alq_updated = gaslift_.maybeDoGasLiftOptimize(simulator_, alq_updated = gaslift_.maybeDoGasLiftOptimize(simulator_,
well_container_, well_container_,
this->wellState(), this->wellState(),
@@ -1661,17 +1657,6 @@ namespace Opm {
} }
template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
initPrimaryVariablesEvaluation() const
{
for (auto& well : well_container_) {
well->initPrimaryVariablesEvaluation();
}
}
template<typename TypeTag> template<typename TypeTag>
ConvergenceReport ConvergenceReport
BlackoilWellModel<TypeTag>:: BlackoilWellModel<TypeTag>::
@@ -2084,7 +2069,6 @@ namespace Opm {
if (events.hasEvent(WellState<Scalar>::event_mask)) { if (events.hasEvent(WellState<Scalar>::event_mask)) {
well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), deferred_logger); well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), deferred_logger);
well->updatePrimaryVariables(simulator_, this->wellState(), deferred_logger); well->updatePrimaryVariables(simulator_, this->wellState(), deferred_logger);
well->initPrimaryVariablesEvaluation();
// There is no new well control change input within a report step, // There is no new well control change input within a report step,
// so next time step, the well does not consider to have effective events anymore. // so next time step, the well does not consider to have effective events anymore.
events.clearEvent(WellState<Scalar>::event_mask); events.clearEvent(WellState<Scalar>::event_mask);

View File

@@ -86,8 +86,6 @@ namespace Opm {
const std::vector<Scalar>& B_avg, const std::vector<Scalar>& B_avg,
const bool changed_to_open_this_step) override; const bool changed_to_open_this_step) override;
void initPrimaryVariablesEvaluation() override;
/// updating the well state based the current control mode /// updating the well state based the current control mode
void updateWellStateWithTarget(const Simulator& simulator, void updateWellStateWithTarget(const Simulator& simulator,
const GroupState<Scalar>& group_state, const GroupState<Scalar>& group_state,

View File

@@ -54,7 +54,7 @@ resize(const int numSegments)
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>
void MultisegmentWellPrimaryVariables<FluidSystem,Indices>:: void MultisegmentWellPrimaryVariables<FluidSystem,Indices>::
init() setEvaluationsFromValues()
{ {
for (std::size_t seg = 0; seg < value_.size(); ++seg) { for (std::size_t seg = 0; seg < value_.size(); ++seg) {
for (int eq_idx = 0; eq_idx < numWellEq; ++eq_idx) { for (int eq_idx = 0; eq_idx < numWellEq; ++eq_idx) {
@@ -152,7 +152,7 @@ update(const WellState<Scalar>& well_state,
} }
} }
} }
init(); setEvaluationsFromValues();
} }
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>
@@ -209,7 +209,7 @@ updateNewton(const BVectorWell& dwells,
if (stop_or_zero_rate_target) { if (stop_or_zero_rate_target) {
value_[0][WQTotal] = 0.; value_[0][WQTotal] = 0.;
} }
init(); setEvaluationsFromValues();
} }
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>

View File

@@ -81,9 +81,6 @@ public:
//! \brief Resize values and evaluations. //! \brief Resize values and evaluations.
void resize(const int numSegments); void resize(const int numSegments);
//! \brief Initialize evaluations from values.
void init();
//! \brief Copy values from well state. //! \brief Copy values from well state.
void update(const WellState<Scalar>& well_state, void update(const WellState<Scalar>& well_state,
const bool stop_or_zero_rate_target); const bool stop_or_zero_rate_target);
@@ -149,6 +146,9 @@ public:
void outputLowLimitPressureSegments(DeferredLogger& deferred_logger) const; void outputLowLimitPressureSegments(DeferredLogger& deferred_logger) const;
private: private:
//! \brief Initialize evaluations from values.
void setEvaluationsFromValues();
//! \brief Handle non-reasonable fractions due to numerical overshoot. //! \brief Handle non-reasonable fractions due to numerical overshoot.
void processFractions(const int seg); void processFractions(const int seg);

View File

@@ -147,18 +147,6 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
initPrimaryVariablesEvaluation()
{
this->primary_variables_.init();
}
template <typename TypeTag> template <typename TypeTag>
void void
MultisegmentWell<TypeTag>:: MultisegmentWell<TypeTag>::
@@ -732,7 +720,6 @@ namespace Opm
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
updatePrimaryVariables(simulator, well_state, deferred_logger); updatePrimaryVariables(simulator, well_state, deferred_logger);
initPrimaryVariablesEvaluation();
computePerfCellPressDiffs(simulator); computePerfCellPressDiffs(simulator);
computeInitialSegmentFluids(simulator); computeInitialSegmentFluids(simulator);
} }
@@ -1582,7 +1569,6 @@ namespace Opm
deferred_logger.debug(sstr.str()); deferred_logger.debug(sstr.str());
} }
updateWellState(simulator, dx_well, well_state, deferred_logger, relaxation_factor); updateWellState(simulator, dx_well, well_state, deferred_logger, relaxation_factor);
initPrimaryVariablesEvaluation();
} }
// TODO: we should decide whether to keep the updated well_state, or recover to use the old well_state // TODO: we should decide whether to keep the updated well_state, or recover to use the old well_state
@@ -1774,7 +1760,6 @@ namespace Opm
} }
} }
updateWellState(simulator, dx_well, well_state, deferred_logger, relaxation_factor); updateWellState(simulator, dx_well, well_state, deferred_logger, relaxation_factor);
initPrimaryVariablesEvaluation();
} }
if (converged) { if (converged) {

View File

@@ -137,8 +137,6 @@ namespace Opm
const std::vector<Scalar>& B_avg, const std::vector<Scalar>& B_avg,
const bool changed_to_open_this_step) override; const bool changed_to_open_this_step) override;
void initPrimaryVariablesEvaluation() override;
/// check whether the well equations get converged for this well /// check whether the well equations get converged for this well
virtual ConvergenceReport getWellConvergence(const Simulator& simulator, virtual ConvergenceReport getWellConvergence(const Simulator& simulator,
const WellState<Scalar>& well_state, const WellState<Scalar>& well_state,

View File

@@ -97,7 +97,7 @@ namespace Opm {
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>
void StandardWellPrimaryVariables<FluidSystem,Indices>:: void StandardWellPrimaryVariables<FluidSystem,Indices>::
init() setEvaluationsFromValues()
{ {
for (int eqIdx = 0; eqIdx < numWellEq_; ++eqIdx) { for (int eqIdx = 0; eqIdx < numWellEq_; ++eqIdx) {
evaluation_[eqIdx] = evaluation_[eqIdx] =
@@ -223,7 +223,7 @@ update(const WellState<Scalar>& well_state,
// BHP // BHP
value_[Bhp] = ws.bhp; value_[Bhp] = ws.bhp;
init(); setEvaluationsFromValues();
} }
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>
@@ -240,6 +240,7 @@ updatePolyMW(const WellState<Scalar>& well_state)
value_[Bhp + 1 + well_.numPerfs() + perf] = skin_pressure[perf]; value_[Bhp + 1 + well_.numPerfs() + perf] = skin_pressure[perf];
} }
} }
setEvaluationsFromValues();
} }
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>
@@ -302,7 +303,7 @@ updateNewton(const BVectorWell& dwells,
// so that bhp constaint can be an active control when needed. // so that bhp constaint can be an active control when needed.
constexpr Scalar bhp_lower_limit = 1. * unit::barsa - 1. * unit::Pascal; constexpr Scalar bhp_lower_limit = 1. * unit::barsa - 1. * unit::Pascal;
value_[Bhp] = std::max(value_[Bhp] - dx1_limited, bhp_lower_limit); value_[Bhp] = std::max(value_[Bhp] - dx1_limited, bhp_lower_limit);
init(); setEvaluationsFromValues();
} }
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>
@@ -322,7 +323,7 @@ updateNewtonPolyMW(const BVectorWell& dwells)
value_[pskin_index] -= relaxation_factor * dx_pskin; value_[pskin_index] -= relaxation_factor * dx_pskin;
} }
} }
init(); setEvaluationsFromValues();
} }
template<class FluidSystem, class Indices> template<class FluidSystem, class Indices>

View File

@@ -92,9 +92,6 @@ public:
: well_(well) : well_(well)
{} {}
//! \brief Initialize evaluations from values.
void init();
//! \brief Resize values and evaluations. //! \brief Resize values and evaluations.
void resize(const int numWellEq); void resize(const int numWellEq);
@@ -151,6 +148,9 @@ public:
{ value_[idx] = val; } { value_[idx] = val; }
private: private:
//! \brief Initialize evaluations from values.
void setEvaluationsFromValues();
//! \brief Calculate a relaxation factor for producers. //! \brief Calculate a relaxation factor for producers.
//! \details To avoid overshoot of the fractions which might result in negative rates. //! \details To avoid overshoot of the fractions which might result in negative rates.
Scalar relaxationFactorFractionsProducer(const BVectorWell& dwells, Scalar relaxationFactorFractionsProducer(const BVectorWell& dwells,

View File

@@ -87,17 +87,6 @@ namespace Opm
template<typename TypeTag>
void StandardWell<TypeTag>::
initPrimaryVariablesEvaluation()
{
this->primary_variables_.init();
}
template<typename TypeTag> template<typename TypeTag>
template<class Value> template<class Value>
void void
@@ -1412,7 +1401,6 @@ namespace Opm
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
updatePrimaryVariables(simulator, well_state, deferred_logger); updatePrimaryVariables(simulator, well_state, deferred_logger);
initPrimaryVariablesEvaluation();
computeWellConnectionPressures(simulator, well_state, deferred_logger); computeWellConnectionPressures(simulator, well_state, deferred_logger);
this->computeAccumWell(); this->computeAccumWell();
} }
@@ -1564,7 +1552,6 @@ namespace Opm
= sign * ws.well_potentials[phase]; = sign * ws.well_potentials[phase];
} }
well_copy.updatePrimaryVariables(simulator, well_state_copy, deferred_logger); well_copy.updatePrimaryVariables(simulator, well_state_copy, deferred_logger);
well_copy.initPrimaryVariablesEvaluation();
well_copy.computeAccumWell(); well_copy.computeAccumWell();
const double dt = simulator.timeStepSize(); const double dt = simulator.timeStepSize();
@@ -1576,7 +1563,6 @@ namespace Opm
} }
well_copy.updatePrimaryVariables(simulator, well_state_copy, deferred_logger); well_copy.updatePrimaryVariables(simulator, well_state_copy, deferred_logger);
well_copy.computeWellConnectionPressures(simulator, well_state_copy, deferred_logger); well_copy.computeWellConnectionPressures(simulator, well_state_copy, deferred_logger);
well_copy.initPrimaryVariablesEvaluation();
well_copy.computeWellRatesWithBhp(simulator, bhp, well_flux, deferred_logger); well_copy.computeWellRatesWithBhp(simulator, bhp, well_flux, deferred_logger);
} }
@@ -2382,7 +2368,6 @@ namespace Opm
// this function or we use different functions for the well testing purposes. // this function or we use different functions for the well testing purposes.
// We don't allow for switching well controls while computing well potentials and testing wells // We don't allow for switching well controls while computing well potentials and testing wells
// updateWellControl(simulator, well_state, deferred_logger); // updateWellControl(simulator, well_state, deferred_logger);
initPrimaryVariablesEvaluation();
} while (it < max_iter); } while (it < max_iter);
return converged; return converged;
@@ -2478,7 +2463,6 @@ namespace Opm
++it; ++it;
solveEqAndUpdateWellState(simulator, well_state, deferred_logger); solveEqAndUpdateWellState(simulator, well_state, deferred_logger);
initPrimaryVariablesEvaluation();
} while (it < max_iter); } while (it < max_iter);

View File

@@ -151,8 +151,6 @@ public:
const std::vector<Scalar>& B_avg, const std::vector<Scalar>& B_avg,
const bool changed_to_open_this_step); const bool changed_to_open_this_step);
virtual void initPrimaryVariablesEvaluation() = 0;
virtual ConvergenceReport getWellConvergence(const Simulator& simulator, virtual ConvergenceReport getWellConvergence(const Simulator& simulator,
const WellState<Scalar>& well_state, const WellState<Scalar>& well_state,
const std::vector<Scalar>& B_avg, const std::vector<Scalar>& B_avg,

View File

@@ -400,7 +400,6 @@ namespace Opm
updateWellStateWithTarget(simulator, group_state, well_state_copy, deferred_logger); updateWellStateWithTarget(simulator, group_state, well_state_copy, deferred_logger);
calculateExplicitQuantities(simulator, well_state_copy, deferred_logger); calculateExplicitQuantities(simulator, well_state_copy, deferred_logger);
updatePrimaryVariables(simulator, well_state_copy, deferred_logger); updatePrimaryVariables(simulator, well_state_copy, deferred_logger);
initPrimaryVariablesEvaluation();
if (this->isProducer()) { if (this->isProducer()) {
const auto& schedule = simulator.vanguard().schedule(); const auto& schedule = simulator.vanguard().schedule();

View File

@@ -153,7 +153,6 @@ BOOST_AUTO_TEST_CASE(G1)
well_model.calculateExplicitQuantities(deferred_logger); well_model.calculateExplicitQuantities(deferred_logger);
well_model.prepareTimeStep(deferred_logger); well_model.prepareTimeStep(deferred_logger);
well_model.updateWellControls(false, deferred_logger); well_model.updateWellControls(false, deferred_logger);
well_model.initPrimaryVariablesEvaluation();
Opm::WellInterface<TypeTag> *well_ptr = well_model.getWell("B-1H").get(); Opm::WellInterface<TypeTag> *well_ptr = well_model.getWell("B-1H").get();
StdWell *std_well = dynamic_cast<StdWell *>(well_ptr); StdWell *std_well = dynamic_cast<StdWell *>(well_ptr);