refactor DynamicState split methods for reuse
friend class Schedule so it can call them.
This commit is contained in:
@@ -56,7 +56,7 @@ namespace Opm {
|
||||
|
||||
template< class T >
|
||||
class DynamicState {
|
||||
|
||||
friend class Schedule;
|
||||
public:
|
||||
typedef typename std::vector< T >::iterator iterator;
|
||||
|
||||
@@ -231,19 +231,19 @@ class DynamicState {
|
||||
template<class Serializer, bool complexType = true>
|
||||
void serializeOp(Serializer& serializer)
|
||||
{
|
||||
auto split = Split();
|
||||
serializer.template vector<T,complexType>(split.first);
|
||||
serializer(split.second);
|
||||
if (m_data.empty())
|
||||
reconstruct(split.first, split.second);
|
||||
std::vector<T> unique;
|
||||
auto indices = split(unique);
|
||||
serializer.template vector<T,complexType>(unique);
|
||||
serializer(indices);
|
||||
if (!serializer.isSerializing())
|
||||
reconstruct(unique, indices);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector< T > m_data;
|
||||
size_t initial_range;
|
||||
|
||||
std::pair<std::vector<T>,std::vector<size_t>> Split() {
|
||||
std::vector<T> unique;
|
||||
std::vector<size_t> split(std::vector<T>& unique) const {
|
||||
std::vector<size_t> idxVec;
|
||||
idxVec.reserve(m_data.size() + 1);
|
||||
for (const auto& w : m_data) {
|
||||
@@ -257,7 +257,7 @@ class DynamicState {
|
||||
}
|
||||
idxVec.push_back(initial_range);
|
||||
|
||||
return std::make_pair(unique, idxVec);
|
||||
return idxVec;
|
||||
}
|
||||
|
||||
void reconstruct(const std::vector<T>& unique,
|
||||
|
||||
@@ -448,50 +448,28 @@ namespace Opm
|
||||
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>>>>
|
||||
std::pair<std::vector<Type>, std::vector<std::pair<Key, std::vector<size_t>>>>
|
||||
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<std::pair<Key, std::vector<size_t>>> 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));
|
||||
auto indices = it.second.split(unique);
|
||||
asMap.push_back(std::make_pair(it.first, indices));
|
||||
}
|
||||
|
||||
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,
|
||||
const std::vector<std::pair<Key, std::vector<size_t>>>& asMap,
|
||||
Map<Key, Opm::DynamicState<Type>>& result)
|
||||
{
|
||||
for (const auto& it : asMap) {
|
||||
reconstructDynState(unique, it.second, result[it.first]);
|
||||
result[it.first].reconstruct(unique, it.second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user