From 26b2a3a55416295a9db53a22f86076b9fb977c5b Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Mar 2020 11:58:23 +0100 Subject: [PATCH 1/2] add serialization template to Schedule --- .../EclipseState/Schedule/Schedule.hpp | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 63f8cd497..fd43e4c04 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -297,6 +297,52 @@ namespace Opm for the schedule instances created by loading a restart file. */ static bool cmp(const Schedule& sched1, const Schedule& sched2, std::size_t report_step); + + template + void serializeOp(Serializer& serializer) + { + serializer(m_timeMap); + auto splitWells = splitDynMap(wells_static); + serializer(splitWells.first); + serializer(splitWells.second); + auto splitGroups = splitDynMap(groups); + serializer(splitGroups.first); + serializer(splitGroups.second); + serializer(m_oilvaporizationproperties); + serializer(m_events); + serializer(m_modifierDeck); + serializer(m_tuning); + serializer(m_messageLimits); + serializer(m_runspec); + auto splitvfpprod = splitDynMap(vfpprod_tables); + serializer(splitvfpprod.first); + serializer(splitvfpprod.second); + auto splitvfpinj = splitDynMap(vfpinj_tables); + serializer(splitvfpinj.first); + serializer(splitvfpinj.second); + serializer(wtest_config); + serializer(wlist_manager); + serializer(udq_config); + serializer(udq_active); + serializer(guide_rate_config); + serializer(gconsale); + serializer(gconsump); + serializer(global_whistctl_mode); + serializer(m_actions); + serializer(rft_config); + serializer(m_nupcol); + serializer(restart_config); + serializer(wellgroup_events); + if (wells_static.size() == 0) + reconstructDynMap(splitWells.first, splitWells.second, wells_static); + if (groups.size() == 0) + reconstructDynMap(splitGroups.first, splitGroups.second, groups); + if (vfpprod_tables.empty()) + reconstructDynMap(splitvfpprod.first, splitvfpprod.second, vfpprod_tables); + if (vfpinj_tables.empty()) + reconstructDynMap(splitvfpinj.first, splitvfpinj.second, vfpinj_tables); + } + private: TimeMap m_timeMap; WellMap wells_static; @@ -421,6 +467,54 @@ namespace Opm const UnitSystem& unit_system, std::vector >& rftProperties); void addWellGroupEvent(const std::string& wellGroup, ScheduleEvents::Events event, size_t reportStep); + + template class Map, class Type, class Key> + std::pair, std::vector>>> + splitDynMap(const Map>& map) + { + // we have to pack the unique ptrs separately, and use an index map + // to allow reconstructing the appropriate structures. + std::vector>> asMap; + std::vector unique; + for (const auto& it : map) { + std::vector idxVec; + for (const auto& w : it.second.data()) { + auto candidate = std::find(unique.begin(), unique.end(), w); + auto idx = candidate - unique.begin(); + if (candidate == unique.end()) { + unique.push_back(w); + idx = unique.size()-1; + } + idxVec.push_back(idx); + } + idxVec.push_back(it.second.initialRange()); + asMap.push_back(std::make_pair(it.first, idxVec)); + } + + return std::make_pair(unique, asMap); + } + + template + void reconstructDynState(const std::vector& unique, + const std::vector& idxVec, + Opm::DynamicState& result) + { + std::vector ptrData; + for (size_t i = 0; i < idxVec.size()-1; ++i) { + ptrData.push_back(unique[idxVec[i]]); + } + result = Opm::DynamicState(ptrData, idxVec.back()); + } + + template class Map, class Type, class Key> + void reconstructDynMap(const std::vector& unique, + const std::vector>>& asMap, + Map>& result) + { + for (const auto& it : asMap) { + reconstructDynState(unique, it.second, result[it.first]); + } + } }; } From e41919c6f57d718b310b9e25c8c2c5c3542dda45 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Mar 2020 12:10:32 +0100 Subject: [PATCH 2/2] remove accessors added for external serialization support --- .../EclipseState/Schedule/Schedule.hpp | 19 --- .../EclipseState/Schedule/Schedule.cpp | 120 ++++-------------- 2 files changed, 24 insertions(+), 115 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index fd43e4c04..2d95966dd 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -268,25 +268,6 @@ namespace Opm void applyAction(size_t reportStep, const Action::ActionX& action, const Action::Result& result); int getNupcol(size_t reportStep) const; - const WellMap& getStaticWells() const; - const GroupMap& getGroups() const; - const DynamicState& getOilVapProps() const; - const DynamicVector& getModifierDeck() const; - const Runspec& getRunspec() const; - const VFPProdMap& getVFPProdTables() const; - const VFPInjMap& getVFPInjTables() const; - const DynamicState>& getWellTestConfig() const; - const DynamicState>& getWListManager() const; - const DynamicState>& getUDQConfig() const; - const DynamicState>& getUDQActive() const; - const DynamicState>& getGuideRateConfig() const; - const DynamicState>& getGConSale() const; - const DynamicState>& getGConSump() const; - const DynamicState& getGlobalWhistCtlMode() const; - const DynamicState>& getActions() const; - const DynamicState& getNupCol() const; - const std::map& getWellGroupEvents() const; - bool operator==(const Schedule& data) const; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index 1f6f91005..2b8144359 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -2856,78 +2856,6 @@ void Schedule::invalidNamePattern( const std::string& namePattern, std::size_t return this->m_nupcol.get(reportStep); } - const Schedule::WellMap& Schedule::getStaticWells() const { - return wells_static; - } - - const Schedule::GroupMap& Schedule::getGroups() const { - return groups; - } - - const DynamicState& Schedule::getOilVapProps() const { - return m_oilvaporizationproperties; - } - - const DynamicVector& Schedule::getModifierDeck() const { - return m_modifierDeck; - } - - const Runspec& Schedule::getRunspec() const { - return m_runspec; - } - - const Schedule::VFPProdMap& Schedule::getVFPProdTables() const { - return vfpprod_tables; - } - - const Schedule::VFPInjMap& Schedule::getVFPInjTables() const { - return vfpinj_tables; - } - - const DynamicState>& Schedule::getWellTestConfig() const { - return wtest_config; - } - - const DynamicState>& Schedule::getWListManager() const { - return wlist_manager; - } - - const DynamicState>& Schedule::getUDQConfig() const { - return udq_config; - } - - const DynamicState>& Schedule::getUDQActive() const { - return udq_active; - } - - const DynamicState>& Schedule::getGuideRateConfig() const { - return guide_rate_config; - } - - const DynamicState>& Schedule::getGConSale() const { - return gconsale; - } - - const DynamicState>& Schedule::getGConSump() const { - return gconsump; - } - - const DynamicState& Schedule::getGlobalWhistCtlMode() const { - return global_whistctl_mode; - } - - const DynamicState>& Schedule::getActions() const { - return m_actions; - } - - const DynamicState& Schedule::getNupCol() const { - return m_nupcol; - } - - const std::map& Schedule::getWellGroupEvents() const { - return wellgroup_events; - } - bool Schedule::operator==(const Schedule& data) const { auto&& comparePtr = [](const auto& t1, const auto& t2) { if ((t1 && !t2) || (!t1 && t2)) @@ -2960,30 +2888,30 @@ void Schedule::invalidNamePattern( const std::string& namePattern, std::size_t return true; }; - return this->getTimeMap() == data.getTimeMap() && - compareMap(this->getStaticWells(), data.getStaticWells()) && - compareMap(this->getGroups(), data.getGroups()) && - this->getOilVapProps() == data.getOilVapProps() && - this->getEvents() == data.getEvents() && - this->getModifierDeck() == data.getModifierDeck() && - this->getTuning() == data.getTuning() && - this->getMessageLimits() == data.getMessageLimits() && - this->getRunspec() == data.getRunspec() && - compareMap(this->getVFPProdTables(), data.getVFPProdTables()) && - compareMap(this->getVFPInjTables(), data.getVFPInjTables()) && - compareDynState(this->getWellTestConfig(), data.getWellTestConfig()) && - compareDynState(this->getWListManager(), data.getWListManager()) && - compareDynState(this->getUDQConfig(), data.getUDQConfig()) && - compareDynState(this->getUDQActive(), data.getUDQActive()) && - compareDynState(this->getGuideRateConfig(), data.getGuideRateConfig()) && - compareDynState(this->getGConSale(), data.getGConSale()) && - compareDynState(this->getGConSump(), data.getGConSump()) && - this->getGlobalWhistCtlMode() == data.getGlobalWhistCtlMode() && - compareDynState(this->getActions(), data.getActions()) && - this->rftConfig () == data.rftConfig() && - this->getNupCol() == data.getNupCol() && - this->restart() == data.restart() && - this->getWellGroupEvents() == data.getWellGroupEvents(); + return this->m_timeMap == data.m_timeMap && + compareMap(this->wells_static, data.wells_static) && + compareMap(this->groups, data.groups) && + this->m_oilvaporizationproperties == data.m_oilvaporizationproperties && + this->m_events == data.m_events && + this->m_modifierDeck == data.m_modifierDeck && + this->m_tuning == data.m_tuning && + this->m_messageLimits == data.m_messageLimits && + this->m_runspec == data.m_runspec && + compareMap(this->vfpprod_tables, data.vfpprod_tables) && + compareMap(this->vfpinj_tables, data.vfpinj_tables) && + compareDynState(this->wtest_config, data.wtest_config) && + compareDynState(this->wlist_manager, data.wlist_manager) && + compareDynState(this->udq_config, data.udq_config) && + compareDynState(this->udq_active, data.udq_active) && + compareDynState(this->guide_rate_config, data.guide_rate_config) && + compareDynState(this->gconsale, data.gconsale) && + compareDynState(this->gconsump, data.gconsump) && + this->global_whistctl_mode == data.global_whistctl_mode && + compareDynState(this->m_actions, data.m_actions) && + rft_config == data.rft_config && + this->m_nupcol == data.m_nupcol && + this->restart_config == data.restart_config && + this->wellgroup_events == data.wellgroup_events; }