From 6e4f9e708e21de6bb8e05ef819449dbac8b9a9c1 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Wed, 16 Nov 2016 14:27:15 +0100 Subject: [PATCH] rewriting the findWellNode function with assuming we should always find the well in the well collection. --- opm/core/wells/WellCollection.cpp | 11 ++++++----- opm/core/wells/WellCollection.hpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/opm/core/wells/WellCollection.cpp b/opm/core/wells/WellCollection.cpp index bd4f250e..ca954f17 100644 --- a/opm/core/wells/WellCollection.cpp +++ b/opm/core/wells/WellCollection.cpp @@ -117,18 +117,19 @@ namespace Opm } - WellNode* WellCollection::findWellNode(const std::string& name) const + WellNode& WellCollection::findWellNode(const std::string& name) const { auto well_node = std::find_if(leaf_nodes_.begin(), leaf_nodes_.end(), [&] ( WellNode* w) { return w->name() == name; }); - if (well_node != leaf_nodes_.end()) { - return *well_node; - } else { - return nullptr; + // Does not find the well + if (well_node == leaf_nodes_.end()) { + OPM_THROW(std::runtime_error, "Could not find well " << name << " in the well collection!\n"); } + + return *(*well_node); } /// Adds the child to the collection diff --git a/opm/core/wells/WellCollection.hpp b/opm/core/wells/WellCollection.hpp index 32b05e81..071e4851 100644 --- a/opm/core/wells/WellCollection.hpp +++ b/opm/core/wells/WellCollection.hpp @@ -96,7 +96,7 @@ namespace Opm const WellsGroupInterface* findNode(const std::string& name) const; - WellNode* findWellNode(const std::string& name) const; + WellNode& findWellNode(const std::string& name) const; /// Applies all group controls (injection and production)