Use multiple returns in init single well

This commit is contained in:
Joakim Hove committed 2021-11-01 16:02:34 +01:00
1 parent 2527970d11
commit 93218b05c2
1 file changed
+65 -61
+65 -61
View File
@@ -18,6 +18,7 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>. along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <fmt/format.h>
#include <config.h> #include <config.h>
#include <opm/simulators/wells/WellState.hpp> #include <opm/simulators/wells/WellState.hpp>
@@ -92,6 +93,15 @@ void WellState::initSingleWell(const std::vector<double>& cellPressures,
ws.status = Well::Status::OPEN; ws.status = Well::Status::OPEN;
} }
// Thp: assign thp equal to thp target/limit, if such a limit exists,
// otherwise keep it zero.
const bool has_thp = well.isInjector() ? inj_controls.hasControl(Well::InjectorCMode::THP)
: prod_controls.hasControl(Well::ProducerCMode::THP);
const double thp_limit = well.isInjector() ? inj_controls.thp_limit : prod_controls.thp_limit;
if (has_thp) {
ws.thp = thp_limit;
}
if (well.getStatus() == Well::Status::STOP) { if (well.getStatus() == Well::Status::STOP) {
// Stopped well: // Stopped well:
// 1. Rates: zero well rates. // 1. Rates: zero well rates.
@@ -103,7 +113,9 @@ void WellState::initSingleWell(const std::vector<double>& cellPressures,
} else { } else {
ws.bhp = global_pressure; ws.bhp = global_pressure;
} }
} else if (is_grup) { return;
}
if (is_grup) {
// Well under group control. // Well under group control.
// 1. Rates: zero well rates. // 1. Rates: zero well rates.
// 2. Bhp: initialize bhp to be a // 2. Bhp: initialize bhp to be a
@@ -112,80 +124,72 @@ void WellState::initSingleWell(const std::vector<double>& cellPressures,
// pressure in first perforation cell. // pressure in first perforation cell.
const double safety_factor = well.isInjector() ? 1.01 : 0.99; const double safety_factor = well.isInjector() ? 1.01 : 0.99;
ws.bhp = safety_factor * global_pressure; ws.bhp = safety_factor * global_pressure;
} else { return;
// Open well, under own control: }
// 1. Rates: initialize well rates to match
// controls if type is ORAT/GRAT/WRAT // Open well, under own control:
// (producer) or RATE (injector). // 1. Rates: initialize well rates to match
// Otherwise, we cannot set the correct // controls if type is ORAT/GRAT/WRAT
// value here and initialize to zero rate. // (producer) or RATE (injector).
if (well.isInjector()) { // Otherwise, we cannot set the correct
if (inj_controls.cmode == Well::InjectorCMode::RATE) { // value here and initialize to zero rate.
switch (inj_controls.injector_type) { if (well.isInjector()) {
case InjectorType::WATER: if (inj_controls.cmode == Well::InjectorCMode::RATE) {
assert(pu.phase_used[BlackoilPhases::Aqua]); switch (inj_controls.injector_type) {
ws.surface_rates[pu.phase_pos[BlackoilPhases::Aqua]] = inj_surf_rate; case InjectorType::WATER:
break;
case InjectorType::GAS:
assert(pu.phase_used[BlackoilPhases::Vapour]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Vapour]] = inj_surf_rate;
break;
case InjectorType::OIL:
assert(pu.phase_used[BlackoilPhases::Liquid]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Liquid]] = inj_surf_rate;
break;
case InjectorType::MULTI:
// Not currently handled, keep zero init.
break;
}
} else {
// Keep zero init.
}
} else {
// Note negative rates for producing wells.
switch (prod_controls.cmode) {
case Well::ProducerCMode::ORAT:
assert(pu.phase_used[BlackoilPhases::Liquid]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Liquid]] = -prod_controls.oil_rate;
break;
case Well::ProducerCMode::WRAT:
assert(pu.phase_used[BlackoilPhases::Aqua]); assert(pu.phase_used[BlackoilPhases::Aqua]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Aqua]] = -prod_controls.water_rate; ws.surface_rates[pu.phase_pos[BlackoilPhases::Aqua]] = inj_surf_rate;
break; break;
case Well::ProducerCMode::GRAT: case InjectorType::GAS:
assert(pu.phase_used[BlackoilPhases::Vapour]); assert(pu.phase_used[BlackoilPhases::Vapour]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Vapour]] = -prod_controls.gas_rate; ws.surface_rates[pu.phase_pos[BlackoilPhases::Vapour]] = inj_surf_rate;
break; break;
default: case InjectorType::OIL:
// Keep zero init. assert(pu.phase_used[BlackoilPhases::Liquid]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Liquid]] = inj_surf_rate;
break;
case InjectorType::MULTI:
// Not currently handled, keep zero init.
break; break;
} }
}
// 2. Bhp: initialize bhp to be target pressure if
// bhp-controlled well, otherwise set to a
// little above or below (depending on if
// the well is an injector or producer)
// pressure in first perforation cell.
if (is_bhp) {
ws.bhp = bhp_limit;
} else { } else {
const double safety_factor = well.isInjector() ? 1.01 : 0.99; // Keep zero init.
ws.bhp = safety_factor * global_pressure; }
} else {
// Note negative rates for producing wells.
switch (prod_controls.cmode) {
case Well::ProducerCMode::ORAT:
assert(pu.phase_used[BlackoilPhases::Liquid]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Liquid]] = -prod_controls.oil_rate;
break;
case Well::ProducerCMode::WRAT:
assert(pu.phase_used[BlackoilPhases::Aqua]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Aqua]] = -prod_controls.water_rate;
break;
case Well::ProducerCMode::GRAT:
assert(pu.phase_used[BlackoilPhases::Vapour]);
ws.surface_rates[pu.phase_pos[BlackoilPhases::Vapour]] = -prod_controls.gas_rate;
break;
default:
// Keep zero init.
break;
} }
} }
// 3. Thp: assign thp equal to thp target/limit, if such a limit exists, // 2. Bhp: initialize bhp to be target pressure if
// otherwise keep it zero. // bhp-controlled well, otherwise set to a
const bool has_thp = well.isInjector() ? inj_controls.hasControl(Well::InjectorCMode::THP) // little above or below (depending on if
: prod_controls.hasControl(Well::ProducerCMode::THP); // the well is an injector or producer)
const double thp_limit = well.isInjector() ? inj_controls.thp_limit : prod_controls.thp_limit; // pressure in first perforation cell.
if (has_thp) { if (is_bhp) {
ws.thp = thp_limit; ws.bhp = bhp_limit;
} else {
const double safety_factor = well.isInjector() ? 1.01 : 0.99;
ws.bhp = safety_factor * global_pressure;
} }
} }
void WellState::init(const std::vector<double>& cellPressures, void WellState::init(const std::vector<double>& cellPressures,
const Schedule& schedule, const Schedule& schedule,
const std::vector<Well>& wells_ecl, const std::vector<Well>& wells_ecl,