libMesh
fe_type.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
35 namespace libMesh
36 {
37 
38 // Forward declarations
39 class QBase;
40 class FEType;
41 
49 {
50 public:
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>
86  inline OrderWrapper & operator+=(T p)
87  {
88  _order += int(p);
89  return *this;
90  }
91 
92  template <typename T>
93  inline OrderWrapper & operator-=(T p)
94  {
95  _order -= int(p);
96  return *this;
97  }
98 
99 private:
100 
104  int _order;
105 
106  friend struct std::hash<FEType>;
107 };
108 
112 inline bool operator==(const OrderWrapper & lhs, const OrderWrapper & rhs){ return lhs.get_order() == rhs.get_order(); }
113 inline bool operator!=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
114 inline bool operator< (const OrderWrapper & lhs, const OrderWrapper & rhs){ return lhs.get_order() < rhs.get_order(); }
115 inline bool operator> (const OrderWrapper & lhs, const OrderWrapper & rhs){ return rhs < lhs; }
116 inline bool operator<=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
117 inline 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 
148 OrderWrapperOperators(unsigned int)
149 #if LIBMESH_SIZEOF_SIZE_T != LIBMESH_SIZEOF_UNSIGNED_INT
150 OrderWrapperOperators(std::size_t)
151 #endif
152 
153 // Now disambiguate all the things
154 inline bool operator==(int lhs, const OrderWrapper & rhs){ return lhs == rhs.get_order(); }
155 inline bool operator==(const OrderWrapper & lhs, int rhs){ return lhs.get_order() == rhs; }
156 inline bool operator==(Order lhs, const OrderWrapper & rhs){ return lhs == rhs.get_order(); }
157 inline bool operator==(const OrderWrapper & lhs, Order rhs){ return lhs.get_order() == rhs; }
158 inline bool operator!=(int lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
159 inline bool operator!=(const OrderWrapper & lhs, int rhs){ return !(lhs == rhs); }
160 inline bool operator!=(Order lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
161 inline bool operator!=(const OrderWrapper & lhs, Order rhs){ return !(lhs == rhs); }
162 inline bool operator< (int lhs, const OrderWrapper & rhs){ return lhs < rhs.get_order(); }
163 inline bool operator< (const OrderWrapper & lhs, int rhs){ return lhs.get_order() < rhs; }
164 inline bool operator< (Order lhs, const OrderWrapper & rhs){ return lhs < rhs.get_order(); }
165 inline bool operator< (const OrderWrapper & lhs, Order rhs){ return lhs.get_order() < rhs; }
166 inline bool operator> (int lhs, const OrderWrapper & rhs){ return rhs < lhs; }
167 inline bool operator> (const OrderWrapper & lhs, int rhs){ return rhs < lhs; }
168 inline bool operator> (Order lhs, const OrderWrapper & rhs){ return rhs < lhs; }
169 inline bool operator> (const OrderWrapper & lhs, Order rhs){ return rhs < lhs; }
170 inline bool operator<=(int lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
171 inline bool operator<=(const OrderWrapper & lhs, int rhs){ return !(lhs > rhs); }
172 inline bool operator<=(Order lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
173 inline bool operator<=(const OrderWrapper & lhs, Order rhs){ return !(lhs > rhs); }
174 inline bool operator>=(int lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
175 inline bool operator>=(const OrderWrapper & lhs, int rhs){ return !(lhs < rhs); }
176 inline bool operator>=(Order lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
177 inline bool operator>=(const OrderWrapper & lhs, Order rhs){ return !(lhs < rhs); }
178 
182 inline std::ostream & operator << (std::ostream & os, const OrderWrapper & order)
183 {
184  os << order.get_order();
185  return os;
186 }
187 
196 class FEType
197 {
198 public:
199 
200 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
201 
206  FEType(const int o = 1,
207  const FEFamily f = LAGRANGE) :
208  order(o),
209  family(f)
210  {}
211 
216 
222 
223 #else
224 
234  FEType(const int o = 1,
235  const FEFamily f = LAGRANGE,
236  const int ro = THIRD,
237  const FEFamily rf = JACOBI_20_00,
238  const InfMapType im = CARTESIAN) :
239  order(o),
240  radial_order(ro),
241  family(f),
242  radial_family(rf),
243  inf_map(im)
244  {}
245 
250 
255 
262 
268 
276 
277 #endif // ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
278 
282  bool operator== (const FEType & f2) const
283  {
284  return (order == f2.order
285  && family == f2.family
286 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
287  && radial_order == f2.radial_order
289  && inf_map == f2.inf_map
290 #endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
291  );
292  }
293 
297  bool operator!= (const FEType & f2) const
298  {
299  return !(*this == f2);
300  }
301 
305  bool operator< (const FEType & f2) const
306  {
307  if (order != f2.order)
308  return (order < f2.order);
309  if (family != f2.family)
310  return (family < f2.family);
311 
312 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
313  if (radial_order != f2.radial_order)
314  return (radial_order < f2.radial_order);
315  if (radial_family != f2.radial_family)
316  return (radial_family < f2.radial_family);
317  if (inf_map != f2.inf_map)
318  return (inf_map < f2.inf_map);
319 #endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
320  return false;
321  }
322 
330 
339  std::unique_ptr<QBase> default_quadrature_rule (const unsigned int dim,
340  const int extraorder=0) const;
341 
350 
358  std::unique_ptr<QBase> unweighted_quadrature_rule (const unsigned int dim,
359  const int extraorder=0) const;
360 
361 
362 private:
363 
364 };
365 
366 
367 
368 //-------------------------------------------------------------------
369 // FEType inline methods
370 inline
372 {
373  return static_cast<Order>(2*static_cast<unsigned int>(order.get_order()) + 1);
374 }
375 
376 inline
378 {
379  return order;
380 }
381 
382 } // namespace libMesh
383 
384 namespace std
385 {
386 template <>
387 struct hash<libMesh::FEType>
388 {
389  std::size_t operator()(const libMesh::FEType & fe_type) const
390  {
391  std::size_t seed = 0;
392  // Old compiler versions seem to need the static_cast
393  libMesh::boostcopy::hash_combine(seed, static_cast<int>(fe_type.family));
395  return seed;
396  }
397 };
398 }
399 
400 #endif // LIBMESH_FE_TYPE_H
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:196
FEFamily family
The type of finite element.
Definition: fe_type.h:221
bool operator==(const FEType &f2) const
Tests equality.
Definition: fe_type.h:282
OrderWrapper(int order)
Constructor.
Definition: fe_type.h:64
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
OrderWrapperOperators(int) OrderWrapperOperators(unsigned int) OrderWrapperOperators(std
Definition: fe_type.h:147
Order unweighted_quadrature_order() const
Definition: fe_type.h:377
void hash_combine(std::size_t &seed, const T &value)
Definition: hashing.h:34
bool operator<(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:114
unsigned int dim
OrderWrapper radial_order
The approximation order in radial direction of the infinite element.
Definition: fe_type.h:254
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition: fe_type.h:182
Order default_quadrature_order() const
Definition: fe_type.h:371
OrderWrapper order
The approximation order of the element.
Definition: fe_type.h:215
bool operator>=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:117
The libMesh namespace provides an interface to certain functionality in the library.
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:116
bool operator!=(const FEType &f2) const
Tests inequality.
Definition: fe_type.h:297
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition: fe_type.C:34
int _order
The approximation order of the element.
Definition: fe_type.h:104
bool operator>(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:115
FEType(const int o=1, const FEFamily f=LAGRANGE)
Constructor.
Definition: fe_type.h:206
This provides a shim class that wraps the Order enum.
Definition: fe_type.h:48
OrderWrapper & operator+=(T p)
Definition: fe_type.h:86
InfMapType inf_map
The coordinate mapping type of the infinite element.
Definition: fe_type.h:275
bool operator==(const OrderWrapper &lhs, const OrderWrapper &rhs)
Overload comparison operators for OrderWrapper.
Definition: fe_type.h:112
bool operator<(const FEType &f2) const
An ordering to make FEType useful as a std::map key.
Definition: fe_type.h:305
FEFamily radial_family
The type of approximation in radial direction.
Definition: fe_type.h:267
OrderWrapper & operator-=(T p)
Definition: fe_type.h:93
int get_order() const
Explicitly request the order as an int.
Definition: fe_type.h:80
std::unique_ptr< QBase > unweighted_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition: fe_type.C:53
InfMapType
defines an enum for the types of coordinate mappings available in infinite elements.
std::size_t operator()(const libMesh::FEType &fe_type) const
Definition: fe_type.h:389
FEFamily
defines an enum for finite element families.
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:234
OrderWrapper(Order order)
Constructor.
Definition: fe_type.h:56
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360