dune-grid  2.9.0
coordfunction.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_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 >
20  class AnalyticalCoordFunction;
21 
22  template< class ct, unsigned int dimR, class Impl >
23  class DiscreteCoordFunction;
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 >
133  : public AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl >
134  {
137 
138  public:
141 
142  protected:
144  AnalyticalCoordFunction ( const This & ) = default;
145  AnalyticalCoordFunction ( This && ) = 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 >
247  : public DiscreteCoordFunctionInterface< ct, dimR, Impl >
248  {
251 
252  public:
254 
255  protected:
256  DiscreteCoordFunction () = default;
257  DiscreteCoordFunction ( const This & ) = default;
258  DiscreteCoordFunction ( This && ) = 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
Include standard header files.
Definition: agrid.hh:60
Derive an implementation of an analytical coordinate function from this class.
Definition: coordfunction.hh:134
Base ::RangeVector RangeVector
Definition: coordfunction.hh:140
This & operator=(const This &)=default
AnalyticalCoordFunction(This &&)=default
Base ::DomainVector DomainVector
Definition: coordfunction.hh:139
AnalyticalCoordFunction(const This &)=default
Derive an implementation of a discrete coordinate function from this class.
Definition: coordfunction.hh:248
Base ::RangeVector RangeVector
Definition: coordfunction.hh:253
void adapt()
Definition: coordfunction.hh:263
This & operator=(const This &)=default
DiscreteCoordFunction(This &&)=default
DiscreteCoordFunction(const This &)=default
Interface class for using an analytical function to define the geometry of a Dune::GeometryGrid....
Definition: coordfunction.hh:44
Impl Implementation
Definition: coordfunction.hh:51
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:64
void evaluate(const DomainVector &x, RangeVector &y) const
evaluate method for global mapping
static const unsigned int dimRange
dimension of the range vector
Definition: coordfunction.hh:59
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:54
static const unsigned int dimDomain
dimension of the range vector (dimensionworld of host grid)
Definition: coordfunction.hh:57
const Implementation & asImp() const
Definition: coordfunction.hh:113
This Interface
Definition: coordfunction.hh:50
Implementation & asImp()
Definition: coordfunction.hh:118
FieldVector< ctype, dimDomain > DomainVector
domain vector for the evaluate method
Definition: coordfunction.hh:62
Interface class for using a discrete function to define the geometry of a Dune::GeometryGrid....
Definition: coordfunction.hh:175
static const unsigned int dimRange
dimension of the range vector
Definition: coordfunction.hh:188
void evaluate(const HostEntity &hostEntity, unsigned int corner, RangeVector &y) const
evaluate method
Definition: coordfunction.hh:211
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:185
Implementation & asImp()
Definition: coordfunction.hh:231
void adapt()
method called from grid.adapt() method to allow adaptation of the discrete coordinate function
Definition: coordfunction.hh:220
const Implementation & asImp() const
Definition: coordfunction.hh:226
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:191
Impl Implementation
Definition: coordfunction.hh:182
This Interface
Definition: coordfunction.hh:181
Definition: coordfunction.hh:282
static const bool value
Definition: coordfunction.hh:283
Definition: coordfunction.hh:307
static const bool value
Definition: coordfunction.hh:308
Definition: coordfunction.hh:325
static void adapt(CoordFunctionInterface &)
Definition: coordfunction.hh:326