Don't crash on models without wells.

The user will legitimately want to run models that do not specify wells
(e.g., using boundary conditions).  While we do not yet fully support
that configuration (no wells), we absolutely must not crash by
dereferencing null pointers or generating pointers into ::empty()
std::vector<>s.

This commit installs the required guards needed to avoid said failure
mode.
This commit is contained in:
Bård Skaflestad 2012-09-20 15:03:38 +02:00
parent fa6b772972
commit bdcd5236bd

View File

@ -123,7 +123,7 @@ namespace Opm
WellState& well_state) WellState& well_state)
{ {
const int nc = grid_.number_of_cells; const int nc = grid_.number_of_cells;
const int nw = wells_->number_of_wells; const int nw = (wells_ != 0) ? wells_->number_of_wells : 0;
// Set up dynamic data. // Set up dynamic data.
computePerSolveDynamicData(dt, state, well_state); computePerSolveDynamicData(dt, state, well_state);
@ -454,8 +454,8 @@ namespace Opm
// std::vector<double> wellperf_A_; // std::vector<double> wellperf_A_;
// std::vector<double> wellperf_phasemob_; // std::vector<double> wellperf_phasemob_;
const int np = props_.numPhases(); const int np = props_.numPhases();
const int nw = wells_->number_of_wells; const int nw = (wells_ != 0) ? wells_->number_of_wells : 0;
const int nperf = wells_->well_connpos[nw]; const int nperf = (wells_ != 0) ? wells_->well_connpos[nw] : 0;
wellperf_A_.resize(nperf*np*np); wellperf_A_.resize(nperf*np*np);
wellperf_phasemob_.resize(nperf*np); wellperf_phasemob_.resize(nperf*np);
// The A matrix is set equal to the perforation grid cells' // The A matrix is set equal to the perforation grid cells'
@ -512,9 +512,9 @@ namespace Opm
const double* z = &state.surfacevol()[0]; const double* z = &state.surfacevol()[0];
UnstructuredGrid* gg = const_cast<UnstructuredGrid*>(&grid_); UnstructuredGrid* gg = const_cast<UnstructuredGrid*>(&grid_);
CompletionData completion_data; CompletionData completion_data;
completion_data.gpot = &wellperf_gpot_[0]; completion_data.gpot = ! wellperf_gpot_.empty() ? &wellperf_gpot_[0] : 0;
completion_data.A = &wellperf_A_[0]; completion_data.A = ! wellperf_A_.empty() ? &wellperf_A_[0] : 0;
completion_data.phasemob = &wellperf_phasemob_[0]; completion_data.phasemob = ! wellperf_phasemob_.empty() ? &wellperf_phasemob_[0] : 0;
cfs_tpfa_res_wells wells_tmp; cfs_tpfa_res_wells wells_tmp;
wells_tmp.W = const_cast<Wells*>(wells_); wells_tmp.W = const_cast<Wells*>(wells_);
wells_tmp.data = &completion_data; wells_tmp.data = &completion_data;
@ -599,9 +599,9 @@ namespace Opm
{ {
UnstructuredGrid* gg = const_cast<UnstructuredGrid*>(&grid_); UnstructuredGrid* gg = const_cast<UnstructuredGrid*>(&grid_);
CompletionData completion_data; CompletionData completion_data;
completion_data.gpot = const_cast<double*>(&wellperf_gpot_[0]); completion_data.gpot = ! wellperf_gpot_.empty() ? const_cast<double*>(&wellperf_gpot_[0]) : 0;
completion_data.A = const_cast<double*>(&wellperf_A_[0]); completion_data.A = ! wellperf_A_.empty() ? const_cast<double*>(&wellperf_A_[0]) : 0;
completion_data.phasemob = const_cast<double*>(&wellperf_phasemob_[0]); completion_data.phasemob = ! wellperf_phasemob_.empty() ? const_cast<double*>(&wellperf_phasemob_[0]) : 0;
cfs_tpfa_res_wells wells_tmp; cfs_tpfa_res_wells wells_tmp;
wells_tmp.W = const_cast<Wells*>(wells_); wells_tmp.W = const_cast<Wells*>(wells_);
wells_tmp.data = &completion_data; wells_tmp.data = &completion_data;
@ -609,6 +609,9 @@ namespace Opm
forces.wells = &wells_tmp; forces.wells = &wells_tmp;
forces.src = NULL; forces.src = NULL;
double* wpress = ! well_state.bhp ().empty() ? & well_state.bhp ()[0] : 0;
double* wflux = ! well_state.perfRates().empty() ? & well_state.perfRates()[0] : 0;
cfs_tpfa_res_flux(gg, cfs_tpfa_res_flux(gg,
&forces, &forces,
props_.numPhases(), props_.numPhases(),
@ -617,9 +620,9 @@ namespace Opm
&face_phasemob_[0], &face_phasemob_[0],
&face_gravcap_[0], &face_gravcap_[0],
&state.pressure()[0], &state.pressure()[0],
&well_state.bhp()[0], wpress,
&state.faceflux()[0], &state.faceflux()[0],
&well_state.perfRates()[0]); wflux);
cfs_tpfa_res_fpress(gg, cfs_tpfa_res_fpress(gg,
props_.numPhases(), props_.numPhases(),
&htrans_[0], &htrans_[0],