v0.15.0
Loading...
Searching...
No Matches
Classes | Functions
Base functions

Calculation of base functions at integration points. More...

Collaboration diagram for Base functions:

Classes

struct  MoFEM::BaseFunctionCtx
 Base class used to exchange data between element data structures and class calculating base functions. More...
 
struct  MoFEM::BaseFunction
 Base class if inherited used to calculate base functions. More...
 
struct  MoFEM::BaseFunction::DofsSideMapData
 
struct  MoFEM::EdgePolynomialBase
 Calculate base functions on tetrahedral. More...
 
struct  MoFEM::EntPolynomialBaseCtx
 Class used to pass element data to calculate base functions on tet,triangle,edge. More...
 
struct  MoFEM::FatPrismPolynomialBaseCtx
 Class used to pass element data to calculate base functions on fat prism. More...
 
struct  MoFEM::FatPrismPolynomialBase
 Calculate base functions on tetrahedralFIXME: Need moab and mofem finite element structure to work (that not perfect) More...
 
struct  MoFEM::FlatPrismPolynomialBaseCtx
 Class used to pass element data to calculate base functions on flat prism. More...
 
struct  MoFEM::FlatPrismPolynomialBase
 Calculate base functions on tetrahedralFIXME: Need moab and mofem finite element structure to work (that not perfect) More...
 
struct  MoFEM::HexPolynomialBase
 Calculate base functions on tetrahedral. More...
 
struct  MoFEM::JacobiPolynomialCtx
 Class used to give arguments to Legendre base functions. More...
 
struct  MoFEM::JacobiPolynomial
 Calculating Legendre base functions. More...
 
struct  MoFEM::LegendrePolynomialCtx
 Context class for Legendre basis function arguments. More...
 
struct  MoFEM::LegendrePolynomial
 Class for calculating Legendre basis functions. More...
 
struct  MoFEM::LobattoPolynomialCtx
 Context class for Lobatto basis function arguments. More...
 
struct  MoFEM::LobattoPolynomial
 Class for calculating Lobatto basis functions. More...
 
struct  MoFEM::KernelLobattoPolynomialCtx
 Context class for Kernel Lobatto basis function arguments. More...
 
struct  MoFEM::KernelLobattoPolynomial
 Class for calculating Kernel Lobatto basis functions. More...
 
struct  MoFEM::QuadPolynomialBase
 Calculate base functions on triangle. More...
 
struct  MoFEM::TetPolynomialBase
 Calculate base functions on tetrahedral. More...
 
struct  MoFEM::TriPolynomialBase
 Calculate base functions on triangle. More...
 

Functions

PetscErrorCode LobattoKernel_polynomials (int p, double s, double *diff_s, double *L, double *diffL, const int dim)
 Calculate Kernel Lobatto base functions.
 
template<typename Scalar , typename DsScalar >
MoFEMErrorCode MoFEM::Legendre_polynomials_T (int p, Scalar &s, DsScalar *diff_s, Scalar *L, Scalar *diffL, int dim)
 Calculate Legendre approximation basis.
 
PetscErrorCode MoFEM::Legendre_polynomials (int p, double s, double *diff_s, double *L, double *diffL, int dim)
 Calculate Legendre approximation basis.
 
PetscErrorCode MoFEM::Lobatto_polynomials (int p, double s, double *diff_s, double *L, double *diffL, const int dim)
 Calculate Lobatto basis functions [24].
 

Detailed Description

Calculation of base functions at integration points.

Function Documentation

◆ Legendre_polynomials()

PetscErrorCode MoFEM::Legendre_polynomials ( int  p,
double  s,
double diff_s,
double L,
double diffL,
int  dim 
)

#include <src/approximation/impl/LegendrePolynomial.cpp>

Calculate Legendre approximation basis.

This function computes Legendre polynomials and their derivatives for use in finite element approximations. Legendre polynomials form a complete orthogonal system on the interval [-1,1] and are widely used in high-order finite element methods due to their excellent numerical properties.

The Legendre polynomials are defined by the recurrence relation:

\[ P_0(s)=1;\quad P_1(s) = s \]

and the following terms are generated inductively using Bonnet's recursion formula:

\[ P_{n+1}(s)=\frac{2n+1}{n+1}sP_n(s)-\frac{n}{n+1}P_{n-1}(s) \]

The parameter \(s\) is the normalized coordinate:

\[ s\in[-1,1] \quad \textrm{and}\; s=s(\xi_0,\xi_1,\xi_2) \]

where \(\xi_i\) are barycentric coordinates of the element.

