two_dimensional

main

class reyna.DGFEM.two_dimensional.main.DGFEM(geometry: DGFEMGeometry, polynomial_degree: int = 1)

Bases: object

This class contains all the methods required for the DGFEM solver.

geometry

The geometry associated with the computation domain for the problem.

Type:

DGFEMGeometry

h

The maximal cell diameter of the mesh.

Type:

float

polydegree

The highest total degree polynomial space required.

Type:

int

advection

The advection coeffient.

Type:

Optional[Callable[[np.ndarray], np.ndarray]]

diffusion

The diffusion coeffient.

Type:

Optional[Callable[[np.ndarray], np.ndarray]]

reaction

The reaction coeffient.

Type:

Optional[Callable[[np.ndarray], np.ndarray]]

forcing

The forcing term.

Type:

Optional[Callable[[np.ndarray], np.ndarray]]

dirichlet_bcs

The dirichlet boundary conditions.

Type:

Optional[Callable[[np.ndarray], np.ndarray]]

boundary_information

The information associated with the boundary of the computational domain and PDE coefficients.

Type:

Optional[BoundaryInformation]

sigma_D

The global penalisation coefficient.

Type:

float

orders

The orders of the tensor-Legendre polynomials.

Type:

Optional[np.ndarray]

dim_elem

The local finite element space dimension.

Type:

Optional[int]

dim_system

The global system dimension.

Type:

Optional[int]

solution

The solution vector for the coefficients of the Legendre polynomials.

Type:

Optional[np.ndarray]

B

The global stiffness matrix (populated when .dgfem() method is called).

Type:

Optional[csr_matrix]

L

The global forcng vector (populated when .dgfem() method is called).

Type:

Optional[np.ndarray]

element_reference_quadrature

The 2d reference quadrature rule.

Type:

Optional[Tuple[np.ndarray, np.ndarray]]

edge_reference_quadrature

The 1d reference quadrature rule.

Type:

Optional[Tuple[np.ndarray, np.ndarray]]

add_data(...)

Add the function coefficients for the non-negative characteristic second order PDE.

dgfem(...)

Run the solver with the information and geometry inputted.

errors(...)

Given the numerically solved PDE, find the errors associated with the numerical solution.

plot_DG(...)

Plot the DGFEM solution.

See also

  • See the reference and example notebooks for examples on how this class is used fully.

add_data(advection: Callable[[ndarray], ndarray] | None = None, diffusion: Callable[[ndarray], ndarray] | None = None, reaction: Callable[[ndarray], ndarray] | None = None, forcing: Callable[[ndarray], ndarray] | None = None, dirichlet_bcs: Callable[[ndarray], ndarray] | None = None)

In this method, we add the data to the problem at hand. We define the relevant advection, diffusion, reaction and source terms as well as the corresponding boundary conditions. Defaults to ‘None’, which simplifies the later numerical method.

This method also generates additional information about the boundary conditions relating to what boundary conditions need to be applied and where.

Parameters:
  • advection – The advection component of the PDE. Must be able to handle inputs with dimension (N,2) and output arrays with dimension (N,2). I.e. the N advection coefficients at the given N 2D input locations.

  • diffusion – The diffusion component of the PDE. Must be able to handle inputs with dimension (N,2) and output arrays with dimension (N,2,2). I.e the N diffusion tensors at the given N 2D input locations. We note that the diffusion tensor must have non-negative characteristic form.

  • reaction – The reaction component of the PDE. Must be able to handle inputs with dimension (N,2) and output arrays with dimension (N,). I.e. the N reaction coefficients at the given N 2D input locations.

  • forcing – The forcing component of the PDE. Must be able to handle inputs with dimension (N,2) and output arrays with dimension (N,). I.e. the N forcing values at the given N 2D input locations.

  • dirichlet_bcs – The Dirichlet boundary conditions associated with the PDE. Must be able to handle inputs with dimension (N,2) and output arrays with dimension (N,). I.e. the N boundary values at the given N 2D input locations. This can be mixed with relavent Neumann boundary conditions or stand-alone.

Raises:
  • ValueError – If Dirichlet boundary conditions are not present.

  • ValueError – If no advection or diffusion terms are present.

