datahandle.hh 2.9 KB
Newer Older
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
1
2
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
Praetorius, Simon's avatar
Praetorius, Simon committed
3
4
#ifndef DUNE_CURVED_SURFACE_GRID_DATAHANDLE_HH
#define DUNE_CURVED_SURFACE_GRID_DATAHANDLE_HH
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
5
6
7
8
9
10
11
12
13

#include <dune/common/typetraits.hh>

#include <dune/grid/common/datahandleif.hh>
#include <dune/grid/common/grid.hh>
#include <dune/curvedsurfacegrid/entity.hh>

namespace Dune
{
Praetorius, Simon's avatar
Praetorius, Simon committed
14
  namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
15
16
17
18
19
20
21
  {

    // CommDataHandle
    // --------------

    template< class Grid, class WrappedHandle >
    class CommDataHandle
Praetorius, Simon's avatar
Praetorius, Simon committed
22
        : public CommDataHandleIF<CommDataHandle<Grid, WrappedHandle>, typename WrappedHandle::DataType>
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
23
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
24
      using Traits = typename std::remove_const_t<Grid>::Traits;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
25
26

    public:
27
28
29
      CommDataHandle (const Grid& grid, WrappedHandle& handle)
        : grid_(grid)
        , wrappedHandle_(handle)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
30
31
      {}

32
      bool contains (int dim, int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
33
      {
34
35
36
        const bool contains = wrappedHandle_.contains(dim, codim);
        if (contains)
          assertHostEntity(dim, codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
37
38
39
        return contains;
      }

40
      bool fixedSize (int dim, int codim) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
41
      {
42
        return wrappedHandle_.fixedSize(dim, codim);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
43
44
45
      }

      template< class HostEntity >
46
      std::size_t size (const HostEntity& hostEntity) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
47
      {
48
49
        using Entity = typename Grid::Traits::template Codim<HostEntity::codimension>::Entity;
        using EntityImpl = typename Grid::Traits::template Codim<HostEntity::codimension>::EntityImpl;
50
        Entity entity(EntityImpl(grid_.gridFunction(), hostEntity));
51
        return wrappedHandle_.size(entity);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
52
53
54
      }

      template< class MessageBuffer, class HostEntity >
55
      void gather (MessageBuffer& buffer, const HostEntity& hostEntity) const
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
56
      {
57
58
        using Entity = typename Grid::Traits::template Codim<HostEntity::codimension>::Entity;
        using EntityImpl = typename Grid::Traits::template Codim<HostEntity::codimension>::EntityImpl;
59
        Entity entity(EntityImpl(grid_.gridFunction(), hostEntity));
60
        wrappedHandle_.gather(buffer, entity);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
61
62
63
      }

      template< class MessageBuffer, class HostEntity >
64
      void scatter (MessageBuffer& buffer, const HostEntity& hostEntity, std::size_t size)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
65
      {
66
67
        using Entity = typename Grid::Traits::template Codim< HostEntity::codimension >::Entity;
        using EntityImpl = typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl;
68
        Entity entity(EntityImpl(grid_.gridFunction(), hostEntity));
69
        wrappedHandle_.scatter(buffer, entity, size);
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
70
71
72
      }

    private:
73
      static void assertHostEntity (int dim, int codim)
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
74
      {
75
76
        if (!Capabilities::CodimCache<Grid>::hasHostEntity(codim))
          DUNE_THROW(NotImplemented, "Host grid has no entities for codimension " << codim << ".");
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
77
78
      }

79
80
81
    private:
      const Grid& grid_;
      WrappedHandle& wrappedHandle_;
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
82
83
    };

Praetorius, Simon's avatar
Praetorius, Simon committed
84
  } // namespace CGeo
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
85
86
} // namespace Dune

Praetorius, Simon's avatar
Praetorius, Simon committed
87
#endif // DUNE_CURVED_SURFACE_GRID_DATAHANDLE_HH