Loading...
Searching...
No Matches
DataHandleWrappers.hpp
//===========================================================================
//
// File: DataHandleWrappers.hpp
//
// Created: Mon Nov 4 2013
//
// Author(s): Markus Blatt <markus@dr-blatt.de>
//
// $Date$
//
// $Revision$
//
//===========================================================================
#ifndef OPM_DATAHANDLEWRAPPERS_HEADER
#define OPM_DATAHANDLEWRAPPERS_HEADER
#include "OrientedEntityTable.hpp"
#include "EntityRep.hpp"
#include <array>
#include <numeric>
#include <vector>
namespace Dune::cpgrid {
template<class Handle>
struct FaceViaCellHandleWrapper
{
using DataType = typename Handle::DataType;
using C2FTable = OrientedEntityTable<0, 1>;
FaceViaCellHandleWrapper(Handle& handle,
const C2FTable& c2fGather,
const C2FTable& c2f)
: handle_(handle), c2fGather_(c2fGather), c2f_(c2f)
{}
bool fixedSize(int, int)
{
return false; // as the faces per cell differ
}
template<class T>
typename std::enable_if<T::codimension != 0, std::size_t>::type
size(const T&)
{
OPM_THROW(std::logic_error, "This should never throw! We only know sizes for cells");
return 1;
}
std::size_t size(const EntityRep<0>& t)
{
const auto& faces = c2fGather_[t];
return std::accumulate(faces.begin(), faces.end(), std::size_t{0},
[this](const auto acc, const auto& face)
{ return acc + handle_.size(face); });
}
bool contains(std::size_t dim, std::size_t codim)
{
return dim==3 && codim == 0;
}
template<class B, class T>
typename std::enable_if<T::codimension != 0, void>::type
gather(B&, const T&)
{
OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
}
template<class B>
void gather(B& buffer, const EntityRep<0>& t)
{
const auto& faces = c2fGather_[t];
for (const auto& face : faces)
{
handle_.gather(buffer, face);
}
}
template<class B, class T>
typename std::enable_if<T::codimension != 0, void>::type
scatter(B&, const T&, std::size_t)
{
OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
}
template<class B>
void scatter(B& buffer, const EntityRep<0>& t, std::size_t)
{
const auto& faces = c2f_[t];
for (const auto& face : faces)
{
// Note that the size (last parameter) is not correct here.
// Therefore this handle needs to know how many data items
// to expect. Not usable outside of CpGrid.
handle_.scatter(buffer, face, 1);
}
}
private:
Handle& handle_;
const C2FTable& c2fGather_, c2f_;
};
struct PointViaCellWarner
{
static bool printWarn;
void warn();
};
template<class Handle>
struct PointViaCellHandleWrapper : public PointViaCellWarner
{
using DataType = typename Handle::DataType;
using C2PTable = std::vector< std::array<int,8> >;
PointViaCellHandleWrapper(Handle& handle,
const C2PTable& c2pGather,
const C2PTable& c2p)
: handle_(handle), c2pGather_(c2pGather), c2p_(c2p)
{}
bool fixedSize(int i, int j)
{
if( ! handle_.fixedSize(i, j))
{
this->warn();
}
return handle_.fixedSize(i, j);
}
template<class T>
typename std::enable_if<T::codimension != 0, std::size_t>::type
size(const T&)
{
OPM_THROW(std::logic_error, "This should never throw! We only know sizes for cells");
return 1;
}
std::size_t size(const EntityRep<0>& t)
{
const auto& points = c2pGather_[t.index()];
return std::accumulate(points.begin(), points.end(), std::size_t{0},
[this](const auto acc, const auto& point)
{ return acc + handle_.size(EntityRep<3>(point, true)); });
}
bool contains(std::size_t dim, std::size_t codim)
{
return dim==3 && codim == 0;
}
template<class B, class T>
typename std::enable_if<T::codimension != 0, void>::type
gather(B&, const T&)
{
OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
}
template<class B>
void gather(B& buffer, const EntityRep<0>& t)
{
const auto& points = c2pGather_[t.index()];
for (const auto& point : points)
{
handle_.gather(buffer, EntityRep<3>(point, true));
}
}
template<class B, class T>
typename std::enable_if<T::codimension != 0, void>::type
scatter(B&, const T&, std::size_t)
{
OPM_THROW(std::logic_error, "This should never throw! We can only gather cell values and indicate that");
}
template<class B>
void scatter(B& buffer, const EntityRep<0>& t, std::size_t s)
{
const auto& points = c2p_[t.index()];
for (const auto& point : points)
{
handle_.scatter(buffer, EntityRep<3>(point, true), s/8);
}
}
private:
Handle& handle_;
const C2PTable& c2pGather_, c2p_;
};
} // end namespace Dune::cpgrid
#endif
Dune::cpgrid::OrientedEntityTable
Represents the topological relationships between sets of entities, for example cells and faces.
Definition OrientedEntityTable.hpp:139
Dune::cpgrid
Copyright 2019 Equinor AS.
Definition GridPartitioning.cpp:673
Dune::cpgrid::FaceViaCellHandleWrapper::FaceViaCellHandleWrapper
FaceViaCellHandleWrapper(Handle &handle, const C2FTable &c2fGather, const C2FTable &c2f)
Constructs the data handle.
Definition DataHandleWrappers.hpp:66
Dune::cpgrid::PointViaCellHandleWrapper::PointViaCellHandleWrapper
PointViaCellHandleWrapper(Handle &handle, const C2PTable &c2pGather, const C2PTable &c2p)
Constructs the data handle.
Definition DataHandleWrappers.hpp:158
Dune::cpgrid::PointViaCellWarner
Definition DataHandleWrappers.hpp:133