diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index 99ecd8a29..b447d985c 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -223,7 +223,7 @@ namespace detail { // TODO: put this for now to avoid modify the following code. // TODO: this code can be fragile. - const Wells* wells_arg = &(asImpl().well_model_.wells()); + const Wells* wells_arg = asImpl().well_model_.wellsPointer(); #if HAVE_MPI if ( linsolver_.parallelInformation().type() == typeid(ParallelISTLInformation) ) diff --git a/opm/autodiff/MultisegmentWells.cpp b/opm/autodiff/MultisegmentWells.cpp index 5a98b201e..7cb88b49b 100644 --- a/opm/autodiff/MultisegmentWells.cpp +++ b/opm/autodiff/MultisegmentWells.cpp @@ -294,6 +294,12 @@ namespace Opm { } + const Wells* + MultisegmentWells::wellsPointer() const + { + return wells_; + } + diff --git a/opm/autodiff/MultisegmentWells.hpp b/opm/autodiff/MultisegmentWells.hpp index e1e9976ba..0d8e5aece 100644 --- a/opm/autodiff/MultisegmentWells.hpp +++ b/opm/autodiff/MultisegmentWells.hpp @@ -102,6 +102,8 @@ namespace Opm { const Wells& wells() const; + const Wells* wellsPointer() const; + int numPhases() const { return num_phases_; }; int numWells() const { return wells_multisegment_.size(); } diff --git a/opm/autodiff/StandardWells.hpp b/opm/autodiff/StandardWells.hpp index 5a1cfe10f..7b367f43a 100644 --- a/opm/autodiff/StandardWells.hpp +++ b/opm/autodiff/StandardWells.hpp @@ -70,10 +70,12 @@ namespace Opm { const WellOps& wellOps() const; - int numPhases() const { return num_phases_; }; + int numPhases() const { return wells().number_of_phases; }; const Wells& wells() const; + const Wells* wellsPointer() const; + /// return true if wells are available in the reservoir bool wellsActive() const; void setWellsActive(const bool wells_active); @@ -172,7 +174,6 @@ namespace Opm { bool wells_active_; const Wells* wells_; const WellOps wops_; - const int num_phases_; const BlackoilPropsAdInterface* fluid_; const std::vector* active_; diff --git a/opm/autodiff/StandardWells_impl.hpp b/opm/autodiff/StandardWells_impl.hpp index 056290388..ccbea3c42 100644 --- a/opm/autodiff/StandardWells_impl.hpp +++ b/opm/autodiff/StandardWells_impl.hpp @@ -72,9 +72,9 @@ namespace Opm StandardWells::StandardWells(const Wells* wells_arg) - : wells_(wells_arg) + : wells_active_(wells_arg!=nullptr) + , wells_(wells_arg) , wops_(wells_arg) - , num_phases_(wells_arg->number_of_phases) , fluid_(nullptr) , active_(nullptr) , phase_condition_(nullptr) @@ -116,6 +116,10 @@ namespace Opm } + const Wells* StandardWells::wellsPointer() const + { + return wells_; + } @@ -149,8 +153,13 @@ namespace Opm int StandardWells::numWellVars() const { + if ( !localWellsActive() ) + { + return 0; + } + // For each well, we have a bhp variable, and one flux per phase. - const int nw = localWellsActive() ? wells().number_of_wells : 0; + const int nw = wells().number_of_wells; return (numPhases() + 1) * nw; } @@ -365,9 +374,10 @@ namespace Opm return; } else { const std::vector& well_cells = wellOps().well_cells; - mob_perfcells.resize(num_phases_, ADB::null()); - b_perfcells.resize(num_phases_, ADB::null()); - for (int phase = 0; phase < num_phases_; ++phase) { + const int num_phases = wells().number_of_phases; + mob_perfcells.resize(num_phases, ADB::null()); + b_perfcells.resize(num_phases, ADB::null()); + for (int phase = 0; phase < num_phases; ++phase) { mob_perfcells[phase] = subset(rq[phase].mob, well_cells); b_perfcells[phase] = subset(rq[phase].b, well_cells); } @@ -390,7 +400,7 @@ namespace Opm { if( ! localWellsActive() ) return ; - const int np = num_phases_; + const int np = wells().number_of_phases; const int nw = wells().number_of_wells; const int nperf = wells().well_connpos[nw]; Vector Tw = Eigen::Map(wells().WI, nperf); @@ -603,7 +613,7 @@ namespace Opm { if( localWellsActive() ) { - const int np = num_phases_; + const int np = wells().number_of_phases; const int nw = wells().number_of_wells; // Extract parts of dwells corresponding to each part.