This repository has been archived by the owner on Jan 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
parfvdatahandle.hh
69 lines (57 loc) · 1.71 KB
/
parfvdatahandle.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef __DUNE_GRID_HOWTO_PARFVDATAHANDLE_HH__
#define __DUNE_GRID_HOWTO_PARFVDATAHANDLE_HH__
#include <dune/grid/common/datahandleif.hh>
// A DataHandle class to exchange entries of a vector
template<class M, class V> // mapper type and vector type
class VectorExchange
: public Dune::CommDataHandleIF<VectorExchange<M,V>,
typename V::value_type>
{
public:
//! export type of data for message buffer
typedef typename V::value_type DataType;
//! returns true if data for this codim should be communicated
bool contains (int dim, int codim) const
{
return (codim==0);
}
//! returns true if size per entity of given dim and codim is a constant
bool fixedsize (int dim, int codim) const
{
return true;
}
/*! how many objects of type DataType have to be sent for a given entity
Note: Only the sender side needs to know this size.
*/
template<class EntityType>
size_t size (EntityType& e) const
{
return 1;
}
//! pack data from user to message buffer
template<class MessageBuffer, class EntityType>
void gather (MessageBuffer& buff, const EntityType& e) const
{
buff.write(c[mapper.index(e)]);
}
/*! unpack data from message buffer to user
n is the number of objects sent by the sender
*/
template<class MessageBuffer, class EntityType>
void scatter (MessageBuffer& buff, const EntityType& e, size_t n)
{
DataType x;
buff.read(x);
c[mapper.index(e)]=x;
}
//! constructor
VectorExchange (const M& mapper_, V& c_)
: mapper(mapper_), c(c_)
{}
private:
const M& mapper;
V& c;
};
#endif // __DUNE_GRID_HOWTO_PARFVDATAHANDLE_HH__