diff --git a/opm/autodiff/BlackoilModelBase.hpp b/opm/autodiff/BlackoilModelBase.hpp index 00af3c86e..60870a69c 100644 --- a/opm/autodiff/BlackoilModelBase.hpp +++ b/opm/autodiff/BlackoilModelBase.hpp @@ -374,6 +374,8 @@ namespace Opm { bool getWellConvergence(const int iteration); + bool isVFPActive(const WellState& well_state) const; + std::vector computePressures(const ADB& po, const ADB& sw, diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index eb7e1a872..c13bf662d 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -774,17 +774,14 @@ namespace detail { { using namespace Opm::AutoDiffGrid; - if (true) { - // Create the primary variables. + // If we have VFP tables, we need the well connection + // pressures for the "simple" hydrostatic correction + // between well depth and vfp table depth. + if (isVFPActive(well_state)) { SolutionState state = asImpl().variableState(reservoir_state, well_state); - - if (true || initial_assembly) { - // Create the (constant, derivativeless) initial state. - SolutionState state0 = state; - asImpl().makeConstantState(state0); - computeWellConnectionPressures(state0, well_state); - } - + SolutionState state0 = state; + asImpl().makeConstantState(state0); + computeWellConnectionPressures(state0, well_state); } // Possibly switch well controls and updating well state to @@ -845,7 +842,7 @@ namespace detail { asImpl().updatePerfPhaseRatesAndPressures(cq_s, state, well_state); asImpl().addWellFluxEq(cq_s, state); asImpl().addWellContributionToMassBalanceEq(cq_s, state, well_state); - addWellControlEq(state, well_state, aliveWells); + addWellControlEq(state, well_state, aliveWells); } @@ -1211,6 +1208,37 @@ namespace detail { } //Namespace + template + bool BlackoilModelBase::isVFPActive(const WellState& xw) const + { + if( ! wellsActive() ) { + return false; + } + + if ( vfp_properties_->getProd()->empty() && vfp_properties_->getInj()->empty() ) { + return false; + } + + const int nw = wells().number_of_wells; + //Loop over all wells + for (int w = 0; w < nw; ++w) { + const WellControls* wc = wells().ctrls[w]; + + const int nwc = well_controls_get_num(wc); + + //Loop over all controls + for (int c=0; c < nwc; ++c) { + const WellControlType ctrl_type = well_controls_iget_type(wc, c); + + if (ctrl_type == THP) { + return true; + } + } + } + + return false; + } + template void BlackoilModelBase::updateWellControls(WellState& xw) const diff --git a/opm/autodiff/VFPInjProperties.hpp b/opm/autodiff/VFPInjProperties.hpp index 42bbe8fba..c097aeba3 100644 --- a/opm/autodiff/VFPInjProperties.hpp +++ b/opm/autodiff/VFPInjProperties.hpp @@ -132,6 +132,13 @@ public: */ const VFPInjTable* getTable(const int table_id) const; + /** + * Returns true if no vfp tables are in the current map + */ + inline const bool empty() const { + return m_tables.empty(); + } + private: // Map which connects the table number with the table itself std::map m_tables; diff --git a/opm/autodiff/VFPProdProperties.hpp b/opm/autodiff/VFPProdProperties.hpp index 877b51de3..cd117f779 100644 --- a/opm/autodiff/VFPProdProperties.hpp +++ b/opm/autodiff/VFPProdProperties.hpp @@ -143,6 +143,13 @@ public: */ const VFPProdTable* getTable(const int table_id) const; + /** + * Returns true if no vfp tables are in the current map + */ + inline const bool empty() const { + return m_tables.empty(); + } + private: // Map which connects the table number with the table itself std::map m_tables; diff --git a/opm/autodiff/VFPProperties.hpp b/opm/autodiff/VFPProperties.hpp index 0a289bd69..6387638e3 100644 --- a/opm/autodiff/VFPProperties.hpp +++ b/opm/autodiff/VFPProperties.hpp @@ -58,14 +58,14 @@ public: /** * Returns the VFP properties for injection wells */ - const VFPInjProperties* getInj() const { + inline const VFPInjProperties* getInj() const { return m_inj.get(); } /** * Returns the VFP properties for production wells */ - const VFPProdProperties* getProd() const { + inline const VFPProdProperties* getProd() const { return m_prod.get(); }