Working version (but not pretty)

This commit is contained in:
Vegard Kippe 2023-09-29 14:23:24 +02:00
parent 0aa0af9f57
commit aa2220979b
4 changed files with 19 additions and 6 deletions

View File

@ -45,6 +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; }
std::optional<int> vfp_table() const;
AlqEQ alq_eq() const;
std::optional<double> alq_value() const;

View File

@ -39,7 +39,7 @@ public:
bool active() const;
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);
void drop_branch(const std::string& uptree_node, const std::string& downtree_node, const bool recurse = true);
bool has_node(const std::string& name) const;
void update_node(Node node);
const Node& node(const std::string& name) const;

View File

@ -101,11 +101,11 @@ void ExtNetwork::add_or_replace_branch(Branch branch)
}
}
// Remote any other branch uptree from downtree_node
// Remove any other branch uptree from downtree_node
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);
this->drop_branch(old_uptree_node, downtree_node, false);
}
// Update existing branch
@ -122,14 +122,14 @@ void ExtNetwork::add_or_replace_branch(Branch branch)
}
void ExtNetwork::drop_branch(const std::string& uptree_node, const std::string& downtree_node) {
void ExtNetwork::drop_branch(const std::string& uptree_node, const std::string& downtree_node, const bool recurse) {
auto downtree_branches = this->downtree_branches( downtree_node );
if (downtree_branches.empty()) {
if (downtree_branches.empty() || !recurse) {
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())
this->m_branches.erase( branch_iter );
this->m_nodes.erase( downtree_node );
if (downtree_branches.empty()) this->m_nodes.erase( downtree_node );
} else {
for (const auto& branch : downtree_branches)
this->drop_branch(branch.uptree_node(), branch.downtree_node());

View File

@ -1395,6 +1395,18 @@ File {} line {}.)", pattern, location.keyword, location.filename, location.linen
new_child_group.updateParent(parent_name);
this->snapshots.back().groups.update( std::move(new_child_group) );
}
// Update network if required
auto network = this->snapshots.back().network.get();
if (network.has_node(child_name)) {
auto old_branch = network.uptree_branch(child_name);
if (old_branch.has_value()) {
auto new_branch = old_branch.value();
new_branch.set_uptree_node(parent_name);
network.add_or_replace_branch(new_branch);
}
// If no previous uptree branch the child is a fixed-pressure node, so no need to update network
}
}
void Schedule::addWellToGroup( const std::string& group_name, const std::string& well_name , std::size_t timeStep) {