Notes

  • It’s important to note the shapes of the functions that are inputted. All need to be able ot take in a (N,2) array and return an array of varying shapes depending on the dimension of the output of the coefficient.

  • These functions must also be ‘numba’ compatible. This means certain ‘numpy’ functions are not allowed.

See also

Please see here numba for more documentation on numba compatible functions.

dgfem(solve: bool = True, verbose: int = 0)

This is the main method to the class and generates all the stiffness matrices and data vector values. It also generates the solution vector to the problem.

Parameters:
  • solve (bool) – This method generates the linear system associated with the DGFEM solution to the inputted problem. Selecting solve will also solve this linear system.

  • verbose (int) – This is the verbose level of the method. 0 is no verbose, 1 gives the assembly time.

Returns:

None

Raises:

ValueError – If the parameter ‘verbose’ is not contained in the right interval.

errors(exact_solution: Callable[[ndarray], ndarray], grad_exact_solution: Callable[[ndarray], ndarray] | None = None, div_advection: Callable[[ndarray], ndarray] | None = None) Tuple[float, float, float | None]

This function calculates three (semi-) norms associated with the discontinuous Galerkin scheme employed here. First the L2 norm as well as the DG norm (the sum of the convective and diffusive norms) and the H1 semi-norm.

Parameters:
  • exact_solution – The exact solution. Must take in an array of size (N,2) and return an array which outputs values in a (N,) array.

  • grad_exact_solution – The gradient of the exact solution. Must take in an array of size (N,2) and return an array which outputs values in a (N,2) array.

  • div_advection – The divergence of the advection coeffiecient. This is required for the DG norm. This has to take in an array of size (N,2) and return an array which outputs values in a (N,) array.

Returns:

The L2 norm, the DG norm, the H1 semi-norm and the dg subnorm dict respectively.

Return type:

(float, float, Optional[float], Optional[dict])

Raises:
  • ValueError – If the ‘solution’ property is not filled before running.

  • ValueError – If ‘self.diffusion’ and the parameter ‘grad_exact_solution’ are not both fulled or empty.

plot_DG()

This function plots the DGFEM solution using Matplotlib. For more customisability, use the ‘plot_DG’ function in ‘./plotter’. This is a quick reference plotter.

Returns:

None

Raises:

ValueError – If there is not a populated ‘solution’ property, this function returns an error.

Notes

  • This function is only able to plot the solutions which are piecewise linear (i.e. polynomial degree 1)

tools

reyna.DGFEM.two_dimensional.tools.evaluate(x: ndarray, dg_coefficients: ndarray, bounding_box: ndarray, polynomial_degree: int | None = None, orders: ndarray | None = None) ndarray

A simple element-wise evaluation function. Given a set of points, one may evalulate the DG solution at these points. Additionally, the bounding box of the element in question is required to specify the basis functions. This function also requires either the polynomial degree of the FEM space or the FEM orders. Either of these may be left blank but at the cost of additional computational overhead. Placing the orders in directly is the most efficient.

Notes

The input points x must lie within the element in question (or on the boundary). If not this does not reflect the correct FEM solution.

Parameters:
  • x (np.ndarray) – the points to evaluate.

  • dg_coefficients (np.ndarray) – The DG coefficients.

  • bounding_box (np.ndarray) – The bounding box of the element in question.

  • polynomial_degree (Optional[int]) – The polynomial of the corresponding FEM space.

  • orders (Optional[np.ndarray]) – The FEM indecies of the tensored polynomials.

Returns:

The finite element solution at the given basis elements.

Return type:

(np.ndarray)

reyna.DGFEM.two_dimensional.tools.plot_DG(numerical_solution: ndarray, geometry: DGFEMGeometry, poly_degree: int) None

This function plots the DGFEM solution using matplotlib.

Parameters:
  • numerical_solution (np.ndarray) – The numerical solution of the DGFEM problem. This must be in the form that is outputted from the .dgfem method of the DGFEM class.

  • geometry (DGFEMGeometry) – The geometry of the DGFEM problem.

  • poly_degree (int) – The highest total degree polynomial space required.

Returns:

None

Notes

  • This function will be recieving large updates in a near update to allow significantly more customisation in the plots themselves as well as saving the plots.