mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #4084 from akva2/tran_distribute_eclmpiserializer
changed: use EclMpiSerializer to distribute transmissibilities
This commit is contained in:
commit
15ca494164
@ -109,6 +109,18 @@ public:
|
|||||||
void apply_tran(const std::string& keyword, std::vector<double>& trans) const override;
|
void apply_tran(const std::string& keyword, std::vector<double>& trans) const override;
|
||||||
|
|
||||||
void deserialize_tran(const std::vector<char>& buffer) override;
|
void deserialize_tran(const std::vector<char>& buffer) override;
|
||||||
|
|
||||||
|
void copyTran(const FieldPropsManager& from)
|
||||||
|
{
|
||||||
|
m_tran = from.getTran();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer.map(m_tran);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<std::string, Fieldprops::FieldData<int>> m_intProps; //!< Map of integer properties in process-local compressed indices.
|
std::map<std::string, Fieldprops::FieldData<int>> m_intProps; //!< Map of integer properties in process-local compressed indices.
|
||||||
std::map<std::string, Fieldprops::FieldData<double>> m_doubleProps; //!< Map of double properties in process-local compressed indices.
|
std::map<std::string, Fieldprops::FieldData<double>> m_doubleProps; //!< Map of double properties in process-local compressed indices.
|
||||||
|
@ -65,44 +65,34 @@ public:
|
|||||||
const EclipseGrid* eclGridOnRoot,
|
const EclipseGrid* eclGridOnRoot,
|
||||||
std::vector<double>& centroids,
|
std::vector<double>& centroids,
|
||||||
const typename Dune::CartesianIndexMapper<Grid>& cartMapper)
|
const typename Dune::CartesianIndexMapper<Grid>& cartMapper)
|
||||||
: m_grid(grid), m_distributed_fieldProps(eclState.m_fieldProps),
|
: m_grid(grid),
|
||||||
|
m_distributed_fieldProps(eclState.m_fieldProps),
|
||||||
m_centroids(centroids)
|
m_centroids(centroids)
|
||||||
{
|
{
|
||||||
// Scatter the keys
|
// Scatter the keys
|
||||||
const Parallel::Communication comm = m_grid.comm();
|
const Parallel::Communication comm = m_grid.comm();
|
||||||
if (comm.rank() == 0)
|
if (comm.rank() == 0)
|
||||||
{
|
{
|
||||||
const auto& globalProps = eclState.globalFieldProps();
|
const FieldPropsManager& globalProps = eclState.globalFieldProps();
|
||||||
m_intKeys = globalProps.keys<int>();
|
m_intKeys = globalProps.keys<int>();
|
||||||
m_doubleKeys = globalProps.keys<double>();
|
m_doubleKeys = globalProps.keys<double>();
|
||||||
std::size_t packSize = Mpi::packSize(m_intKeys, comm) +
|
m_distributed_fieldProps.copyTran(globalProps);
|
||||||
Mpi::packSize(m_doubleKeys,comm);
|
}
|
||||||
std::vector<char> buffer(packSize);
|
|
||||||
int position = 0;
|
|
||||||
Mpi::pack(m_intKeys, buffer, position, comm);
|
|
||||||
Mpi::pack(m_doubleKeys, buffer, position, comm);
|
|
||||||
int calcStart = position;
|
|
||||||
{
|
|
||||||
std::vector<char> tran_buffer = globalProps.serialize_tran();
|
|
||||||
position += tran_buffer.size();
|
|
||||||
buffer.insert(buffer.end(), std::make_move_iterator(tran_buffer.begin()), std::make_move_iterator(tran_buffer.end()));
|
|
||||||
}
|
|
||||||
comm.broadcast(&position, 1, 0);
|
|
||||||
comm.broadcast(buffer.data(), position, 0);
|
|
||||||
|
|
||||||
// Unpack Calculator as we need it here, too.
|
EclMpiSerializer ser(comm);
|
||||||
m_distributed_fieldProps.deserialize_tran( std::vector<char>(buffer.begin() + calcStart, buffer.end()) );
|
ser.broadcast(*this);
|
||||||
|
|
||||||
// copy data to persistent map based on local id
|
m_no_data = m_intKeys.size() + m_doubleKeys.size() + Grid::dimensionworld;
|
||||||
m_no_data = m_intKeys.size() + m_doubleKeys.size() +
|
|
||||||
Grid::dimensionworld;
|
if (comm.rank() == 0) {
|
||||||
|
const FieldPropsManager& globalProps = eclState.globalFieldProps();
|
||||||
const auto& idSet = m_grid.localIdSet();
|
const auto& idSet = m_grid.localIdSet();
|
||||||
const auto& gridView = m_grid.levelGridView(0);
|
const auto& gridView = m_grid.levelGridView(0);
|
||||||
using ElementMapper =
|
using ElementMapper =
|
||||||
Dune::MultipleCodimMultipleGeomTypeMapper<typename Grid::LevelGridView>;
|
Dune::MultipleCodimMultipleGeomTypeMapper<typename Grid::LevelGridView>;
|
||||||
ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
|
ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
|
||||||
|
|
||||||
for( const auto &element : elements( gridView, Dune::Partitions::interiorBorder ) )
|
for (const auto &element : elements(gridView, Dune::Partitions::interiorBorder))
|
||||||
{
|
{
|
||||||
const auto& id = idSet.id(element);
|
const auto& id = idSet.id(element);
|
||||||
auto index = elemMapper.index(element);
|
auto index = elemMapper.index(element);
|
||||||
@ -132,31 +122,18 @@ public:
|
|||||||
data.emplace_back(center[dim], '1'); // write garbage for value_status
|
data.emplace_back(center[dim], '1'); // write garbage for value_status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
int bufferSize;
|
|
||||||
comm.broadcast(&bufferSize, 1, 0);
|
|
||||||
std::vector<char> buffer(bufferSize);
|
|
||||||
comm.broadcast(buffer.data(), bufferSize, 0);
|
|
||||||
int position{};
|
|
||||||
Mpi::unpack(m_intKeys, buffer, position, comm);
|
|
||||||
Mpi::unpack(m_doubleKeys, buffer, position, comm);
|
|
||||||
m_distributed_fieldProps.deserialize_tran( std::vector<char>(buffer.begin() + position, buffer.end()) );
|
|
||||||
m_no_data = m_intKeys.size() + m_doubleKeys.size() +
|
|
||||||
Grid::dimensionworld;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~PropsCentroidsDataHandle()
|
~PropsCentroidsDataHandle()
|
||||||
{
|
{
|
||||||
// distributed grid is now correctly set up.
|
// distributed grid is now correctly set up.
|
||||||
for(const auto& intKey : m_intKeys)
|
for (const auto& intKey : m_intKeys)
|
||||||
{
|
{
|
||||||
m_distributed_fieldProps.m_intProps[intKey].data.resize(m_grid.size(0));
|
m_distributed_fieldProps.m_intProps[intKey].data.resize(m_grid.size(0));
|
||||||
m_distributed_fieldProps.m_intProps[intKey].value_status.resize(m_grid.size(0));
|
m_distributed_fieldProps.m_intProps[intKey].value_status.resize(m_grid.size(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const auto& doubleKey : m_doubleKeys)
|
for (const auto& doubleKey : m_doubleKeys)
|
||||||
{
|
{
|
||||||
m_distributed_fieldProps.m_doubleProps[doubleKey].data.resize(m_grid.size(0));
|
m_distributed_fieldProps.m_doubleProps[doubleKey].data.resize(m_grid.size(0));
|
||||||
m_distributed_fieldProps.m_doubleProps[doubleKey].value_status.resize(m_grid.size(0));
|
m_distributed_fieldProps.m_doubleProps[doubleKey].value_status.resize(m_grid.size(0));
|
||||||
@ -171,7 +148,7 @@ public:
|
|||||||
Dune::MultipleCodimMultipleGeomTypeMapper<typename Grid::LevelGridView>;
|
Dune::MultipleCodimMultipleGeomTypeMapper<typename Grid::LevelGridView>;
|
||||||
ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
|
ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
|
||||||
|
|
||||||
for( const auto &element : elements( gridView, Dune::Partitions::all ) )
|
for (const auto &element : elements( gridView, Dune::Partitions::all))
|
||||||
{
|
{
|
||||||
std::size_t counter{};
|
std::size_t counter{};
|
||||||
const auto& id = idSet.id(element);
|
const auto& id = idSet.id(element);
|
||||||
@ -179,14 +156,14 @@ public:
|
|||||||
auto data = elementData_.find(id);
|
auto data = elementData_.find(id);
|
||||||
assert(data != elementData_.end());
|
assert(data != elementData_.end());
|
||||||
|
|
||||||
for(const auto& intKey : m_intKeys)
|
for (const auto& intKey : m_intKeys)
|
||||||
{
|
{
|
||||||
const auto& pair = data->second[counter++];
|
const auto& pair = data->second[counter++];
|
||||||
m_distributed_fieldProps.m_intProps[intKey].data[index] = static_cast<int>(pair.first);
|
m_distributed_fieldProps.m_intProps[intKey].data[index] = static_cast<int>(pair.first);
|
||||||
m_distributed_fieldProps.m_intProps[intKey].value_status[index] = static_cast<value::status>(pair.second);
|
m_distributed_fieldProps.m_intProps[intKey].value_status[index] = static_cast<value::status>(pair.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const auto& doubleKey : m_doubleKeys)
|
for (const auto& doubleKey : m_doubleKeys)
|
||||||
{
|
{
|
||||||
const auto& pair = data->second[counter++];
|
const auto& pair = data->second[counter++];
|
||||||
m_distributed_fieldProps.m_doubleProps[doubleKey].data[index] = pair.first;
|
m_distributed_fieldProps.m_doubleProps[doubleKey].data[index] = pair.first;
|
||||||
@ -225,7 +202,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto iter = elementData_.find(m_grid.localIdSet().id(e));
|
auto iter = elementData_.find(m_grid.localIdSet().id(e));
|
||||||
assert(iter != elementData_.end());
|
assert(iter != elementData_.end());
|
||||||
for(const auto& data : iter->second)
|
for (const auto& data : iter->second)
|
||||||
{
|
{
|
||||||
buffer.write(data);
|
buffer.write(data);
|
||||||
}
|
}
|
||||||
@ -237,12 +214,20 @@ public:
|
|||||||
assert(n == m_no_data);
|
assert(n == m_no_data);
|
||||||
auto& array = elementData_[m_grid.localIdSet().id(e)];
|
auto& array = elementData_[m_grid.localIdSet().id(e)];
|
||||||
array.resize(n);
|
array.resize(n);
|
||||||
for(auto& data: array)
|
for (auto& data : array)
|
||||||
{
|
{
|
||||||
buffer.read(data);
|
buffer.read(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(m_intKeys);
|
||||||
|
serializer(m_doubleKeys);
|
||||||
|
m_distributed_fieldProps.serializeOp(serializer);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using LocalIdSet = typename Grid::LocalIdSet;
|
using LocalIdSet = typename Grid::LocalIdSet;
|
||||||
const Grid& m_grid;
|
const Grid& m_grid;
|
||||||
|
Loading…
Reference in New Issue
Block a user