projection_trace.py

An implementation of the projection for the trace spaces on a 3D surface \Gamma. 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_trace.py]. Dependence may exist. In case of error, check import and install required packages or download required scripts. © mathischeap.com

class projection_trace.ReconstructionTrace(bf, ct)[source]

A wrapper of reconstruction functions.

Parameters:
Example:

>>> def p(x,y,z): return np.sin(np.pi*x) * np.sin(np.pi*y) * np.sin(np.pi*z)
>>> from mimetic_basis_polynomials_2d import MimeticBasisPolynomials2D
>>> from coordinate_transformation_surface import CoordinateTransformationSurface
>>> from coordinate_transformation_surface import Psi, d_Psi
>>> bf = MimeticBasisPolynomials2D('Lobatto-20', 'Lobatto-20')
>>> ct = CoordinateTransformationSurface(Psi, d_Psi)
>>> Rd = ReductionTrace(bf, ct)
>>> dofs = Rd.TF(p)
>>> Rc = ReconstructionTrace(bf, ct)
>>> rho = np.linspace(-1,1,5)
>>> tau = np.linspace(-1,1,5)
>>> xyz, v = Rc.TF(dofs, rho, tau)
>>> np.max(np.abs(p(*xyz) - v)) # the max error from the exact function 
0.0002989...
TE(loc_dofs, rho, tau, ravel=False)[source]

Reconstruct a discrete trace polynomial in \text{TE}_{N-1}(\Gamma) evaluated at \Psi\circ \text{grid2d}(\varrho, \tau)`.

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

  • rho (1d np.array) – \varrho.

  • tau (1d np.array) – \tau. The reconstruction will be evaluated at \Psi\circ \text{grid2d}(
\varrho, \tau)`.

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

Returns:

A tuple of two outputs:

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

    (x,y,z):=\Psi\circ \text{grid2d}(\varrho, \tau).

  • values: The values of the reconstructed variable at (x,y,z).

TF(loc_dofs, rho, tau, ravel=False)[source]

Reconstruct a discrete trace polynomial in \text{TF}_{N-1}(\Gamma) evaluated at \Psi\circ \text{grid2d}(\varrho, \tau)`.

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

  • rho (1d np.array) – \varrho.

  • tau (1d np.array) – \tau. The reconstruction will be evaluated at \Psi\circ \text{grid2d}(
\varrho, \tau)`.

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

Returns:

A tuple of two outputs:

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

    (x,y,z):=\Psi\circ \text{grid2d}(\varrho, \tau).

  • values: The values of the reconstructed variable at (x,y,z).

TN(loc_dofs, rho, tau, ravel=False)[source]

Reconstruct a discrete trace polynomial in \text{TN}_{N}(\Gamma) evaluated at \Psi\circ \text{grid2d}(\varrho, \tau)`.

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

  • rho (1d np.array) – \varrho.

  • tau (1d np.array) – \tau. The reconstruction will be evaluated at \Psi\circ \text{grid2d}(
\varrho, \tau)`.

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

Returns:

A tuple of two outputs:

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

    (x,y,z):=\Psi\circ \text{grid2d}(\varrho, \tau).

  • values: The values of the reconstructed variable at (x,y,z).

class projection_trace.ReductionTrace(bf, ct, quad_degree=None)[source]

A wrapper of reduction functions.

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

  • ct (CoordinateTransformationSurface) –

    The coordinate transformation representing the mapping \Psi,

    \Psi: \Pi_{\mathrm{ref}}\to\Gamma

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

Example:

>>> def p(x,y,z): return np.sin(np.pi*x) * np.sin(np.pi*y) * np.sin(np.pi*z)
>>> from mimetic_basis_polynomials_2d import MimeticBasisPolynomials2D
>>> from coordinate_transformation_surface import CoordinateTransformationSurface
>>> from coordinate_transformation_surface import Psi, d_Psi
>>> bf = MimeticBasisPolynomials2D('Lobatto-3', 'Lobatto-3')
>>> ct = CoordinateTransformationSurface(Psi, d_Psi)
>>> Rd = ReductionTrace(bf, ct)
>>> Rd.TF(p)
array([0.03873144, 0.02717954, 0.02752846, 0.02717954, 0.04952738,
       0.04752636, 0.02752846, 0.04752636, 0.01838736])
TE(vector)[source]

Reduce a vector on \Gamma to \text{TE}_{N-1}(\Gamma).

Parameters:

vector

Returns:

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

TF(scalar)[source]

Reduce a scalar on \Gamma to \text{TF}_{N-1}(\Gamma).

Parameters:

scalar

Returns:

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

TN(scalar)[source]

Reduce a scalar on \Gamma to \text{TN}_{N}(\Gamma).

Parameters:

scalar

Returns:

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

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