libMesh
fe_type.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 private:
86 
90  int _order;
91 
92  friend struct std::hash<FEType>;
93 };
94 
98 inline bool operator==(const OrderWrapper & lhs, const OrderWrapper & rhs){ return lhs.get_order() == rhs.get_order(); }
99 inline bool operator!=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
100 inline bool operator< (const OrderWrapper & lhs, const OrderWrapper & rhs){ return lhs.get_order() < rhs.get_order(); }
101 inline bool operator> (const OrderWrapper & lhs, const OrderWrapper & rhs){ return rhs < lhs; }
102 inline bool operator<=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
103 inline bool operator>=(const OrderWrapper & lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
104 
105 // First disambiguate everything that would be ambiguated by the
106 // subsequent disambiguations
107 #define OrderWrapperOperators(comparisontype) \
108  inline bool operator==(comparisontype lhs, Order rhs) \
109  { return lhs == static_cast<comparisontype>(rhs); } \
110  inline bool operator==(Order lhs, comparisontype rhs) \
111  { return static_cast<comparisontype>(lhs) == rhs; } \
112  inline bool operator!=(comparisontype lhs, Order rhs) \
113  { return !(lhs == rhs); } \
114  inline bool operator!=(Order lhs, comparisontype rhs) \
115  { return !(lhs == rhs); } \
116  inline bool operator< (comparisontype lhs, Order rhs) \
117  { return lhs < static_cast<comparisontype>(rhs); } \
118  inline bool operator< (Order lhs, comparisontype rhs) \
119  { return static_cast<comparisontype>(lhs) < rhs; } \
120  inline bool operator> (comparisontype lhs, Order rhs) \
121  { return rhs < lhs; } \
122  inline bool operator> (Order lhs, comparisontype rhs) \
123  { return rhs < lhs; } \
124  inline bool operator<=(comparisontype lhs, Order rhs) \
125  { return !(lhs > rhs); } \
126  inline bool operator<=(Order lhs, comparisontype rhs) \
127  { return !(lhs > rhs); } \
128  inline bool operator>=(comparisontype lhs, Order rhs) \
129  { return !(lhs < rhs); } \
130  inline bool operator>=(Order lhs, comparisontype rhs) \
131  { return !(lhs < rhs); }
132 
134 OrderWrapperOperators(unsigned int)
135 #if LIBMESH_SIZEOF_SIZE_T != LIBMESH_SIZEOF_UNSIGNED_INT
136 OrderWrapperOperators(std::size_t)
137 #endif
138 
139 // Now disambiguate all the things
140 inline bool operator==(int lhs, const OrderWrapper & rhs){ return lhs == rhs.get_order(); }
141 inline bool operator==(const OrderWrapper & lhs, int rhs){ return lhs.get_order() == rhs; }
142 inline bool operator==(Order lhs, const OrderWrapper & rhs){ return lhs == rhs.get_order(); }
143 inline bool operator==(const OrderWrapper & lhs, Order rhs){ return lhs.get_order() == rhs; }
144 inline bool operator!=(int lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
145 inline bool operator!=(const OrderWrapper & lhs, int rhs){ return !(lhs == rhs); }
146 inline bool operator!=(Order lhs, const OrderWrapper & rhs){ return !(lhs == rhs); }
147 inline bool operator!=(const OrderWrapper & lhs, Order rhs){ return !(lhs == rhs); }
148 inline bool operator< (int lhs, const OrderWrapper & rhs){ return lhs < rhs.get_order(); }
149 inline bool operator< (const OrderWrapper & lhs, int rhs){ return lhs.get_order() < rhs; }
150 inline bool operator< (Order lhs, const OrderWrapper & rhs){ return lhs < rhs.get_order(); }
151 inline bool operator< (const OrderWrapper & lhs, Order rhs){ return lhs.get_order() < rhs; }
152 inline bool operator> (int lhs, const OrderWrapper & rhs){ return rhs < lhs; }
153 inline bool operator> (const OrderWrapper & lhs, int rhs){ return rhs < lhs; }
154 inline bool operator> (Order lhs, const OrderWrapper & rhs){ return rhs < lhs; }
155 inline bool operator> (const OrderWrapper & lhs, Order rhs){ return rhs < lhs; }
156 inline bool operator<=(int lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
157 inline bool operator<=(const OrderWrapper & lhs, int rhs){ return !(lhs > rhs); }
158 inline bool operator<=(Order lhs, const OrderWrapper & rhs){ return !(lhs > rhs); }
159 inline bool operator<=(const OrderWrapper & lhs, Order rhs){ return !(lhs > rhs); }
160 inline bool operator>=(int lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
161 inline bool operator>=(const OrderWrapper & lhs, int rhs){ return !(lhs < rhs); }
162 inline bool operator>=(Order lhs, const OrderWrapper & rhs){ return !(lhs < rhs); }
163 inline bool operator>=(const OrderWrapper & lhs, Order rhs){ return !(lhs < rhs); }
164 
168 inline std::ostream & operator << (std::ostream & os, const OrderWrapper & order)
169 {
170  os << order.get_order();
171  return os;
172 }
173 
182 class FEType
183 {
184 public:
185 
186 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
187 
192  FEType(const int o = 1,
193  const FEFamily f = LAGRANGE) :
194  order(o),
195  family(f)
196  {}
197 
202 
208 
209 #else
210 
220  FEType(const int o = 1,
221  const FEFamily f = LAGRANGE,
222  const int ro = THIRD,
223  const FEFamily rf = JACOBI_20_00,
224  const InfMapType im = CARTESIAN) :
225  order(o),
226  radial_order(ro),
227  family(f),
228  radial_family(rf),
229  inf_map(im)
230  {}
231 
236 
241 
248 
254 
262 
263 #endif // ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
264 
268  bool operator== (const FEType & f2) const
269  {
270  return (order == f2.order
271  && family == f2.family
272 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
273  && radial_order == f2.radial_order
275  && inf_map == f2.inf_map
276 #endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
277  );
278  }
279 
283  bool operator!= (const FEType & f2) const
284  {
285  return !(*this == f2);
286  }
287 
291  bool operator< (const FEType & f2) const
292  {
293  if (order != f2.order)
294  return (order < f2.order);
295  if (family != f2.family)
296  return (family < f2.family);
297 
298 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
299  if (radial_order != f2.radial_order)
300  return (radial_order < f2.radial_order);
301  if (radial_family != f2.radial_family)
302  return (radial_family < f2.radial_family);
303  if (inf_map != f2.inf_map)
304  return (inf_map < f2.inf_map);
305 #endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
306  return false;
307  }
308 
316 
325  std::unique_ptr<QBase> default_quadrature_rule (const unsigned int dim,
326  const int extraorder=0) const;
327 
336 
344  std::unique_ptr<QBase> unweighted_quadrature_rule (const unsigned int dim,
345  const int extraorder=0) const;
346 
347 
348 private:
349 
350 };
351 
352 
353 
354 //-------------------------------------------------------------------
355 // FEType inline methods
356 inline
358 {
359  return static_cast<Order>(2*static_cast<unsigned int>(order.get_order()) + 1);
360 }
361 
362 inline
364 {
365  return order;
366 }
367 
368 } // namespace libMesh
369 
370 namespace std
371 {
372 template <>
373 struct hash<libMesh::FEType>
374 {
375  std::size_t operator()(const libMesh::FEType & fe_type) const
376  {
377  std::size_t seed = 0;
378  // Old compiler versions seem to need the static_cast
379  libMesh::boostcopy::hash_combine(seed, static_cast<int>(fe_type.family));
381  return seed;
382  }
383 };
384 }
385 
386 #endif // LIBMESH_FE_TYPE_H
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:182
FEFamily family
The type of finite element.
Definition: fe_type.h:207
bool operator==(const FEType &f2) const
Tests equality.
Definition: fe_type.h:268
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:133
Order unweighted_quadrature_order() const
Definition: fe_type.h:363
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:100
unsigned int dim
OrderWrapper radial_order
The approximation order in radial direction of the infinite element.
Definition: fe_type.h:240
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
Definition: fe_type.h:168
Order default_quadrature_order() const
Definition: fe_type.h:357
OrderWrapper order
The approximation order of the element.
Definition: fe_type.h:201
bool operator>=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:103
The libMesh namespace provides an interface to certain functionality in the library.
bool operator!=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:99
bool operator<=(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:102
bool operator!=(const FEType &f2) const
Tests inequality.
Definition: fe_type.h:283
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:90
bool operator>(const OrderWrapper &lhs, const OrderWrapper &rhs)
Definition: fe_type.h:101
FEType(const int o=1, const FEFamily f=LAGRANGE)
Constructor.
Definition: fe_type.h:192
This provides a shim class that wraps the Order enum.
Definition: fe_type.h:48
InfMapType inf_map
The coordinate mapping type of the infinite element.
Definition: fe_type.h:261
bool operator==(const OrderWrapper &lhs, const OrderWrapper &rhs)
Overload comparison operators for OrderWrapper.
Definition: fe_type.h:98
bool operator<(const FEType &f2) const
An ordering to make FEType useful as a std::map key.
Definition: fe_type.h:291
FEFamily radial_family
The type of approximation in radial direction.
Definition: fe_type.h:253
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:375
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:220
OrderWrapper(Order order)
Constructor.
Definition: fe_type.h:56
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360