libMesh
Loading...
Searching...
No Matches
fe_abstract.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_ABSTRACT_H
21#define LIBMESH_FE_ABSTRACT_H
22
23// Local includes
24#include "libmesh/reference_counted_object.h"
25#include "libmesh/point.h"
26#include "libmesh/vector_value.h"
27#include "libmesh/fe_type.h"
28#include "libmesh/fe_map.h"
29#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
30#include "libmesh/tensor_value.h"
31#endif
32
33// C++ includes
34#include <cstddef>
35#include <vector>
36#include <memory>
37
38#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
39#define virtual_for_inffe virtual
40#else
41#define virtual_for_inffe
42#endif
43
44
45namespace libMesh
46{
47
48
49// forward declarations
50template <typename T> class DenseMatrix;
51template <typename T> class DenseVector;
52class BoundaryInfo;
53class DofConstraints;
54class DofMap;
55class Elem;
56class MeshBase;
57template <typename T> class NumericVector;
58class QBase;
59enum ElemType : int;
60
61#ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
62class NodeConstraints;
63#endif
64
65#ifdef LIBMESH_ENABLE_PERIODIC
66class PeriodicBoundaries;
67class PointLocatorBase;
68#endif
69
70#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
71template <unsigned int Dim, FEFamily T_radial, InfMapType T_map>
72class InfFE;
73#endif
74
75
76
99class FEAbstract : public ReferenceCountedObject<FEAbstract>
100{
101protected:
102
108 FEAbstract (const unsigned int dim,
109 const FEType & fet);
110
111public:
112
116 virtual ~FEAbstract();
117
124 static std::unique_ptr<FEAbstract> build (const unsigned int dim,
125 const FEType & type);
126
141 virtual void reinit (const Elem * elem,
142 const std::vector<Point> * const pts = nullptr,
143 const std::vector<Real> * const weights = nullptr) = 0;
144
150 virtual void reinit_dual_shape_coeffs (const Elem * /*elem*/,
151 const std::vector<Point> & /*pts*/,
152 const std::vector<Real> & /*JxW*/)
153 {
154 libmesh_error_msg("Customized dual shape coefficient calculation has not been implemented for this FE type.");
155 }
156
161 virtual void reinit_default_dual_shape_coeffs (const Elem * /*elem*/)
162 {
163 libmesh_error_msg("Default dual shape coefficient calculation has not been implemented for this FE type.");
164 }
165
174 virtual void reinit (const Elem * elem,
175 const unsigned int side,
176 const Real tolerance = TOLERANCE,
177 const std::vector<Point> * const pts = nullptr,
178 const std::vector<Real> * const weights = nullptr) = 0;
179
188 virtual void edge_reinit (const Elem * elem,
189 const unsigned int edge,
190 const Real tolerance = TOLERANCE,
191 const std::vector<Point> * pts = nullptr,
192 const std::vector<Real> * weights = nullptr) = 0;
193
198 virtual void side_map (const Elem * elem,
199 const Elem * side,
200 const unsigned int s,
201 const std::vector<Point> & reference_side_points,
202 std::vector<Point> & reference_points) = 0;
203
204#ifdef LIBMESH_ENABLE_DEPRECATED
217 static bool on_reference_element(const Point & p,
218 const ElemType t,
219 const Real eps = TOLERANCE);
220#endif // LIBMESH_ENABLE_DEPRECATED
221
226 static void get_refspace_nodes(const ElemType t,
227 std::vector<Point> & nodes);
228
229
230#ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
235 static void compute_node_constraints (NodeConstraints & constraints,
236 const Elem * elem);
237#endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
238
239#ifdef LIBMESH_ENABLE_PERIODIC
240
241#ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
246 static void compute_periodic_node_constraints (NodeConstraints & constraints,
247 const PeriodicBoundaries & boundaries,
248 const MeshBase & mesh,
249 const PointLocatorBase * point_locator,
250 const Elem * elem);
251#endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
252
253#endif // LIBMESH_ENABLE_PERIODIC
254
258 unsigned int get_dim() const
259 { return dim; }
260
269 void get_nothing() const
270 { calculate_nothing = true; }
271
279 virtual_for_inffe
280 const std::vector<Point> & get_xyz() const
281 { calculate_map = true; return this->_fe_map->get_xyz(); }
282
283
284#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
292 virtual const std::vector<Real> & get_JxWxdecay_sq () const
293 { return get_JxW();}
294#endif
295
302 virtual_for_inffe
303 const std::vector<Real> & get_JxW() const
304 { calculate_map = true; return this->_fe_map->get_JxW(); }
305
310 virtual_for_inffe
311 const std::vector<RealGradient> & get_dxyzdxi() const
312 { calculate_map = true; return this->_fe_map->get_dxyzdxi(); }
313
318 virtual_for_inffe
319 const std::vector<RealGradient> & get_dxyzdeta() const
320 { calculate_map = true; return this->_fe_map->get_dxyzdeta(); }
321
326 virtual_for_inffe
327 const std::vector<RealGradient> & get_dxyzdzeta() const
328 { return _fe_map->get_dxyzdzeta(); }
329
330#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
331
335 virtual_for_inffe
336 const std::vector<RealGradient> & get_d2xyzdxi2() const
337 { calculate_map = true; return this->_fe_map->get_d2xyzdxi2(); }
338
342 virtual_for_inffe
343 const std::vector<RealGradient> & get_d2xyzdeta2() const
344 { calculate_map = true; return this->_fe_map->get_d2xyzdeta2(); }
345
349 virtual_for_inffe
350 const std::vector<RealGradient> & get_d2xyzdzeta2() const
351 { calculate_map = true; return this->_fe_map->get_d2xyzdzeta2(); }
352
356 virtual_for_inffe
357 const std::vector<RealGradient> & get_d2xyzdxideta() const
358 { calculate_map = true; return this->_fe_map->get_d2xyzdxideta(); }
359
363 virtual_for_inffe
364 const std::vector<RealGradient> & get_d2xyzdxidzeta() const
365 { calculate_map = true; return this->_fe_map->get_d2xyzdxidzeta(); }
366
370 virtual_for_inffe
371 const std::vector<RealGradient> & get_d2xyzdetadzeta() const
372 { calculate_map = true; return this->_fe_map->get_d2xyzdetadzeta(); }
373
374#endif
375
380 virtual_for_inffe
381 const std::vector<Real> & get_dxidx() const
382 { calculate_map = true; return this->_fe_map->get_dxidx(); }
383
388 virtual_for_inffe
389 const std::vector<Real> & get_dxidy() const
390 { calculate_map = true; return this->_fe_map->get_dxidy(); }
391
396 virtual_for_inffe
397 const std::vector<Real> & get_dxidz() const
398 { calculate_map = true; return this->_fe_map->get_dxidz(); }
399
404 virtual_for_inffe
405 const std::vector<Real> & get_detadx() const
406 { calculate_map = true; return this->_fe_map->get_detadx(); }
407
412 virtual_for_inffe
413 const std::vector<Real> & get_detady() const
414 { calculate_map = true; return this->_fe_map->get_detady(); }
415
420 virtual_for_inffe
421 const std::vector<Real> & get_detadz() const
422 { calculate_map = true; return this->_fe_map->get_detadz(); }
423
428 virtual_for_inffe
429 const std::vector<Real> & get_dzetadx() const
430 { calculate_map = true; return this->_fe_map->get_dzetadx(); }
431
436 virtual_for_inffe
437 const std::vector<Real> & get_dzetady() const
438 { calculate_map = true; return this->_fe_map->get_dzetady(); }
439
444 virtual_for_inffe
445 const std::vector<Real> & get_dzetadz() const
446 { calculate_map = true; return this->_fe_map->get_dzetadz(); }
447
451 virtual_for_inffe
452 const std::vector<std::vector<Point>> & get_tangents() const
453 { calculate_map = true; return this->_fe_map->get_tangents(); }
454
458 virtual_for_inffe
459 const std::vector<Point> & get_normals() const
460 { calculate_map = true; return this->_fe_map->get_normals(); }
461
462#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
466 virtual_for_inffe
467 const std::vector<Real> & get_curvatures() const
468 { calculate_map = true; return this->_fe_map->get_curvatures();}
469
470#endif
471
476 virtual void attach_quadrature_rule (QBase * q) = 0;
477
483 virtual unsigned int n_shape_functions () const = 0;
484
489 virtual unsigned int n_quadrature_points () const;
490
496 const Elem * get_elem() const { return _elem; }
497
509 ElemType get_type() const { return _elem_type; }
510
515 unsigned int get_p_level() const { return _p_level; }
516
520 FEType get_fe_type() const { return fe_type; }
521
526 { return fe_type.order + _p_level; }
527
531 void set_fe_order(int new_order) { fe_type.order = new_order; }
532
536 virtual FEContinuity get_continuity() const = 0;
537
542 virtual bool is_hierarchic() const = 0;
543
547 FEFamily get_family() const { return fe_type.family; }
548
554 const FEMap & get_fe_map() const { return *_fe_map.get(); }
555 FEMap & get_fe_map() { return *_fe_map.get(); }
556
560 void print_JxW(std::ostream & os) const;
561
567 virtual void print_phi(std::ostream & os) const =0;
568 virtual void print_dual_phi(std::ostream & os) const =0;
569
575 virtual void print_dphi(std::ostream & os) const =0;
576 virtual void print_dual_dphi(std::ostream & os) const =0;
577
578#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
579
585 virtual void print_d2phi(std::ostream & os) const =0;
586 virtual void print_dual_d2phi(std::ostream & os) const =0;
587
588#endif
589
594 void print_xyz(std::ostream & os) const;
595
599 void print_info(std::ostream & os) const;
600
604 friend std::ostream & operator << (std::ostream & os, const FEAbstract & fe);
605
609 virtual void request_phi() const = 0;
610 virtual void request_dual_phi() const = 0;
611
615 virtual void request_dphi() const = 0;
616 virtual void request_dual_dphi() const = 0;
617
621 void set_calculate_dual(const bool val){calculate_dual = val; }
622
627
632
637
638protected:
639
652 virtual void compute_shape_functions(const Elem *, const std::vector<Point> & ) =0;
653
654 std::unique_ptr<FEMap> _fe_map;
655
656
660 const unsigned int dim;
661
667
671 mutable bool calculate_dual;
672
677
681 mutable bool calculate_nothing;
682
686 mutable bool calculate_map;
687
691 mutable bool calculate_phi;
692
696 mutable bool calculate_dphi;
697
698#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
702 mutable bool calculate_d2phi;
703#else
704 // Otherwise several interfaces need to be redone.
705 const bool calculate_d2phi=false;
706
707#endif
708
712 mutable bool calculate_curl_phi;
713
717 mutable bool calculate_div_phi;
718
722 mutable bool calculate_dphiref;
723
724
731
736
740 const Elem * _elem;
741
751 unsigned int _elem_p_level;
752
757 unsigned int _p_level;
758
763
769
774 unsigned int _n_total_qp;
775
782 virtual bool shapes_need_reinit() const = 0;
783
788};
789
790} // namespace libMesh
791
792#endif // LIBMESH_FE_ABSTRACT_H
void ErrorVector unsigned int
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This class forms the foundation from which generic finite elements may be derived.
bool calculate_map
Are we calculating mapping functions?
std::unique_ptr< FEMap > _fe_map
bool calculate_nothing
Are we potentially deliberately calculating nothing?
virtual void reinit(const Elem *elem, const unsigned int side, const Real tolerance=TOLERANCE, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)=0
Reinitializes all the physical element-dependent data based on the side of the element elem.
virtual_for_inffe const std::vector< Real > & get_dxidz() const
virtual bool shapes_need_reinit() const =0
virtual_for_inffe const std::vector< Real > & get_dzetadz() const
virtual_for_inffe const std::vector< RealGradient > & get_d2xyzdxideta() const
const Elem * get_elem() const
bool calculate_d2phi
Should we calculate shape function hessians?
Order get_order() const
virtual_for_inffe const std::vector< RealGradient > & get_dxyzdeta() const
virtual ~FEAbstract()
Destructor.
void add_p_level_in_reinit(bool value)
Indicate whether to add p-refinement levels in init/reinit methods.
const Elem * _elem
The element the current data structures were set up for.
FEFamily get_family() const
bool add_p_level_in_reinit() const
Whether to add p-refinement levels in init/reinit methods.
virtual void side_map(const Elem *elem, const Elem *side, const unsigned int s, const std::vector< Point > &reference_side_points, std::vector< Point > &reference_points)=0
Computes the reference space quadrature points on the side of an element based on the side quadrature...
virtual void request_dual_dphi() const =0
virtual_for_inffe const std::vector< Real > & get_detadx() const
unsigned int _p_level
The p refinement level the current data structures are set up for.
virtual void print_dual_d2phi(std::ostream &os) const =0
virtual_for_inffe const std::vector< RealGradient > & get_d2xyzdeta2() const
virtual_for_inffe const std::vector< RealGradient > & get_d2xyzdxi2() const
virtual bool is_hierarchic() const =0
void get_nothing() const
FEType fe_type
The finite element type for this object.
const unsigned int dim
The dimensionality of the object.
bool calculate_default_dual_coeff
Are we calculating the coefficient for the dual basis using the default qrule?
bool calculate_phi
Should we calculate shape functions?
virtual_for_inffe const std::vector< Real > & get_detady() const
static void compute_node_constraints(NodeConstraints &constraints, const Elem *elem)
Computes the nodal constraint contributions (for non-conforming adapted meshes), using Lagrange geome...
virtual void attach_quadrature_rule(QBase *q)=0
Provides the class with the quadrature rule.
ElemType _elem_type
The element type the current data structures were set up for.
virtual void reinit_default_dual_shape_coeffs(const Elem *)
This re-computes the dual shape function coefficients using DEFAULT qrule.
void print_JxW(std::ostream &os) const
Prints the Jacobian times the weight for each quadrature point.
virtual void request_dual_phi() const =0
virtual void edge_reinit(const Elem *elem, const unsigned int edge, const Real tolerance=TOLERANCE, const std::vector< Point > *pts=nullptr, const std::vector< Real > *weights=nullptr)=0
Reinitializes all the physical element-dependent data based on the edge of the element elem.
virtual void print_d2phi(std::ostream &os) const =0
Prints the value of each shape function's second derivatives at each quadrature point.
virtual_for_inffe const std::vector< Real > & get_dzetady() const
virtual FEContinuity get_continuity() const =0
virtual_for_inffe const std::vector< RealGradient > & get_d2xyzdetadzeta() const
virtual void compute_shape_functions(const Elem *, const std::vector< Point > &)=0
After having updated the jacobian and the transformation from local to global coordinates in FEMap::c...
virtual_for_inffe const std::vector< Point > & get_normals() const
bool calculate_dphi
Should we calculate shape function gradients?
bool calculate_curl_phi
Should we calculate shape function curls?
virtual_for_inffe const std::vector< std::vector< Point > > & get_tangents() const
bool shapes_on_quadrature
A flag indicating if current data structures correspond to quadrature rule points.
virtual_for_inffe const std::vector< Real > & get_dxidy() const
virtual_for_inffe const std::vector< RealGradient > & get_dxyzdzeta() const
virtual void print_dphi(std::ostream &os) const =0
Prints the value of each shape function's derivative at each quadrature point.
unsigned int get_dim() const
static void compute_periodic_node_constraints(NodeConstraints &constraints, const PeriodicBoundaries &boundaries, const MeshBase &mesh, const PointLocatorBase *point_locator, const Elem *elem)
Computes the node position constraint equation contributions (for meshes with periodic boundary condi...
void set_calculate_dual(const bool val)
set calculate_dual as needed
bool calculations_started
Have calculations with this object already been started? Then all get_* functions should already have...
bool _add_p_level_in_reinit
Whether to add p-refinement levels in init/reinit methods.
unsigned int _elem_p_level
The element p-refinement level the current data structures are set up for.
virtual unsigned int n_quadrature_points() const
void set_calculate_default_dual_coeff(const bool val)
set calculate_default_dual_coeff as needed
virtual_for_inffe const std::vector< Real > & get_JxW() const
virtual_for_inffe const std::vector< RealGradient > & get_dxyzdxi() const
virtual void reinit_dual_shape_coeffs(const Elem *, const std::vector< Point > &, const std::vector< Real > &)
This re-computes the dual shape function coefficients using CUSTOMIZED qrule.
virtual_for_inffe const std::vector< RealGradient > & get_d2xyzdxidzeta() const
void set_fe_order(int new_order)
Sets the base FE order of the finite element.
virtual_for_inffe const std::vector< Real > & get_curvatures() const
QBase * qrule
A pointer to the quadrature rule employed.
virtual_for_inffe const std::vector< Point > & get_xyz() const
virtual void reinit(const Elem *elem, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)=0
This is at the core of this class.
unsigned int get_p_level() const
ElemType get_type() const
virtual void print_dual_phi(std::ostream &os) const =0
static bool on_reference_element(const Point &p, const ElemType t, const Real eps=TOLERANCE)
virtual void request_phi() const =0
request phi calculations
static std::unique_ptr< FEAbstract > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
Definition fe_abstract.C:78
virtual unsigned int n_shape_functions() const =0
FEType get_fe_type() const
virtual void print_phi(std::ostream &os) const =0
Prints the value of each shape function at each quadrature point.
bool calculate_dual
Are we calculating dual basis?
virtual_for_inffe const std::vector< Real > & get_dxidx() const
bool calculate_dphiref
Should we calculate reference shape function gradients?
virtual_for_inffe const std::vector< Real > & get_detadz() const
virtual_for_inffe const std::vector< RealGradient > & get_d2xyzdzeta2() const
friend std::ostream & operator<<(std::ostream &os, const FEAbstract &fe)
Same as above, but allows you to print to a stream.
unsigned int _n_total_qp
The total number of quadrature points for the current configuration.
virtual_for_inffe const std::vector< Real > & get_dzetadx() const
virtual void request_dphi() const =0
request dphi calculations
void print_xyz(std::ostream &os) const
Prints the spatial location of each quadrature point (on the physical element).
virtual void print_dual_dphi(std::ostream &os) const =0
bool calculate_div_phi
Should we calculate shape function divergences?
void print_info(std::ostream &os) const
Prints all the relevant information about the current element.
const FEMap & get_fe_map() const
virtual const std::vector< Real > & get_JxWxdecay_sq() const
This function is the variant of get_JxW() for InfFE.
static void get_refspace_nodes(const ElemType t, std::vector< Point > &nodes)
Class contained in FE that encapsulates mapping (i.e.
Definition fe_map.h:48
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
Definition fe_type.h:203
FEFamily family
The type of finite element.
Definition fe_type.h:228
This is the MeshBase class.
Definition mesh_base.h:81
The Node constraint storage format.
Definition dof_map.h:160
We're using a class instead of a typedef to allow forward declarations and future flexibility.
This is the base class for point locators.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The QBase class provides the basic functionality from which various quadrature rules can be derived.
Definition quadrature.h:62
This class implements reference counting.
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const bool value
Definition xdr_io.C:55