26#ifndef PROPS_DATAHANDLE_HPP
27#define PROPS_DATAHANDLE_HPP
31#include <opm/input/eclipse/EclipseState/Grid/FieldData.hpp>
36#include <dune/grid/common/datahandleif.hh>
37#include <dune/grid/common/mcmgmapper.hh>
38#include <dune/grid/common/partitionset.hh>
39#include <dune/common/parallel/mpihelper.hh>
40#include <unordered_map>
53 :
public Dune::CommDataHandleIF< PropsDataHandle<Grid>, double>
57 using DataType = std::pair<double, unsigned char>;
65 m_distributed_fieldProps(eclState.m_fieldProps)
72 m_intKeys = globalProps.keys<
int>();
73 m_doubleKeys = globalProps.keys<
double>();
74 m_distributed_fieldProps.
copyTran(globalProps);
80 m_no_data = m_intKeys.size() + m_doubleKeys.size();
82 if (comm.rank() == 0) {
84 const auto& idSet = m_grid.localIdSet();
85 const auto& gridView = m_grid.levelGridView(0);
87 Dune::MultipleCodimMultipleGeomTypeMapper<typename Grid::LevelGridView>;
88 ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
90 for (
const auto &element : elements(gridView, Dune::Partitions::interiorBorder))
92 const auto&
id = idSet.id(element);
93 auto index = elemMapper.index(element);
94 auto& data = elementData_[id];
95 data.reserve(m_no_data);
97 for (
const auto& intKey : m_intKeys)
99 const auto& fieldData = globalProps.get_int_field_data(intKey);
100 data.emplace_back(fieldData.data[index],
101 static_cast<unsigned char>(fieldData.value_status[index]));
104 for (
const auto& doubleKey : m_doubleKeys)
108 const auto& fieldData = globalProps.get_double_field_data(doubleKey,
110 data.emplace_back(fieldData.data[index],
111 static_cast<unsigned char>(fieldData.value_status[index]));
120 for (
const auto& intKey : m_intKeys)
122 m_distributed_fieldProps.
m_intProps[intKey].data.resize(m_grid.size(0));
123 m_distributed_fieldProps.
m_intProps[intKey].value_status.resize(m_grid.size(0));
126 for (
const auto& doubleKey : m_doubleKeys)
128 m_distributed_fieldProps.
m_doubleProps[doubleKey].data.resize(m_grid.size(0));
129 m_distributed_fieldProps.
m_doubleProps[doubleKey].value_status.resize(m_grid.size(0));
133 const auto& idSet = m_grid.localIdSet();
134 const auto& gridView = m_grid.levelGridView(0);
135 using ElementMapper =
136 Dune::MultipleCodimMultipleGeomTypeMapper<typename Grid::LevelGridView>;
137 ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
139 for (
const auto &element : elements( gridView, Dune::Partitions::all))
141 std::size_t counter{};
142 const auto&
id = idSet.id(element);
143 auto index = elemMapper.index(element);
144 auto data = elementData_.find(
id);
145 assert(data != elementData_.end());
147 for (
const auto& intKey : m_intKeys)
149 const auto& pair = data->second[counter++];
150 m_distributed_fieldProps.
m_intProps[intKey].data[index] =
static_cast<int>(pair.first);
151 m_distributed_fieldProps.
m_intProps[intKey].value_status[index] =
static_cast<value::status
>(pair.second);
154 for (
const auto& doubleKey : m_doubleKeys)
156 const auto& pair = data->second[counter++];
157 m_distributed_fieldProps.
m_doubleProps[doubleKey].data[index] = pair.first;
158 m_distributed_fieldProps.
m_doubleProps[doubleKey].value_status[index] =
static_cast<value::status
>(pair.second);
177 template<
class EntityType>
178 std::size_t
size(
const EntityType )
183 template<
class BufferType,
class EntityType>
184 void gather(BufferType& buffer,
const EntityType& e)
const
186 auto iter = elementData_.find(m_grid.localIdSet().id(e));
187 assert(iter != elementData_.end());
188 for (
const auto& data : iter->second)
194 template<
class BufferType,
class EntityType>
195 void scatter(BufferType& buffer,
const EntityType& e, std::size_t n)
197 assert(n == m_no_data);
198 auto& array = elementData_[m_grid.localIdSet().id(e)];
200 for (
auto& data : array)
206 template<
class Serializer>
209 serializer(m_intKeys);
210 serializer(m_doubleKeys);
215 using LocalIdSet =
typename Grid::LocalIdSet;
220 std::vector<std::string> m_intKeys;
222 std::vector<std::string> m_doubleKeys;
226 std::unordered_map<typename LocalIdSet::IdType, std::vector<std::pair<double,unsigned char> > > elementData_;
228 std::size_t m_no_data;
Class for serializing and broadcasting data using MPI.
Definition: MPISerializer.hpp:31
void broadcast(T &data, int root=0)
Serialize and broadcast on root process, de-serialize on others.
Definition: MPISerializer.hpp:46
Parallel frontend to the EclipseState.
Definition: ParallelEclipseState.hpp:147
const FieldPropsManager & globalFieldProps() const override
Returns a const ref to global field properties.
Parallel frontend to the field properties.
Definition: ParallelEclipseState.hpp:42
std::map< std::string, Fieldprops::FieldData< int > > m_intProps
Map of integer properties in process-local compressed indices.
Definition: ParallelEclipseState.hpp:126
void serializeOp(Serializer &serializer)
Definition: ParallelEclipseState.hpp:120
void copyTran(const FieldPropsManager &from)
Definition: ParallelEclipseState.hpp:114
std::map< std::string, Fieldprops::FieldData< double > > m_doubleProps
Map of double properties in process-local compressed indices.
Definition: ParallelEclipseState.hpp:127
A Data handle to communicate the field properties during load balance.
Definition: PropsDataHandle.hpp:54
PropsDataHandle(const Grid &grid, ParallelEclipseState &eclState)
Constructor.
Definition: PropsDataHandle.hpp:63
std::size_t size(const EntityType)
Definition: PropsDataHandle.hpp:178
std::pair< double, unsigned char > DataType
the data type we send (ints are converted to double)
Definition: PropsDataHandle.hpp:57
void serializeOp(Serializer &serializer)
Definition: PropsDataHandle.hpp:207
bool fixedSize(int, int)
Definition: PropsDataHandle.hpp:172
bool fixedsize(int, int)
Definition: PropsDataHandle.hpp:168
bool contains(int, int codim)
Definition: PropsDataHandle.hpp:163
~PropsDataHandle()
Definition: PropsDataHandle.hpp:117
void gather(BufferType &buffer, const EntityType &e) const
Definition: PropsDataHandle.hpp:184
void scatter(BufferType &buffer, const EntityType &e, std::size_t n)
Definition: PropsDataHandle.hpp:195
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:37