v0.14.0
Functions
Base functions

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

Collaboration diagram for Base functions:

Functions

PetscErrorCode Legendre_polynomials (int p, double s, double *diff_s, double *L, double *diffL, const int dim)
 Calculate Legendre approximation basis. More...
 
PetscErrorCode Lobatto_polynomials (int p, double s, double *diff_s, double *L, double *diffL, const int dim)
 Calculate Lobatto base functions [29]. More...
 
PetscErrorCode LobattoKernel_polynomials (int p, double s, double *diff_s, double *L, double *diffL, const int dim)
 Calculate Kernel Lobatto base functions. More...
 

Detailed Description

Calculation of base functions at integration points.

Function Documentation

◆ Legendre_polynomials()

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

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
Examples
edge_and_bubble_shape_functions_on_quad.cpp.

Definition at line 15 of file base_functions.c.

16  {
18 #ifndef NDEBUG
19  if (dim < 1)
20  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
21  if (dim > 3)
22  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
23  if (p < 0)
24  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 0");
25 #endif // NDEBUG
26 
27  L[0] = 1;
28  if (diffL != NULL) {
29  for (int d = 0; d != dim; ++d) {
30  diffL[d * (p + 1) + 0] = 0;
31  }
32  }
33  if (p == 0)
35 
36  L[1] = s;
37  if (diffL != NULL) {
38 #ifndef NDEBUG
39  if (diff_s == NULL) {
40  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
41  }
42 #endif // NDEBUG
43  for (int d = 0; d != dim; ++d) {
44  diffL[d * (p + 1) + 1] = diff_s[d];
45  }
46  }
47  if (p == 1)
49 
50  int l = 1;
51  for (; l < p; l++) {
52  double A = ((2 * (double)l + 1) / ((double)l + 1));
53  double B = ((double)l / ((double)l + 1));
54  L[l + 1] = A * s * L[l] - B * L[l - 1];
55  if (diffL != NULL) {
56  for (int d = 0; d != dim; ++d) {
57  diffL[d * (p + 1) + l + 1] =
58  A * (diff_s[d] * L[l] + s * diffL[d * (p + 1) + l]) -
59  B * diffL[d * (p + 1) + l - 1];
60  }
61  }
62  }
63 
65 }

◆ Lobatto_polynomials()

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

Calculate Lobatto base functions [29].

Order of first function is 2 and goes to p.

Parameters
pis approximation order
sis a mapping of coordinates of edge to \([-1, 1]\), i.e., \(s(\xi_1,\cdot,\xi_{dim})\in[-1,1]\)
diff_sjacobian of the transformation, i.e. \(\frac{\partial s}{\partial \xi_i}\)
  • output
Return values
Lvalues basis functions at s
diffLderivatives of basis functions at s, i.e. \(\frac{\partial L}{\partial \xi_i}\)
Parameters
dimdimension
Returns
error code

Definition at line 199 of file base_functions.c.

200  {
201 
203 #ifndef NDEBUG
204  if (dim < 1)
205  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
206  if (dim > 3)
207  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
208  if (p < 2)
209  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 2");
210 #endif // NDEBUG
211  double l[p + 1];
212  ierr = Legendre_polynomials(p, s, NULL, l, NULL, 1);
213  CHKERRQ(ierr);
214 
215  L[0] = 1;
216  if (diffL != NULL) {
217  for (int d = 0; d != dim; ++d) {
218  diffL[d * (p + 1) + 0] = 0;
219  }
220  }
221  L[1] = s;
222  if (diffL != NULL) {
223 #ifndef NDEBUG
224  if (diff_s == NULL) {
225  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
226  }
227 #endif // NDEBUG
228  for (int d = 0; d != dim; ++d) {
229  diffL[d * (p + 1) + 1] = diff_s[d];
230  }
231  }
232 
233  // Integrated Legendre
234  for (int k = 2; k <= p; k++) {
235  const double factor = 2 * (2 * k - 1);
236  L[k] = 1.0 / factor * (l[k] - l[k - 2]);
237  }
238 
239  if (diffL != NULL) {
240  for (int k = 2; k <= p; k++) {
241  double a = l[k - 1] / 2.;
242  for (int d = 0; d != dim; ++d) {
243  diffL[d * (p + 1) + k] = a * diff_s[d];
244  }
245  }
246  }
248 }

◆ LobattoKernel_polynomials()

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

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 345 of file base_functions.c.

347  {
349 #ifndef NDEBUG
350  if (dim < 1)
351  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
352  if (dim > 3)
353  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
354  if (p < 0)
355  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 0");
356  if (p > 9)
357  SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
358  "Polynomial beyond order 9 is not implemented");
359 #endif // NDEBUG
360  if (L) {
361  int l = 0;
362  for (; l != p + 1; l++) {
363  L[l] = f_phi[l](s);
364  }
365  }
366  if (diffL != NULL) {
367 #ifndef NDEBUG
368  if (diff_s == NULL) {
369  SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
370  }
371 #endif // NDEBUG
372  int l = 0;
373  for (; l != p + 1; l++) {
374  double a = f_phix[l](s);
375  diffL[0 * (p + 1) + l] = diff_s[0] * a;
376  if (dim >= 2) {
377  diffL[1 * (p + 1) + l] = diff_s[1] * a;
378  if (dim == 3) {
379  diffL[2 * (p + 1) + l] = diff_s[2] * a;
380  }
381  }
382  }
383  }
385 }
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
sdf_hertz.d
float d
Definition: sdf_hertz.py:5
ierr
static PetscErrorCode ierr
Definition: base_functions.c:13
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
f_phi
static double(* f_phi[])(double x)
Definition: base_functions.c:261
a
constexpr double a
Definition: approx_sphere.cpp:30
double
MoFEM::L
VectorDouble L
Definition: Projection10NodeCoordsOnField.cpp:124
Legendre_polynomials
PetscErrorCode Legendre_polynomials(int p, double s, double *diff_s, double *L, double *diffL, const int dim)
Calculate Legendre approximation basis.
Definition: base_functions.c:15
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
f_phix
static double(* f_phix[])(double x)
Definition: base_functions.c:275
MOFEM_NOT_IMPLEMENTED
@ MOFEM_NOT_IMPLEMENTED
Definition: definitions.h:32
l
FTensor::Index< 'l', 3 > l
Definition: matrix_function.cpp:21
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36