"""
Here we compute the trace matrices :math:`\\mathbb{T}_{\\text{N}}`,
:math:`\\mathbb{T}_{\\text{E}}` and :math:`\\mathbb{T}_{\\text{F}}`.
⭕ To access the source code, click on the [source] button at the right
side or click on
:download:`[trace_matrices.py]</contents/LIBRARY/ptc/mathischeap_ptc/trace_matrices.py>`.
Dependence may exist. In case of error, check import and install required
packages or download required scripts. © mathischeap.com
"""
import numpy as np
from scipy.sparse import csr_matrix
from incidence_matrices import local_numbering_NP
from incidence_matrices import local_numbering_EP
from incidence_matrices import local_numbering_FP
[docs]
def TN(N_xi, N_et, N_sg):
"""The trace matrix :math:`\\mathbb{T}_{\\text{N}}` for mimetic
polynomials constructed on three sets of nodes,
:math:`\\left\\lbrace\\xi_0,\\xi_1,\\cdots, \\xi_{N0}
\\right\\rbrace`, :math:`\\left\\lbrace\\eta_0,\\eta_1,\\cdots,
\\eta_{N1}\\right\\rbrace` and :math:`\\left\\lbrace\\varsigma_0,
\\varsigma_1,\\cdots, \\varsigma_{N2}\\right\\rbrace`.
:param N_xi: ``N_xi + 1`` nodes in set :math:`\\left\\lbrace\\xi_0,
\\xi_1,\\cdots, \\xi_{N_\\xi} \\right\\rbrace`.
:param N_et: ``N_et + 1`` nodes in set :math:`\\left\\lbrace\\eta_0,
\\eta_1,\\cdots, \\eta_{N_\\eta} \\right\\rbrace`.
:param N_sg: ``N_sg + 1`` nodes in set :math:`\\left\\lbrace
\\varsigma_0, \\varsigma_1,\\cdots, \\varsigma_{N_\\varsigma}
\\right\\rbrace`.
:type N_xi: positive integer
:type N_et: positive integer
:type N_sg: positive integer
:return: A csr_matrix :math:`\\mathbb{T}_{\\text{N}}`.
:example:
"""
raise NotImplementedError(f"Could you code it?")
[docs]
def TE(N_xi, N_et, N_sg):
"""The trace matrix :math:`\\mathbb{T}_{\\text{E}}` for mimetic
polynomials constructed on three sets of nodes,
:math:`\\left\\lbrace\\xi_0,\\xi_1,\\cdots, \\xi_{N0}
\\right\\rbrace`, :math:`\\left\\lbrace\\eta_0,\\eta_1,\\cdots,
\\eta_{N1}\\right\\rbrace` and :math:`\\left\\lbrace\\varsigma_0,
\\varsigma_1,\\cdots, \\varsigma_{N2}\\right\\rbrace`.
:param N_xi: ``N_xi + 1`` nodes in set :math:`\\left\\lbrace\\xi_0,
\\xi_1,\\cdots, \\xi_{N_\\xi} \\right\\rbrace`.
:param N_et: ``N_et + 1`` nodes in set :math:`\\left\\lbrace\\eta_0,
\\eta_1,\\cdots, \\eta_{N_\\eta} \\right\\rbrace`.
:param N_sg: ``N_sg + 1`` nodes in set :math:`\\left\\lbrace
\\varsigma_0, \\varsigma_1,\\cdots, \\varsigma_{N_\\varsigma}
\\right\\rbrace`.
:type N_xi: positive integer
:type N_et: positive integer
:type N_sg: positive integer
:return: A csc_matrix :math:`\\mathbb{T}_{\\text{E}}`.
:example:
"""
raise NotImplementedError(f"Could you code it?")
[docs]
def TF(N_xi, N_et, N_sg):
"""The trace matrix :math:`\\mathbb{T}_{\\text{F}}` for mimetic
polynomials constructed on three sets of nodes,
:math:`\\left\\lbrace\\xi_0,\\xi_1,\\cdots, \\xi_{N0}
\\right\\rbrace`, :math:`\\left\\lbrace\\eta_0,\\eta_1,\\cdots,
\\eta_{N1}\\right\\rbrace` and :math:`\\left\\lbrace\\varsigma_0,
\\varsigma_1,\\cdots, \\varsigma_{N2}\\right\\rbrace`.
:param N_xi: ``N_xi + 1`` nodes in set :math:`\\left\\lbrace\\xi_0,
\\xi_1,\\cdots, \\xi_{N_\\xi} \\right\\rbrace`.
:param N_et: ``N_et + 1`` nodes in set :math:`\\left\\lbrace\\eta_0,
\\eta_1,\\cdots, \\eta_{N_\\eta} \\right\\rbrace`.
:param N_sg: ``N_sg + 1`` nodes in set :math:`\\left\\lbrace
\\varsigma_0, \\varsigma_1,\\cdots, \\varsigma_{N_\\varsigma}
\\right\\rbrace`.
:type N_xi: positive integer
:type N_et: positive integer
:type N_sg: positive integer
:return: A csr_matrix :math:`\\mathbb{T}_{\\text{F}}`.
:example:
>>> T = TF(2, 2, 2)
>>> T.indices
array([ 0, 3, 6, 9, 2, 5, 8, 11, 12, 13, 18, 19, 16, 17, 22, 23, 24,
25, 26, 27, 32, 33, 34, 35], dtype=int32)
>>> T.data
array([-1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1,
-1, -1, -1, 1, 1, 1, 1], dtype=int32)
"""
num_dofs_FP = (N_xi+1)*N_et*N_sg + \
N_xi*(N_et+1)*N_sg + \
N_xi*N_et*(N_sg+1)
NF = local_numbering_FP(N_xi, N_et, N_sg)
N = NF[0][0, :, :].ravel('F')
S = NF[0][-1, :, :].ravel('F')
W = NF[1][:, 0, :].ravel('F')
E = NF[1][:, -1, :].ravel('F')
B = NF[2][:, :, 0].ravel('F')
F = NF[2][:, :, -1].ravel('F')
Tn = np.zeros((N_et*N_sg, num_dofs_FP), dtype='int')
Ts = np.zeros((N_et*N_sg, num_dofs_FP), dtype='int')
Tw = np.zeros((N_xi*N_sg, num_dofs_FP), dtype='int')
Te = np.zeros((N_xi*N_sg, num_dofs_FP), dtype='int')
Tb = np.zeros((N_xi*N_et, num_dofs_FP), dtype='int')
Tf = np.zeros((N_xi*N_et, num_dofs_FP), dtype='int')
for i, j in enumerate(N):
Tn[i, j] = -1
for i, j in enumerate(S):
Ts[i, j] = 1
for i, j in enumerate(W):
Tw[i, j] = -1
for i, j in enumerate(E):
Te[i, j] = 1
for i, j in enumerate(B):
Tb[i, j] = -1
for i, j in enumerate(F):
Tf[i, j] = 1
T = np.vstack((Tn, Ts, Tw, Te, Tb, Tf))
return csr_matrix(T)
if __name__ == '__main__':
import doctest
doctest.testmod()
N = 1
TF(N, N, N)
print(TF(N, N, N).toarray())