projection_dual.py¶
An implementation of the projection for the dual mimetic spaces. 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 assembles the coefficients with the correct basis functions and leads to evaluable function.
⭕ To access the source code, click on the [source] button at the right
side or click on
[projection_dual.py]
.
Dependence may exist. In case of error, check import and install required
packages or download required scripts. © mathischeap.com
- class projection_dual.ReconstructionDual(bf, ct)[source]¶
Reconstruction functions for spaces , , and .
- 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') >>> 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) >>> dofs_N = rd.NP(pressure) >>> dofs_E = rd.EP((velocity_x, velocity_y, velocity_z)) >>> dofs_F = rd.FP((velocity_x, velocity_y, velocity_z)) >>> dofs_V = rd.VP(source) >>> rdd = ReductionDual(bf, ct) >>> d_dofs_N = rdd.NP(pressure) >>> d_dofs_E = rdd.EP((velocity_x, velocity_y, velocity_z)) >>> d_dofs_F = rdd.FP((velocity_x, velocity_y, velocity_z)) >>> d_dofs_V = rdd.VP(source)
>>> xi = np.linspace(-1, 1, 50) >>> et = np.linspace(-1, 1, 50) >>> sg = np.linspace(-1, 1, 50)
>>> rc = Reconstruction(bf, ct) >>> xyz_p, p = rc.NP(dofs_N, xi, et, sg) >>> xyz_w, w = rc.EP(dofs_E, xi, et, sg) >>> xyz_u, u = rc.FP(dofs_F, xi, et, sg) >>> xyz_f, f = rc.VP(dofs_V, xi, et, sg)
>>> rcd = ReconstructionDual(bf, ct) >>> XYZ_p, P = rcd.NP(d_dofs_N, xi, et, sg) >>> XYZ_w, W = rcd.EP(d_dofs_E, xi, et, sg) >>> XYZ_u, U = rcd.FP(d_dofs_F, xi, et, sg) >>> XYZ_f, F = rcd.VP(d_dofs_V, xi, et, sg)
>>> np.testing.assert_array_almost_equal(p, P) >>> np.testing.assert_array_almost_equal(w[0], W[0]) >>> np.testing.assert_array_almost_equal(w[1], W[1]) >>> np.testing.assert_array_almost_equal(w[2], W[2]) >>> np.testing.assert_array_almost_equal(u[0], U[0]) >>> np.testing.assert_array_almost_equal(u[1], U[1]) >>> np.testing.assert_array_almost_equal(u[2], U[2]) >>> np.testing.assert_array_almost_equal(f, F) >>> np.testing.assert_array_almost_equal(xyz_p[1], XYZ_f[1]) >>> np.testing.assert_array_almost_equal(XYZ_w[0], xyz_u[0]) >>> np.testing.assert_array_almost_equal(XYZ_f[2], XYZ_u[2])
- 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
) Ifravel
isTrue
, 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
) Ifravel
isTrue
, 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
) Ifravel
isTrue
, 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
) Ifravel
isTrue
, 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 .
- class projection_dual.ReductionDual(bf, ct, quad_degree=None)[source]¶
The reduction for spaces , , and .
- 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') >>> rdd = ReductionDual(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) >>> rdd.NP(pressure) array([ 4.55293100e-05, 4.23149147e-04, 4.96681526e-05,... >>> rdd.EP((velocity_x, velocity_y, velocity_z)) array([-4.46767360e-03, 3.73876731e-03, 1.82174958e-03,... >>> rdd.FP((velocity_x, velocity_y, velocity_z)) array([ 0.04649943, -0.03142164, -0.07862941, 0.03226957,... >>> rdd.VP(pressure) array([ 0.14087023, 0.17787218, -0.02315247, 0.17787218,...
↩️ Back to Ph.D. thesis complements (ptc).