diff --git a/opm/simulators/wells/StandardWellAssemble.cpp b/opm/simulators/wells/StandardWellAssemble.cpp index c06107f53..8c248c62f 100644 --- a/opm/simulators/wells/StandardWellAssemble.cpp +++ b/opm/simulators/wells/StandardWellAssemble.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -80,48 +81,43 @@ private: }; template -template void StandardWellAssemble:: assembleControlEq(const WellState& well_state, const GroupState& group_state, const Schedule& schedule, const SummaryState& summaryState, - const int numWellEq, - const EvalWell& wqTotal, - const EvalWell& bhp, - const std::function& getQs, + const PrimaryVariables& primary_variables, const double rho, - const int Bhp, StandardWellEquations& eqns1, DeferredLogger& deferred_logger) const { static constexpr int Water = BlackoilPhases::Aqua; static constexpr int Oil = BlackoilPhases::Liquid; static constexpr int Gas = BlackoilPhases::Vapour; - EvalWell control_eq(numWellEq + Indices::numEq, 0.0); + EvalWell control_eq(primary_variables.numWellEq() + Indices::numEq, 0.0); const auto& well = well_.wellEcl(); auto getRates = [&]() { - std::vector rates(3, EvalWell(numWellEq + Indices::numEq, 0.0)); + std::vector rates(3, EvalWell(primary_variables.numWellEq() + Indices::numEq, 0.0)); 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)) { - rates[Oil] = getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx)); + rates[Oil] = primary_variables.getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx)); } if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) { - rates[Gas] = getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx)); + rates[Gas] = primary_variables.getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx)); } return rates; }; if (well_.wellIsStopped()) { - control_eq = wqTotal; + control_eq = primary_variables.eval(PrimaryVariables::WQTotal); } else if (well_.isInjector()) { // Find injection rate. - const EvalWell injection_rate = wqTotal; + const EvalWell injection_rate = primary_variables.eval(PrimaryVariables::WQTotal); // Setup function for evaluation of BHP from THP (used only if needed). std::function bhp_from_thp = [&]() { const auto rates = getRates(); @@ -141,7 +137,7 @@ assembleControlEq(const WellState& well_state, schedule, summaryState, inj_controls, - bhp, + primary_variables.eval(PrimaryVariables::Bhp), injection_rate, bhp_from_thp, control_eq, @@ -166,7 +162,7 @@ assembleControlEq(const WellState& well_state, schedule, summaryState, prod_controls, - bhp, + primary_variables.eval(PrimaryVariables::Bhp), rates, bhp_from_thp, control_eq, @@ -176,14 +172,13 @@ assembleControlEq(const WellState& well_state, // using control_eq to update the matrix and residuals // TODO: we should use a different index system for the well equations StandardWellEquationAccess eqns(eqns1); - eqns.residual()[0][Bhp] = control_eq.value(); - for (int pv_idx = 0; pv_idx < numWellEq; ++pv_idx) { - eqns.D()[0][0][Bhp][pv_idx] = control_eq.derivative(pv_idx + Indices::numEq); + eqns.residual()[0][PrimaryVariables::Bhp] = control_eq.value(); + for (int pv_idx = 0; pv_idx < primary_variables.numWellEq(); ++pv_idx) { + eqns.D()[0][0][PrimaryVariables::Bhp][pv_idx] = control_eq.derivative(pv_idx + Indices::numEq); } } template -template void StandardWellAssemble:: assembleInjectivityEq(const EvalWell& eq_pskin, const EvalWell& eq_wat_vel, @@ -208,7 +203,6 @@ assembleInjectivityEq(const EvalWell& eq_pskin, } template -template void StandardWellAssemble:: assemblePerforationEq(const EvalWell& cq_s_effective, const int componentIdx, @@ -234,7 +228,6 @@ assemblePerforationEq(const EvalWell& cq_s_effective, } template -template void StandardWellAssemble:: assembleSourceEq(const EvalWell& resWell_loc, const int componentIdx, @@ -249,7 +242,6 @@ assembleSourceEq(const EvalWell& resWell_loc, } template -template void StandardWellAssemble:: assembleZFracEq(const EvalWell& cq_s_zfrac_effective, const int cell_idx, @@ -263,56 +255,14 @@ assembleZFracEq(const EvalWell& cq_s_zfrac_effective, } #define INSTANCE(Dim,...) \ -template class StandardWellAssemble,__VA_ARGS__,double>; \ -template void \ -StandardWellAssemble,__VA_ARGS__,double>:: \ - assembleControlEq(const WellState&, \ - const GroupState&, \ - const Schedule&, \ - const SummaryState&, \ - const int, \ - const DenseAd::Evaluation&, \ - const DenseAd::Evaluation&, \ - const std::function(int)>&, \ - const double, \ - const int, \ - StandardWellEquations&, \ - DeferredLogger&) const; \ -template void \ -StandardWellAssemble,__VA_ARGS__,double>:: \ - assembleInjectivityEq(const DenseAd::Evaluation&, \ - const DenseAd::Evaluation&, \ - const int, \ - const int, \ - const int, \ - const int, \ - StandardWellEquations&) const; \ -template void \ -StandardWellAssemble,__VA_ARGS__,double>:: \ - assemblePerforationEq(const DenseAd::Evaluation&, \ - const int, \ - const int, \ - const int, \ - StandardWellEquations&) const; \ -template void \ -StandardWellAssemble,__VA_ARGS__,double>:: \ - assembleZFracEq(const DenseAd::Evaluation&, \ - const int, \ - const int, \ - StandardWellEquations&) const; \ -template void \ -StandardWellAssemble,__VA_ARGS__,double>:: \ - assembleSourceEq(const DenseAd::Evaluation&, \ - const int, \ - const int, \ - StandardWellEquations&) const; +template class StandardWellAssemble,__VA_ARGS__,double>; // One phase INSTANCE(4u, BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) INSTANCE(5u, BlackOilOnePhaseIndices<0u,0u,0u,1u,false,false,0u,1u,0u>) INSTANCE(9u, BlackOilOnePhaseIndices<0u,0u,0u,0u,false,false,0u,1u,5u>) - // Two phase +// Two phase INSTANCE(6u, BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,0u,0u>) INSTANCE(6u, BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,1u,0u>) INSTANCE(6u, BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,false,0u,2u,0u>) @@ -323,7 +273,7 @@ INSTANCE(7u, BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,0u,0u>) INSTANCE(7u, BlackOilTwoPhaseIndices<0u,0u,0u,0u,false,true,0u,2u,0u>) INSTANCE(8u, BlackOilTwoPhaseIndices<0u,0u,2u,0u,false,false,0u,2u,0u>) - // Blackoil +// Blackoil INSTANCE(8u, BlackOilIndices<0u,0u,0u,0u,false,false,0u,0u>) INSTANCE(9u, BlackOilIndices<0u,0u,0u,0u,true,false,0u,0u>) INSTANCE(9u, BlackOilIndices<0u,0u,0u,0u,false,true,0u,0u>) diff --git a/opm/simulators/wells/StandardWellAssemble.hpp b/opm/simulators/wells/StandardWellAssemble.hpp index 35a3a1254..55c6de9e9 100644 --- a/opm/simulators/wells/StandardWellAssemble.hpp +++ b/opm/simulators/wells/StandardWellAssemble.hpp @@ -23,8 +23,6 @@ #ifndef OPM_STANDARDWELL_ASSEMBLE_HEADER_INCLUDED #define OPM_STANDARDWELL_ASSEMBLE_HEADER_INCLUDED -#include - namespace Opm { @@ -32,6 +30,7 @@ class DeferredLogger; class GroupState; class Schedule; template class StandardWellEquations; +template class StandardWellPrimaryVariables; class SummaryState; template class WellInterfaceFluidSystem; class WellState; @@ -41,28 +40,25 @@ template class StandardWellAssemble { public: + using PrimaryVariables = StandardWellPrimaryVariables; + using EvalWell = typename PrimaryVariables::EvalWell; + //! \brief Constructor initializes reference to well. StandardWellAssemble(const WellInterfaceFluidSystem& well) : well_(well) {} //! \brief Assemble control equation. - template void assembleControlEq(const WellState& well_state, const GroupState& group_state, const Schedule& schedule, const SummaryState& summaryState, - const int numWellEq, - const EvalWell& wqTotal, - const EvalWell& bhp, - const std::function& getQs, + const PrimaryVariables& primary_variables, const double rho, - const int Bhp, StandardWellEquations& eqns, DeferredLogger& deferred_logger) const; //! \brief Assemble injectivity equation. - template void assembleInjectivityEq(const EvalWell& eq_pskin, const EvalWell& eq_wat_vel, const int pskin_index, @@ -72,7 +68,6 @@ public: StandardWellEquations& eqns) const; //! \brief Assemble equation for a perforation. - template void assemblePerforationEq(const EvalWell& cq_s_effective, const int componentIdx, const int cell_idx, @@ -80,20 +75,17 @@ public: StandardWellEquations& eqns) const; //! \brief Assemble equation for Z fraction. - template void assembleZFracEq(const EvalWell& cq_s_zfrac_effective, const int cell_idx, const int numWellEq, StandardWellEquations& eqns) const; //! \brief Assemble a source term. - template void assembleSourceEq(const EvalWell& resWell_loc, const int componentIdx, const int numWellEq, StandardWellEquations& eqns) const; - private: const WellInterfaceFluidSystem& well_; //!< Reference to well }; diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index 950c14562..1bf75ddd6 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -542,16 +542,11 @@ namespace Opm const auto& summaryState = ebosSimulator.vanguard().summaryState(); const Schedule& schedule = ebosSimulator.vanguard().schedule(); - std::function gQ = [this](int a) { return this->primary_variables_.getQs(a); }; StandardWellAssemble(*this). assembleControlEq(well_state, group_state, schedule, summaryState, - this->primary_variables_.numWellEq(), - this->primary_variables_.eval(WQTotal), - this->primary_variables_.eval(Bhp), - gQ, + this->primary_variables_, this->getRho(), - Bhp, this->linSys_, deferred_logger);