Dune Core Modules (2.9.1)

quadraturerules.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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6#ifndef DUNE_GEOMETRY_QUADRATURERULES_HH
7#define DUNE_GEOMETRY_QUADRATURERULES_HH
8
9#include <algorithm>
10#include <iostream>
11#include <limits>
12#include <mutex>
13#include <utility>
14#include <vector>
15
19#include <dune/common/stdthread.hh>
21
22#include <dune/geometry/type.hh>
24
30namespace Dune {
31
37
43 template<typename ct, int dim>
45 public:
47 constexpr static int dimension = dim;
48
50 typedef ct Field;
51
54
56 QuadraturePoint (const Vector& x, ct w) : local(x)
57 {
58 weight_ = w;
59 }
60
62 const Vector& position () const
63 {
64 return local;
65 }
66
68 const ct &weight () const
69 {
70 return weight_;
71 }
72
73 protected:
75 ct weight_;
76 };
77
81 namespace QuadratureType {
82 enum Enum {
93
100
107
120
128
136
145 size
146 };
147 }
148
152 template<typename ct, int dim>
153 class QuadratureRule : public std::vector<QuadraturePoint<ct,dim> >
154 {
155 public:
161 QuadratureRule() : delivered_order(-1) {}
162
163 protected:
165 QuadratureRule(GeometryType t) : geometry_type(t), delivered_order(-1) {}
166
168 QuadratureRule(GeometryType t, int order) : geometry_type(t), delivered_order(order) {}
169 public:
171 constexpr static int d = dim;
172
174 typedef ct CoordType;
175
177 virtual int order () const { return delivered_order; }
178
180 virtual GeometryType type () const { return geometry_type; }
181 virtual ~QuadratureRule(){}
182
185 typedef typename std::vector<QuadraturePoint<ct,dim> >::const_iterator iterator;
186
187 protected:
188 GeometryType geometry_type;
189 int delivered_order;
190 };
191
192 // Forward declaration of the factory class,
193 // needed internally by the QuadratureRules container class.
194 template<typename ctype, int dim> class QuadratureRuleFactory;
195
199 template<typename ctype, int dim>
201
204
205 // indexed by quadrature order
206 using QuadratureOrderVector = std::vector<std::pair<std::once_flag, QuadratureRule> >;
207
208 // indexed by geometry type
209 using GeometryTypeVector = std::vector<std::pair<std::once_flag, QuadratureOrderVector> >;
210
211 // indexed by quadrature type enum
212 using QuadratureCacheVector = std::vector<std::pair<std::once_flag, GeometryTypeVector> >;
213
216 {
217 assert(t.dim()==dim);
218
219 DUNE_ASSERT_CALL_ONCE();
220
221 static QuadratureCacheVector quadratureCache(QuadratureType::size);
222
223 auto& [ onceFlagQuadratureType, geometryTypes ] = quadratureCache[qt];
224 // initialize geometry types for this quadrature type once
225 std::call_once(onceFlagQuadratureType, [&types = geometryTypes]{
226 types = GeometryTypeVector(LocalGeometryTypeIndex::size(dim));
227 });
228
229 auto& [ onceFlagGeometryType, quadratureOrders ] = geometryTypes[LocalGeometryTypeIndex::index(t)];
230 // initialize quadrature orders for this geometry type and quadrature type once
231 std::call_once(onceFlagGeometryType, [&, &orders = quadratureOrders]{
232 // we only need one quadrature rule for points, not maxint
233 const auto numRules = dim == 0 ? 1 : QuadratureRuleFactory<ctype,dim>::maxOrder(t, qt)+1;
234 orders = QuadratureOrderVector(numRules);
235 });
236
237 // we only have one quadrature rule for points
238 auto& [ onceFlagQuadratureOrder, quadratureRule ] = quadratureOrders[dim == 0 ? 0 : p];
239 // initialize quadrature rule once
240 std::call_once(onceFlagQuadratureOrder, [&, &rule = quadratureRule]{
242 });
243
244 return quadratureRule;
245 }
246
248 DUNE_EXPORT static QuadratureRules& instance()
249 {
250 static QuadratureRules instance;
251 return instance;
252 }
253
255 QuadratureRules () = default;
256 public:
258 static unsigned
261 {
263 }
264
267 {
268 return instance()._rule(t,p,qt);
269 }
270
273 {
274 GeometryType gt(t,dim);
275 return instance()._rule(gt,p,qt);
276 }
277 };
278
279} // end namespace Dune
280
281#define DUNE_INCLUDING_IMPLEMENTATION
282
283// 0d rules
284#include "quadraturerules/pointquadrature.hh"
285// 1d rules
286#include "quadraturerules/gausslobattoquadrature.hh"
287#include "quadraturerules/gaussquadrature.hh"
288#include "quadraturerules/gaussradauleftquadrature.hh"
289#include "quadraturerules/gaussradaurightquadrature.hh"
290#include "quadraturerules/jacobi1quadrature.hh"
291#include "quadraturerules/jacobi2quadrature.hh"
292#include "quadraturerules/jacobiNquadrature.hh"
293// 3d rules
294#include "quadraturerules/prismquadrature.hh"
295// general rules
296#include "quadraturerules/simplexquadrature.hh"
297#include "quadraturerules/tensorproductquadrature.hh"
298
299#undef DUNE_INCLUDING_IMPLEMENTATION
300
301namespace Dune {
302
309 template<typename ctype, int dim>
311 private:
312 friend class QuadratureRules<ctype, dim>;
313 static unsigned maxOrder(const GeometryType &t, QuadratureType::Enum qt)
314 {
315 return TensorProductQuadratureRule<ctype,dim>::maxOrder(t.id(), qt);
316 }
317 static QuadratureRule<ctype, dim> rule(const GeometryType& t, int p, QuadratureType::Enum qt)
318 {
319 return TensorProductQuadratureRule<ctype,dim>(t.id(), p, qt);
320 }
321 };
322
323 template<typename ctype>
324 class QuadratureRuleFactory<ctype, 0> {
325 private:
326 constexpr static int dim = 0;
327 friend class QuadratureRules<ctype, dim>;
328 static unsigned maxOrder(const GeometryType &t, QuadratureType::Enum)
329 {
330 if (t.isVertex())
331 {
333 }
334 DUNE_THROW(Exception, "Unknown GeometryType");
335 }
336 static QuadratureRule<ctype, dim> rule(const GeometryType& t, int , QuadratureType::Enum)
337 {
338 if (t.isVertex())
339 {
340 return PointQuadratureRule<ctype>();
341 }
342 DUNE_THROW(Exception, "Unknown GeometryType");
343 }
344 };
345
346 template<typename ctype>
347 class QuadratureRuleFactory<ctype, 1> {
348 private:
349 constexpr static int dim = 1;
350 friend class QuadratureRules<ctype, dim>;
351 static unsigned maxOrder(const GeometryType &t, QuadratureType::Enum qt)
352 {
353 if (t.isLine())
354 {
355 switch (qt) {
357 return GaussQuadratureRule1D<ctype>::highest_order;
359 return Jacobi1QuadratureRule1D<ctype>::highest_order;
361 return Jacobi2QuadratureRule1D<ctype>::highest_order;
363 return GaussLobattoQuadratureRule1D<ctype>::highest_order;
365 return JacobiNQuadratureRule1D<ctype>::maxOrder();
367 return GaussRadauLeftQuadratureRule1D<ctype>::highest_order;
369 return GaussRadauRightQuadratureRule1D<ctype>::highest_order;
370 default :
371 DUNE_THROW(Exception, "Unknown QuadratureType");
372 }
373 }
374 DUNE_THROW(Exception, "Unknown GeometryType");
375 }
376 static QuadratureRule<ctype, dim> rule(const GeometryType& t, int p, QuadratureType::Enum qt)
377 {
378 if (t.isLine())
379 {
380 switch (qt) {
382 return GaussQuadratureRule1D<ctype>(p);
384 return Jacobi1QuadratureRule1D<ctype>(p);
386 return Jacobi2QuadratureRule1D<ctype>(p);
388 return GaussLobattoQuadratureRule1D<ctype>(p);
390 return JacobiNQuadratureRule1D<ctype>(p);
392 return GaussRadauLeftQuadratureRule1D<ctype>(p);
394 return GaussRadauRightQuadratureRule1D<ctype>(p);
395 default :
396 DUNE_THROW(Exception, "Unknown QuadratureType");
397 }
398 }
399 DUNE_THROW(Exception, "Unknown GeometryType");
400 }
401 };
402
403 template<typename ctype>
404 class QuadratureRuleFactory<ctype, 2> {
405 private:
406 constexpr static int dim = 2;
407 friend class QuadratureRules<ctype, dim>;
408 static unsigned maxOrder(const GeometryType &t, QuadratureType::Enum qt)
409 {
410 unsigned order =
411 TensorProductQuadratureRule<ctype,dim>::maxOrder(t.id(), qt);
412 if (t.isSimplex())
413 order = std::max
414 (order, unsigned(SimplexQuadratureRule<ctype,dim>::highest_order));
415 return order;
416 }
417 static QuadratureRule<ctype, dim> rule(const GeometryType& t, int p, QuadratureType::Enum qt)
418 {
419 if (t.isSimplex()
421 && p <= SimplexQuadratureRule<ctype,dim>::highest_order)
422 {
423 return SimplexQuadratureRule<ctype,dim>(p);
424 }
425 return TensorProductQuadratureRule<ctype,dim>(t.id(), p, qt);
426 }
427 };
428
429 template<typename ctype>
430 class QuadratureRuleFactory<ctype, 3> {
431 private:
432 constexpr static int dim = 3;
433 friend class QuadratureRules<ctype, dim>;
434 static unsigned maxOrder(const GeometryType &t, QuadratureType::Enum qt)
435 {
436 unsigned order =
437 TensorProductQuadratureRule<ctype,dim>::maxOrder(t.id(), qt);
438 if (t.isSimplex())
439 order = std::max
440 (order, unsigned(SimplexQuadratureRule<ctype,dim>::highest_order));
441 if (t.isPrism())
442 order = std::max
443 (order, unsigned(PrismQuadratureRule<ctype,dim>::highest_order));
444 return order;
445 }
446 static QuadratureRule<ctype, dim> rule(const GeometryType& t, int p, QuadratureType::Enum qt)
447 {
448
449 if (t.isSimplex()
451 && p <= SimplexQuadratureRule<ctype,dim>::highest_order)
452 {
453 return SimplexQuadratureRule<ctype,dim>(p);
454 }
455 if (t.isPrism()
457 && p <= PrismQuadratureRule<ctype,dim>::highest_order)
458 {
459 return PrismQuadratureRule<ctype,dim>(p);
460 }
461 return TensorProductQuadratureRule<ctype,dim>(t.id(), p, qt);
462 }
463 };
464
465#ifndef DUNE_NO_EXTERN_QUADRATURERULES
466 extern template class GaussLobattoQuadratureRule<double, 1>;
467 extern template class GaussQuadratureRule<double, 1>;
468 extern template class GaussRadauLeftQuadratureRule<double, 1>;
469 extern template class GaussRadauRightQuadratureRule<double, 1>;
470 extern template class Jacobi1QuadratureRule<double, 1>;
471 extern template class Jacobi2QuadratureRule<double, 1>;
472 extern template class JacobiNQuadratureRule<double, 1>;
473 extern template class PrismQuadratureRule<double, 3>;
474 extern template class SimplexQuadratureRule<double, 2>;
475 extern template class SimplexQuadratureRule<double, 3>;
476#endif // !DUNE_NO_EXTERN_QUADRATURERULES
477
478} // end namespace
479
480#endif // DUNE_GEOMETRY_QUADRATURERULES_HH
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:126
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:291
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:372
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:132
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:377
static constexpr std::size_t size(std::size_t dim)
Compute total number of geometry types for the given dimension.
Definition: typeindex.hh:61
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type within its dimension.
Definition: typeindex.hh:73
Default exception for dummy implementations.
Definition: exceptions.hh:263
Exception thrown if a desired QuadratureRule is not available, because the requested order is to high...
Definition: quadraturerules.hh:36
Single evaluation point in a quadrature rule.
Definition: quadraturerules.hh:44
const Vector & position() const
return local coordinates of integration point i
Definition: quadraturerules.hh:62
Dune::FieldVector< ct, dim > Vector
Type used for the position of a quadrature point.
Definition: quadraturerules.hh:53
ct Field
Number type used for coordinates and quadrature weights.
Definition: quadraturerules.hh:50
const ct & weight() const
return weight associated with integration point i
Definition: quadraturerules.hh:68
static constexpr int dimension
Dimension of the integration domain.
Definition: quadraturerules.hh:47
QuadraturePoint(const Vector &x, ct w)
set up quadrature of given order in d dimensions
Definition: quadraturerules.hh:56
Factory class for creation of quadrature rules, depending on GeometryType, order and QuadratureType.
Definition: quadraturerules.hh:310
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:154
static constexpr int d
The space dimension.
Definition: quadraturerules.hh:171
virtual GeometryType type() const
return type of element
Definition: quadraturerules.hh:180
QuadratureRule(GeometryType t, int order)
Constructor for a given geometry type and a given quadrature order.
Definition: quadraturerules.hh:168
ct CoordType
The type used for coordinates.
Definition: quadraturerules.hh:174
QuadratureRule()
Default constructor.
Definition: quadraturerules.hh:161
virtual int order() const
return order
Definition: quadraturerules.hh:177
QuadratureRule(GeometryType t)
Constructor for a given geometry type. Leaves the quadrature order invalid
Definition: quadraturerules.hh:165
std::vector< QuadraturePoint< ct, dim > >::const_iterator iterator
Definition: quadraturerules.hh:185
A container for all quadrature rules of dimension dim
Definition: quadraturerules.hh:200
static unsigned maxOrder(const GeometryType &t, QuadratureType::Enum qt=QuadratureType::GaussLegendre)
maximum quadrature order for given geometry type and quadrature type
Definition: quadraturerules.hh:259
static const QuadratureRule & rule(const GeometryType::BasicType t, int p, QuadratureType::Enum qt=QuadratureType::GaussLegendre)
select the appropriate QuadratureRule for GeometryType t and order p
Definition: quadraturerules.hh:272
static const QuadratureRule & rule(const GeometryType &t, int p, QuadratureType::Enum qt=QuadratureType::GaussLegendre)
select the appropriate QuadratureRule for GeometryType t and order p
Definition: quadraturerules.hh:266
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Enum
Definition: quadraturerules.hh:82
@ GaussJacobi_n_0
Gauss-Legendre rules with .
Definition: quadraturerules.hh:119
@ GaussJacobi_2_0
Gauss-Legendre rules with .
Definition: quadraturerules.hh:106
@ GaussRadauRight
Gauss-Radau rules including the right endpoint.
Definition: quadraturerules.hh:144
@ GaussJacobi_1_0
Gauss-Jacobi rules with .
Definition: quadraturerules.hh:99
@ GaussLobatto
Gauss-Lobatto rules.
Definition: quadraturerules.hh:127
@ GaussRadauLeft
Gauss-Radau rules including the left endpoint.
Definition: quadraturerules.hh:135
@ GaussLegendre
Gauss-Legendre rules (default)
Definition: quadraturerules.hh:92
Dune namespace.
Definition: alignedallocator.hh:13
Standard Dune debug streams.
A unique label for each type of element that can occur in a grid.
Helper classes to provide indices for geometrytypes for use in a vector.
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:20
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)