Dune Core Modules (2.9.0)

gridview.hh
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_GRID_COMMON_GRIDVIEW_HH
6 #define DUNE_GRID_COMMON_GRIDVIEW_HH
7 
8 #include <typeinfo>
9 
10 #include <dune/common/std/type_traits.hh>
11 #include <dune/common/iteratorrange.hh>
12 #include <dune/common/parallel/future.hh>
13 
14 #include <dune/geometry/type.hh>
15 
17 #include <dune/grid/common/rangegenerators.hh>
18 
19 namespace Dune
20 {
21 
22  template< int, int, class, class >
23  class GridDefaultImplementation;
24 
25 
26 
64  template< class ViewTraits >
65  class GridView
66  {
68 
69  public:
75  typedef typename ViewTraits :: GridViewImp Implementation;
76 
77  typedef typename ViewTraits :: GridViewImp GridViewImp;
78 
80  typedef ViewTraits Traits;
81 
83  typedef typename Traits :: Grid Grid;
84 
86  typedef typename Traits :: IndexSet IndexSet;
87 
89  typedef typename Traits :: Intersection Intersection;
90 
92  typedef typename Traits :: IntersectionIterator IntersectionIterator;
93 
94  protected:
95  template <class T>
96  using Communication_t = typename T :: Communication;
97  template <class T>
98  using DeprecatedCollectiveCommunication_t = typename T :: CollectiveCommunication;
99 
100  public:
105  // if this line produces a warning then the Communication typedef is missing
106  // in the Traits
107  using Communication = detected_or_fallback_t<DeprecatedCollectiveCommunication_t,
108  Communication_t, Traits>;
109 
112  using CollectiveCommunication [[deprecated("CollectiveCommunication is deprecated, use Communication instead!")]] = Communication;
113 
117  template< int cd >
118  struct Codim {
120  typedef typename Traits :: template Codim<cd> :: Iterator Iterator;
121 
123  typedef typename Traits :: template Codim<cd> :: Entity Entity;
124 
126  typedef typename Traits :: template Codim<cd> :: Geometry Geometry;
127 
129  typedef typename Traits :: template Codim<cd> :: LocalGeometry LocalGeometry;
130 
132  template< PartitionIteratorType pit >
133  struct Partition
134  {
136  typedef typename Traits :: template Codim< cd >
138  };
139  }; //: public Traits :: template Codim<cd> {};
140 
142  constexpr static bool conforming = Traits :: conforming;
143 
145  typedef typename Grid::ctype ctype;
146 
148  constexpr static int dimension = Grid :: dimension;
149 
151  constexpr static int dimensionworld = Grid :: dimensionworld;
152 
153  public:
154 
155  //===========================================================
159  //===========================================================
161  GridView ( const Implementation &imp )
162  : impl_( imp )
163  {}
165 
167  GridView ( const ThisType &other )
168  : impl_( other.impl_ )
169  {}
170 
172  ThisType &operator= ( const ThisType &other )
173  {
174  impl_ = other.impl_;
175  return *this;
176  }
177 
178  public:
180  const Grid &grid () const
181  {
182  return impl().grid();
183  }
184 
191  const IndexSet &indexSet () const
192  {
193  return impl().indexSet();
194  }
195 
197  int size ( int codim ) const
198  {
199  return impl().size( codim );
200  }
201 
203  int size ( const GeometryType &type ) const
204  {
205  return impl().size( type );
206  }
207 
209  bool isConforming () const
210  {
211  // if implementation provides a method isConforming, call it
212  if constexpr ( CheckIsConformingImpl< Implementation >::type::value )
213  {
214  return impl().isConforming();
215  }
216  else
217  {
218  // otherwise default to static conforming flag
219  return this->isConformingDefaultImplementation();
220  }
221  }
222 
229  template<class EntityType>
230  bool contains (const EntityType& e) const
231  {
232  return impl().indexSet().contains(e);
233  }
234 
236  template< int cd >
237  typename Codim< cd > :: Iterator begin () const
238  {
239  return impl().template begin<cd>();
240  }
241 
243  template< int cd >
244  typename Codim< cd > :: Iterator end () const
245  {
246  return impl().template end<cd>();
247  }
248 
250  template< int cd , PartitionIteratorType pitype >
251  typename Codim< cd > :: template Partition< pitype > :: Iterator
252  begin () const
253  {
254  return impl().template begin<cd,pitype>();
255  }
256 
258  template< int cd, PartitionIteratorType pitype >
259  typename Codim< cd > :: template Partition< pitype > :: Iterator
260  end () const
261  {
262  return impl().template end<cd,pitype>();
263  }
264 
267  ibegin ( const typename Codim< 0 > :: Entity &entity ) const
268  {
269  return impl().ibegin(entity);
270  }
271 
274  iend ( const typename Codim< 0 > :: Entity &entity ) const
275  {
276  return impl().iend(entity);
277  }
278 
280  const Communication &comm () const
281  {
282  return impl().comm();
283  }
284 
286  int overlapSize(int codim) const
287  {
288  return impl().overlapSize(codim);
289  }
290 
292  int ghostSize(int codim) const
293  {
294  return impl().ghostSize(codim);
295  }
296 
298  template< class DataHandleImp, class DataType >
300  InterfaceType iftype,
301  CommunicationDirection dir ) const
302  {
303  typedef decltype( impl().communicate(data,iftype,dir) ) CommFuture;
304  return communicate( data,iftype, dir,
305  std::integral_constant< bool, std::is_same< CommFuture, void > :: value >() );
306  }
307 
313  Implementation &impl () { return impl_; }
314 
320  const Implementation &impl () const { return impl_; }
321 
322  protected:
324  template< class DataHandleImp, class DataType >
326  InterfaceType iftype,
327  CommunicationDirection dir, std::integral_constant< bool, false > ) const
328  {
329  return impl().communicate(data,iftype,dir);
330  }
331 
332  struct DeprecatedMethodEmptyFuture : public Future<void>
333  {
334  void printMessage() const
335  {
336  std::cerr << "WARNING: GridView::communicate of '" <<
337  typeid( Implementation ).name() << "' still returns void. Please update implementation to new interface returning a future object!" << std::endl;
338  }
339 
340  bool ready () {
341  printMessage();
342  return true;
343  }
344  void wait () { printMessage(); }
345  bool valid () const { printMessage(); return true; }
346  };
347 
349  template< class DataHandleImp, class DataType >
351  InterfaceType iftype,
352  CommunicationDirection dir, std::integral_constant< bool, true > ) const
353  {
354  impl().communicate(data,iftype,dir);
355  return DeprecatedMethodEmptyFuture();
356  }
357 
358  template <class M>
359  class CheckIsConformingImpl
360  {
361  // check for 'bool isConforming () const'
362  template <class T, class R> static std::true_type testSignature(R (T::*)() const);
363 
364  template <class T>
365  static decltype(testSignature(&T::isConforming)) test(std::nullptr_t);
366 
367  template <class T>
368  static std::false_type test(...);
369 
370  public:
371  using type = decltype(test<M>(nullptr));
372  };
373 
374  [[deprecated("GridView implementation is missing a method 'bool isConforming() const'")]]
375  bool isConformingDefaultImplementation() const { return bool(conforming); }
376 
377  Implementation impl_;
378  };
379 
380 } // namespace Dune
381 
382 #endif // #ifndef DUNE_GRID_COMMON_GRIDVIEW_HH
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
Type-erasure for future-like objects. A future-like object is a object satisfying the interface of Fu...
Definition: future.hh:28
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
Grid view abstract base class.
Definition: gridview.hh:66
constexpr static int dimension
The dimension of the grid.
Definition: grid.hh:387
constexpr static int dimensionworld
The dimension of the world the grid lives in.
Definition: grid.hh:390
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:532
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: intersectioniterator.hh:83
Describes the parallel communication interface class for MessageBuffers and DataHandles.
const Implementation & impl() const
access to the underlying implementation
Definition: gridview.hh:320
Traits ::IntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: gridview.hh:92
Communication CollectiveCommunication
Definition: gridview.hh:112
const Communication & comm() const
obtain communication object
Definition: gridview.hh:280
ViewTraits Traits
Traits class.
Definition: gridview.hh:80
IntersectionIterator ibegin(const typename Codim< 0 > ::Entity &entity) const
obtain begin intersection iterator with respect to this view
Definition: gridview.hh:267
Implementation & impl()
access to the underlying implementation
Definition: gridview.hh:313
int overlapSize(int codim) const
Return size of the overlap region for a given codim on the grid view.
Definition: gridview.hh:286
int size(const GeometryType &type) const
obtain number of entities with a given geometry type
Definition: gridview.hh:203
int size(int codim) const
obtain number of entities in a given codimension
Definition: gridview.hh:197
Traits ::IndexSet IndexSet
type of the index set
Definition: gridview.hh:86
auto communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir) const
Communicate data on this view.
Definition: gridview.hh:299
auto communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir, std::integral_constant< bool, false >) const
Communicate data on this view.
Definition: gridview.hh:325
Traits ::template Codim< cd >::template Partition< pit >::Iterator Iterator
iterator over a given codim and partition type
Definition: gridview.hh:137
ViewTraits ::GridViewImp Implementation
type of underlying implementation
Definition: gridview.hh:75
Traits ::template Codim< cd >::Iterator Iterator
type of iterator returned by the grid view
Definition: gridview.hh:120
constexpr static int dimension
The dimension of the grid.
Definition: gridview.hh:148
constexpr static int dimensionworld
The dimension of the world the grid lives in.
Definition: gridview.hh:151
Codim< cd >::template Partition< pitype >::Iterator begin() const
obtain begin iterator for this view
Definition: gridview.hh:252
Codim< cd >::Iterator begin() const
obtain begin iterator for this view
Definition: gridview.hh:237
Codim< cd >::template Partition< pitype >::Iterator end() const
obtain end iterator for this view
Definition: gridview.hh:260
Traits ::template Codim< cd >::Geometry Geometry
type of the geometry implementation
Definition: gridview.hh:126
Traits ::template Codim< cd >::Entity Entity
type of corresponding entity
Definition: gridview.hh:123
ThisType & operator=(const ThisType &other)
assignment operator
Definition: gridview.hh:172
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: gridview.hh:180
GridView(const Implementation &imp)
constructor (engine concept)
Definition: gridview.hh:161
IntersectionIterator iend(const typename Codim< 0 > ::Entity &entity) const
obtain end intersection iterator with respect to this view
Definition: gridview.hh:274
Grid::ctype ctype
type used for coordinates in grid
Definition: gridview.hh:145
auto communicate(CommDataHandleIF< DataHandleImp, DataType > &data, InterfaceType iftype, CommunicationDirection dir, std::integral_constant< bool, true >) const
Communicate data on this view.
Definition: gridview.hh:350
bool contains(const EntityType &e) const
Return true if the given entity is contained in this grid view.
Definition: gridview.hh:230
detected_or_fallback_t< DeprecatedCollectiveCommunication_t, Communication_t, Traits > Communication
A type that is a model of Dune::Communication. It provides a portable way for communication on the se...
Definition: gridview.hh:108
Traits ::template Codim< cd >::LocalGeometry LocalGeometry
type of the implementation for local geometries
Definition: gridview.hh:129
Traits ::Intersection Intersection
type of the intersection
Definition: gridview.hh:89
Traits ::Grid Grid
type of the grid
Definition: gridview.hh:83
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:191
constexpr static bool conforming
Export if this grid view is guaranteed conforming.
Definition: gridview.hh:142
bool isConforming() const
return true if current state of grid view represents a conforming grid
Definition: gridview.hh:209
GridView(const ThisType &other)
Copy constructor.
Definition: gridview.hh:167
Codim< cd >::Iterator end() const
obtain end iterator for this view
Definition: gridview.hh:244
int ghostSize(int codim) const
Return size of the ghost region for a given codim on the grid view.
Definition: gridview.hh:292
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
Dune namespace.
Definition: alignedallocator.hh:13
Std::detected_or_t< decltype(detail::warningIfNotDefined< Std::detected_t< Fallback, Args... > >(std::declval< const Std::detected_t< TargetType, Args... > * >())), TargetType, Args... > detected_or_fallback_t
This type will be either TargetType<Args...> if it exists, or the Fallback<Args......
Definition: type_traits.hh:300
Communication< T > CollectiveCommunication
Definition: communication.hh:541
Define types needed to iterate over entities of a given partition type.
Definition: gridview.hh:134
A struct that collects all associated types of one implementation from the Traits class.
Definition: gridview.hh:118
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 29, 22:29, 2024)