Helper Scripts
Minor helper functions for FEM problems.
Bram Lagerweij COHMAS Mechanical Engineering KAUST 2021
- helper.E1(fun, fun_h, x)
Calculate the \(E_1\) error.
\[E_1 := \int_\Omega | f(x) - f_h(x) | dx\]- Parameters
fun (array_like) – The solution of the exact equation at location \(x\).
fun_h (array_like) – The solution of the approximation equation at location \(x\).
x (array_like) – The locations where the function is analyzed.
- Returns
Error of the approximation.
- Return type
float
- helper.E2(fun, fun_h, x)
Calculate the \(E_2\) error.
\[E_2 := \sqrt{\int_\Omega \big(f(x) - f_h(x)\big)^2 dx}\]- Parameters
fun (array_like) – The solution of the exact equation at location \(x\).
fun_h (array_like) – The solution of the approximation equation at location \(x\).
x (array_like) – The locations where the function is analyzed.
- Returns
Error of the approximation.
- Return type
float
- helper.gauss(num)
Gaussian integration points and weights for num sample points.
Computes the sample points and weights for Gauss-Legendre quadrature. These sample points and weights will correctly integrate polynomials of degree \(2\cdot num - 1\) or less over the interval \([0, 1]\) with the weight function \(f(x) = 1\).
- Parameters
num (int) – Number of sample points and weights. It must be 1 <= num <= 5.
- Returns
xi (array_like(float)) – 1D array containing the sample points.
w (array_like(float)) – 1D array containing the weights at the sample points.
- helper.quadtri(num)
Symetric quadrature points and weights for num sample points in a triangle.
Computes the sample points and weights through the Dunavant unnit trianglue rule 1. These sample points and weights will correctly integrate polynomials of:
num
1
3
4
7
\(p\)
1
2
3
4
- Parameters
num (int) – Number of sample points and weights. It must be 1, 3, 4, or 7.
- Returns
xi (array_like(float)) – 1D array containing the sample points in local coordinates.
w (array_like(float)) – 1D array containing the weights at the sample points.
References
- 1
Dunavant, D.A. (1985), High degree efficient symmetrical Gaussian quadrature rules for the triangle. Int. J. Numer. Meth. Engng., 21: 1129-1148. DOI:10.1002/nme.1620210612