diff --git a/opm/autodiff/BlackoilModel.hpp b/opm/autodiff/BlackoilModel.hpp index c5006b217..4a349c516 100644 --- a/opm/autodiff/BlackoilModel.hpp +++ b/opm/autodiff/BlackoilModel.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace Opm { @@ -40,10 +41,10 @@ namespace Opm { /// It uses automatic differentiation via the class AutoDiffBlock /// to simplify assembly of the jacobian matrix. template - class BlackoilModel : public BlackoilModelBase > + class BlackoilModel : public BlackoilModelBase, StandardWells> { public: - typedef BlackoilModelBase > Base; + typedef BlackoilModelBase, StandardWells> Base; /// Construct the model. It will retain references to the /// arguments of this functions, and they are expected to diff --git a/opm/autodiff/BlackoilModelBase.hpp b/opm/autodiff/BlackoilModelBase.hpp index 9a59a7f64..fc4a493e1 100644 --- a/opm/autodiff/BlackoilModelBase.hpp +++ b/opm/autodiff/BlackoilModelBase.hpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -106,7 +105,7 @@ namespace Opm { /// to simplify assembly of the jacobian matrix. /// \tparam Grid UnstructuredGrid or CpGrid. /// \tparam Implementation Provides concrete state types. - template + template class BlackoilModelBase { public: @@ -276,7 +275,7 @@ namespace Opm { const BlackoilPropsAdInterface& fluid_; const DerivedGeology& geo_; const RockCompressibility* rock_comp_props_; - StandardWells std_wells_; + WellModel std_wells_; VFPProperties vfp_properties_; const NewtonIterationBlackoilInterface& linsolver_; // For each canonical phase -> true if active @@ -328,11 +327,11 @@ namespace Opm { return static_cast(*this); } - /// return the StandardWells object - StandardWells& stdWells() { return std_wells_; } - const StandardWells& stdWells() const { return std_wells_; } + /// return the WellModel object + WellModel& stdWells() { return std_wells_; } + const WellModel& stdWells() const { return std_wells_; } - /// return the Well struct in the StandardWells + /// return the Well struct in the WellModel const Wells& wells() const { return std_wells_.wells(); } /// return true if wells are available in the reservoir diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index dffd81769..0afbe6fe2 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -143,8 +143,8 @@ namespace detail { } // namespace detail - template - BlackoilModelBase:: + template + BlackoilModelBase:: BlackoilModelBase(const ModelParameters& param, const Grid& grid , const BlackoilPropsAdInterface& fluid, @@ -217,9 +217,9 @@ namespace detail { - template + template void - BlackoilModelBase:: + BlackoilModelBase:: prepareStep(const double dt, ReservoirState& reservoir_state, WellState& /* well_state */) @@ -234,10 +234,10 @@ namespace detail { - template + template template IterationReport - BlackoilModelBase:: + BlackoilModelBase:: nonlinearIteration(const int iteration, const double dt, NonlinearSolverType& nonlinear_solver, @@ -289,9 +289,9 @@ namespace detail { - template + template void - BlackoilModelBase:: + BlackoilModelBase:: afterStep(const double /* dt */, ReservoirState& /* reservoir_state */, WellState& /* well_state */) @@ -303,9 +303,9 @@ namespace detail { - template + template int - BlackoilModelBase:: + BlackoilModelBase:: sizeNonLinear() const { return residual_.sizeNonLinear(); @@ -315,9 +315,9 @@ namespace detail { - template + template int - BlackoilModelBase:: + BlackoilModelBase:: linearIterationsLastSolve() const { return linsolver_.iterations(); @@ -327,9 +327,9 @@ namespace detail { - template + template bool - BlackoilModelBase:: + BlackoilModelBase:: terminalOutputEnabled() const { return terminal_output_; @@ -339,9 +339,9 @@ namespace detail { - template + template int - BlackoilModelBase:: + BlackoilModelBase:: numPhases() const { return fluid_.numPhases(); @@ -351,9 +351,9 @@ namespace detail { - template + template int - BlackoilModelBase:: + BlackoilModelBase:: numMaterials() const { return material_name_.size(); @@ -363,9 +363,9 @@ namespace detail { - template + template const std::string& - BlackoilModelBase:: + BlackoilModelBase:: materialName(int material_index) const { assert(material_index < numMaterials()); @@ -376,9 +376,9 @@ namespace detail { - template + template void - BlackoilModelBase:: + BlackoilModelBase:: setThresholdPressures(const std::vector& threshold_pressures) { const int num_faces = AutoDiffGrid::numFaces(grid_); @@ -407,8 +407,9 @@ namespace detail { - template - BlackoilModelBase::ReservoirResidualQuant::ReservoirResidualQuant() + template + BlackoilModelBase:: + ReservoirResidualQuant::ReservoirResidualQuant() : accum(2, ADB::null()) , mflux( ADB::null()) , b ( ADB::null()) @@ -421,9 +422,9 @@ namespace detail { - template + template int - BlackoilModelBase::numWellVars() const + BlackoilModelBase::numWellVars() const { // For each well, we have a bhp variable, and one flux per phase. const int nw = stdWells().localWellsActive() ? wells().number_of_wells : 0; @@ -434,9 +435,10 @@ namespace detail { - template + template void - BlackoilModelBase::makeConstantState(SolutionState& state) const + BlackoilModelBase:: + makeConstantState(SolutionState& state) const { // HACK: throw away the derivatives. this may not be the most // performant way to do things, but it will make the state @@ -463,10 +465,11 @@ namespace detail { - template - typename BlackoilModelBase::SolutionState - BlackoilModelBase::variableState(const ReservoirState& x, - const WellState& xw) const + template + typename BlackoilModelBase::SolutionState + BlackoilModelBase:: + variableState(const ReservoirState& x, + const WellState& xw) const { std::vector vars0 = asImpl().variableStateInitials(x, xw); std::vector vars = ADB::variables(vars0); @@ -477,10 +480,11 @@ namespace detail { - template + template std::vector - BlackoilModelBase::variableStateInitials(const ReservoirState& x, - const WellState& xw) const + BlackoilModelBase:: + variableStateInitials(const ReservoirState& x, + const WellState& xw) const { assert(active_[ Oil ]); @@ -499,9 +503,10 @@ namespace detail { - template + template void - BlackoilModelBase::variableReservoirStateInitials(const ReservoirState& x, std::vector& vars0) const + BlackoilModelBase:: + variableReservoirStateInitials(const ReservoirState& x, std::vector& vars0) const { using namespace Opm::AutoDiffGrid; const int nc = numCells(grid_); @@ -537,9 +542,10 @@ namespace detail { - template + template void - BlackoilModelBase::variableWellStateInitials(const WellState& xw, std::vector& vars0) const + BlackoilModelBase:: + variableWellStateInitials(const WellState& xw, std::vector& vars0) const { // Initial well rates. if ( stdWells().localWellsActive() ) @@ -571,9 +577,10 @@ namespace detail { - template + template std::vector - BlackoilModelBase::variableStateIndices() const + BlackoilModelBase:: + variableStateIndices() const { assert(active_[Oil]); std::vector indices(5, -1); @@ -594,9 +601,10 @@ namespace detail { - template + template std::vector - BlackoilModelBase::variableWellStateIndices() const + BlackoilModelBase:: + variableWellStateIndices() const { // Black oil model standard is 5 equation. // For the pure well solve, only the well equations are picked. @@ -612,11 +620,12 @@ namespace detail { - template - typename BlackoilModelBase::SolutionState - BlackoilModelBase::variableStateExtractVars(const ReservoirState& x, - const std::vector& indices, - std::vector& vars) const + template + typename BlackoilModelBase::SolutionState + BlackoilModelBase:: + variableStateExtractVars(const ReservoirState& x, + const std::vector& indices, + std::vector& vars) const { //using namespace Opm::AutoDiffGrid; const int nc = Opm::AutoDiffGrid::numCells(grid_); @@ -684,11 +693,12 @@ namespace detail { - template + template void - BlackoilModelBase::variableStateExtractWellsVars(const std::vector& indices, - std::vector& vars, - SolutionState& state) const + BlackoilModelBase:: + variableStateExtractWellsVars(const std::vector& indices, + std::vector& vars, + SolutionState& state) const { // Qs. state.qs = std::move(vars[indices[Qs]]); @@ -701,10 +711,11 @@ namespace detail { - template + template void - BlackoilModelBase::computeAccum(const SolutionState& state, - const int aix ) + BlackoilModelBase:: + computeAccum(const SolutionState& state, + const int aix ) { const Opm::PhaseUsage& pu = fluid_.phaseUsage(); @@ -763,9 +774,10 @@ namespace detail { - template - void BlackoilModelBase::computeWellConnectionPressures(const SolutionState& state, - const WellState& xw) + template + void BlackoilModelBase:: + computeWellConnectionPressures(const SolutionState& state, + const WellState& xw) { if( ! localWellsActive() ) return ; @@ -780,8 +792,8 @@ namespace detail { asImpl().stdWells().computePropertiesForWellConnectionPressures(state, xw, fluid_, active_, phaseCondition_, b_perf, rsmax_perf, rvmax_perf, surf_dens_perf); // Extract well connection depths. - const StandardWells::Vector depth = cellCentroidsZToEigen(grid_); - const StandardWells::Vector pdepth = subset(depth, asImpl().stdWells().wellOps().well_cells); + const typename WellModel::Vector depth = cellCentroidsZToEigen(grid_); + const typename WellModel::Vector pdepth = subset(depth, asImpl().stdWells().wellOps().well_cells); const int nperf = wells().well_connpos[wells().number_of_wells]; const std::vector depth_perf(pdepth.data(), pdepth.data() + nperf); @@ -796,9 +808,9 @@ namespace detail { - template + template void - BlackoilModelBase:: + BlackoilModelBase:: assemble(const ReservoirState& reservoir_state, WellState& well_state, const bool initial_assembly) @@ -874,9 +886,9 @@ namespace detail { - template + template void - BlackoilModelBase:: + BlackoilModelBase:: assembleMassBalanceEq(const SolutionState& state) { // Compute b_p and the accumulation term b_p*s_p for each phase, @@ -942,9 +954,10 @@ namespace detail { - template + template void - BlackoilModelBase::updateEquationsScaling() { + BlackoilModelBase:: + updateEquationsScaling() { ADB::V B; const Opm::PhaseUsage& pu = fluid_.phaseUsage(); for ( int idx=0; idx + template void - BlackoilModelBase::addWellContributionToMassBalanceEq(const std::vector& cq_s, - const SolutionState&, - const WellState&) + BlackoilModelBase:: + addWellContributionToMassBalanceEq(const std::vector& cq_s, + const SolutionState&, + const WellState&) { if ( !asImpl().localWellsActive() ) { @@ -1001,11 +1015,12 @@ namespace detail { - template + template void - BlackoilModelBase::extractWellPerfProperties(const SolutionState&, - std::vector& mob_perfcells, - std::vector& b_perfcells) const + BlackoilModelBase:: + extractWellPerfProperties(const SolutionState&, + std::vector& mob_perfcells, + std::vector& b_perfcells) const { // If we have wells, extract the mobilities and b-factors for // the well-perforated cells. @@ -1029,9 +1044,11 @@ namespace detail { - template - void BlackoilModelBase::addWellFluxEq(const std::vector& cq_s, - const SolutionState& state) + template + void + BlackoilModelBase:: + addWellFluxEq(const std::vector& cq_s, + const SolutionState& state) { if( !asImpl().localWellsActive() ) { @@ -1055,8 +1072,9 @@ namespace detail { - template - bool BlackoilModelBase::isVFPActive() const + template + bool BlackoilModelBase:: + isVFPActive() const { if( ! localWellsActive() ) { return false; @@ -1089,11 +1107,12 @@ namespace detail { - template - bool BlackoilModelBase::solveWellEq(const std::vector& mob_perfcells, - const std::vector& b_perfcells, - SolutionState& state, - WellState& well_state) + template + bool BlackoilModelBase:: + solveWellEq(const std::vector& mob_perfcells, + const std::vector& b_perfcells, + SolutionState& state, + WellState& well_state) { V aliveWells; const int np = wells().number_of_phases; @@ -1196,10 +1215,11 @@ namespace detail { - template - void BlackoilModelBase::addWellControlEq(const SolutionState& state, - const WellState& xw, - const V& aliveWells) + template + void BlackoilModelBase:: + addWellControlEq(const SolutionState& state, + const WellState& xw, + const V& aliveWells) { if( ! localWellsActive() ) return; @@ -1362,8 +1382,10 @@ namespace detail { - template - V BlackoilModelBase::solveJacobianSystem() const + template + V + BlackoilModelBase:: + solveJacobianSystem() const { return linsolver_.computeNewtonIncrement(residual_); } @@ -1473,10 +1495,12 @@ namespace detail { - template - void BlackoilModelBase::updateState(const V& dx, - ReservoirState& reservoir_state, - WellState& well_state) + template + void + BlackoilModelBase:: + updateState(const V& dx, + ReservoirState& reservoir_state, + WellState& well_state) { using namespace Opm::AutoDiffGrid; const int np = fluid_.numPhases(); @@ -1800,9 +1824,10 @@ namespace detail { - template + template std::vector - BlackoilModelBase::computeRelPerm(const SolutionState& state) const + BlackoilModelBase:: + computeRelPerm(const SolutionState& state) const { using namespace Opm::AutoDiffGrid; const int nc = numCells(grid_); @@ -1829,9 +1854,9 @@ namespace detail { - template + template std::vector - BlackoilModelBase:: + BlackoilModelBase:: computePressures(const ADB& po, const ADB& sw, const ADB& so, @@ -1866,12 +1891,13 @@ namespace detail { - template + template V - BlackoilModelBase::computeGasPressure(const V& po, - const V& sw, - const V& so, - const V& sg) const + BlackoilModelBase:: + computeGasPressure(const V& po, + const V& sw, + const V& so, + const V& sg) const { assert (active_[Gas]); std::vector cp = fluid_.capPress(ADB::constant(sw), @@ -1883,15 +1909,16 @@ namespace detail { - template + template void - BlackoilModelBase::computeMassFlux(const int actph , - const V& transi, - const ADB& kr , - const ADB& mu , - const ADB& rho , - const ADB& phasePressure, - const SolutionState& state) + BlackoilModelBase:: + computeMassFlux(const int actph , + const V& transi, + const ADB& kr , + const ADB& mu , + const ADB& rho , + const ADB& phasePressure, + const SolutionState& state) { // Compute and store mobilities. const ADB tr_mult = transMult(state.pressure); @@ -1916,9 +1943,10 @@ namespace detail { - template + template void - BlackoilModelBase::applyThresholdPressures(ADB& dp) + BlackoilModelBase:: + applyThresholdPressures(ADB& dp) { // We support reversible threshold pressures only. // Method: if the potential difference is lower (in absolute @@ -1948,9 +1976,10 @@ namespace detail { - template + template std::vector - BlackoilModelBase::computeResidualNorms() const + BlackoilModelBase:: + computeResidualNorms() const { std::vector residualNorms; @@ -1988,9 +2017,9 @@ namespace detail { } - template + template double - BlackoilModelBase:: + BlackoilModelBase:: relativeChange(const SimulationDataContainer& previous, const SimulationDataContainer& current ) const { @@ -2029,16 +2058,17 @@ namespace detail { } } - template + template double - BlackoilModelBase::convergenceReduction(const Eigen::Array& B, - const Eigen::Array& tempV, - const Eigen::Array& R, - std::vector& R_sum, - std::vector& maxCoeff, - std::vector& B_avg, - std::vector& maxNormWell, - int nc) const + BlackoilModelBase:: + convergenceReduction(const Eigen::Array& B, + const Eigen::Array& tempV, + const Eigen::Array& R, + std::vector& R_sum, + std::vector& maxCoeff, + std::vector& B_avg, + std::vector& maxNormWell, + int nc) const { const int np = asImpl().numPhases(); const int nm = asImpl().numMaterials(); @@ -2115,9 +2145,10 @@ namespace detail { - template + template bool - BlackoilModelBase::getConvergence(const double dt, const int iteration) + BlackoilModelBase:: + getConvergence(const double dt, const int iteration) { const double tol_mb = param_.tolerance_mb_; const double tol_cnv = param_.tolerance_cnv_; @@ -2239,9 +2270,10 @@ namespace detail { - template + template bool - BlackoilModelBase::getWellConvergence(const int iteration) + BlackoilModelBase:: + getWellConvergence(const int iteration) { const double tol_wells = param_.tolerance_wells_; @@ -2318,14 +2350,15 @@ namespace detail { - template + template ADB - BlackoilModelBase::fluidViscosity(const int phase, - const ADB& p , - const ADB& temp , - const ADB& rs , - const ADB& rv , - const std::vector& cond) const + BlackoilModelBase:: + fluidViscosity(const int phase, + const ADB& p , + const ADB& temp , + const ADB& rs , + const ADB& rv , + const std::vector& cond) const { switch (phase) { case Water: @@ -2343,14 +2376,15 @@ namespace detail { - template + template ADB - BlackoilModelBase::fluidReciprocFVF(const int phase, - const ADB& p , - const ADB& temp , - const ADB& rs , - const ADB& rv , - const std::vector& cond) const + BlackoilModelBase:: + fluidReciprocFVF(const int phase, + const ADB& p , + const ADB& temp , + const ADB& rs , + const ADB& rv , + const std::vector& cond) const { switch (phase) { case Water: @@ -2368,12 +2402,13 @@ namespace detail { - template + template ADB - BlackoilModelBase::fluidDensity(const int phase, - const ADB& b, - const ADB& rs, - const ADB& rv) const + BlackoilModelBase:: + fluidDensity(const int phase, + const ADB& b, + const ADB& rs, + const ADB& rv) const { const V& rhos = fluid_.surfaceDensity(phase, cells_); const Opm::PhaseUsage& pu = fluid_.phaseUsage(); @@ -2391,11 +2426,12 @@ namespace detail { - template + template V - BlackoilModelBase::fluidRsSat(const V& p, - const V& satOil, - const std::vector& cells) const + BlackoilModelBase:: + fluidRsSat(const V& p, + const V& satOil, + const std::vector& cells) const { return fluid_.rsSat(ADB::constant(p), ADB::constant(satOil), cells).value(); } @@ -2404,11 +2440,12 @@ namespace detail { - template + template ADB - BlackoilModelBase::fluidRsSat(const ADB& p, - const ADB& satOil, - const std::vector& cells) const + BlackoilModelBase:: + fluidRsSat(const ADB& p, + const ADB& satOil, + const std::vector& cells) const { return fluid_.rsSat(p, satOil, cells); } @@ -2417,11 +2454,12 @@ namespace detail { - template + template V - BlackoilModelBase::fluidRvSat(const V& p, - const V& satOil, - const std::vector& cells) const + BlackoilModelBase:: + fluidRvSat(const V& p, + const V& satOil, + const std::vector& cells) const { return fluid_.rvSat(ADB::constant(p), ADB::constant(satOil), cells).value(); } @@ -2430,11 +2468,12 @@ namespace detail { - template + template ADB - BlackoilModelBase::fluidRvSat(const ADB& p, - const ADB& satOil, - const std::vector& cells) const + BlackoilModelBase:: + fluidRvSat(const ADB& p, + const ADB& satOil, + const std::vector& cells) const { return fluid_.rvSat(p, satOil, cells); } @@ -2443,9 +2482,10 @@ namespace detail { - template + template ADB - BlackoilModelBase::poroMult(const ADB& p) const + BlackoilModelBase:: + poroMult(const ADB& p) const { const int n = p.size(); if (rock_comp_props_ && rock_comp_props_->isActive()) { @@ -2473,9 +2513,10 @@ namespace detail { - template + template ADB - BlackoilModelBase::transMult(const ADB& p) const + BlackoilModelBase:: + transMult(const ADB& p) const { const int n = p.size(); if (rock_comp_props_ && rock_comp_props_->isActive()) { @@ -2503,9 +2544,10 @@ namespace detail { - template + template void - BlackoilModelBase::classifyCondition(const ReservoirState& state) + BlackoilModelBase:: + classifyCondition(const ReservoirState& state) { using namespace Opm::AutoDiffGrid; const int nc = numCells(grid_); @@ -2543,9 +2585,10 @@ namespace detail { - template + template void - BlackoilModelBase::updatePrimalVariableFromState(const ReservoirState& state) + BlackoilModelBase:: + updatePrimalVariableFromState(const ReservoirState& state) { using namespace Opm::AutoDiffGrid; const int nc = numCells(grid_); @@ -2593,9 +2636,10 @@ namespace detail { /// Update the phaseCondition_ member based on the primalVariable_ member. - template + template void - BlackoilModelBase::updatePhaseCondFromPrimalVariable() + BlackoilModelBase:: + updatePhaseCondFromPrimalVariable() { if (! active_[Gas]) { OPM_THROW(std::logic_error, "updatePhaseCondFromPrimarVariable() logic requires active gas phase."); @@ -2633,10 +2677,11 @@ namespace detail { // TODO: only kept for now due to flow_multisegment // will be removed soon - template + template void - BlackoilModelBase::updateWellState(const V& dwells, - WellState& well_state) + BlackoilModelBase:: + updateWellState(const V& dwells, + WellState& well_state) { const double gravity = detail::getGravity(geo_.gravity(), UgGridHelpers::dimensions(grid_)); asImpl().stdWells().updateWellState(dwells, gravity, dpMaxRel(), fluid_.phaseUsage(),