dune-grid  2.11
coordfunction.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © 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_COORDFUNCTION_HH
6 #define DUNE_GEOGRID_COORDFUNCTION_HH
7 
8 #include <cassert>
9 
10 #include <dune/common/fvector.hh>
11 #include <dune/common/std/type_traits.hh>
12 
13 namespace Dune
14 {
15 
16  // Internal Forward Declarations
17  // -----------------------------
18 
19  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
21 
22  template< class ct, unsigned int dimR, class Impl >
24 
25 
26 
27  // AnalyticalCoordFunctionInterface
28  // --------------------------------
29 
42  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
44  {
46 
47  friend class AnalyticalCoordFunction< ct, dimD, dimR, Impl >;
48 
49  public:
50  typedef This Interface;
51  typedef Impl Implementation;
52 
54  typedef ct ctype;
55 
57  static const unsigned int dimDomain = dimD;
59  static const unsigned int dimRange = dimR;
60 
62  typedef FieldVector< ctype, dimDomain > DomainVector;
64  typedef FieldVector< ctype, dimRange > RangeVector;
65 
66  private:
68  AnalyticalCoordFunctionInterface ( const This & ) = default;
69  AnalyticalCoordFunctionInterface ( This && ) = default;
71  This &operator= ( const This & ) = default;
72  This &operator= ( This && ) = default;
73 
74  // helper for picking the correct version of evaluate further down
75  template<typename F, typename DV>
76  using has_operator_parentheses = decltype(std::declval<F>()(std::declval<DV>()));
77 
78  public:
79 
80 #ifdef DOXYGEN
81 
83  void evaluate ( const DomainVector &x, RangeVector &y ) const;
84 
85 #else
86 
87  template<typename DV>
88  std::enable_if_t<
89  Std::is_detected<has_operator_parentheses,Impl,DV>::value
90  >
91  evaluate ( const DV &x, RangeVector &y ) const
92  {
93  y = asImp()(x);
94  }
95 
96  template<typename DV>
97  std::enable_if_t<
98  not Std::is_detected<has_operator_parentheses,Impl,DV>::value
99  >
100  evaluate ( const DV &x, RangeVector &y ) const
101  {
102  assert(
103  static_cast<void(This::*)(const DomainVector&, RangeVector&) const>(&This::evaluate) !=
104  static_cast<void(Impl::*)(const DomainVector&, RangeVector&) const>(&Impl::evaluate) &&
105  "You need to implement either operator() or evaluate() in your coordinate function!");
106  asImp().evaluate( x, y );
107  }
108 
109 #endif // DOXYGEN
110 
111  protected:
112 
113  const Implementation &asImp () const
114  {
115  return static_cast< const Implementation & >( *this );
116  }
117 
119  {
120  return static_cast< Implementation & >( *this );
121  }
122  };
123 
124 
125 
126  // AnalyticalCoordFunction
127  // -----------------------
131  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
132  class AnalyticalCoordFunction
133  : public AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl >
134  {
135  typedef AnalyticalCoordFunction< ct, dimD, dimR, Impl > This;
136  typedef AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl > Base;
137 
138  public:
141 
142  protected:
143  AnalyticalCoordFunction () = default;
144  AnalyticalCoordFunction ( const This & ) = default;
145  AnalyticalCoordFunction ( This && ) = default;
146  ~AnalyticalCoordFunction () = default;
147  This &operator= ( const This & ) = default;
148  This &operator= ( This && ) = default;
149 
150  private:
151 
152  };
153 
154 
155 
156  // DiscreteCoordFunctionInterface
157  // ------------------------------
158 
173  template< class ct, unsigned int dimR, class Impl >
175  {
177 
178  friend class DiscreteCoordFunction< ct, dimR, Impl >;
179 
180  public:
181  typedef This Interface;
182  typedef Impl Implementation;
183 
185  typedef ct ctype;
186 
188  static const unsigned int dimRange = dimR;
189 
191  typedef FieldVector< ctype, dimRange > RangeVector;
192 
193  private:
194  DiscreteCoordFunctionInterface () = default;
195  DiscreteCoordFunctionInterface ( const This & ) = default;
196  DiscreteCoordFunctionInterface ( This && ) = default;
197  ~DiscreteCoordFunctionInterface () = default;
198  This &operator= ( const This & ) = default;
199  This &operator= ( This && ) = default;
200 
201  public:
210  template< class HostEntity >
211  void evaluate ( const HostEntity &hostEntity, unsigned int corner,
212  RangeVector &y ) const
213  {
214  asImp().evaluate( hostEntity, corner, y );
215  }
216 
220  void adapt ()
221  {
222  asImp().adapt();
223  }
224 
225  protected:
226  const Implementation &asImp () const
227  {
228  return static_cast< const Implementation & >( *this );
229  }
230 
232  {
233  return static_cast< Implementation & >( *this );
234  }
235  };
236 
237 
238 
239  // DiscreteCoordFunction
240  // ---------------------
241  //
245  template< class ct, unsigned int dimR, class Impl >
246  class DiscreteCoordFunction
247  : public DiscreteCoordFunctionInterface< ct, dimR, Impl >
248  {
249  typedef DiscreteCoordFunction< ct, dimR, Impl > This;
250  typedef DiscreteCoordFunctionInterface< ct, dimR, Impl > Base;
251 
252  public:
254 
255  protected:
256  DiscreteCoordFunction () = default;
257  DiscreteCoordFunction ( const This & ) = default;
258  DiscreteCoordFunction ( This && ) = default;
259  ~DiscreteCoordFunction () = default;
260  This &operator= ( const This & ) = default;
261  This &operator= ( This && ) = default;
262 
263  void adapt ()
264  {}
265 
266  private:
267  template< class HostEntity >
268  void evaluate ( const HostEntity &hostEntity, unsigned int corner,
269  RangeVector &y ) const;
270  };
271 
272 
273 
274  namespace GeoGrid
275  {
276 
277  // isCoordFunctionInterface
278  // ------------------------
279 
280  template< class CoordFunctionInterface >
282  {
283  static const bool value = false;
284  };
285 
286  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
288  < AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl > >
289  {
290  static const bool value = true;
291  };
292 
293  template< class ct, unsigned int dimR, class Impl >
294  struct isCoordFunctionInterface
295  < DiscreteCoordFunctionInterface< ct, dimR, Impl > >
296  {
297  static const bool value = true;
298  };
299 
300 
301 
302  // isDiscreteCoordFunctionInterface
303  // --------------------------------
304 
305  template< class CoordFunctionInterface >
307  {
308  static const bool value = false;
309  };
310 
311  template< class ct, unsigned int dimR, class Impl >
313  < DiscreteCoordFunctionInterface< ct, dimR, Impl > >
314  {
315  static const bool value = true;
316  };
317 
318 
319 
320  // AdaptCoordFunction
321  // ------------------
322 
323  template< class CoordFunctionInterface >
325  {
326  static void adapt ( CoordFunctionInterface & )
327  {}
328  };
329 
330  template< class ct, unsigned int dimR, class Impl >
331  struct AdaptCoordFunction< DiscreteCoordFunctionInterface< ct, dimR, Impl > >
332  {
333  typedef DiscreteCoordFunctionInterface< ct, dimR, Impl > CoordFunctionInterface;
334 
335  static void adapt ( CoordFunctionInterface &coordFunction )
336  {
337  coordFunction.adapt();
338  }
339  };
340 
341  } // namespace GeoGrid
342 
343 } // namespace Dune
344 
345 #endif // #ifndef DUNE_GEOGRID_COORDFUNCTION_HH
Definition: coordfunction.hh:281
Derive an implementation of a discrete coordinate function from this class.
Definition: coordfunction.hh:23
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:185
static const unsigned int dimRange
dimension of the range vector
Definition: coordfunction.hh:59
This & operator=(const This &)=default
Definition: coordfunction.hh:324
Implementation & asImp()
Definition: coordfunction.hh:118
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:54
Base ::DomainVector DomainVector
Definition: coordfunction.hh:139
void adapt()
Definition: coordfunction.hh:263
const Implementation & asImp() const
Definition: coordfunction.hh:226
Base ::RangeVector RangeVector
Definition: coordfunction.hh:140
static const bool value
Definition: coordfunction.hh:283
static const bool value
Definition: coordfunction.hh:308
Implementation & asImp()
Definition: coordfunction.hh:231
const Implementation & asImp() const
Definition: coordfunction.hh:113
This Interface
Definition: coordfunction.hh:181
static void adapt(CoordFunctionInterface &)
Definition: coordfunction.hh:326
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:191
Interface class for using a discrete function to define the geometry of a Dune::GeometryGrid. An implementation should be derived from Dune::DiscreteCoordinateFunction and the evaluate method taking an entity of the host grid together with the number of a vertex returns the coordinate in of that corner. The user must ensure continuity of this mapping. In addition an adapt method is provided which is called whenever adapt() is called on the Dune::GeometryGrid.
Definition: coordfunction.hh:174
void evaluate(const HostEntity &hostEntity, unsigned int corner, RangeVector &y) const
evaluate method
Definition: coordfunction.hh:211
Include standard header files.
Definition: agrid.hh:59
FieldVector< ctype, dimDomain > DomainVector
domain vector for the evaluate method
Definition: coordfunction.hh:62
Impl Implementation
Definition: coordfunction.hh:182
static const unsigned int dimDomain
dimension of the range vector (dimensionworld of host grid)
Definition: coordfunction.hh:57
Base ::RangeVector RangeVector
Definition: coordfunction.hh:253
Derive an implementation of an analytical coordinate function from this class.
Definition: coordfunction.hh:20
void evaluate(const DomainVector &x, RangeVector &y) const
evaluate method for global mapping
Definition: dgfgeogrid.hh:43
static const unsigned int dimRange
dimension of the range vector
Definition: coordfunction.hh:188
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:64
Impl Implementation
Definition: coordfunction.hh:51
This Interface
Definition: coordfunction.hh:50
void adapt()
method called from grid.adapt() method to allow adaptation of the discrete coordinate function ...
Definition: coordfunction.hh:220
Interface class for using an analytical function to define the geometry of a Dune::GeometryGrid. An implementation should be derived from Dune::AnalyticalCoordFunction and the evaluate method mapping has to be supplied.
Definition: coordfunction.hh:43
This & operator=(const This &)=default
Definition: cachedcoordfunction.hh:26
Definition: coordfunction.hh:306