Dune Core Modules (2.10.0)

coordfunction.hh
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
11#include <dune/common/std/type_traits.hh>
12
13namespace 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
65
66 private:
68 AnalyticalCoordFunctionInterface ( const 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<
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<
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
118 Implementation &asImp ()
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:
139 typedef typename Base :: DomainVector DomainVector;
140 typedef typename Base :: RangeVector RangeVector;
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
192
193 private:
195 DiscreteCoordFunctionInterface ( const This & ) = default;
196 DiscreteCoordFunctionInterface ( This && ) = 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
231 Implementation &asImp ()
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:
253 typedef typename Base :: RangeVector RangeVector;
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 >
281 struct isCoordFunctionInterface
282 {
283 static const bool value = false;
284 };
285
286 template< class ct, unsigned int dimD, unsigned int dimR, class Impl >
287 struct isCoordFunctionInterface
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 >
306 struct isDiscreteCoordFunctionInterface
307 {
308 static const bool value = false;
309 };
310
311 template< class ct, unsigned int dimR, class Impl >
312 struct isDiscreteCoordFunctionInterface
313 < DiscreteCoordFunctionInterface< ct, dimR, Impl > >
314 {
315 static const bool value = true;
316 };
317
318
319
320 // AdaptCoordFunction
321 // ------------------
322
323 template< class CoordFunctionInterface >
324 struct AdaptCoordFunction
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
Interface class for using an analytical function to define the geometry of a Dune::GeometryGrid....
Definition: coordfunction.hh:44
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
FieldVector< ctype, dimDomain > DomainVector
domain vector for the evaluate method
Definition: coordfunction.hh:62
Derive an implementation of an analytical coordinate function from this class.
Definition: coordfunction.hh:134
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
void adapt()
method called from grid.adapt() method to allow adaptation of the discrete coordinate function
Definition: coordfunction.hh:220
FieldVector< ctype, dimRange > RangeVector
range vector for the evaluate method
Definition: coordfunction.hh:191
Derive an implementation of a discrete coordinate function from this class.
Definition: coordfunction.hh:248
vector space out of a tensor product of fields.
Definition: fvector.hh:91
Implements a vector constructed from a given type representing a field and a compile-time given size.
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:145
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)