libMesh
Loading...
Searching...
No Matches
fe_type.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_FE_TYPE_H
21#define LIBMESH_FE_TYPE_H
22
23// Local includes
24#include "libmesh/compare_types.h"
25#include "libmesh/libmesh_config.h"
26#include "libmesh/enum_order.h" // return Order objects
27#include "libmesh/enum_fe_family.h" // LAGRANGE
28#include "libmesh/enum_inf_map_type.h" // CARTESIAN
29#include "libmesh/hashing.h"
30
31// C++ includes
32#include <memory>
33#include <functional>
34
35namespace libMesh
36{
37
38// Forward declarations
39class QBase;
40class FEType;
41
49{
50public:
51
57 _order(static_cast<int>(order))
58 {}
59
64 OrderWrapper(int order) :
65 _order(order)
66 {}
67
72 operator Order() const
73 {
74 return static_cast<Order>(_order);
75 }
76
80 int get_order() const
81 {
82 return _order;
83 }
84
85 template <typename T>
87 {
88 _order += int(p);
89 return *this;
90 }
91
92 template <typename T>
94 {
95 _order -= int(p);
96 return *this;
97 }
98
99private:
100
105
106 friend struct std::hash<FEType>;
107};
108
112inline bool operator==(const OrderWrapper & lhs, const OrderWrapper & rhs){ return lhs.get_order() == rhs.get_order(); }
113inline bool operator!=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
114inline bool operator< (const OrderWrapper & lhs, const OrderWrapper & rhs){ return lhs.get_order() < rhs.get_order(); }
115inline bool operator> (const OrderWrapper & lhs, const OrderWrapper & rhs){ return rhs < lhs; }
116inline bool operator<=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
117inline bool operator>=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
118
119// First disambiguate everything that would be ambiguated by the
120// subsequent disambiguations
121#define OrderWrapperOperators(comparisontype) \
122 inline bool operator==(comparisontype lhs, Order rhs) \
123 { return lhs == static_cast<comparisontype>(rhs); } \
124 inline bool operator==(Order lhs, comparisontype rhs) \
125 { return static_cast<comparisontype>(lhs) == rhs; } \
126 inline bool operator!=(comparisontype lhs, Order rhs) \
127 { return !(lhs == rhs); } \
128 inline bool operator!=(Order lhs, comparisontype rhs) \
129 { return !(lhs == rhs); } \
130 inline bool operator< (comparisontype lhs, Order rhs) \
131 { return lhs < static_cast<comparisontype>(rhs); } \
132 inline bool operator< (Order lhs, comparisontype rhs) \
133 { return static_cast<comparisontype>(lhs) < rhs; } \
134 inline bool operator> (comparisontype lhs, Order rhs) \
135 { return rhs < lhs; } \
136 inline bool operator> (Order lhs, comparisontype rhs) \
137 { return rhs < lhs; } \
138 inline bool operator<=(comparisontype lhs, Order rhs) \
139 { return !(lhs > rhs); } \
140 inline bool operator<=(Order lhs, comparisontype rhs) \
141 { return !(lhs > rhs); } \
142 inline bool operator>=(comparisontype lhs, Order rhs) \
143 { return !(lhs < rhs); } \
144 inline bool operator>=(Order lhs, comparisontype rhs) \
145 { return !(lhs < rhs); }
146
148OrderWrapperOperators(unsigned int)
149#if LIBMESH_SIZEOF_SIZE_T != LIBMESH_SIZEOF_UNSIGNED_INT
150OrderWrapperOperators(std::size_t)
151#endif
152
153// Now disambiguate all the things
154inline bool operator==(int lhs, const OrderWrapper & rhs){ return lhs == rhs.get_order(); }
155inline bool operator==(const OrderWrapper & lhs, int rhs){ return lhs.get_order() == rhs; }
156inline bool operator==(Order lhs, const OrderWrapper & rhs){ return lhs == rhs.get_order(); }
157inline bool operator==(const OrderWrapper & lhs, Order rhs){ return lhs.get_order() == rhs; }
158inline bool operator!=(int lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
159inline bool operator!=(const OrderWrapper & lhs, int rhs){ return !(lhs == rhs); }
160inline bool operator!=(Order lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
161inline bool operator!=(const OrderWrapper & lhs, Order rhs){ return !(lhs == rhs); }
162inline bool operator< (int lhs, const OrderWrapper & rhs){ return lhs < rhs.get_order(); }
163inline bool operator< (const OrderWrapper & lhs, int rhs){ return lhs.get_order() < rhs; }
164inline bool operator< (Order lhs, const OrderWrapper & rhs){ return lhs < rhs.get_order(); }
165inline bool operator< (const OrderWrapper & lhs, Order rhs){ return lhs.get_order() < rhs; }
166inline bool operator> (int lhs, const OrderWrapper & rhs){ return rhs < lhs; }
167inline bool operator> (const OrderWrapper & lhs, int rhs){ return rhs < lhs; }
168inline bool operator> (Order lhs, const OrderWrapper & rhs){ return rhs < lhs; }
169inline bool operator> (const OrderWrapper & lhs, Order rhs){ return rhs < lhs; }
170inline bool operator<=(int lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
171inline bool operator<=(const OrderWrapper & lhs, int rhs){ return !(lhs > rhs); }
172inline bool operator<=(Order lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
173inline bool operator<=(const OrderWrapper & lhs, Order rhs){ return !(lhs > rhs); }
174inline bool operator>=(int lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
175inline bool operator>=(const OrderWrapper & lhs, int rhs){ return !(lhs < rhs); }
176inline bool operator>=(Order lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
177inline bool operator>=(const OrderWrapper & lhs, Order rhs){ return !(lhs < rhs); }
178
182inline std::ostream & operator << (std::ostream & os, const OrderWrapper & order)
183{
184 os << order.get_order();
185 return os;
186}
187
197{
198public:
199
204
205#ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
206
217 FEType(const int o = 1,
218 const FEFamily f = LAGRANGE) :
219 order(o),
220 family(f),
221 p_refinement(true)
222 {}
223
229
230#else
231
246 FEType(const int o = 1,
247 const FEFamily f = LAGRANGE,
248 const int ro = THIRD,
249 const FEFamily rf = JACOBI_20_00,
250 const InfMapType im = CARTESIAN
251 ) :
252 order(o),
253 radial_order(ro),
254 family(f),
255 radial_family(rf),
256 inf_map(im),
257 p_refinement(true)
258 {}
259
264
271
277
285
286#endif // ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
287
293
299 {
300 this->p_refinement = p;
301 return *this;
302 }
303
309 {
310 this->p_refinement = p;
311 return std::move(*this);
312 }
313
317 bool operator== (const FEType & f2) const
318 {
319 return (order == f2.order
320 && family == f2.family
322#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
325 && inf_map == f2.inf_map
326#endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
327 );
328 }
329
333 bool operator!= (const FEType & f2) const
334 {
335 return !(*this == f2);
336 }
337
341 bool operator< (const FEType & f2) const
342 {
343 if (order != f2.order)
344 return (order < f2.order);
345 if (family != f2.family)
346 return (family < f2.family);
347 if (p_refinement != f2.p_refinement)
348 return (p_refinement < f2.p_refinement);
349#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
350 if (radial_order != f2.radial_order)
351 return (radial_order < f2.radial_order);
353 return (radial_family < f2.radial_family);
354 if (inf_map != f2.inf_map)
355 return (inf_map < f2.inf_map);
356#endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
357 return false;
358 }
359
368
379 std::unique_ptr<QBase> default_quadrature_rule (const unsigned int dim,
380 const int extraorder=0) const;
381
392
402 std::unique_ptr<QBase> unweighted_quadrature_rule (const unsigned int dim,
403 const int extraorder=0) const;
404
405
406private:
407
408};
409
410
411
412//-------------------------------------------------------------------
413// FEType inline methods
414inline
416{
417 return static_cast<Order>(2*static_cast<unsigned int>(order.get_order()) + 1);
418}
419
420inline
422{
423 return order;
424}
425
426} // namespace libMesh
427
428namespace std
429{
430template <>
431struct hash<libMesh::FEType>
432{
433 std::size_t operator()(const libMesh::FEType & fe_type) const
434 {
435 std::size_t seed = 0;
436 // Old compiler versions seem to need the static_cast
437 libMesh::boostcopy::hash_combine(seed, static_cast<int>(fe_type.family));
439 libMesh::boostcopy::hash_combine(seed, static_cast<int>(fe_type.p_refinement));
440#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
441 libMesh::boostcopy::hash_combine(seed, static_cast<int>(fe_type.radial_family));
443 libMesh::boostcopy::hash_combine(seed, static_cast<int>(fe_type.inf_map));
444#endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
445 return seed;
446 }
447};
448}
449
450#endif // LIBMESH_FE_TYPE_H
unsigned int dim
void ErrorVector unsigned int
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
FEType(const int o=1, const FEFamily f=LAGRANGE, const int ro=THIRD, const FEFamily rf=JACOBI_20_00, const InfMapType im=CARTESIAN)
Constructor.
Definition fe_type.h:246
InfMapType inf_map
The coordinate mapping type of the infinite element.
Definition fe_type.h:284
OrderWrapper radial_order
The approximation order in radial direction of the infinite element.
Definition fe_type.h:263
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition fe_type.C:34
FEType set_p_refinement(bool p) &&
Specialization for rvalues so we don't return a dangling reference to a temporary.
Definition fe_type.h:308
std::unique_ptr< QBase > unweighted_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition fe_type.C:53
Order default_quadrature_order() const
Definition fe_type.h:415
bool operator!=(const FEType &f2) const
Tests inequality.
Definition fe_type.h:333
FEType(const int o=1, const FEFamily f=LAGRANGE)
Constructor.
Definition fe_type.h:217
bool operator==(const FEType &f2) const
Tests equality.
Definition fe_type.h:317
FEType set_p_refinement(bool p) &
"Fluent API" for constructing a non-default p_refinement, for easier compatibility between non-InfFE ...
Definition fe_type.h:298
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
Definition fe_type.h:203
bool p_refinement
Whether or not the finite elements for this type increase their p refinement level on geometric eleme...
Definition fe_type.h:292
FEFamily radial_family
The type of approximation in radial direction.
Definition fe_type.h:276
bool operator<(const FEType &f2) const
An ordering to make FEType useful as a std::map key.
Definition fe_type.h:341
FEFamily family
The type of finite element.
Definition fe_type.h:228
Order unweighted_quadrature_order() const
Definition fe_type.h:421
This provides a shim class that wraps the Order enum.
Definition fe_type.h:49
OrderWrapper & operator+=(T p)
Definition fe_type.h:86
OrderWrapper & operator-=(T p)
Definition fe_type.h:93
OrderWrapper(int order)
Constructor.
Definition fe_type.h:64
OrderWrapper(Order order)
Constructor.
Definition fe_type.h:56
int _order
The approximation order of the element.
Definition fe_type.h:104
int get_order() const
Explicitly request the order as an int.
Definition fe_type.h:80
void hash_combine(std::size_t &seed, const T &value)
Definition hashing.h:34
The libMesh namespace provides an interface to certain functionality in the library.
OrderWrapperOperators(int) OrderWrapperOperators(unsigned int) OrderWrapperOperators(std
Definition fe_type.h:147
bool operator!=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition fe_type.h:113
bool operator<(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition fe_type.h:114
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition fe_type.h:182
bool operator==(const OrderWrapper &lhs, const OrderWrapper &rhs)
Overload comparison operators for OrderWrapper.
Definition fe_type.h:112
bool operator<=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition fe_type.h:116
bool operator>=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition fe_type.h:117
bool operator>(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition fe_type.h:115
std::size_t operator()(const libMesh::FEType &fe_type) const
Definition fe_type.h:433