dune-grid  2.9.0
geometrygrid/datahandle.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GEOGRID_DATAHANDLE_HH
6 #define DUNE_GEOGRID_DATAHANDLE_HH
7 
8 #include <dune/common/typetraits.hh>
9 
11 #include <dune/grid/common/grid.hh>
14 
15 namespace Dune
16 {
17 
18  namespace GeoGrid
19  {
20 
21  // GeometryGridDataHandle
22  // ----------------------
23 
24  template< class Grid, class WrappedHandle >
26  : public CommDataHandleIF< CommDataHandle< Grid, WrappedHandle >, typename WrappedHandle::DataType >
27  {
28  typedef typename std::remove_const< Grid >::type::Traits Traits;
29 
30  public:
31  CommDataHandle ( const Grid &grid, WrappedHandle &handle )
32  : grid_( grid ),
33  wrappedHandle_( handle )
34  {}
35 
36  bool contains ( int dim, int codim ) const
37  {
38  const bool contains = wrappedHandle_.contains( dim, codim );
39  if( contains )
40  assertHostEntity( dim, codim );
41  return contains;
42  }
43 
44  bool fixedSize ( int dim, int codim ) const
45  {
46  return wrappedHandle_.fixedSize( dim, codim );
47  }
48 
49  template< class HostEntity >
50  size_t size ( const HostEntity &hostEntity ) const
51  {
52  typedef typename Grid::Traits::template Codim< HostEntity::codimension >::Entity Entity;
53  typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl;
54  Entity entity( EntityImpl( grid_, hostEntity ) );
55  return wrappedHandle_.size( entity );
56  }
57 
58  template< class MessageBuffer, class HostEntity >
59  void gather ( MessageBuffer &buffer, const HostEntity &hostEntity ) const
60  {
61  typedef typename Grid::Traits::template Codim< HostEntity::codimension >::Entity Entity;
62  typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl;
63  Entity entity( EntityImpl( grid_, hostEntity ) );
64  wrappedHandle_.gather( buffer, entity );
65  }
66 
67  template< class MessageBuffer, class HostEntity >
68  void scatter ( MessageBuffer &buffer, const HostEntity &hostEntity, size_t size_ )
69  {
70  typedef typename Grid::Traits::template Codim< HostEntity::codimension >::Entity Entity;
71  typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl;
72  Entity entity( EntityImpl( grid_, hostEntity ) );
73  wrappedHandle_.scatter( buffer, entity, size_ );
74  }
75 
76  private:
77  static void assertHostEntity ( int , int codim )
78  {
80  DUNE_THROW( NotImplemented, "Host grid has no entities for codimension " << codim << "." );
81  }
82 
83  const Grid &grid_;
84  WrappedHandle &wrappedHandle_;
85  };
86 
87  } // namespace GeoGrid
88 
89 } // namespace Dune
90 
91 #endif // #ifndef DUNE_GEOGRID_DATAHANDLE_HH
Describes the parallel communication interface class for MessageBuffers and DataHandles.
Include standard header files.
Definition: agrid.hh:60
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
Grid abstract base class.
Definition: common/grid.hh:375
Definition: geometrygrid/capabilities.hh:116
Definition: geometrygrid/datahandle.hh:27
bool fixedSize(int dim, int codim) const
Definition: geometrygrid/datahandle.hh:44
bool contains(int dim, int codim) const
Definition: geometrygrid/datahandle.hh:36
size_t size(const HostEntity &hostEntity) const
Definition: geometrygrid/datahandle.hh:50
CommDataHandle(const Grid &grid, WrappedHandle &handle)
Definition: geometrygrid/datahandle.hh:31
void gather(MessageBuffer &buffer, const HostEntity &hostEntity) const
Definition: geometrygrid/datahandle.hh:59
void scatter(MessageBuffer &buffer, const HostEntity &hostEntity, size_t size_)
Definition: geometrygrid/datahandle.hh:68
DUNE-conform implementation of the entity.
Definition: geometrygrid/entity.hh:34
Different resources needed by all grid implementations.