From e02fa5d04fa24ddce2418a4f3294a7de38aca69c Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 29 Jul 2019 15:23:09 +0200 Subject: [PATCH] WIP --- opm/output/eclipse/AggregateUDQData.hpp | 36 +--- src/opm/output/eclipse/AggregateUDQData.cpp | 219 +++++++------------- src/opm/output/eclipse/CreateUdqDims.cpp | 19 +- tests/test_UDQ_x.cpp | 4 +- 4 files changed, 83 insertions(+), 195 deletions(-) diff --git a/opm/output/eclipse/AggregateUDQData.hpp b/opm/output/eclipse/AggregateUDQData.hpp index 7ab929524..5384c7634 100644 --- a/opm/output/eclipse/AggregateUDQData.hpp +++ b/opm/output/eclipse/AggregateUDQData.hpp @@ -45,39 +45,6 @@ namespace Opm { namespace Opm { namespace RestartIO { namespace Helpers { -class iUADData { -public: - const std::vector & wgkey_udqkey_ctrl_type() const { - return m_wgkey_udqkey_ctrl_type; - } - const std::vector & wgkey_ctrl_type() const { - return m_wgkey_ctrl_type; - } - const std::vector& udq_seq_no() const { - return m_udq_seq_no; - } - const std::vector& no_use_wgkey() const { - return m_no_use_wgkey; - } - const std::vector& first_use_wg() const { - return m_first_use_wg; - } - std::size_t count() { - return m_count; - } - - - void noIUADs(const Opm::Schedule& sched, const std::size_t simStep); - -private: - std::vector m_wgkey_udqkey_ctrl_type; - std::vector m_wgkey_ctrl_type; - std::vector m_udq_seq_no; - std::vector m_no_use_wgkey; - std::vector m_first_use_wg; - std::size_t m_count; -}; - class igphData { public: const std::map currentGroupMapIndexGroup(const Opm::Schedule& sched, const size_t simStep, const std::vector& inteHead); @@ -91,7 +58,8 @@ public: explicit AggregateUDQData(const std::vector& udqDims); void captureDeclaredUDQData(const Opm::Schedule& sched, - const std::size_t simStep); + const std::size_t simStep, + const std::vector& ih); const std::vector& getIUDQ() const { diff --git a/src/opm/output/eclipse/AggregateUDQData.cpp b/src/opm/output/eclipse/AggregateUDQData.cpp index 7e02e4c9a..ae099a542 100644 --- a/src/opm/output/eclipse/AggregateUDQData.cpp +++ b/src/opm/output/eclipse/AggregateUDQData.cpp @@ -47,7 +47,7 @@ namespace { - + // maximum number of groups std::size_t ngmaxz(const std::vector& inteHead) { @@ -88,7 +88,6 @@ namespace { allocate(const std::vector& udqDims) { using WV = Opm::RestartIO::Helpers::WindowedArray; - printf("iUAD num:%d ws:%d \n ", udqDims[2], udqDims[3]); return WV { WV::NumWindows{ static_cast(udqDims[2]) }, WV::WindowSize{ static_cast(udqDims[3]) } @@ -96,20 +95,18 @@ namespace { } template - void staticContrib(const Opm::RestartIO::Helpers::iUADData& iuad_data, - const int indUad, - IUADArray& iUad) + void staticContrib(const Opm::UDQConfig& udq_config, const Opm::UDQActive& udq_active, std::size_t iactive, IUADArray& iUad) { - // numerical key for well/group control keyword plus control type, see iUADData::UDACtrlType - iUad[0] = iuad_data.wgkey_ctrl_type()[indUad]; - // sequence number of UDQ used (from input sequence) for the actual constraint/target - iUad[1] = iuad_data.udq_seq_no()[indUad]; + const auto& udq = udq_active[iactive]; + + iUad[0] = Opm::UDQ::uadCode(udq.control); + iUad[1] = udq.index; + // entry 3 - unknown meaning - value = 1 iUad[2] = 1; - // entry 4 - - iUad[3] = iuad_data.no_use_wgkey()[indUad]; - // entry 3 - - iUad[4] = iuad_data.first_use_wg()[indUad]; + + iUad[3] = udq_active.use_count(udq.udq); + iUad[4] = udq_config[udq.udq].index.typed_insert_index; } } // iUad @@ -202,144 +199,79 @@ namespace { const int indGph, IGPHArray& iGph) { - - } + + } } // iGph -} // Anonymous +} // ===================================================================== - template < typename T> - std::pair findInVector(const std::vector & vecOfElements, const T & element) +template < typename T> +std::pair findInVector(const std::vector & vecOfElements, const T & element) +{ + std::pair result; + + // Find given element in vector + auto it = std::find(vecOfElements.begin(), vecOfElements.end(), element); + + if (it != vecOfElements.end()) { - std::pair 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; + result.second = std::distance(vecOfElements.begin(), it); + result.first = true; } - - void Opm::RestartIO::Helpers::iUADData::iuad(const Opm::Schedule& sched, const std::size_t simStep) + else { - auto udq_cfg = sched.getUDQConfig(simStep); - auto udq_active = sched.udqActive(simStep); - - // Loop over the number of Active UDQs and set all UDQActive restart data items - - std::vector wgkey_udqkey_ctrl_type; - std::vector wgkey_ctrl_type; - std::vector udq_seq_no; - std::vector no_use_wgkey; - std::vector first_use_wg; - std::size_t count = 0; - - auto mx_iuads = udq_active.size(); - wgkey_udqkey_ctrl_type.resize(mx_iuads, ""); - wgkey_ctrl_type.resize(mx_iuads, 0); - udq_seq_no.resize(mx_iuads, 0); - no_use_wgkey.resize(mx_iuads, 0); - first_use_wg.resize(mx_iuads, 0); - - std::size_t cnt_inp = 0; - for (auto it = udq_active.begin(); it != udq_active.end(); it++) - { - cnt_inp+=1; - auto udq_key = it->udq; - //auto ctrl_keywrd = it->keyword; - auto name = it->wgname; - auto ctrl_type = it->control; - //std::cout << "ctrl_type: " << static_cast(ctrl_type) << std::endl; - std::string wg_udqk_kc = udq_key + "_" + std::to_string(static_cast(ctrl_type)); - - //std::cout << "iuad:" << ind << " " << udq_key << " " << name << " " << static_cast(ctrl_type) << " " << wg_udqk_kc << std::endl; + result.first = false; + result.second = -1; + } + return result; +} - const auto v_typ = UDQ::uadCode(ctrl_type); - std::pair res = findInVector(wgkey_udqkey_ctrl_type, wg_udqk_kc); - if (res.first) { - auto key_ind = res.second; - no_use_wgkey[key_ind] += 1; - - //std::cout << "key exists - key_ind:" << key_ind << " no_use_wgkey: " << no_use_wgkey[key_ind] << std::endl; - } - else { - wgkey_ctrl_type[count] = v_typ; - wgkey_udqkey_ctrl_type[count] = wg_udqk_kc; - udq_seq_no[count] = udq_cfg[udq_key].index.insert_index; - no_use_wgkey[count] = 1; - - //std::cout << "new key - key_ind:" << count << " wgkey_ctrl_type: " << wgkey_ctrl_type[count] << " udq_seq_no: " << udq_seq_no[count]; - //std::cout << " no_use_wgkey:" << no_use_wgkey[count] << " first_use_wg: " << first_use_wg[count] << std::endl; - - count+=1; - } - } - - // Loop over all iUADs to set the first use paramter - int cnt_use = 0; - for (std::size_t it = 0; it < count; it++) { - first_use_wg[it] = cnt_use + 1; - cnt_use += no_use_wgkey[it]; - } - this->m_wgkey_ctrl_type = wgkey_ctrl_type; - this->m_udq_seq_no = udq_seq_no; - this->m_no_use_wgkey = no_use_wgkey; - this->m_first_use_wg = first_use_wg; - this->m_count = count; - } - - const std::map Opm::RestartIO::Helpers::igphData::currentGroupMapIndexGroup(const Opm::Schedule& sched, - const size_t simStep, - const std::vector& inteHead) +const std::map Opm::RestartIO::Helpers::igphData::currentGroupMapIndexGroup(const Opm::Schedule& sched, + const size_t simStep, + const std::vector& inteHead) +{ + // make group index for current report step + std::map indexGroupMap; + for (const auto& group_name : sched.groupNames(simStep)) { + const auto& group = sched.getGroup(group_name); + int ind = (group.name() == "FIELD") + ? ngmaxz(inteHead)-1 : group.seqIndex()-1; + + const std::pair groupPair = std::make_pair(static_cast(ind), std::addressof(group)); + indexGroupMap.insert(groupPair); + } + return indexGroupMap; +} + + +const std::vector Opm::RestartIO::Helpers::igphData::ig_phase(const Opm::Schedule& sched, + const std::size_t simStep, + const std::vector& inteHead) +{ + //construct the current list of groups to output the IGPH array + const auto indexGroupMap = Opm::RestartIO::Helpers::igphData::currentGroupMapIndexGroup(sched, simStep, inteHead); + //std::vector curGroups(ngmaxz(inteHead), nullptr); + std::vector inj_phase(ngmaxz(inteHead), 0); + + auto it = indexGroupMap.begin(); + while (it != indexGroupMap.end()) { - // make group index for current report step - std::map indexGroupMap; - for (const auto& group_name : sched.groupNames(simStep)) { - const auto& group = sched.getGroup(group_name); - int ind = (group.name() == "FIELD") - ? ngmaxz(inteHead)-1 : group.seqIndex()-1; - - const std::pair groupPair = std::make_pair(static_cast(ind), std::addressof(group)); - indexGroupMap.insert(groupPair); + auto ind = static_cast(it->first); + auto group_ptr = it->second; + if (group_ptr->isInjectionGroup(simStep)) { + auto phase = group_ptr->getInjectionPhase(simStep); + if ( phase == Opm::Phase::WATER ) inj_phase[ind] = 2; } - return indexGroupMap; + it++; } - - const std::vector Opm::RestartIO::Helpers::igphData::ig_phase(const Opm::Schedule& sched, - const std::size_t simStep, - const std::vector& inteHead) - { - //construct the current list of groups to output the IGPH array - const auto indexGroupMap = Opm::RestartIO::Helpers::igphData::currentGroupMapIndexGroup(sched, simStep, inteHead); - //std::vector curGroups(ngmaxz(inteHead), nullptr); - std::vector inj_phase(ngmaxz(inteHead), 0); - - auto it = indexGroupMap.begin(); - while (it != indexGroupMap.end()) - { - auto ind = static_cast(it->first); - auto group_ptr = it->second; - if (group_ptr->isInjectionGroup(simStep)) { - auto phase = group_ptr->getInjectionPhase(simStep); - if ( phase == Opm::Phase::WATER ) inj_phase[ind] = 2; - } - it++; - } - } - + return inj_phase; +} + + Opm::RestartIO::Helpers::AggregateUDQData:: AggregateUDQData(const std::vector& udqDims) : iUDQ_ (iUdq::allocate(udqDims)), @@ -358,7 +290,6 @@ captureDeclaredUDQData(const Opm::Schedule& sched, const std::vector& inteHead) { auto udqCfg = sched.getUDQConfig(simStep); - auto udq_active = sched.udqActive(simStep); for (const auto& udq_input : udqCfg.input()) { auto udq_index = udq_input.index.insert_index; { @@ -375,15 +306,13 @@ captureDeclaredUDQData(const Opm::Schedule& sched, } } + auto udq_active = sched.udqActive(simStep); if (udq_active) { - Opm::RestartIO::Helpers::iUADData iuad_data; - iuad_data.noIUADs(sched, simStep); - - // Loop not correct ... - for (const auto& udq_input : udqCfg.input()) { - auto i_uad = this->iUAD_[udq_index]; - iUad::staticContrib(iuad_data, udq_input.index.insert_index, i_uad); + for (std::size_t iactive = 0; iactive < udq_active.size(); iactive++) { + auto i_uad = this->iUAD_[iactive]; + iUad::staticContrib(udqCfg, udq_active, iactive, i_uad); } } } + diff --git a/src/opm/output/eclipse/CreateUdqDims.cpp b/src/opm/output/eclipse/CreateUdqDims.cpp index dd83f2d90..399a39844 100755 --- a/src/opm/output/eclipse/CreateUdqDims.cpp +++ b/src/opm/output/eclipse/CreateUdqDims.cpp @@ -39,12 +39,6 @@ namespace { -std::size_t noUDQs(const Opm::Schedule& sched, const std::size_t simStep) -{ - auto udqCfg = sched.getUDQConfig(simStep); - return udqCfg.size(); -} - std::size_t entriesPerIUDQ() { @@ -84,17 +78,16 @@ std::size_t entriesPerIGph(const std::vector& inteHead) std::vector Opm::RestartIO::Helpers:: createUdqDims(const Schedule& sched, - const std::size_t lookup_step, - const std::vector& inteHead) + const std::size_t simStep, + const std::vector& inteHead) { - Opm::RestartIO::Helpers::iUADData iuad_data; - iuad_data.iuad(sched, lookup_step); - const auto& no_iuad = iuad_data.count(); + const auto& udqCfg = sched.getUDQConfig(simStep); + const auto& udqActive = sched.udqActive(simStep); std::vector udqDims(7); - udqDims[0] = noUDQs(sched, lookup_step); + udqDims[0] = udqCfg.size(); udqDims[1] = entriesPerIUDQ(); - udqDims[2] = no_iuad; + udqDims[2] = udqActive.size(); udqDims[3] = entriesPerIUAD(); udqDims[4] = entriesPerZUDN(); udqDims[5] = entriesPerZUDL(); diff --git a/tests/test_UDQ_x.cpp b/tests/test_UDQ_x.cpp index f56d3451c..cee354b0e 100644 --- a/tests/test_UDQ_x.cpp +++ b/tests/test_UDQ_x.cpp @@ -508,8 +508,6 @@ BOOST_AUTO_TEST_CASE (Constructor) const auto udqDims = Opm::RestartIO::Helpers::createUdqDims(sched, rptStep, ih); auto udqData = Opm::RestartIO::Helpers::AggregateUDQData(udqDims); - Opm::RestartIO::Helpers::iUADData iuad_test; - iuad_test.iuad(sched, rptStep); udqData.captureDeclaredUDQData(sched, rptStep, ih); rstFile.write("IUDQ", udqData.getIUDQ()); @@ -519,4 +517,4 @@ BOOST_AUTO_TEST_CASE (Constructor) } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END()