various code improvements based on Joakims review
This commit is contained in:
parent
b403e2ae48
commit
dafd605eaa
@ -38,9 +38,7 @@ public:
|
||||
ExtNetwork() = default;
|
||||
bool active() const;
|
||||
bool has_node(const std::string& name) const;
|
||||
bool has_indexed_node_name(std::string name) const;
|
||||
void add_node(Node node);
|
||||
void add_indexed_node_name(std::string name);
|
||||
void add_branch(Branch branch);
|
||||
void drop_branch(const std::string& uptree_node, const std::string& downtree_node);
|
||||
const Node& node(const std::string& name) const;
|
||||
@ -49,7 +47,6 @@ public:
|
||||
std::vector<const Branch*> branches() const;
|
||||
std::optional<Branch> uptree_branch(const std::string& node) const;
|
||||
std::vector<std::string> node_names() const;
|
||||
std::vector<std::string> insert_index_nd_names() const;
|
||||
int NoOfBranches() const;
|
||||
|
||||
bool operator==(const ExtNetwork& other) const;
|
||||
@ -67,6 +64,8 @@ private:
|
||||
std::vector<Branch> m_branches;
|
||||
std::vector<std::string> insert_indexed_node_names;
|
||||
std::map<std::string, Node> m_nodes;
|
||||
bool has_indexed_node_name(const std::string name) const;
|
||||
void add_indexed_node_name(std::string name);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -45,6 +45,8 @@
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <optional>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#define ENABLE_GCNTL_DEBUG_OUTPUT 0
|
||||
|
||||
@ -109,45 +111,33 @@ void branchLoop(const std::vector<const Opm::Network::Branch*>& branches,
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T>
|
||||
std::pair<bool, int > findInVector(const std::vector<T> & vecOfElements, const T & element)
|
||||
template <typename T>
|
||||
std::optional<int> findInVector(const std::vector<T> & vecOfElements, const T & element)
|
||||
{
|
||||
std::pair<bool, int > result;
|
||||
|
||||
// Find given element in vector
|
||||
auto it = std::find(vecOfElements.begin(), vecOfElements.end(), element);
|
||||
|
||||
if (it != vecOfElements.end())
|
||||
{
|
||||
result.second = std::distance(vecOfElements.begin(), it);
|
||||
result.first = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.first = false;
|
||||
result.second = -1;
|
||||
}
|
||||
return result;
|
||||
return (it != vecOfElements.end()) ? std::optional<int>{std::distance(vecOfElements.begin(), it)} : std::nullopt;
|
||||
}
|
||||
|
||||
int next_branch(int node_no, std::vector<int> inlets, std::vector<int> outlets)
|
||||
int next_branch(int node_no, std::vector<int>& inlets, std::vector<int>& outlets)
|
||||
{
|
||||
int nxt_br = 0;
|
||||
auto res_inlets = findInVector<int>(inlets, node_no);
|
||||
auto res_outlets = findInVector<int>(outlets, node_no);
|
||||
|
||||
if ((!res_inlets.first) && (!res_outlets.first)) {
|
||||
if ((!res_inlets) && (!res_outlets)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (res_outlets.first) {
|
||||
nxt_br = res_outlets.second + 1;
|
||||
if (res_outlets) {
|
||||
nxt_br = res_outlets.value() + 1;
|
||||
}
|
||||
if (res_inlets.first) {
|
||||
if (res_inlets) {
|
||||
if (nxt_br > 0) {
|
||||
nxt_br = (nxt_br > res_inlets.second + 1) ? (res_inlets.second + 1) * (-1) : nxt_br;
|
||||
nxt_br = (nxt_br > res_inlets.value() + 1) ? (res_inlets.value() + 1) * (-1) : nxt_br;
|
||||
} else {
|
||||
nxt_br = (res_inlets.second + 1) * (-1);
|
||||
nxt_br = (res_inlets.value() + 1) * (-1);
|
||||
}
|
||||
}
|
||||
return nxt_br;
|
||||
@ -158,7 +148,7 @@ std::vector<int> inobrFunc( const Opm::Schedule& sched,
|
||||
const std::size_t lookup_step
|
||||
)
|
||||
{
|
||||
const auto& ntwNdNm = sched[lookup_step].network().insert_index_nd_names();
|
||||
const auto& ntwNdNm = sched[lookup_step].network().node_names();
|
||||
const auto& branchPtrs = sched[lookup_step].network().branches();
|
||||
|
||||
std::vector<int> newInobr;
|
||||
@ -169,10 +159,10 @@ std::vector<int> inobrFunc( const Opm::Schedule& sched,
|
||||
|
||||
for (const auto& branch : branchPtrs) {
|
||||
auto dwntr_nd_res = findInVector<std::string>(ntwNdNm, branch->downtree_node());
|
||||
ind = (dwntr_nd_res.first) ? dwntr_nd_res.second + 1 : 0 ;
|
||||
ind = (dwntr_nd_res) ? dwntr_nd_res.value() + 1 : 0 ;
|
||||
inlets.push_back(ind);
|
||||
auto uptr_nd_res = findInVector<std::string>(ntwNdNm, branch->uptree_node());
|
||||
ind = (dwntr_nd_res.first) ? uptr_nd_res.second + 1 : 0 ;
|
||||
ind = (dwntr_nd_res) ? uptr_nd_res.value() + 1 : 0 ;
|
||||
outlets.push_back(ind);
|
||||
}
|
||||
|
||||
@ -254,9 +244,8 @@ double nodePressure(const Opm::Schedule& sched,
|
||||
if (network.uptree_branch(node_name).has_value()) {
|
||||
upt_br = network.uptree_branch(node_name).value();
|
||||
} else {
|
||||
std::stringstream str;
|
||||
str << "Node: " << nodeName << " has no uptree node with fixed pressure condition, uppermost node: " << node_name;
|
||||
throw std::invalid_argument(str.str());
|
||||
auto msg = fmt::format("Node: {} has no uptree node with fixed pressure condition, uppermost node is: {} ", nodeName, node_name);
|
||||
throw std::logic_error(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -282,13 +271,6 @@ nodeProps wellGroupRateDensity(const Opm::EclipseState& es,
|
||||
const size_t lookup_step
|
||||
)
|
||||
{
|
||||
auto get = [&smry](const std::string& well_name, const std::string& vector)
|
||||
{
|
||||
const auto key = vector + ':' + well_name;
|
||||
|
||||
return smry.has(key) ? smry.get(key) : 0.0;
|
||||
};
|
||||
|
||||
const auto& stdDensityTable = es.getTableManager().getDensityTable();
|
||||
|
||||
double deno = 0.;
|
||||
@ -307,13 +289,14 @@ nodeProps wellGroupRateDensity(const Opm::EclipseState& es,
|
||||
const auto& well = sched.getWell(well_name, lookup_step);
|
||||
if (well.isProducer()) {
|
||||
const auto& pvtNum = well.pvt_table_number();
|
||||
t_opr = get(well.name(),"WOPR");
|
||||
t_opr = smry.get_well_var(well.name(), "WOPR", 0.0);
|
||||
deno += t_opr * stdDensityTable[pvtNum-1].oil;
|
||||
opr += t_opr;
|
||||
t_wpr = get(well.name(),"WWPR");
|
||||
t_wpr = smry.get_well_var(well.name(), "WWPR", 0.0);
|
||||
denw += t_wpr * stdDensityTable[pvtNum-1].water;
|
||||
wpr += t_wpr;
|
||||
t_gpr = (get(well.name(),"WGPR") + get(well.name(),"WGLIR"))*well.getEfficiencyFactor();
|
||||
t_gpr = (smry.get_well_var(well.name(), "WGPR", 0.0) + smry.get_well_var(well.name(), "WGLIR", 0.0))*
|
||||
well.getEfficiencyFactor();
|
||||
deng += t_gpr * stdDensityTable[pvtNum-1].gas;
|
||||
gpr += t_gpr;
|
||||
}
|
||||
@ -372,9 +355,8 @@ nodeProps nodeRateDensity(const Opm::EclipseState& es,
|
||||
nd_prop_vec.push_back(nd_prop);
|
||||
}
|
||||
} else {
|
||||
std::stringstream str;
|
||||
str << "Node: " << node_nm << " should be a group but is not: " << node_nm;
|
||||
throw std::invalid_argument(str.str());
|
||||
auto msg = fmt::format("Node: {} should be a group but is not", node_nm );
|
||||
throw std::logic_error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,9 +408,8 @@ int numberOfBranchesConnToNode(const Opm::Schedule& sched, const std::string& no
|
||||
noBranches = (network.uptree_branch(nodeName).has_value()) ? noBranches+1 : noBranches;
|
||||
return noBranches;
|
||||
} else {
|
||||
std::stringstream str;
|
||||
str << "actual node: " << nodeName << " has not been defined at report time: " << lookup_step+1;
|
||||
throw std::invalid_argument(str.str());
|
||||
auto msg = fmt::format("Actual node: {} has not been defined at report time: {} ", nodeName, lookup_step+1);
|
||||
throw std::logic_error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -437,21 +418,20 @@ int cumNumberOfBranchesConnToNode(const Opm::Schedule& sched, const std::string&
|
||||
auto& network = sched[lookup_step].network();
|
||||
std::size_t ind_name = 0;
|
||||
int cumNoBranches = 1;
|
||||
auto result = findInVector<std::string>(network.insert_index_nd_names(), nodeName);
|
||||
if (result.first) {
|
||||
ind_name = result.second;
|
||||
auto result = findInVector<std::string>(network.node_names(), nodeName);
|
||||
if (result) {
|
||||
ind_name = result.value();
|
||||
if (ind_name == 0) {
|
||||
return cumNoBranches;
|
||||
} else {
|
||||
for (std::size_t n_ind = 0; n_ind < ind_name; n_ind++) {
|
||||
cumNoBranches += numberOfBranchesConnToNode(sched, network.insert_index_nd_names()[n_ind], lookup_step);
|
||||
cumNoBranches += numberOfBranchesConnToNode(sched, network.node_names()[n_ind], lookup_step);
|
||||
}
|
||||
return cumNoBranches;
|
||||
}
|
||||
} else {
|
||||
std::stringstream str;
|
||||
str << "actual node: " << nodeName << " has not been defined at report time: " << lookup_step+1;
|
||||
throw std::invalid_argument(str.str());
|
||||
auto msg = fmt::format("Actual node: {} has not been defined at report time: {} ", nodeName, lookup_step+1);
|
||||
throw std::logic_error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,6 +449,7 @@ void staticContrib(const Opm::Schedule& sched,
|
||||
iNode[Ix::Group] = sched.getGroup(nodeName, lookup_step).insert_index();
|
||||
}
|
||||
iNode[Ix::FixedPresNode] = (fixedPressureNode(sched, nodeName, lookup_step)) ? 1 : 0;
|
||||
// the meaning of the value of item [4] is currently not known, the constant value used cover all cases so far
|
||||
iNode[4] = 1;
|
||||
}
|
||||
|
||||
@ -498,13 +479,13 @@ void staticContrib(const Opm::Schedule& sched,
|
||||
IBranArray& iBran)
|
||||
{
|
||||
using Ix = ::Opm::RestartIO::Helpers::VectorItems::IBran::index;
|
||||
const auto& nodeNames = sched[lookup_step].network().insert_index_nd_names();
|
||||
const auto& nodeNames = sched[lookup_step].network().node_names();
|
||||
|
||||
auto dwntr_nd_res = findInVector<std::string>(nodeNames, branch.downtree_node());
|
||||
iBran[Ix::DownTreeNode] = (dwntr_nd_res.first) ? dwntr_nd_res.second + 1 : 0 ;
|
||||
iBran[Ix::DownTreeNode] = (dwntr_nd_res) ? dwntr_nd_res.value() + 1 : 0 ;
|
||||
|
||||
auto uptr_nd_res = findInVector<std::string>(nodeNames, branch.uptree_node());
|
||||
iBran[Ix::UpTreeNode] = (uptr_nd_res.first) ? uptr_nd_res.second + 1 : 0 ;
|
||||
iBran[Ix::UpTreeNode] = (uptr_nd_res) ? uptr_nd_res.value() + 1 : 0 ;
|
||||
|
||||
iBran[Ix::VfpTableNo] = (branch.vfp_table().has_value()) ? branch.vfp_table().value() : 0;
|
||||
}
|
||||
@ -591,8 +572,7 @@ void dynamicContrib(const Opm::Schedule& sched,
|
||||
{
|
||||
using Ix = ::Opm::RestartIO::Helpers::VectorItems::RNode::index;
|
||||
// node dynamic pressure
|
||||
std::string compKey = "GPR:" + nodeName;
|
||||
rNode[Ix::NodePres] = (sumState.has(compKey)) ? sumState.get(compKey) : 0.;
|
||||
rNode[Ix::NodePres] = sumState.get_group_var(nodeName, "GPR", 0.);
|
||||
|
||||
// equal to 0. for fixed pressure nodes, 1. otherwise
|
||||
rNode[Ix::FixedPresNode] = (fixedPressureNode(sched, nodeName, lookup_step)) ? 0. : 1.;
|
||||
@ -600,7 +580,7 @@ void dynamicContrib(const Opm::Schedule& sched,
|
||||
// equal to i) highest well p_thp if wellgroup and ii) pressure of uptree node with fixed pressure
|
||||
rNode[Ix::PressureLimit] = nodePressure(sched, sumState, nodeName, units, lookup_step);
|
||||
|
||||
// fixed value
|
||||
//the meaning of item [15] is not known at the moment, so far a constant value covers all cases studied
|
||||
rNode[15] = 1.;
|
||||
|
||||
}
|
||||
@ -679,7 +659,7 @@ captureDeclaredNetworkData(const Opm::EclipseState& es,
|
||||
const std::vector<int>& inteHead)
|
||||
{
|
||||
|
||||
auto ntwNdNm = sched[lookup_step].network().insert_index_nd_names();
|
||||
auto ntwNdNm = sched[lookup_step].network().node_names();
|
||||
std::size_t wdmax = ntwNdNm.size();
|
||||
std::vector<const std::string*> ndNmPt(wdmax + 1 , nullptr );
|
||||
std::size_t ind_nm = 0;
|
||||
@ -714,9 +694,8 @@ captureDeclaredNetworkData(const Opm::EclipseState& es,
|
||||
|
||||
// Define Static Contributions to INobr Array
|
||||
if (inobr.size() != entriesPerInobr(inteHead)) {
|
||||
std::stringstream str;
|
||||
str << "Actual size of inobr: " << inobr.size() << " different from required size: " << entriesPerInobr(inteHead);
|
||||
throw std::invalid_argument(str.str());
|
||||
auto msg = fmt::format("Actual size of inobr: {} is different from required size: {} ", inobr.size(), entriesPerInobr(inteHead));
|
||||
throw std::logic_error(msg);
|
||||
}
|
||||
auto i_nobr = this->iNobr_[0];
|
||||
INobr::staticContrib(inobr, i_nobr);
|
||||
|
@ -125,9 +125,6 @@ namespace {
|
||||
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);
|
||||
|
||||
if (!ext_network.has_indexed_node_name(downtree_node)) ext_network.add_indexed_node_name(downtree_node);
|
||||
if (!ext_network.has_indexed_node_name(uptree_node)) ext_network.add_indexed_node_name(uptree_node);
|
||||
const int vfp_table = record.getItem<ParserKeywords::BRANPROP::VFP_TABLE>().get<int>(0);
|
||||
|
||||
if (vfp_table == 0) {
|
||||
|
@ -70,6 +70,12 @@ const Node& ExtNetwork::root() const {
|
||||
|
||||
void ExtNetwork::add_branch(Branch branch)
|
||||
{
|
||||
if (!this->has_indexed_node_name(branch.downtree_node())) {
|
||||
this->add_indexed_node_name(branch.downtree_node());
|
||||
}
|
||||
if (!this->has_indexed_node_name(branch.uptree_node())) {
|
||||
this->add_indexed_node_name(branch.uptree_node());
|
||||
}
|
||||
this->m_branches.push_back( std::move(branch) );
|
||||
}
|
||||
|
||||
@ -163,36 +169,15 @@ void ExtNetwork::add_indexed_node_name(std::string name)
|
||||
this->insert_indexed_node_names.emplace_back(name);
|
||||
}
|
||||
|
||||
bool ExtNetwork::has_indexed_node_name(std::string name) const
|
||||
bool ExtNetwork::has_indexed_node_name(const std::string name) const
|
||||
{
|
||||
// Find given element in vector
|
||||
auto it = std::find(this->insert_indexed_node_names.begin(), this->insert_indexed_node_names.end(), name);
|
||||
|
||||
if (it != this->insert_indexed_node_names.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (it != this->insert_indexed_node_names.end());
|
||||
}
|
||||
|
||||
std::vector<std::string> ExtNetwork::node_names() const
|
||||
{
|
||||
auto nodes = std::vector<std::string>{};
|
||||
nodes.reserve(this->m_nodes.size());
|
||||
|
||||
std::transform(this->m_nodes.begin(), this->m_nodes.end(), std::back_inserter(nodes),
|
||||
[](const auto& node_pair)
|
||||
{
|
||||
return node_pair.first;
|
||||
});
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
std::vector<std::string> ExtNetwork::insert_index_nd_names() const
|
||||
{
|
||||
return this->insert_indexed_node_names;
|
||||
}
|
||||
|
@ -59,31 +59,34 @@ namespace {
|
||||
{
|
||||
auto state = Opm::SummaryState{std::chrono::system_clock::now()};
|
||||
|
||||
state.update("WOPR:P1", 3342.673828);
|
||||
state.update("WWPR:P1", 0.000005);
|
||||
state.update("WGPR:P1", 334267.375);
|
||||
state.update("WGLIR:P1", 111000.);
|
||||
state.update_well_var("P1", "WOPR", 3342.673828);
|
||||
state.update_well_var("P1", "WWPR", 0.000005);
|
||||
state.update_well_var("P1", "WGPR", 334267.375);
|
||||
state.update_well_var("P1", "WGLIR", 111000.);
|
||||
|
||||
state.update("WOPR:P2", 3882.443848);
|
||||
state.update("WWPR:P2", 0.000002);
|
||||
state.update("WGPR:P2", 672736.9375);
|
||||
state.update("WGLIR:P2", 99666.);
|
||||
state.update_well_var("P2", "WOPR", 3882.443848);
|
||||
state.update_well_var("P2", "WWPR", 0.000002);
|
||||
state.update_well_var("P2", "WGPR", 672736.9375);
|
||||
state.update_well_var("P2", "WGLIR", 99666.);
|
||||
|
||||
state.update("WOPR:P3", 3000.000000);
|
||||
state.update("WWPR:P3", 0.000002);
|
||||
state.update("WGPR:P3", 529658.8125);
|
||||
state.update("WGLIR:P3", 55000.);
|
||||
state.update_well_var("P3", "WOPR", 3000.000000);
|
||||
state.update_well_var("P3", "WWPR", 0.000002);
|
||||
state.update_well_var("P3", "WGPR", 529658.8125);
|
||||
state.update_well_var("P3", "WGLIR", 55000.);
|
||||
|
||||
|
||||
state.update("GPR:B1", 81.6848);
|
||||
state.update("GPR:N1", 72.);
|
||||
state.update("GPR:N2", 69.);
|
||||
state.update("GPR:PLAT-A", 67.);
|
||||
state.update("GPR:B2", 79.0666);
|
||||
state.update("GPR:M1", 72.);
|
||||
state.update_group_var("B1", "GPR", 81.6848);
|
||||
state.update_group_var("N1", "GPR", 72.);
|
||||
state.update_group_var("N2", "GPR", 69.);
|
||||
state.update_group_var("PLAT-A", "GPR", 67.);
|
||||
state.update_group_var("B2", "GPR", 79.0666);
|
||||
state.update_group_var("M1", "GPR", 72.);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
std::string pad8(const std::string& s) {
|
||||
return s + std::string( 8 - s.size(), ' ');
|
||||
}
|
||||
}
|
||||
|
||||
struct SimulationCase
|
||||
@ -212,30 +215,32 @@ BOOST_AUTO_TEST_CASE (Constructor)
|
||||
BOOST_CHECK_EQUAL(iBran[start + 2], 8);
|
||||
|
||||
//ZNode-parameters
|
||||
const std::string blank8 = " ";
|
||||
|
||||
const auto& zNode = networkData.getZNode();
|
||||
start = 0*ih[VI::NZNODE];
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), "B1 ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), " ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), pad8("B1"));
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), blank8);
|
||||
|
||||
start = 1*ih[VI::NZNODE];
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), "N1 ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), " ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), pad8("N1"));
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), blank8);
|
||||
|
||||
start = 2*ih[VI::NZNODE];
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), "N2 ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), " ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), pad8("N2"));
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), blank8);
|
||||
|
||||
start = 3*ih[VI::NZNODE];
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), "PLAT-A ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), " ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), pad8("PLAT-A"));
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), blank8);
|
||||
|
||||
start = 4*ih[VI::NZNODE];
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), "B2 ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), " ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), pad8("B2"));
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), blank8);
|
||||
|
||||
start = 5*ih[VI::NZNODE];
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), "M1 ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), " ");
|
||||
BOOST_CHECK_EQUAL(zNode[start + 0].c_str(), pad8("M1"));
|
||||
BOOST_CHECK_EQUAL(zNode[start + 1].c_str(), blank8);
|
||||
|
||||
//INobr-parameters
|
||||
const auto& iNobr = networkData.getINobr();
|
||||
|
Loading…
Reference in New Issue
Block a user