Re-introducing throws on undefined nodes

This commit is contained in:
Vegard Kippe 2023-11-07 23:50:25 +01:00
parent 3519a3a9ab
commit f8a38064e1
2 changed files with 15 additions and 3 deletions

View File

@ -19,6 +19,7 @@
#include <algorithm>
#include <iterator>
#include <stdexcept>
#include <fmt/format.h>
#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
@ -132,7 +133,10 @@ void ExtNetwork::drop_branch(const std::string& uptree_node, const std::string&
std::optional<Branch> ExtNetwork::uptree_branch(const std::string& node) const {
if (!this->has_node(node)) return {};
if (!this->has_node(node)) {
auto msg = fmt::format("Requesting uptree branch of undefined node: {}", node);
throw std::out_of_range(msg);
}
std::vector<Branch> branches;
std::copy_if(this->m_branches.begin(), this->m_branches.end(), std::back_inserter(branches), [&node](const Branch& b) { return b.downtree_node() == node; });
@ -149,7 +153,10 @@ std::optional<Branch> ExtNetwork::uptree_branch(const std::string& node) const {
std::vector<Branch> ExtNetwork::downtree_branches(const std::string& node) const {
std::vector<Branch> branches;
if (!this->has_node(node)) return branches;
if (!this->has_node(node)) {
auto msg = fmt::format("Requesting downtree branches of undefined node: {}", node);
throw std::out_of_range(msg);
}
std::copy_if(this->m_branches.begin(), this->m_branches.end(), std::back_inserter(branches), [&node](const Branch& b) { return b.uptree_node() == node; });
return branches;

View File

@ -37,6 +37,7 @@
#include <opm/input/eclipse/Units/UnitSystem.hpp>
#include <opm/input/eclipse/Units/Units.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <algorithm>
#include <cstddef>
@ -246,6 +247,10 @@ double nodePressure(const Opm::Schedule& sched,
if (network.uptree_branch(node_name).has_value()) {
upt_br = network.uptree_branch(node_name).value();
} else {
auto msg = fmt::format("Node: {} does not belong to the network at report step: {} - node pressure set to zero.",
node_name,
lookup_step+1);
Opm::OpmLog::warning(msg);
return 0.0; // Subtree not belonging to the network right now
}
}
@ -409,7 +414,7 @@ int numberOfBranchesConnToNode(const Opm::Schedule& sched, const std::string& no
noBranches = (network.uptree_branch(nodeName).has_value()) ? noBranches+1 : noBranches;
return noBranches;
} else {
auto msg = fmt::format("Actual node: {} has not been defined at report time: {} ", nodeName, lookup_step+1);
auto msg = fmt::format("Trying to find number of branches connected to undefined node: {} at report time: {} ", nodeName, lookup_step+1);
throw std::logic_error(msg);
}
}