From c9604fae4758e90a7b3a673dbda41b664e691293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 3 May 2012 12:48:56 +0200 Subject: [PATCH 1/2] Fix recently created bug in append_well_controls(). --- opm/core/utility/newwells.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opm/core/utility/newwells.c b/opm/core/utility/newwells.c index 25692389..fadc2003 100644 --- a/opm/core/utility/newwells.c +++ b/opm/core/utility/newwells.c @@ -160,7 +160,7 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl) if (target != NULL) { ctrl->target = target; ok++; } if (distr != NULL) { ctrl->distr = distr ; ok++; } - if (ok == 2) { + if (ok == 3) { m = ctrl->data; for (c = m->cpty; c < nctrl; c++) { ctrl->type [c] = BHP; @@ -173,7 +173,7 @@ well_controls_reserve(int nctrl, int nphases, struct WellControls *ctrl) m->cpty = nctrl; } - return ok == 2; + return ok == 3; } From ccbb553a2b12708ee77b93564cd5bb9f64e2ee62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 3 May 2012 12:49:37 +0200 Subject: [PATCH 2/2] Fix bug in use of perforation data, and check that well contstruction calls succeed. --- opm/core/WellsManager.cpp | 73 ++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/opm/core/WellsManager.cpp b/opm/core/WellsManager.cpp index 5a8b75c6..9ce6ff10 100644 --- a/opm/core/WellsManager.cpp +++ b/opm/core/WellsManager.cpp @@ -367,14 +367,17 @@ namespace Opm std::vector perf_cells(w_num_perf); std::vector perf_prodind(w_num_perf); for (int perf = 0; perf < w_num_perf; ++perf) { - perf_cells[0] = wellperf_data[w][perf].cell; - perf_prodind[0] = wellperf_data[w][perf].well_index; + perf_cells[perf] = wellperf_data[w][perf].cell; + perf_prodind[perf] = wellperf_data[w][perf].well_index; } const double* comp_frac = NULL; // We initialize all wells with a null component fraction, // and must (for injection wells) overwrite it later. - add_well(well_data[w].type, well_data[w].reference_bhp_depth, w_num_perf, - comp_frac, &perf_cells[0], &perf_prodind[0], w_); + int ok = add_well(well_data[w].type, well_data[w].reference_bhp_depth, w_num_perf, + comp_frac, &perf_cells[0], &perf_prodind[0], w_); + if (!ok) { + THROW("Failed adding well " << well_names[w] << " to Wells data structure."); + } } // Get WCONINJE data, add injection controls to wells. @@ -400,27 +403,31 @@ namespace Opm } // Add all controls that are present in well. + int ok = 1; int control_pos[5] = { -1, -1, -1, -1, -1 }; - if (wci_line.surface_flow_max_rate_ > 0.0) { + if (ok && wci_line.surface_flow_max_rate_ > 0.0) { control_pos[InjectionControl::RATE] = w_->ctrls[wix]->num; const double distr[3] = { 1.0, 1.0, 1.0 }; - append_well_controls(SURFACE_RATE, wci_line.surface_flow_max_rate_, - distr, wix, w_); + ok = append_well_controls(SURFACE_RATE, wci_line.surface_flow_max_rate_, + distr, wix, w_); } - if (wci_line.reservoir_flow_max_rate_ > 0.0) { + if (ok && wci_line.reservoir_flow_max_rate_ > 0.0) { control_pos[InjectionControl::RESV] = w_->ctrls[wix]->num; const double distr[3] = { 1.0, 1.0, 1.0 }; - append_well_controls(RESERVOIR_RATE, wci_line.reservoir_flow_max_rate_, - distr, wix, w_); + ok = append_well_controls(RESERVOIR_RATE, wci_line.reservoir_flow_max_rate_, + distr, wix, w_); } - if (wci_line.BHP_limit_ > 0.0) { + if (ok && wci_line.BHP_limit_ > 0.0) { control_pos[InjectionControl::BHP] = w_->ctrls[wix]->num; - append_well_controls(BHP, wci_line.BHP_limit_, - NULL, wix, w_); + ok = append_well_controls(BHP, wci_line.BHP_limit_, + NULL, wix, w_); } - if (wci_line.THP_limit_ > 0.0) { + if (ok && wci_line.THP_limit_ > 0.0) { THROW("We cannot handle THP limit for well " << well_names[wix]); } + if (!ok) { + THROW("Failure occured appending controls for well " << well_names[wix]); + } InjectionControl::Mode mode = InjectionControl::mode(wci_line.control_mode_); const int cpos = control_pos[mode]; if (cpos == -1 && mode != InjectionControl::GRUP) { @@ -477,37 +484,38 @@ namespace Opm } // Add all controls that are present in well. int control_pos[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 }; - if (wcp_line.oil_max_rate_ > 0.0) { + int ok = 1; + if (ok && wcp_line.oil_max_rate_ > 0.0) { if (!pu.phase_used[BlackoilPhases::Liquid]) { THROW("Oil phase not active and ORAT control specified."); } control_pos[ProductionControl::ORAT] = w_->ctrls[wix]->num; double distr[3] = { 0.0, 0.0, 0.0 }; distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0; - append_well_controls(SURFACE_RATE, wcp_line.oil_max_rate_, - distr, wix, w_); + ok = append_well_controls(SURFACE_RATE, wcp_line.oil_max_rate_, + distr, wix, w_); } - if (wcp_line.water_max_rate_ > 0.0) { + if (ok && wcp_line.water_max_rate_ > 0.0) { if (!pu.phase_used[BlackoilPhases::Aqua]) { THROW("Water phase not active and WRAT control specified."); } control_pos[ProductionControl::WRAT] = w_->ctrls[wix]->num; double distr[3] = { 0.0, 0.0, 0.0 }; distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0; - append_well_controls(SURFACE_RATE, wcp_line.water_max_rate_, - distr, wix, w_); + ok = append_well_controls(SURFACE_RATE, wcp_line.water_max_rate_, + distr, wix, w_); } - if (wcp_line.gas_max_rate_ > 0.0) { + if (ok && wcp_line.gas_max_rate_ > 0.0) { if (!pu.phase_used[BlackoilPhases::Vapour]) { THROW("Gas phase not active and GRAT control specified."); } control_pos[ProductionControl::GRAT] = w_->ctrls[wix]->num; double distr[3] = { 0.0, 0.0, 0.0 }; distr[pu.phase_pos[BlackoilPhases::Vapour]] = 1.0; - append_well_controls(SURFACE_RATE, wcp_line.gas_max_rate_, - distr, wix, w_); + ok = append_well_controls(SURFACE_RATE, wcp_line.gas_max_rate_, + distr, wix, w_); } - if (wcp_line.liquid_max_rate_ > 0.0) { + if (ok && wcp_line.liquid_max_rate_ > 0.0) { if (!pu.phase_used[BlackoilPhases::Aqua]) { THROW("Water phase not active and LRAT control specified."); } @@ -518,23 +526,26 @@ namespace Opm double distr[3] = { 0.0, 0.0, 0.0 }; distr[pu.phase_pos[BlackoilPhases::Aqua]] = 1.0; distr[pu.phase_pos[BlackoilPhases::Liquid]] = 1.0; - append_well_controls(SURFACE_RATE, wcp_line.liquid_max_rate_, - distr, wix, w_); + ok = append_well_controls(SURFACE_RATE, wcp_line.liquid_max_rate_, + distr, wix, w_); } - if (wcp_line.reservoir_flow_max_rate_ > 0.0) { + if (ok && wcp_line.reservoir_flow_max_rate_ > 0.0) { control_pos[ProductionControl::RESV] = w_->ctrls[wix]->num; double distr[3] = { 1.0, 1.0, 1.0 }; - append_well_controls(RESERVOIR_RATE, wcp_line.reservoir_flow_max_rate_, + ok = append_well_controls(RESERVOIR_RATE, wcp_line.reservoir_flow_max_rate_, distr, wix, w_); } - if (wcp_line.BHP_limit_ > 0.0) { + if (ok && wcp_line.BHP_limit_ > 0.0) { control_pos[ProductionControl::BHP] = w_->ctrls[wix]->num; - append_well_controls(BHP, wcp_line.BHP_limit_, + ok = append_well_controls(BHP, wcp_line.BHP_limit_, NULL, wix, w_); } - if (wcp_line.THP_limit_ > 0.0) { + if (ok && wcp_line.THP_limit_ > 0.0) { THROW("We cannot handle THP limit for well " << well_names[wix]); } + if (!ok) { + THROW("Failure occured appending controls for well " << well_names[wix]); + } ProductionControl::Mode mode = ProductionControl::mode(wcp_line.control_mode_); const int cpos = control_pos[mode]; if (cpos == -1 && mode != ProductionControl::GRUP) {