# 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 .

Parameters:
• bf (MimeticBasisPolynomials) – The basis functions in .

• ct (CoordinateTransformation) –

The coordinate transformation representing the mapping , 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 - 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 - 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 .

Parameters:
• loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete vector in .

• xi (1d np.array) – .

• et (1d np.array) – .

• sg (1d np.array) – . The reconstructed vector will be evaluated at .

• 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:

• : The reconstructed scalar is evaluated at .

• : Three components of the reconstructed

vector evaluated at .

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

Reconstruct a vector of face polynomials evaluated at .

Parameters:
• loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete vector in .

• xi (1d np.array) – .

• et (1d np.array) – .

• sg (1d np.array) – . The reconstructed vector will be evaluated at .

• 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:

• : The reconstructed scalar is evaluated at .

• : Three components of the reconstructed

vector evaluated at .

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

Reconstruct a node polynomial evaluated at .

Parameters:
• loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete scalar in .

• xi (1d np.array) – .

• et (1d np.array) – .

• sg (1d np.array) – . The reconstructed scalar will be evaluated at .

• 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:

• : The reconstructed scalar is evaluated at .

• values: The values of the reconstructed scalar evaluated

at .

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

Reconstruct a volume polynomial evaluated at .

Parameters:
• loc_dofs (np.array) – A 1d np.array containing the coefficients of the discrete scala in .

• xi (1d np.array) – .

• et (1d np.array) – .

• sg (1d np.array) – . The reconstructed scalar will be evaluated at .

• 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:

• : The reconstructed scalar is evaluated at .

• values: The values of the reconstructed scalar evaluated

at .

A wrapper of reduction functions.

Parameters:
• bf (MimeticBasisPolynomials) – The basis functions in .

• ct (CoordinateTransformation) –

The coordinate transformation representing the mapping , • 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 .

Parameters:

vector (list, tuple) – A list or tuple of three functions which represents the vector in to be reduced to .

Returns:

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

FP(vector)[source]

Reduce a vector to .

Parameters:

vector (list, tuple) – A list or tuple of three functions which represents the vector in to be reduced to .

Returns:

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

NP(scalar)[source]

Reduce a scalar to .

Parameters:

scalar (function) – A function in to be reduced to .

Returns:

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

VP(scalar)[source]

Reduce a scalar to .

Parameters:

scalar (function) – A function in to be reduced to .

Returns:

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

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