lagrange

dg_maxwell.lagrange.L1_norm(u)[source]

A function to calculate the L1 norm of error using the polynomial obtained using Lagrange interpolation

Parameters:

u : arrayfire.Array [N_LGL N_Elements 1 1]

Difference between analytical and numerical u at the mapped LGL points.

Returns:

L1_norm : float64

The L1 norm of error.

dg_maxwell.lagrange.LGL_points(N)[source]

Calculates \(N\) Legendre-Gauss-Lobatto (LGL) points. LGL points are the roots of the polynomial

\[(1 - \xi^2) P_{n - 1}'(\xi) = 0\]

Where \(P_{n}(\xi)\) are the Legendre polynomials. This function finds the roots of the above polynomial.

Parameters:

N : int

Number of LGL nodes required

Returns:

lgl : arrayfire.Array [N 1 1 1]

The Lagrange-Gauss-Lobatto Nodes.

See: document

dg_maxwell.lagrange.gauss_nodes(n)[source]

Calculates \(N\) Gaussian nodes used for Integration by Gaussia quadrature. Gaussian node \(x_i\) is the \(i^{th}\) root of \(P_n(\xi)\) Where \(P_{n}(\xi)\) are the Legendre polynomials.

Parameters:

n : int

The number of Gaussian nodes required.

Returns:

gauss_nodes : numpy.ndarray

The Gauss nodes \(x_i\).

See: A Wikipedia article about the Gauss-Legendre quadrature here

dg_maxwell.lagrange.gaussian_weights(N)[source]

Returns the gaussian weights \(w_i\) for \(N\) Gaussian Nodes at index \(i\). They are given by

\[w_i = \frac{2}{(1 - x_i^2) P'n(x_i)}\]

Where \(x_i\) are the Gaussian nodes and \(P_{n}(\xi)\) are the Legendre polynomials.

Parameters:

N : int

Number of Gaussian nodes for which the weight is to be calculated.

Returns:

gaussian_weight : arrayfire.Array [N_quad 1 1 1]

The gaussian weights.

dg_maxwell.lagrange.integrate(integrand_coeffs)[source]

Performs integration according to the given quadrature method by taking in the coefficients of the polynomial and the number of quadrature points. The number of quadrature points and the quadrature scheme are set in params.py module.

Parameters:

integrand_coeffs : arrayfire.Array [M N 1 1]

The coefficients of M number of polynomials of order N arranged in a 2D array.

Returns

——-

Integral : arrayfire.Array [M 1 1 1]

The value of the definite integration performed using the specified quadrature method for M polynomials.

dg_maxwell.lagrange.lagrange_function_value(lagrange_coeff_array)[source]

Funtion to calculate the value of lagrange basis functions over LGL nodes.

Parameters:

lagrange_coeff_array : arrayfire.Array[N_LGL N_LGL 1 1]

Contains the coefficients of the Lagrange basis polynomials

Returns:

L_i : arrayfire.Array [N 1 1 1]

The value of lagrange basis functions calculated over the LGL nodes.

Examples

lagrange_function_value(4) gives the value of the four

Lagrange basis functions evaluated over 4 LGL points

arranged in a 2D array where Lagrange polynomials

evaluated at the same LGL point are in the same column.

Also the value lagrange basis functions at LGL points has the property,

L_i(xi_k) = 0 for i != k

= 1 for i = k

It follows then that lagrange_function_value returns an identity matrix.

dg_maxwell.lagrange.lagrange_interpolation(fn_i)[source]

Finds the general interpolation of a function.

Parameters:

fn_i : af.Array [N N_LGL 1 1]

Value of \(N\) functions at the LGL points.

Returns:

lagrange_interpolation : af.Array [N N_LGL 1 1]

\(N\) interpolated polynomials for \(N\) functions.

dg_maxwell.lagrange.lagrange_interpolation_u(u)[source]

Calculates the coefficients of the Lagrange interpolation using the value of u at the mapped LGL points in the domain.

The interpolation using the Lagrange basis polynomials is given by

\(L_i(\xi) u_i(\xi)\)

Where L_i are the Lagrange basis polynomials and u_i is the value of u at the LGL points.

Parameters:

u : arrayfire.Array [N_LGL N_Elements 1 1]

The value of u at the mapped LGL points.

Returns:

lagrange_interpolated_coeffs : arrayfire.Array[1 N_LGL N_Elements 1]

The coefficients of the polynomials obtained by Lagrange interpolation. Each polynomial is of order N_LGL - 1.

dg_maxwell.lagrange.lagrange_polynomials(x)[source]

A function to get the analytical form and the coefficients of Lagrange basis polynomials evaluated using x nodes.

It calculates the Lagrange basis polynomials using the formula:

\[\ L_i = \prod_{m = 0, m \notin i}^{N - 1}\frac{(x - x_m)}{(x_i - x_m)}\]
Parameters:

x : numpy.array [N_LGL 1 1 1]

Contains the \(x\) nodes using which the lagrange basis functions need to be evaluated.

Returns:

lagrange_basis_poly : list

A list of size x.shape[0] containing the analytical form of the Lagrange basis polynomials in numpy.poly1d form. This list is used in integrate() function which requires the analytical form of the integrand.

lagrange_basis_coeffs : numpy.ndarray

A \(N \times N\) matrix containing the coefficients of the Lagrange basis polynomials such that \(i^{th}\) lagrange polynomial will be the \(i^{th}\) row of the matrix.

Examples

lagrange_polynomials(4)[0] gives the lagrange polynomials obtained using

4 LGL points in poly1d form

lagrange_polynomials(4)[0][2] is \(L_2(\xi)\)

lagrange_polynomials(4)[1] gives the coefficients of the above mentioned

lagrange basis polynomials in a 2D array.

lagrange_polynomials(4)[1][2] gives the coefficients of \(L_2(\xi)\)

in the form [a^2_3, a^2_2, a^2_1, a^2_0]

dg_maxwell.lagrange.lobatto_weights(n)[source]

Calculates and returns the weight function for an index n and points x.

Parameters:

n : int

Lobatto weights for n quadrature points.

Returns:

Lobatto_weights : arrayfire.Array

An array of lobatto weight functions for the given x points and index.

See: Gauss-Lobatto weights Wikipedia link.

Examples

lobatto_weight_function(4) returns the Gauss-Lobatto weights

which are to be used with the Lobatto nodes ‘LGL_points(4)’

to integrate using Lobatto quadrature.