dune-grid  2.6-git
coordfunction.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOGRID_COORDFUNCTION_HH
4 #define DUNE_GEOGRID_COORDFUNCTION_HH
5 
6 #include <cassert>
7 
8 #include <dune/common/fvector.hh>
9 #include <dune/common/std/type_traits.hh>
10 
11 namespace Dune
12 {
13 
14  // Internal Forward Declarations
15  // -----------------------------
16 
17  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
19 
20  template< class ct, unsigned int dimR, class Impl >
22 
23 
24 
25  // AnalyticalCoordFunctionInterface
26  // --------------------------------
27 
40  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
42  {
44 
45  friend class AnalyticalCoordFunction< ct, dimD, dimR, Impl >;
46 
47  public:
48  typedef This Interface;
49  typedef Impl Implementation;
50 
52  typedef ct ctype;
53 
55  static const unsigned int dimDomain = dimD;
57  static const unsigned int dimRange = dimR;
58 
60  typedef FieldVector< ctype, dimDomain > DomainVector;
62  typedef FieldVector< ctype, dimRange > RangeVector;
63 
64  private:
66  AnalyticalCoordFunctionInterface ( const This & ) = default;
67  AnalyticalCoordFunctionInterface ( This && ) = default;
69  This &operator= ( const This & ) = default;
70  This &operator= ( This && ) = default;
71 
72  // helper for picking the correct version of evaluate further down
73  template<typename F, typename DV>
74  using has_operator_parentheses = decltype(std::declval<F>()(std::declval<DV>()));
75 
76  public:
77 
78 #ifdef DOXYGEN
79 
81  void evaluate ( const DomainVector &x, RangeVector &y ) const;
82 
83 #else
84 
85  template<typename DV>
86  std::enable_if_t<
87  Std::is_detected<has_operator_parentheses,Impl,DV>::value
88  >
89  evaluate ( const DV &x, RangeVector &y ) const
90  {
91  y = asImp()(x);
92  }
93 
94  template<typename DV>
95  std::enable_if_t<
96  not Std::is_detected<has_operator_parentheses,Impl,DV>::value
97  >
98  evaluate ( const DV &x, RangeVector &y ) const
99  {
100  assert(
101  static_cast<void(This::*)(const DomainVector&, RangeVector&) const>(&This::evaluate) !=
102  static_cast<void(Impl::*)(const DomainVector&, RangeVector&) const>(&Impl::evaluate) &&
103  "You need to implement either operator() or evaluate() in your coordinate function!");
104  asImp().evaluate( x, y );
105  }
106 
107 #endif // DOXYGEN
108 
109  protected:
110 
111  const Implementation &asImp () const
112  {
113  return static_cast< const Implementation & >( *this );
114  }
115 
116  Implementation &asImp ()
117  {
118  return static_cast< Implementation & >( *this );
119  }
120  };
121 
122 
123 
124  // AnalyticalCoordFunction
125  // -----------------------
129  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
131  : public AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl >
132  {
135 
136  public:
137  typedef typename Base :: DomainVector DomainVector;
138  typedef typename Base :: RangeVector RangeVector;
139 
140  protected:
141  AnalyticalCoordFunction () = default;
142  AnalyticalCoordFunction ( const This & ) = default;
143  AnalyticalCoordFunction ( This && ) = default;
144  ~AnalyticalCoordFunction () = default;
145  This &operator= ( const This & ) = default;
146  This &operator= ( This && ) = default;
147 
148  private:
149 
150  };
151 
152 
153 
154  // DiscreteCoordFunctionInterface
155  // ------------------------------
156 
171  template< class ct, unsigned int dimR, class Impl >
173  {
175 
176  friend class DiscreteCoordFunction< ct, dimR, Impl >;
177 
178  public:
179  typedef This Interface;
180  typedef Impl Implementation;
181 
183  typedef ct ctype;
184 
186  static const unsigned int dimRange = dimR;
187 
189  typedef FieldVector< ctype, dimRange > RangeVector;
190 
191  private:
192  DiscreteCoordFunctionInterface () = default;
193  DiscreteCoordFunctionInterface ( const This & ) = default;
194  DiscreteCoordFunctionInterface ( This && ) = default;
195  ~DiscreteCoordFunctionInterface () = default;
196  This &operator= ( const This & ) = default;
197  This &operator= ( This && ) = default;
198 
199  public:
205  template< class HostEntity >
206  void evaluate ( const HostEntity &hostEntity, unsigned int corner,
207  RangeVector &y ) const
208  {
209  asImp().evaluate( hostEntity, corner, y );
210  }
211 
215  void adapt ()
216  {
217  asImp().adapt();
218  }
219 
220  protected:
221  const Implementation &asImp () const
222  {
223  return static_cast< const Implementation & >( *this );
224  }
225 
226  Implementation &asImp ()
227  {
228  return static_cast< Implementation & >( *this );
229  }
230  };
231 
232 
233 
234  // DiscreteCoordFunction
235  // ---------------------
236  //
240  template< class ct, unsigned int dimR, class Impl >
242  : public DiscreteCoordFunctionInterface< ct, dimR, Impl >
243  {
246 
247  public:
248  typedef typename Base :: RangeVector RangeVector;
249 
250  protected:
251  DiscreteCoordFunction () = default;
252  DiscreteCoordFunction ( const This & ) = default;
253  DiscreteCoordFunction ( This && ) = default;
254  ~DiscreteCoordFunction () = default;
255  This &operator= ( const This & ) = default;
256  This &operator= ( This && ) = default;
257 
258  void adapt ()
259  {}
260 
261  private:
262  template< class HostEntity >
263  void evaluate ( const HostEntity &hostEntity, unsigned int corner,
264  RangeVector &y ) const;
265  };
266 
267 
268 
269  namespace GeoGrid
270  {
271 
272  // isCoordFunctionInterface
273  // ------------------------
274 
275  template< class CoordFunctionInterface >
277  {
278  static const bool value = false;
279  };
280 
281  template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
283  < AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl > >
284  {
285  static const bool value = true;
286  };
287 
288  template< class ct, unsigned int dimR, class Impl >
290  < DiscreteCoordFunctionInterface< ct, dimR, Impl > >
291  {
292  static const bool value = true;
293  };
294 
295 
296 
297  // isDiscreteCoordFunctionInterface
298  // --------------------------------
299 
300  template< class CoordFunctionInterface >
302  {
303  static const bool value = false;
304  };
305 
306  template< class ct, unsigned int dimR, class Impl >
308  < DiscreteCoordFunctionInterface< ct, dimR, Impl > >
309  {
310  static const bool value = true;
311  };
312 
313 
314 
315  // AdaptCoordFunction
316  // ------------------
317 
318  template< class CoordFunctionInterface >
320  {
321  static void adapt ( CoordFunctionInterface &coordFunction )
322  {}
323  };
324 
325  template< class ct, unsigned int dimR, class Impl >
326  struct AdaptCoordFunction< DiscreteCoordFunctionInterface< ct, dimR, Impl > >
327  {
328  typedef DiscreteCoordFunctionInterface< ct, dimR, Impl > CoordFunctionInterface;
329 
330  static void adapt ( CoordFunctionInterface &coordFunction )
331  {
332  coordFunction.adapt();
333  }
334  };
335 
336  } // namespace GeoGrid
337 
338 } // namespace Dune
339 
340 #endif // #ifndef DUNE_GEOGRID_COORDFUNCTION_HH
Include standard header files.
Definition: agrid.hh:58
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:41
const Implementation & asImp() const
Definition: coordfunction.hh:111
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:189
Definition: coordfunction.hh:301
Definition: coordfunction.hh:276
Derive an implementation of a discrete coordinate function from this class.
Definition: coordfunction.hh:21
Implementation & asImp()
Definition: coordfunction.hh:116
static const unsigned int dimDomain
dimension of the range vector (dimensionworld of host grid)
Definition: coordfunction.hh:55
Definition: coordfunction.hh:319
Implementation & asImp()
Definition: coordfunction.hh:226
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:62
void evaluate(const DomainVector &x, RangeVector &y) const
evaluate method for global mapping
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:172
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:52
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:183
FieldVector< ctype, dimDomain > DomainVector
domain vector for the evaluate method
Definition: coordfunction.hh:60
const Implementation & asImp() const
Definition: coordfunction.hh:221
Impl Implementation
Definition: coordfunction.hh:49
This Interface
Definition: coordfunction.hh:179
void adapt()
method called from grid.adapt() method to allow adaptation of the discrete coordinate function ...
Definition: coordfunction.hh:215
Impl Implementation
Definition: coordfunction.hh:180
static const unsigned int dimRange
dimension of the range vector
Definition: coordfunction.hh:57
Base ::RangeVector RangeVector
Definition: coordfunction.hh:248
Base ::DomainVector DomainVector
Definition: coordfunction.hh:137
void evaluate(const HostEntity &hostEntity, unsigned int corner, RangeVector &y) const
evaluate method
Definition: coordfunction.hh:206
Base ::RangeVector RangeVector
Definition: coordfunction.hh:138
Derive an implementation of an analytical coordinate function from this class.
Definition: coordfunction.hh:18
This Interface
Definition: coordfunction.hh:48
void adapt()
Definition: coordfunction.hh:258
static void adapt(CoordFunctionInterface &coordFunction)
Definition: coordfunction.hh:321