From 182c5897c8de548df43b58d42ca2b61dd3d7fdfa Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Fri, 31 Mar 2017 16:30:25 +0200 Subject: [PATCH] adding leastStrictBhpFromBhpLimits() to pick the least strict bhp limits in the well controls. It is used to calculate the well potential when there is no thp limits there. If there is thp limits there, it will be used for further chosing of the bhp value for well potential calculation. --- opm/autodiff/StandardWellsDense.hpp | 1 + opm/autodiff/StandardWellsDense_impl.hpp | 57 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+) 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