L2_error_dual.py

Compute the L^2-error between an infinite dimensional variable and its finite dimensional (discrete) projection in the mimetic polynomial space.

⭕ To access the source code, click on the [source] button at the right side or click on [L2_error.py]. Dependence may exist. In case of error, check import and install required packages or download required scripts. © mathischeap.com

class L2_error_dual.L2ErrorDual(bf, ct, quad_degree=None)[source]

A wrapper of all functions for computing L^2-error. in the dual spaces \widetilde{\text{NP}}_{N}(\Omega), \widetilde{\text{EP}}_{N-1}(\Omega), \widetilde{\text{FP}}_{N-1}(\Omega) and \widetilde{\text{VP}}_{N-1}(\Omega).

Parameters:
  • bf (MimeticBasisPolynomials) – The basis functions in \Omega_{\mathrm{ref}}.

  • ct (CoordinateTransformation) –

    The coordinate transformation representing the mapping \Phi,

    \Phi: \Omega_{\mathrm{ref}}\to\Omega

  • quad_degree (list, tuple) – (default: None) The degree used for the numerical integral. It should be a list or tuple of three positive integers. If it is None, a suitable degree will be obtained from bf.

Example:

>>> import numpy as np
>>> from numpy import sin, cos, pi
>>> from coordinate_transformation import CoordinateTransformation
>>> from coordinate_transformation import Phi, d_Phi
>>> from mimetic_basis_polynomials import MimeticBasisPolynomials
>>> from projection_dual import ReductionDual
>>> ct = CoordinateTransformation(Phi, d_Phi)
>>> bf = MimeticBasisPolynomials('Lobatto-5','Lobatto-5','Lobatto-5')
>>> def pressure(x,y,z):
...     return sin(np.pi*x) * sin(pi*y) * sin(pi*z)
>>> def velocity_x(x,y,z):
...     return pi * cos(pi*x) * sin(pi*y) * sin(pi*z)
>>> def velocity_y(x,y,z):
...     return pi * sin(pi*x) * cos(pi*y) * sin(pi*z)
>>> def velocity_z(x,y,z):
...     return pi * sin(pi*x) * sin(pi*y) * cos(pi*z)
>>> def source(x,y,z):
...     return -3 * pi**2 * sin(np.pi*x) * sin(pi*y) * sin(pi*z)
>>> rd = ReductionDual(bf, ct)
>>> loc_dofs_N = rd.NP(pressure)
>>> loc_dofs_E = rd.EP((velocity_x, velocity_y, velocity_z))
>>> loc_dofs_F = rd.FP((velocity_x, velocity_y, velocity_z))
>>> loc_dofs_V = rd.VP(source)
>>> L2e = L2ErrorDual(bf, ct)
>>> L2e.NP(loc_dofs_N, pressure) 
0.0228947239...
>>> L2e.EP(loc_dofs_E, (velocity_x, velocity_y, velocity_z)) 
0.3612213119...
>>> L2e.FP(loc_dofs_F, (velocity_x, velocity_y, velocity_z)) 
0.4178056796...
>>> L2e.VP(loc_dofs_V, source) 
2.8203143473...
EP(loc_dofs, exact_solution)[source]

Let \boldsymbol{\omega}\in H^1(\Omega) and \boldsymbol{\omega}^h=\pi\left(
\boldsymbol{\omega}\right)\in
\widetilde{\text{EP}}_{N-1}(\Omega), we compute \left\|\boldsymbol{\omega}^h-\boldsymbol{\omega}
\right\|_{L^2\text{-error}}.

Parameters:
  • loc_dofs – The local dofs of \boldsymbol{\omega}^h.

  • exact_solution – A tuple of three functions representing the three components of the vector \boldsymbol{\omega}.

Returns:

A float representing the L^2-error.

FP(loc_dofs, exact_solution)[source]

Let \boldsymbol{\omega}\in H^1(\Omega) and \boldsymbol{u}^h=\pi\left(
\boldsymbol{u}\right)\in
\widetilde{\text{FP}}_{N-1}(u), we compute \left\|\boldsymbol{u}^h-\boldsymbol{u}
\right\|_{L^2\text{-error}}.

Parameters:
  • loc_dofs – The local dofs of \boldsymbol{u}^h.

  • exact_solution – A tuple of three functions representing the three components of the vector \boldsymbol{u}.

Returns:

A float representing the L^2-error.

NP(loc_dofs, exact_solution)[source]

Let \psi\in H^1(\Omega) and \psi^h=\pi\left(\psi\right)\in
\widetilde{\text{NP}}_{N}(\Omega), we compute \left\|\psi^h-\psi\right\|_{L^2\text{-error}}.

Parameters:
  • loc_dofs – The local dofs of \psi^h.

  • exact_solution – The scalar/function \psi.

Returns:

A float representing the L^2-error.

VP(loc_dofs, exact_solution, n=2)[source]

Let f\in L^2(\Omega) and f^h=\pi\left(f\right)\in
\widetilde{\text{VP}}_{N-1}(\Omega), we compute \left\|f^h-f\right\|_{L^n\text{-error}}.

Parameters:
  • loc_dofs – The local dofs of f^h.

  • exact_solution – The scalar/function f.

  • n – (default: 2) We compute L^{n}-error.

Returns:

A float representing the L^n-error.

↩️ Back to Ph.D. thesis complements (ptc).