Merge pull request #1565 from akva2/serializer_schedule
Add serialization template to Schedule
This commit is contained in:
commit
62caad82a3
@ -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<OilVaporizationProperties>& getOilVapProps() const;
|
||||
const DynamicVector<Deck>& getModifierDeck() const;
|
||||
const Runspec& getRunspec() const;
|
||||
const VFPProdMap& getVFPProdTables() const;
|
||||
const VFPInjMap& getVFPInjTables() const;
|
||||
const DynamicState<std::shared_ptr<WellTestConfig>>& getWellTestConfig() const;
|
||||
const DynamicState<std::shared_ptr<WListManager>>& getWListManager() const;
|
||||
const DynamicState<std::shared_ptr<UDQConfig>>& getUDQConfig() const;
|
||||
const DynamicState<std::shared_ptr<UDQActive>>& getUDQActive() const;
|
||||
const DynamicState<std::shared_ptr<GuideRateConfig>>& getGuideRateConfig() const;
|
||||
const DynamicState<std::shared_ptr<GConSale>>& getGConSale() const;
|
||||
const DynamicState<std::shared_ptr<GConSump>>& getGConSump() const;
|
||||
const DynamicState<Well::ProducerCMode>& getGlobalWhistCtlMode() const;
|
||||
const DynamicState<std::shared_ptr<Action::Actions>>& getActions() const;
|
||||
const DynamicState<int>& getNupCol() const;
|
||||
const std::map<std::string,Events>& getWellGroupEvents() const;
|
||||
|
||||
bool operator==(const Schedule& data) const;
|
||||
|
||||
|
||||
@ -297,6 +278,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<class Serializer>
|
||||
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 +448,54 @@ namespace Opm
|
||||
const UnitSystem& unit_system,
|
||||
std::vector<std::pair<const DeckKeyword*, size_t > >& rftProperties);
|
||||
void addWellGroupEvent(const std::string& wellGroup, ScheduleEvents::Events event, size_t reportStep);
|
||||
|
||||
template<template<class, class> class Map, class Type, class Key>
|
||||
std::pair<std::vector<Type>, std::vector<std::pair<Key, std::vector<int>>>>
|
||||
splitDynMap(const Map<Key, Opm::DynamicState<Type>>& map)
|
||||
{
|
||||
// we have to pack the unique ptrs separately, and use an index map
|
||||
// to allow reconstructing the appropriate structures.
|
||||
std::vector<std::pair<Key, std::vector<int>>> asMap;
|
||||
std::vector<Type> unique;
|
||||
for (const auto& it : map) {
|
||||
std::vector<int> 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<class Type>
|
||||
void reconstructDynState(const std::vector<Type>& unique,
|
||||
const std::vector<int>& idxVec,
|
||||
Opm::DynamicState<Type>& result)
|
||||
{
|
||||
std::vector<Type> ptrData;
|
||||
for (size_t i = 0; i < idxVec.size()-1; ++i) {
|
||||
ptrData.push_back(unique[idxVec[i]]);
|
||||
}
|
||||
result = Opm::DynamicState<Type>(ptrData, idxVec.back());
|
||||
}
|
||||
|
||||
template<template<class, class> class Map, class Type, class Key>
|
||||
void reconstructDynMap(const std::vector<Type>& unique,
|
||||
const std::vector<std::pair<Key, std::vector<int>>>& asMap,
|
||||
Map<Key, Opm::DynamicState<Type>>& result)
|
||||
{
|
||||
for (const auto& it : asMap) {
|
||||
reconstructDynState(unique, it.second, result[it.first]);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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<OilVaporizationProperties>& Schedule::getOilVapProps() const {
|
||||
return m_oilvaporizationproperties;
|
||||
}
|
||||
|
||||
const DynamicVector<Deck>& 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<std::shared_ptr<WellTestConfig>>& Schedule::getWellTestConfig() const {
|
||||
return wtest_config;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<WListManager>>& Schedule::getWListManager() const {
|
||||
return wlist_manager;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<UDQConfig>>& Schedule::getUDQConfig() const {
|
||||
return udq_config;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<UDQActive>>& Schedule::getUDQActive() const {
|
||||
return udq_active;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<GuideRateConfig>>& Schedule::getGuideRateConfig() const {
|
||||
return guide_rate_config;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<GConSale>>& Schedule::getGConSale() const {
|
||||
return gconsale;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<GConSump>>& Schedule::getGConSump() const {
|
||||
return gconsump;
|
||||
}
|
||||
|
||||
const DynamicState<Well::ProducerCMode>& Schedule::getGlobalWhistCtlMode() const {
|
||||
return global_whistctl_mode;
|
||||
}
|
||||
|
||||
const DynamicState<std::shared_ptr<Action::Actions>>& Schedule::getActions() const {
|
||||
return m_actions;
|
||||
}
|
||||
|
||||
const DynamicState<int>& Schedule::getNupCol() const {
|
||||
return m_nupcol;
|
||||
}
|
||||
|
||||
const std::map<std::string,Events>& 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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user