Addressing review comments, in particular, ensuring that extended network is not updated with a GRUPTREE update.
This commit is contained in:
parent
4192c19d3c
commit
0ae1588e00
@ -45,7 +45,7 @@ public:
|
||||
|
||||
const std::string& downtree_node() const;
|
||||
const std::string& uptree_node() const;
|
||||
void set_uptree_node(const std::string& new_uptree_node) { m_uptree_node = new_uptree_node; }
|
||||
void set_uptree_node(const std::string& new_uptree_node);
|
||||
std::optional<int> vfp_table() const;
|
||||
AlqEQ alq_eq() const;
|
||||
std::optional<double> alq_value() const;
|
||||
|
@ -37,6 +37,8 @@ class ExtNetwork {
|
||||
public:
|
||||
ExtNetwork() = default;
|
||||
bool active() const;
|
||||
bool is_standard_network() const;
|
||||
void set_standard_network(bool is_standard_network);
|
||||
void add_branch(Branch branch);
|
||||
void add_or_replace_branch(Branch branch);
|
||||
void drop_branch(const std::string& uptree_node, const std::string& downtree_node);
|
||||
@ -44,7 +46,6 @@ public:
|
||||
void update_node(Node node);
|
||||
const Node& node(const std::string& name) const;
|
||||
const Node& root() const;
|
||||
bool is_disconnected(const std::string& node) const;
|
||||
std::vector<Branch> downtree_branches(const std::string& node) const;
|
||||
std::vector<const Branch*> branches() const;
|
||||
std::optional<Branch> uptree_branch(const std::string& node) const;
|
||||
@ -60,12 +61,14 @@ public:
|
||||
serializer(m_branches);
|
||||
serializer(insert_indexed_node_names);
|
||||
serializer(m_nodes);
|
||||
serializer(m_is_standard_network);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Branch> m_branches;
|
||||
std::vector<std::string> insert_indexed_node_names;
|
||||
std::map<std::string, Node> m_nodes;
|
||||
bool m_is_standard_network{false};
|
||||
bool has_indexed_node_name(const std::string& name) const;
|
||||
void add_indexed_node_name(std::string name);
|
||||
};
|
||||
|
@ -167,7 +167,11 @@ namespace {
|
||||
|
||||
void Schedule::handleBRANPROP(HandlerContext& handlerContext) {
|
||||
auto ext_network = this->snapshots.back().network.get();
|
||||
|
||||
if (ext_network.active() && ext_network.is_standard_network()) {
|
||||
std::string msg = "Cannot have standard and extended network defined simultaneously.";
|
||||
throw OpmInputError(msg, handlerContext.keyword.location());
|
||||
}
|
||||
ext_network.set_standard_network(false);
|
||||
for (const auto& record : handlerContext.keyword) {
|
||||
const auto& downtree_node = record.getItem<ParserKeywords::BRANPROP::DOWNTREE_NODE>().get<std::string>(0);
|
||||
const auto& uptree_node = record.getItem<ParserKeywords::BRANPROP::UPTREE_NODE>().get<std::string>(0);
|
||||
@ -828,6 +832,11 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno)
|
||||
|
||||
void Schedule::handleGRUPNET(HandlerContext& handlerContext) {
|
||||
auto network = this->snapshots.back().network.get();
|
||||
if (network.active() && !network.is_standard_network()) {
|
||||
std::string msg = "Cannot have standard and extended network defined simultaneously.";
|
||||
throw OpmInputError(msg, handlerContext.keyword.location());
|
||||
}
|
||||
network.set_standard_network(true);
|
||||
std::vector<Network::Node> nodes;
|
||||
for (const auto& record : handlerContext.keyword) {
|
||||
const std::string& groupNamePattern = record.getItem<ParserKeywords::GRUPNET::NAME>().getTrimmedString(0);
|
||||
@ -993,6 +1002,10 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno)
|
||||
|
||||
void Schedule::handleNODEPROP(HandlerContext& handlerContext) {
|
||||
auto ext_network = this->snapshots.back().network.get();
|
||||
if (ext_network.active() && ext_network.is_standard_network()) {
|
||||
std::string msg = "Cannot have standard and extended network defined simultaneously.";
|
||||
throw OpmInputError(msg, handlerContext.keyword.location());
|
||||
}
|
||||
|
||||
for (const auto& record : handlerContext.keyword) {
|
||||
const auto& name = record.getItem<ParserKeywords::NODEPROP::NAME>().get<std::string>(0);
|
||||
|
@ -65,6 +65,10 @@ const std::string& Branch::downtree_node() const {
|
||||
return this->m_downtree_node;
|
||||
}
|
||||
|
||||
void Branch::set_uptree_node(const std::string& new_uptree_node) {
|
||||
this->m_uptree_node = new_uptree_node;
|
||||
}
|
||||
|
||||
bool Branch::operator==(const Branch& other) const {
|
||||
return this->m_downtree_node == other.m_downtree_node &&
|
||||
this->m_uptree_node == other.m_uptree_node &&
|
||||
|
@ -30,6 +30,7 @@ ExtNetwork ExtNetwork::serializationTestObject() {
|
||||
object.m_branches = {Branch::serializationTestObject()};
|
||||
object.insert_indexed_node_names = {"test1", "test2"};
|
||||
object.m_nodes = {{"test3", Node::serializationTestObject()}};
|
||||
object.m_is_standard_network = false;
|
||||
return object;
|
||||
}
|
||||
|
||||
@ -37,6 +38,14 @@ bool ExtNetwork::active() const {
|
||||
return !this->m_branches.empty() && !this->m_nodes.empty();
|
||||
}
|
||||
|
||||
bool ExtNetwork::is_standard_network() const {
|
||||
return this->m_is_standard_network;
|
||||
}
|
||||
|
||||
void ExtNetwork::set_standard_network(bool is_standard_network) {
|
||||
this->m_is_standard_network = is_standard_network;
|
||||
}
|
||||
|
||||
bool ExtNetwork::operator==(const ExtNetwork& rhs) const {
|
||||
return this->m_branches == rhs.m_branches
|
||||
&& this->insert_indexed_node_names == rhs.insert_indexed_node_names
|
||||
@ -100,39 +109,18 @@ void ExtNetwork::add_or_replace_branch(Branch branch)
|
||||
this->add_indexed_node_name(nodename);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any other branch uptree from downtree_node (gathering tree structure required)
|
||||
|
||||
// Remove any existing branch uptree from downtree_node (gathering tree structure required)
|
||||
// (If it is an existing branch that should be updated, it will be added again below)
|
||||
auto uptree_link = this->uptree_branch( downtree_node );
|
||||
if (uptree_link.has_value()){
|
||||
const auto& old_uptree_node = uptree_link.value().uptree_node();
|
||||
this->drop_branch(old_uptree_node, downtree_node);
|
||||
}
|
||||
|
||||
// Update existing branch if it exists
|
||||
auto downtree_branches = this->downtree_branches( uptree_node );
|
||||
if (!downtree_branches.empty()) {
|
||||
auto branch_iter = std::find_if(this->m_branches.begin(), this->m_branches.end(), [&uptree_node, &downtree_node](const Branch& b) { return (b.uptree_node() == uptree_node && b.downtree_node() == downtree_node); });
|
||||
if (branch_iter != this->m_branches.end()) {
|
||||
*branch_iter = branch;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this->m_branches.push_back( std::move(branch) );
|
||||
}
|
||||
|
||||
bool ExtNetwork::is_disconnected(const std::string& node_name) const {
|
||||
if (!this->has_node(node_name)) return false;
|
||||
|
||||
if (this->downtree_branches(node_name).empty()) {
|
||||
for (const auto& branch : this->m_branches)
|
||||
if (branch.downtree_node() == node_name) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ExtNetwork::drop_branch(const std::string& uptree_node, const std::string& downtree_node) {
|
||||
auto branch_iter = std::find_if(this->m_branches.begin(),
|
||||
this->m_branches.end(),
|
||||
@ -154,7 +142,7 @@ std::optional<Branch> ExtNetwork::uptree_branch(const std::string& node) const {
|
||||
if (branches.size() == 1)
|
||||
return std::move(branches[0]);
|
||||
|
||||
throw std::logic_error("Bug - more than uptree branch for node: " + node);
|
||||
throw std::logic_error("Bug - more than one uptree branch for node: " + node);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1396,8 +1396,10 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
|
||||
this->snapshots.back().groups.update( std::move(new_child_group) );
|
||||
}
|
||||
|
||||
// Update network if required
|
||||
// Update standard network if required
|
||||
auto network = this->snapshots.back().network.get();
|
||||
if (!network.is_standard_network())
|
||||
return;
|
||||
if (network.has_node(child_name)) {
|
||||
auto old_branch = network.uptree_branch(child_name);
|
||||
if (old_branch.has_value()) {
|
||||
|
Loading…
Reference in New Issue
Block a user