For more information on Legendre polynomials, see: https://en.wikipedia.org/wiki/Legendre_polynomials

Parameters
papproximation order (degree of highest polynomial)
sposition parameter \(s\in[-1,1]\) at which to evaluate polynomials
diff_sderivatives of coordinate transformation, i.e. \(\frac{\partial s}{\partial \xi_i}\)
L[out] array of Legendre polynomial values \(P_0(s), P_1(s), \ldots, P_p(s)\)
diffL[out] array of polynomial derivatives, i.e. \(\frac{\partial P_k}{\partial \xi_i}\)
dimspatial dimension for derivative calculations
Returns
PetscErrorCode indicating success or failure
Note
The output arrays L and diffL must be pre-allocated with sufficient size
For complex-valued evaluations, use the overloaded version with complex arguments

Definition at line 132 of file LegendrePolynomial.cpp.

133 {
134 return Legendre_polynomials_T(p, s, diff_s, L, diffL, dim);
135}
MoFEMErrorCode Legendre_polynomials_T(int p, Scalar &s, DsScalar *diff_s, Scalar *L, Scalar *diffL, int dim)
Calculate Legendre approximation basis.

◆ Legendre_polynomials_T()

template<typename Scalar , typename DsScalar >
MoFEMErrorCode MoFEM::Legendre_polynomials_T ( int  p,
Scalar &  s,
DsScalar *  diff_s,
Scalar *  L,
Scalar *  diffL,
int  dim 
)
inline

#include <src/approximation/impl/LegendrePolynomial.cpp>

Calculate Legendre approximation basis.

Lagrange polynomial is given by

\[ L_0(s)=1;\quad L_1(s) = s \]

and following terms are generated inductively

\[ L_{l+1}=\frac{2l+1}{l+1}sL_l(s)-\frac{l}{l+1}L_{l-1}(s) \]

Note that:

\[ s\in[-1,1] \quad \textrm{and}\; s=s(\xi_0,\xi_1,\xi_2) \]

where \(\xi_i\) are barycentric coordinates of element.

Parameters
pis approximation order
sis position \(s\in[-1,1]\)
diff_sderivatives of shape functions, i.e. \(\frac{\partial s}{\partial \xi_i}\)
Return values
Lapproximation functions
diffLderivatives, i.e. \(\frac{\partial L}{\partial \xi_i}\)
Parameters
dimdimension
Returns
error code

Definition at line 71 of file LegendrePolynomial.cpp.

78 {
80
81#ifndef NDEBUG
82 if (dim < 1)
83 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
84 if (dim > 3)
85 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
86 if (p < 0)
87 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 0");
88 if (diffL != nullptr && diff_s == nullptr)
89 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
90 "diff_s == NULL while diffL requested");
91#endif
92
93 // P0
94 L[0] = Scalar(1);
95 if (diffL) {
96 for (int d = 0; d < dim; ++d)
97 diffL[d * (p + 1) + 0] = Scalar(0);
98 }
99 if (p == 0)
101
102 // P1
103 L[1] = s;
104 if (diffL) {
105 for (int d = 0; d < dim; ++d)
106 diffL[d * (p + 1) + 1] = static_cast<Scalar>(diff_s[d]);
107 }
108 if (p == 1)
110
111 // Recurrence: P_{l+1} = A_l * s * P_l - B_l * P_{l-1}
112 for (int l = 1; l < p; ++l) {
113 const Scalar A = Scalar((2.0 * l + 1.0) / (l + 1.0));
114 const Scalar B = Scalar(double(l) / (l + 1.0));
115
116 L[l + 1] = A * s * L[l] - B * L[l - 1];
117
118 if (diffL) {
119 for (int d = 0; d < dim; ++d) {
120 const Scalar ds = static_cast<Scalar>(diff_s[d]);
121 // Chain rule: dP_{l+1} = A*( ds*P_l + s*dP_l ) - B*dP_{l-1}
122 diffL[d * (p + 1) + (l + 1)] =
123 A * (ds * L[l] + s * diffL[d * (p + 1) + l]) -
124 B * diffL[d * (p + 1) + (l - 1)];
125 }
126 }
127 }
128
130};
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
FTensor::Index< 'l', 3 > l
constexpr AssemblyType A

◆ Lobatto_polynomials()

PetscErrorCode MoFEM::Lobatto_polynomials ( int  p,
double  s,
double diff_s,
double L,
double diffL,
const int  dim 
)

#include <src/approximation/impl/LobattoPolynomial.cpp>

Calculate Lobatto basis functions [24].

