Merge pull request #3609 from plgbrts/std-network

Enable standard network using GRUPNET
This commit is contained in:
Kai Bao
2023-08-23 23:03:12 +02:00
committed by GitHub
4 changed files with 93 additions and 46 deletions

View File

@@ -766,18 +766,59 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno)
}
void Schedule::handleGRUPNET(HandlerContext& handlerContext) {
auto network = this->snapshots.back().network.get();
std::vector<Network::Node> nodes;
for (const auto& record : handlerContext.keyword) {
const auto& groupName = record.getItem("NAME").getTrimmedString(0);
const std::string& groupNamePattern = record.getItem<ParserKeywords::GRUPNET::NAME>().getTrimmedString(0);
const auto group_names = this->groupNames(groupNamePattern);
if (group_names.empty())
this->invalidNamePattern(groupNamePattern, handlerContext);
const auto& pressure_item = record.getItem<ParserKeywords::GRUPNET::TERMINAL_PRESSURE>();
const int vfp_table = record.getItem<ParserKeywords::GRUPNET::VFP_TABLE>().get<int>(0);
if (!this->snapshots.back().groups.has(groupName))
addGroup(groupName , handlerContext.currentStep);
int table = record.getItem("VFP_TABLE").get< int >(0);
auto new_group = this->snapshots.back().groups.get( groupName );
if (new_group.updateNetVFPTable(table))
this->snapshots.back().groups.update( std::move(new_group) );
for (const auto& group_name : group_names) {
const auto& group = this->snapshots.back().groups.get(group_name);
const std::string& downtree_node = group_name;
const std::string& uptree_node = group.parent();
Network::Node node { group_name };
// A terminal node is a node with a fixed pressure
const bool is_terminal_node = pressure_item.hasValue(0) && (pressure_item.get<double>(0) >= 0);
if (is_terminal_node) {
if (vfp_table > 0) {
std::string msg = fmt::format("The group {} is a terminal node of the network and should not have a vfp table assigned to it.", group_name);
throw OpmInputError(msg, handlerContext.keyword.location());
}
node.terminal_pressure(pressure_item.getSIDouble(0));
nodes.push_back(node);
// Remove the branch upstream if it was part of the network
if (network.has_node(downtree_node) && network.has_node(uptree_node))
network.drop_branch(uptree_node, downtree_node);
} else {
if (vfp_table <= 0) {
// If vfp table is defaulted (or set to <=0) then the group is not part of the network.
// If the branch was part of the network then drop it
if (network.has_node(downtree_node) && network.has_node(uptree_node))
network.drop_branch(uptree_node, downtree_node);
} else {
if (!uptree_node.empty()) {
const auto alq_eq = Network::Branch::AlqEqfromString(record.getItem<ParserKeywords::GRUPNET::ALQ_SURFACE_DENSITY>().get<std::string>(0));
if (alq_eq == Network::Branch::AlqEQ::ALQ_INPUT) {
const double alq_value = record.getItem<ParserKeywords::GRUPNET::ALQ>().get<double>(0);
network.add_branch(Network::Branch(downtree_node, uptree_node, vfp_table, alq_value));
} else {
network.add_branch(Network::Branch(downtree_node, uptree_node, vfp_table, alq_eq));
}
}
nodes.push_back(node);
}
}
}
}
// To use update_node the node should be associated to a branch via add_branch()
// so the update of nodes is postponed after creation of branches
for(const auto& node: nodes)
network.update_node(node);
this->snapshots.back().network.update( std::move(network));
}
void Schedule::handleGRUPTREE(HandlerContext& handlerContext) {

View File

@@ -11,7 +11,8 @@
},
{
"name": "TERMINAL_PRESSURE",
"value_type": "DOUBLE"
"value_type": "DOUBLE",
"dimension": "Pressure"
},
{
"name": "VFP_TABLE",
@@ -34,7 +35,7 @@
"default": "NO"
},
{
"name": "ALQ_SURFACE_EQV",
"name": "ALQ_SURFACE_DENSITY",
"value_type": "STRING",
"default": "NONE"
}

View File

@@ -179,41 +179,6 @@ WCONPROD
}
BOOST_AUTO_TEST_CASE(createDeckWithGRUPNET) {
const std::string input = R"(
START -- 0
31 AUG 1993 /
SCHEDULE
GRUPNET
'FIELD' 20.000 5* /
'PROD' 20.000 5* /
'MANI-B2' 1* 8 1* 'NO' 2* /
'MANI-B1' 1* 8 1* 'NO' 2* /
'MANI-K1' 1* 9999 4* /
'B1-DUMMY' 1* 9999 4* /
'MANI-D1' 1* 8 1* 'NO' 2* /
'MANI-D2' 1* 8 1* 'NO' 2* /
'MANI-K2' 1* 9999 4* /
'D2-DUMMY' 1* 9999 4* /
'MANI-E1' 1* 9 1* 'NO' 2* /
'MANI-E2' 1* 9 4* /
/)";
auto schedule = create_schedule(input);
const auto& group1 = schedule.getGroup("PROD", 0);
const auto& group2 = schedule.getGroup("MANI-E2", 0);
const auto& group3 = schedule.getGroup("MANI-K1", 0);
BOOST_CHECK_EQUAL(group1.getGroupNetVFPTable(), 0);
BOOST_CHECK_EQUAL(group2.getGroupNetVFPTable(), 9);
BOOST_CHECK_EQUAL(group3.getGroupNetVFPTable(), 9999);
}
BOOST_AUTO_TEST_CASE(GroupCreate) {
Opm::Group g1("NAME", 1, 0, UnitSystem::newMETRIC());
Opm::Group g2("NAME", 1, 0, UnitSystem::newMETRIC());

View File

@@ -369,3 +369,43 @@ BRANPROP
BOOST_CHECK_EQUAL_COLLECTIONS(nodes.begin(), nodes.end(), expect.begin(), expect.end());
}
BOOST_AUTO_TEST_CASE(StandardNetwork) {
const std::string input = R"(
SCHEDULE
GRUPTREE
'PROD' 'FIELD' /
'M5S' 'PLAT-A' /
'M5N' 'PLAT-A' /
'C1' 'M5N' /
'F1' 'M5N' /
'B1' 'M5S' /
'G1' 'M5S' /
/
GRUPNET
'PLAT-A' 21.000 5* /
'M5S' 1* 3 1* 'NO' 2* /
'B1' 1* 5 1* 'NO' 2* /
'C1' 1* 4 1* 'NO' 2* /
/)";
auto schedule = make_schedule(input);
const auto& network = schedule[0].network.get();
const auto& b1 = network.node("B1");
const auto upbranch = network.uptree_branch(b1.name());
const auto vfp_table = (*upbranch).vfp_table();
BOOST_CHECK_EQUAL(vfp_table.value(), 5);
BOOST_CHECK(!b1.terminal_pressure());
const auto& p = network.node("PLAT-A");
BOOST_CHECK(p.terminal_pressure());
BOOST_CHECK_EQUAL(p.terminal_pressure().value(), 21 * 100000);
BOOST_CHECK(p == network.root());
}