diff --git a/opm/autodiff/StandardWellsDense.hpp b/opm/autodiff/StandardWellsDense.hpp index a77ee6631..75ed4b1e6 100644 --- a/opm/autodiff/StandardWellsDense.hpp +++ b/opm/autodiff/StandardWellsDense.hpp @@ -374,6 +374,7 @@ enum WellVariablePositions { const int well_index, std::vector& well_flux) const; + double leastStrictBhpFromBhpLimits(const int well_index) const; }; diff --git a/opm/autodiff/StandardWellsDense_impl.hpp b/opm/autodiff/StandardWellsDense_impl.hpp index f0d2f4d42..13ffe1987 100644 --- a/opm/autodiff/StandardWellsDense_impl.hpp +++ b/opm/autodiff/StandardWellsDense_impl.hpp @@ -2806,4 +2806,61 @@ namespace Opm { } } + + + + + + template + double + StandardWellsDense:: + leastStrictBhpFromBhpLimits(const int well_index) const + { + double bhp; + + // type of the well, INJECTOR or PRODUCER + const WellType& well_type = wells().type[well_index]; + // initial bhp value, making the value not usable + switch(well_type) { + case INJECTOR: + bhp = std::numeric_limits::max(); + break; + case PRODUCER: + bhp = -std::numeric_limits::max(); + break; + default: + OPM_THROW(std::logic_error, "Expected PRODUCER or INJECTOR type for well " << wells().name[well_index]); + } + + // the well controls + const WellControls* well_control = wells().ctrls[well_index]; + // The number of the well controls/constraints + const int nwc = well_controls_get_num(well_control); + + for (int ctrl_index = 0; ctrl_index < nwc; ++ctrl_index) { + // finding a BHP constraint + if (well_controls_iget_type(well_control, ctrl_index) == BHP) { + // get the bhp constraint value, it should always be postive assummingly + const double bhp_target = well_controls_iget_target(well_control, ctrl_index); + + switch(well_type) { + case INJECTOR: // using the lower bhp contraint from Injectors + if (bhp_target < bhp) { + bhp = bhp_target; + } + break; + case PRODUCER: + if (bhp_target > bhp) { + bhp = bhp_target; + } + break; + default: + OPM_THROW(std::logic_error, "Expected PRODUCER or INJECTOR type for well " << wells().name[well_index]); + } // end of switch + } + } + + return bhp; + } + } // namespace Opm