Lobatto polynomials are hierarchical basis functions that include vertex modes and edge/internal modes. They are constructed from Legendre polynomials and provide excellent conditioning properties for high-order finite element methods.

The first function corresponds to order 2 and the sequence continues up to order p. These polynomials are particularly useful for spectral element methods due to their orthogonality properties on the reference interval [-1,1].

For more information on Lobatto polynomials, see: https://en.wikipedia.org/wiki/Gauss%E2%80%93Lobatto_quadrature

Parameters
papproximation order (maximum polynomial degree)
scoordinate mapping from edge to \([-1, 1]\), i.e., \(s(\xi_1,\cdot,\xi_{dim})\in[-1,1]\)
diff_s[in] Jacobian of the coordinate transformation, i.e. \(\frac{\partial s}{\partial \xi_i}\)
L[out] values of basis functions evaluated at coordinate s
diffL[out] derivatives of basis functions at s, i.e. \(\frac{\partial L}{\partial \xi_i}\)
dimspatial dimension
Returns
PetscErrorCode indicating success or failure
Note
Output arrays L and diffL must be pre-allocated with sufficient size

Definition at line 80 of file LobattoPolynomial.cpp.

81 {
82
84#ifndef NDEBUG
85 if (dim < 1)
86 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
87 if (dim > 3)
88 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
89 if (p < 2)
90 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 2");
91#endif // NDEBUG
92 double l[p + 1];
93 ierr = Legendre_polynomials(p, s, NULL, l, NULL, 1);
94 CHKERRQ(ierr);
95
96 L[0] = 1;
97 if (diffL != NULL) {
98 for (int d = 0; d != dim; ++d) {
99 diffL[d * (p + 1) + 0] = 0;
100 }
101 }
102 L[1] = s;
103 if (diffL != NULL) {
104#ifndef NDEBUG
105 if (diff_s == NULL) {
106 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
107 }
108#endif // NDEBUG
109 for (int d = 0; d != dim; ++d) {
110 diffL[d * (p + 1) + 1] = diff_s[d];
111 }
112 }
113
114 // Integrated Legendre
115 for (int k = 2; k <= p; k++) {
116 const double factor = 2 * (2 * k - 1);
117 L[k] = 1.0 / factor * (l[k] - l[k - 2]);
118 }
119
120 if (diffL != NULL) {
121 for (int k = 2; k <= p; k++) {
122 double a = l[k - 1] / 2.;
123 for (int d = 0; d != dim; ++d) {
124 diffL[d * (p + 1) + k] = a * diff_s[d];
125 }
126 }
127 }
129}
constexpr double a
static PetscErrorCode ierr
PetscErrorCode Legendre_polynomials(int p, double s, double *diff_s, double *L, double *diffL, int dim)
Calculate Legendre approximation basis.
FTensor::Index< 'k', 3 > k

◆ LobattoKernel_polynomials()

PetscErrorCode LobattoKernel_polynomials ( int  p,
double  s,
double diff_s,
double L,
double diffL,
const int  dim 
)

#include <src/approximation/c/base_functions.h>

Calculate Kernel Lobatto base functions.

This is implemented using definitions from Hermes2d https://github.com/hpfem/hermes following book by Pavel Solin et al [solin2003higher].

Parameters
pis approximation order
sis position \(s\in[-1,1]\)
diff_sderivatives of shape functions, i.e. \(\frac{\partial s}{\partial \xi_i}\)
Return values
Lapproximation functions
diffLderivatives, i.e. \(\frac{\partial L}{\partial \xi_i}\)
Parameters
dimdimension
Returns
error code

Definition at line 229 of file base_functions.c.

231 {
233#ifndef NDEBUG
234 if (dim < 1)
235 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
236 if (dim > 3)
237 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
238 if (p < 0)
239 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 0");
240 if (p > 9)
241 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
242 "Polynomial beyond order 9 is not implemented");
243 if (diffL != NULL) {
244 if (diff_s == NULL) {
245 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
246 }
247 }
248
249#endif // NDEBUG
250 if (L) {
251 int l = 0;
252 for (; l != p + 1; l++) {
253 L[l] = f_phi[l](s);
254 }
255 }
256 if (diffL != NULL) {
257 int l = 0;
258 for (; l != p + 1; l++) {
259 double a = f_phix[l](s);
260 int d = 0;
261 for (; d < dim; ++d) {
262 diffL[d * (p + 1) + l] = diff_s[d] * a;
263 }
264 }
265 }
267}
static double(* f_phi[])(double x)
static double(* f_phix[])(double x)
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32