DUNE-ACFEM (unstable)

dofmappertupledatahandle.hh
1 #ifndef __DUNE_ACFEM_DOFMAPPERTUPLEDATAHANDLE_HH__
2 #define __DUNE_ACFEM_DOFMAPPERTUPLEDATAHANDLE_HH__
3 
4 #include <dune/grid/common/datahandleif.hh>
5 
6 #include "containertuple.hh"
7 
8 namespace Dune {
9 
10  namespace ACFem {
11 
13  template<class... Storages>
15  {
16  typedef ContainerTuple<Storages...> StorageType;
17  typedef typename StorageType::ConstValueType DataItemType;
18  typedef typename StorageType::ValueType DataItemScatterType;
19  };
20 
40  template<class Mapper, class Operation, class... Storages>
42  : public CommDataHandleIF<DofMapperTupleDataHandle<Mapper, Operation, Storages...>,
43  typename DofMapperTupleDataHandleTraits<Storages...>::DataItemType>
44  {
45  public:
46  typedef Mapper MapperType;
47  typedef Operation OperationType;
48  private:
49  typedef DofMapperTupleDataHandleTraits<Storages...> TraitsType;
50  typedef typename TraitsType::DataItemType DataItemType;
51  typedef typename TraitsType::DataItemScatterType DataItemScatterType;
52  typedef ContainerTuple<Storages...> StorageTupleType;
53  public:
73  DofMapperTupleDataHandle(const MapperType& mapper,
74  const Operation& operation,
75  Storages&... storages)
76  : mapper_(mapper), operation_(operation), storages_(storages...)
77  {}
78 
80  : mapper_(other.mapper_), operation_(other.operation_), storages_(other.storages_)
81  {}
82 
84  bool contains(int dim, int codim) const
85  {
86  return mapper_.contains(codim);
87  }
88 
92  bool fixedSize(int dim, int codim) const
93  {
94  return false;
95  }
96 
100  template<class Entity>
101  size_t size(const Entity& entity) const
102  {
103  return mapper_.numEntityDofs(entity);
104  }
105 
107  template<class MessageBuffer, class Entity>
108  void gather(MessageBuffer& buff, const Entity& entity) const
109  {
110  size_t localBlocks = mapper_.numEntityDofs(entity);
111  std::vector<std::size_t> globalBlockDofs(localBlocks);
112  mapper_.mapEntityDofs(entity, globalBlockDofs);
113  assert(size(entity) == globalBlockDofs.size());
114  for (size_t localBlock = 0; localBlock < globalBlockDofs.size(); ++ localBlock) {
115  buff.write(storages_[globalBlockDofs[localBlock]]);
116  }
117  }
118 
120  template<class MessageBuffer, class Entity>
121  void scatter(MessageBuffer& buff, const Entity& entity, size_t n)
122  {
123  size_t localBlocks = mapper_.numEntityDofs(entity);
124  std::vector<std::size_t> globalBlockDofs(localBlocks);
125  mapper_.mapEntityDofs(entity, globalBlockDofs);
126  assert(size(entity) == n);
127  assert(size(entity) == globalBlockDofs.size());
128  for (size_t localBlock = 0; localBlock < globalBlockDofs.size(); ++ localBlock) {
129  DataItemType src;
130  buff.read(src);
131  // We need the variable dest, because if one of the
132  // tuple-components uses Fem::SubVector as blocks then dest
133  // must contain a non-const copy of the block. Hence we
134  // cannot pass dest as a const argument to operation_(), but
135  // then without dest we would pass a non-const rvalue
136  // reference as an lvalue reference to operation_() which is
137  // not allowed.
138  auto dest = storages_[globalBlockDofs[localBlock]];
139  operation_(src, dest);
140  }
141  }
142 
143  private:
144  const MapperType& mapper_;
145  const Operation operation_;
146  StorageTupleType storages_;
147  };
148 
163  template<class Space, class Operation, class... Storages,
164  std::enable_if_t<sizeof(typename Space::BlockMapperType) >= 0, int> = 0>
165  auto dofMapperTupleDataHandle(const Space& space,
166  const Operation& operation,
167  Storages&... storages)
168  {
169  typedef DofMapperTupleDataHandle<typename Space::BlockMapperType, Operation, Storages...> ResultType;
170  return ResultType(space.blockMapper(), operation, storages...);
171  }
172 
173  } // namespace ACFem
174 
175 } // namespace Dune
176 
177 
178 #endif // __DUNE_ACFEM_DOFMAPPERTUPLEDATAHANDLE_HH__
Create a tuple of values from a tuple of containers.
Definition: containertuple.hh:35
Potential all - all communication for mapped data.
Definition: dofmappertupledatahandle.hh:44
bool fixedSize(int dim, int codim) const
We don't have a fixed-size.
Definition: dofmappertupledatahandle.hh:92
DofMapperTupleDataHandle(const MapperType &mapper, const Operation &operation, Storages &... storages)
Construct the data handle from the given mapper and storage container.
Definition: dofmappertupledatahandle.hh:73
void gather(MessageBuffer &buff, const Entity &entity) const
pack data from user to message buffer
Definition: dofmappertupledatahandle.hh:108
bool contains(int dim, int codim) const
returns true if data for this codim should be communicated
Definition: dofmappertupledatahandle.hh:84
void scatter(MessageBuffer &buff, const Entity &entity, size_t n)
unpack data from message to user buffer
Definition: dofmappertupledatahandle.hh:121
size_t size(const Entity &entity) const
how many objects of type DataItemType have to be sent for a given entity.
Definition: dofmappertupledatahandle.hh:101
Traits for just something indexable.
Definition: dofmappertupledatahandle.hh:15
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 3, 22:32, 2024)