From 011143829d38ae53315aa5f8281554e94e629636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Petter=20=C3=98ren=20Hauge?= Date: Tue, 13 Feb 2018 15:32:24 +0100 Subject: [PATCH] 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 --- opm/core/wells/WellsManager.cpp | 4 ++-- opm/core/wells/WellsManager_impl.hpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/opm/core/wells/WellsManager.cpp b/opm/core/wells/WellsManager.cpp index 663ae1a65..e37eeb42c 100644 --- a/opm/core/wells/WellsManager.cpp +++ b/opm/core/wells/WellsManager.cpp @@ -315,7 +315,7 @@ namespace Opm /// Default constructor. 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 size_t timeStep, 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 whether this is the correct thing to do here. diff --git a/opm/core/wells/WellsManager_impl.hpp b/opm/core/wells/WellsManager_impl.hpp index fbb58b837..d310a15c4 100644 --- a/opm/core/wells/WellsManager_impl.hpp +++ b/opm/core/wells/WellsManager_impl.hpp @@ -260,13 +260,15 @@ void WellsManager::createWellsFromSpecs(std::vector& wells, size_t for (int w = 0; w < num_wells; ++w) { num_perfs += wellperf_data[w].size(); } - // Create the well data structures. - w_ = create_wells(phaseUsage.num_phases, num_wells, num_perfs); - if (!w_) { + struct Wells* w = create_wells(phaseUsage.num_phases, num_wells, num_perfs); + + if (!w) { OPM_THROW(std::runtime_error, "Failed creating Wells struct."); } + std::swap( w, w_ ); + destroy_wells( w ); // Add wells. for (int w = 0; w < num_wells; ++w) { @@ -320,7 +322,7 @@ WellsManager(const Opm::EclipseState& eclipseState, const DynamicListEconLimited& list_econ_limited, bool is_parallel_run, const std::unordered_set& 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, cart_dims, dimensions,