5#ifndef DUNE_GRIDGLUE_ADAPTER_GRIDGLUECOMMUNICATE_HH
6#define DUNE_GRIDGLUE_ADAPTER_GRIDGLUECOMMUNICATE_HH
15#include <dune/common/bartonnackmanifcheck.hh>
16#include <dune/common/parallel/communicator.hh>
17#include <dune/grid/common/datahandleif.hh>
18#include <dune/grid/common/gridenums.hh>
24 typedef std::pair<int, int> RankPair;
25 struct GlobalId :
public std::pair<RankPair, unsigned int>
31 this->first.first = 0;
32 this->first.second = 0;
39 this->first.first = i;
40 this->first.second = i;
48 GlobalId(
int i,
int j,
unsigned int n) {
49 this->first.first = std::min(i,j);
50 this->first.second = std::max(i,j);
55 inline std::ostream& operator<<(std::ostream& os,
const GlobalId &
id)
58 <<
id.first.first <<
"," <<
id.first.second <<
","
75 template <
class DataHandleImp,
class DataTypeImp>
91 template<
class RISType>
92 size_t size (RISType& i)
const
94 CHECK_INTERFACE_IMPLEMENTATION((asImp().
size(i)));
95 return asImp().size(i);
103 template<
class MessageBufferImp,
class EntityType,
class RISType>
104 void gather (MessageBufferImp& buff,
const EntityType& e,
const RISType & i)
const
106 MessageBufferIF<MessageBufferImp> buffIF(buff);
107 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().
gather(buffIF,e,i)));
117 template<
class MessageBufferImp,
class EntityType,
class RISType>
118 void scatter (MessageBufferImp& buff,
const EntityType& e,
const RISType & i,
size_t n)
120 MessageBufferIF<MessageBufferImp> buffIF(buff);
121 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().
scatter(buffIF,e,i,n)));
126 DataHandleImp& asImp () {
127 return static_cast<DataHandleImp &
> (*this);
130 const DataHandleImp& asImp ()
const
132 return static_cast<const DataHandleImp &
>(*this);
140 template<
typename DT>
143 typedef DT value_type;
155 void write (
const Y& data)
157 static_assert(std::is_same<DT,Y>::value,
"DataType mismatch");
163 void read (Y& data)
const
165 static_assert(std::is_same<DT,Y>::value,
"DataType mismatch");
169 size_t counter()
const {
return i; }
196 template<
class CommInfo>
197 static const typename CommInfo::DataType& gather(
const CommInfo& commInfo,
size_t i,
size_t j = 0)
200 typedef typename CommInfo::GridGlue::Intersection
Intersection;
201 Intersection ris(commInfo.gridglue->getIntersection(i));
206 commInfo.mbuffer.clear();
207 if (dir == Dune::ForwardCommunication)
211 commInfo.data->gather(commInfo.mbuffer, ris.
inside(), ris);
217 commInfo.data->gather(commInfo.mbuffer, ris.
outside(), ris.
flip());
222 assert(j < commInfo.mbuffer.i);
223 return commInfo.buffer[j];
226 template<
class CommInfo>
227 static void scatter(
CommInfo& commInfo,
const typename CommInfo::DataType& v, std::size_t i, std::size_t j = 0)
230 typedef typename CommInfo::GridGlue::Intersection
Intersection;
231 Intersection ris(commInfo.gridglue->getIntersection(i));
236 commInfo.mbuffer.clear();
237 commInfo.currentsize = commInfo.data->size(ris);
241 commInfo.buffer[j] = v;
244 if (j == commInfo.currentsize-1)
246 if (dir == Dune::ForwardCommunication)
250 commInfo.data->scatter(commInfo.mbuffer, ris.
outside(), ris.
flip(), commInfo.currentsize);
256 commInfo.data->scatter(commInfo.mbuffer, ris.
inside(), ris, commInfo.currentsize);
258 assert(commInfo.mbuffer.j <= commInfo.currentsize);
270 template <
typename GG,
class DataHandleImp,
class DataTypeImp>
273 typedef DataTypeImp value_type;
275 typedef DataTypeImp DataType;
277 CommInfo() : buffer(100), mbuffer(&buffer[0])
281 const GridGlue * gridglue;
285 std::vector<DataType> buffer;
286 mutable ::Dune::GridGlue::StreamingMessageBuffer<DataType> mbuffer;
288 Dune::CommunicationDirection dir;
298 template<
typename GG,
class DataHandleImp,
class DataTypeImp>
304 typedef ::Dune::GridGlue::CommInfo<GG, DataHandleImp, DataTypeImp>
Type;
323 typedef typename Type::GridGlue::Intersection Intersection;
324 Intersection ris(commInfo.gridglue->getIntersection(i));
327 return commInfo.data->size(ris);
describes the features of a data handle for communication in parallel runs using the GridGlue::commun...
Definition: gridgluecommunicate.hh:77
size_t size(RISType &i) const
Definition: gridgluecommunicate.hh:92
void scatter(MessageBufferImp &buff, const EntityType &e, const RISType &i, size_t n)
Definition: gridgluecommunicate.hh:118
void gather(MessageBufferImp &buff, const EntityType &e, const RISType &i) const
pack data from user to message buffer
Definition: gridgluecommunicate.hh:104
DataTypeImp DataType
data type of data to communicate
Definition: gridgluecommunicate.hh:80
forward gather scatter to user defined CommInfo class
Definition: gridgluecommunicate.hh:194
The intersection of two entities of the two patches of a GridGlue.
Definition: intersection.hh:257
Intersection< P0, P1, O, I > flip() const
Return a copy of the intersection with inside and outside switched.
Definition: intersection.hh:474
bool self() const
For parallel computations: Return true if inside() entity exists locally.
Definition: intersection.hh:384
InsideEntity inside(unsigned int parentId=0) const
Return element on the inside of this intersection.
Definition: intersection.hh:315
size_t neighbor(unsigned int g=0) const
Return number of embeddings into local grid0 (grid1) entities.
Definition: intersection.hh:390
OutsideEntity outside(unsigned int parentId=0) const
Return element on the outside of this intersection.
Definition: intersection.hh:324
Definition: gridgluecommunicate.hh:141
static size_t getSize(const Type &commInfo, size_t i)
Get the number of objects at an intersection.
Definition: gridgluecommunicate.hh:320
DataTypeImp IndexedType
The datatype that should be communicated.
Definition: gridgluecommunicate.hh:309
::Dune::GridGlue::CommInfo< GG, DataHandleImp, DataTypeImp > Type
The type of the GridGlueCommInfo.
Definition: gridgluecommunicate.hh:304
VariableSize IndexedTypeFlag
Each intersection can communicate a different number of objects.
Definition: gridgluecommunicate.hh:315
collects all GridGlue data required for communication
Definition: gridgluecommunicate.hh:272