Allow Wells struct initialization without wells

Calling wells()->number_of_wells on nullptr causes segmentation fault. This
occurs when running a deck without wells. Allowing WellsManager::init to
continue for decks without wells enables the well struct to be set.

Authored by Sveinung Rundhovde & Lars Petter Hauge
This commit is contained in:
Lars Petter Øren Hauge 2018-02-13 15:32:24 +01:00
parent 5ac22e9f42
commit 011143829d
2 changed files with 8 additions and 6 deletions

View File

@ -315,7 +315,7 @@ namespace Opm
/// Default constructor. /// Default constructor.
WellsManager::WellsManager() WellsManager::WellsManager()
: w_(0), is_parallel_run_(false) : w_(create_wells(0,0,0)), is_parallel_run_(false)
{ {
} }
@ -330,7 +330,7 @@ namespace Opm
const Opm::Schedule& schedule, const Opm::Schedule& schedule,
const size_t timeStep, const size_t timeStep,
const UnstructuredGrid& grid) const UnstructuredGrid& grid)
: w_(0), is_parallel_run_(false) : w_(create_wells(0,0,0)), is_parallel_run_(false)
{ {
// TODO: not sure about the usage of this WellsManager constructor // TODO: not sure about the usage of this WellsManager constructor
// TODO: not sure whether this is the correct thing to do here. // TODO: not sure whether this is the correct thing to do here.

View File

@ -260,13 +260,15 @@ void WellsManager::createWellsFromSpecs(std::vector<const Well*>& wells, size_t
for (int w = 0; w < num_wells; ++w) { for (int w = 0; w < num_wells; ++w) {
num_perfs += wellperf_data[w].size(); num_perfs += wellperf_data[w].size();
} }
// Create the well data structures. // Create the well data structures.
w_ = create_wells(phaseUsage.num_phases, num_wells, num_perfs); struct Wells* w = create_wells(phaseUsage.num_phases, num_wells, num_perfs);
if (!w_) {
if (!w) {
OPM_THROW(std::runtime_error, "Failed creating Wells struct."); OPM_THROW(std::runtime_error, "Failed creating Wells struct.");
} }
std::swap( w, w_ );
destroy_wells( w );
// Add wells. // Add wells.
for (int w = 0; w < num_wells; ++w) { for (int w = 0; w < num_wells; ++w) {
@ -320,7 +322,7 @@ WellsManager(const Opm::EclipseState& eclipseState,
const DynamicListEconLimited& list_econ_limited, const DynamicListEconLimited& list_econ_limited,
bool is_parallel_run, bool is_parallel_run,
const std::unordered_set<std::string>& deactivated_wells) const std::unordered_set<std::string>& deactivated_wells)
: w_(0), is_parallel_run_(is_parallel_run) : w_(create_wells(0,0,0)), is_parallel_run_(is_parallel_run)
{ {
init(eclipseState, schedule, timeStep, number_of_cells, global_cell, init(eclipseState, schedule, timeStep, number_of_cells, global_cell,
cart_dims, dimensions, cart_dims, dimensions,