projection.py

An implementation of the projection. The projection can be divided into two processes, reduction and reconstruction.

The reduction process will use the given scalar or vector to obtain the coefficients of its projection in the discrete space.

The reconstruction process first assembles the coefficients with the correct basis functions and evaluates the discrete variable at given points.

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

class projection.Reconstruction(bf, ct)[source]

A wrapper of reconstruction functions in \Omega.

Parameters:
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
>>> 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 = Reduction(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)
>>> rc = Reconstruction(bf, ct)
>>> xi = np.linspace(-1, 1, 50)
>>> et = np.linspace(-1, 1, 50)
>>> sg = np.linspace(-1, 1, 50)
>>> xyz_p, p = rc.NP(loc_dofs_N, xi, et, sg)
>>> xyz_w, w = rc.EP(loc_dofs_E, xi, et, sg)
>>> xyz_u, u = rc.FP(loc_dofs_F, xi, et, sg)
>>> xyz_f, f = rc.VP(loc_dofs_V, xi, et, sg)
>>> p - pressure(*xyz_p) # the error 
array([[[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00,  0.00000000e+00],...
>>> w[0] - velocity_x(*xyz_w) # the error 
array([[[ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, ...,
          0.00000000e+00,  0.00000000e+00,  0.00000000e+00],
        [ 0.00000000e+00,  2.29166833e-02,  2.98219834e-02, ...,
          3.36914832e-03, -5.18668625e-03,  6.18969815e-18],...
>>> u[0] - velocity_x(*xyz_u) # the error 
array([[[ 1.34796048e-05,  4.22664447e-04,  8.32751318e-04, ...,
          8.32751318e-04,  4.22664447e-04,  1.34796048e-05],
        [ 4.22664447e-04,  3.56786323e-04,  3.72185374e-04, ...,
          3.72185374e-04,  3.56786323e-04,  4.22664447e-04],...
>>> f - source(*xyz_f) # the error 
array([[[-0.77424798, -1.49814167, -2.09148356, ..., -1.60496992,
         -3.0320961 , -4.59503016],
        [-1.49814167, -1.29548405, -1.11149995, ..., -0.90717392,
         -1.6210195 , -2.40674137],...
EP(loc_dofs, xi, et, sg, ravel=False)[source]

Reconstruct a vector of edge polynomials evaluated at \Phi\circ \text{meshgrid}(\xi, \eta, \varsigma)`.

Parameters:
  • loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete vector in \text{EP}_{N-1}(\Omega).

  • xi (1d np.array) – \xi.

  • et (1d np.array) – \eta.

  • sg (1d np.array) – \varsigma. The reconstructed vector will be evaluated at \Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma)`.

  • ravel – (default: False) If ravel is True, we will flat the outputs (as a 1d array) according to local numbering. Otherwise, you get 3d outputs corresponding to the indexing.

Returns:

A tuple of two outputs:

  • (x,y,z): The reconstructed scalar is evaluated at

    (x,y,z):=\Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma).

  • (u,v,w): Three components of the reconstructed

    vector evaluated at (x,y,z).

FP(loc_dofs, xi, et, sg, ravel=False)[source]

Reconstruct a vector of face polynomials evaluated at \Phi\circ \text{meshgrid}(\xi, \eta, \varsigma)`.

Parameters:
  • loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete vector in \text{FP}_{N-1}(\Omega).

  • xi (1d np.array) – \xi.

  • et (1d np.array) – \eta.

  • sg (1d np.array) – \varsigma. The reconstructed vector will be evaluated at \Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma)`.

  • ravel – (default: False) If ravel is True, we will flat the outputs (as a 1d array) according to local numbering. Otherwise, you get 3d outputs corresponding to the indexing.

Returns:

A tuple of two outputs:

  • (x,y,z): The reconstructed scalar is evaluated at

    (x,y,z):=\Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma).

  • (u,v,w): Three components of the reconstructed

    vector evaluated at (x,y,z).

NP(loc_dofs, xi, et, sg, ravel=False)[source]

Reconstruct a node polynomial evaluated at \Phi\circ \text{meshgrid}(\xi, \eta, \varsigma)`.

Parameters:
  • loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete scalar in \text{NP}_{N}(\Omega).

  • xi (1d np.array) – \xi.

  • et (1d np.array) – \eta.

  • sg (1d np.array) – \varsigma. The reconstructed scalar will be evaluated at \Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma)`.

  • ravel – (default: False) If ravel is True, we will flat the outputs (as a 1d array) according to local numbering. Otherwise, you get 3d outputs corresponding to the indexing.

Returns:

A tuple of two outputs:

  • (x,y,z): The reconstructed scalar is evaluated at

    (x,y,z):=\Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma).

  • values: The values of the reconstructed scalar evaluated

    at (x,y,z).

VP(loc_dofs, xi, et, sg, ravel=False)[source]

Reconstruct a volume polynomial evaluated at \Phi\circ \text{meshgrid}(\xi, \eta, \varsigma)`.

Parameters:
  • loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete scala in \text{VP}_{N-1}(\Omega).

  • xi (1d np.array) – \xi.

  • et (1d np.array) – \eta.

  • sg (1d np.array) – \varsigma. The reconstructed scalar will be evaluated at \Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma)`.

  • ravel – (default: False) If ravel is True, we will flat the outputs (as a 1d array) according to local numbering. Otherwise, you get 3d outputs corresponding to the indexing.

Returns:

A tuple of two outputs:

  • (x,y,z): The reconstructed scalar is evaluated at

    (x,y,z):=\Phi\circ \text{meshgrid}(
\xi, \eta, \varsigma).

  • values: The values of the reconstructed scalar evaluated

    at (x,y,z).

class projection.Reduction(bf, ct, quad_degree=None)[source]

A wrapper of reduction functions.

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:

>>> from numpy import sin, cos, pi
>>> from coordinate_transformation import CoordinateTransformation
>>> from coordinate_transformation import Phi, d_Phi
>>> from mimetic_basis_polynomials import MimeticBasisPolynomials
>>> ct = CoordinateTransformation(Phi, d_Phi)
>>> bf = MimeticBasisPolynomials('Lobatto-3', 'Lobatto-3', 'Lobatto-3')
>>> rd = Reduction(bf, ct)
>>> 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)
>>> rd.NP(pressure) 
array([0.00000000e+00, 0.00000000e+00, 0.00000000e+00,...
>>> rd.EP((velocity_x, velocity_y, velocity_z)) 
array([ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,...
>>> rd.FP((velocity_x, velocity_y, velocity_z)) 
array([ 0.03986372, -0.00413826,  0.03344094, -0.03986372,...
>>> rd.VP(pressure) 
array([0.00445833, 0.00454444, 0.00079032, 0.00454444, 0.01872708,
       0.00615386, 0.00079032, 0.00615386, 0.00079032, ...
EP(vector)[source]

Reduce a vector to \text{EP}_{N-1}(\Omega).

Parameters:

vector (list, tuple) – A list or tuple of three functions which represents the vector in H(\mathrm{curl};\Omega) to be reduced to \text{FP}_{N-1}(\Omega).

Returns:

A 1d np.array representing the local coefficients/dofs of the discrete vector.

FP(vector)[source]

Reduce a vector to \text{FP}_{N-1}(\Omega).

Parameters:

vector (list, tuple) – A list or tuple of three functions which represents the vector in H(\mathrm{div};\Omega) to be reduced to \text{FP}_{N-1}(\Omega).

Returns:

A 1d np.array representing the local coefficients/dofs of the discrete vector.

NP(scalar)[source]

Reduce a scalar to \text{NP}_{N}(\Omega).

Parameters:

scalar (function) – A function in H^1(\Omega) to be reduced to \text{NP}_{N}(\Omega).

Returns:

A 1d np.array representing the local coefficients/dofs of the discrete scalar.

VP(scalar)[source]

Reduce a scalar to \text{VP}_{N-1}(\Omega).

Parameters:

scalar (function) – A function in L^2(\Omega) to be reduced to \text{VP}_{N-1}(\Omega).

Returns:

A 1d np.array representing the local coefficients/dofs of the discrete scalar.

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