MultisegmentWellAssemble: simplify assembleControlEq

by passing primary variables
This commit is contained in:
Arne Morten Kvarving 2022-12-19 11:49:00 +01:00
parent 3b80b913da
commit 654c252bb8
3 changed files with 14 additions and 19 deletions

View File

@ -31,6 +31,7 @@
#include <opm/models/blackoil/blackoiltwophaseindices.hh> #include <opm/models/blackoil/blackoiltwophaseindices.hh>
#include <opm/simulators/wells/MultisegmentWellEquations.hpp> #include <opm/simulators/wells/MultisegmentWellEquations.hpp>
#include <opm/simulators/wells/MultisegmentWellPrimaryVariables.hpp>
#include <opm/simulators/wells/WellAssemble.hpp> #include <opm/simulators/wells/WellAssemble.hpp>
#include <opm/simulators/wells/WellBhpThpCalculator.hpp> #include <opm/simulators/wells/WellBhpThpCalculator.hpp>
#include <opm/simulators/wells/WellInterfaceIndices.hpp> #include <opm/simulators/wells/WellInterfaceIndices.hpp>
@ -87,9 +88,7 @@ assembleControlEq(const WellState& well_state,
const Well::InjectionControls& inj_controls, const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls, const Well::ProductionControls& prod_controls,
const double rho, const double rho,
const EvalWell& wqTotal, const PrimaryVariables& primary_variables,
const EvalWell& bhp,
const std::function<EvalWell(const int)>& getQs,
Equations& eqns1, Equations& eqns1,
DeferredLogger& deferred_logger) const DeferredLogger& deferred_logger) const
{ {
@ -104,19 +103,19 @@ assembleControlEq(const WellState& well_state,
auto getRates = [&]() { auto getRates = [&]() {
std::vector<EvalWell> rates(3, 0.0); std::vector<EvalWell> rates(3, 0.0);
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) { if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
rates[Water] = getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx)); rates[Water] = primary_variables.getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx));
} }
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) { if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
rates[Oil] = getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx)); rates[Oil] = primary_variables.getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx));
} }
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) { if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
rates[Gas] = getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx)); rates[Gas] = primary_variables.getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx));
} }
return rates; return rates;
}; };
if (well_.wellIsStopped()) { if (well_.wellIsStopped()) {
control_eq = wqTotal; control_eq = primary_variables.getWQTotal();
} else if (well_.isInjector() ) { } else if (well_.isInjector() ) {
// Find scaling factor to get injection rate, // Find scaling factor to get injection rate,
const InjectorType injectorType = inj_controls.injector_type; const InjectorType injectorType = inj_controls.injector_type;
@ -141,7 +140,7 @@ assembleControlEq(const WellState& well_state,
default: default:
throw("Expected WATER, OIL or GAS as type for injectors " + well.name()); throw("Expected WATER, OIL or GAS as type for injectors " + well.name());
} }
const EvalWell injection_rate = wqTotal / scaling; const EvalWell injection_rate = primary_variables.getWQTotal() / scaling;
// Setup function for evaluation of BHP from THP (used only if needed). // Setup function for evaluation of BHP from THP (used only if needed).
std::function<EvalWell()> bhp_from_thp = [&]() { std::function<EvalWell()> bhp_from_thp = [&]() {
const auto rates = getRates(); const auto rates = getRates();
@ -158,7 +157,7 @@ assembleControlEq(const WellState& well_state,
schedule, schedule,
summaryState, summaryState,
inj_controls, inj_controls,
bhp, primary_variables.getBhp(),
injection_rate, injection_rate,
bhp_from_thp, bhp_from_thp,
control_eq, control_eq,
@ -181,7 +180,7 @@ assembleControlEq(const WellState& well_state,
schedule, schedule,
summaryState, summaryState,
prod_controls, prod_controls,
bhp, primary_variables.getBhp(),
rates, rates,
bhp_from_thp, bhp_from_thp,
control_eq, control_eq,

View File

@ -26,14 +26,13 @@
#include <opm/input/eclipse/Schedule/Well/Well.hpp> #include <opm/input/eclipse/Schedule/Well/Well.hpp>
#include <opm/material/densead/Evaluation.hpp> #include <opm/material/densead/Evaluation.hpp>
#include <functional>
namespace Opm namespace Opm
{ {
class DeferredLogger; class DeferredLogger;
class GroupState; class GroupState;
template<class Scalar, int numWellEq, int numEq> class MultisegmentWellEquations; template<class Scalar, int numWellEq, int numEq> class MultisegmentWellEquations;
template<class FluidSystem, class Indices, class Scalar> class MultisegmentWellPrimaryVariables;
class Schedule; class Schedule;
class SummaryState; class SummaryState;
template<class FluidSystem, class Indices, class Scalar> class WellInterfaceIndices; template<class FluidSystem, class Indices, class Scalar> class WellInterfaceIndices;
@ -61,7 +60,9 @@ class MultisegmentWellAssemble
public: public:
static constexpr int numWellEq = Indices::numPhases+1; static constexpr int numWellEq = Indices::numPhases+1;
using Equations = MultisegmentWellEquations<Scalar,numWellEq,Indices::numEq>; using Equations = MultisegmentWellEquations<Scalar,numWellEq,Indices::numEq>;
using PrimaryVariables = MultisegmentWellPrimaryVariables<FluidSystem,Indices,Scalar>;
using EvalWell = DenseAd::Evaluation<Scalar, numWellEq+Indices::numEq>; using EvalWell = DenseAd::Evaluation<Scalar, numWellEq+Indices::numEq>;
//! \brief Constructor initializes reference to well. //! \brief Constructor initializes reference to well.
MultisegmentWellAssemble(const WellInterfaceIndices<FluidSystem,Indices,Scalar>& well) MultisegmentWellAssemble(const WellInterfaceIndices<FluidSystem,Indices,Scalar>& well)
: well_(well) : well_(well)
@ -75,9 +76,7 @@ public:
const Well::InjectionControls& inj_controls, const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls, const Well::ProductionControls& prod_controls,
const double rho, const double rho,
const EvalWell& wqTotal, const PrimaryVariables& primary_variables,
const EvalWell& bhp,
const std::function<EvalWell(const int)>& getQs,
Equations& eqns, Equations& eqns,
DeferredLogger& deferred_logger) const; DeferredLogger& deferred_logger) const;

View File

@ -1645,7 +1645,6 @@ namespace Opm
if (seg == 0) { // top segment, pressure equation is the control equation if (seg == 0) { // top segment, pressure equation is the control equation
const auto& summaryState = ebosSimulator.vanguard().summaryState(); const auto& summaryState = ebosSimulator.vanguard().summaryState();
const Schedule& schedule = ebosSimulator.vanguard().schedule(); const Schedule& schedule = ebosSimulator.vanguard().schedule();
std::function<EvalWell(const int)> gQ = [this](int a) { return this->primary_variables_.getQs(a); };
MultisegmentWellAssemble<FluidSystem,Indices,Scalar>(*this). MultisegmentWellAssemble<FluidSystem,Indices,Scalar>(*this).
assembleControlEq(well_state, assembleControlEq(well_state,
group_state, group_state,
@ -1654,9 +1653,7 @@ namespace Opm
inj_controls, inj_controls,
prod_controls, prod_controls,
getRefDensity(), getRefDensity(),
this->primary_variables_.getWQTotal(), this->primary_variables_,
this->primary_variables_.getBhp(),
gQ,
this->linSys_, this->linSys_,
deferred_logger); deferred_logger);
} else { } else {