| Author: | Francois Cuvelier <cuvelier@math.univ-paris13.fr> |
|---|---|
| Date: | 15/09/2013 |
Contains functions to build some finite element matrices using
-Lagrange finite elements on a 3D mesh.
Each assembly matrix is computed by three differents versions called base,
OptV1 and OptV2 (see here)
Contents
Let
be a tetrahedral mesh of
corresponding
to the following structure data:
![\mbox{\begin{tabular}{lccll}
\hline
\textbf{name} & \textbf{type} & \textbf{dimension} & \textbf{description} & \textbf{Python}\\
\hline
$\nq$ & integer & 1 & number of vertices & \texttt{nq}\\
$\nme$ & integer & 1 & number of elements & \texttt{nme}\\
$\q$ & double & $3 \times {\nq}$ &
\begin{minipage}[t]{7.9cm}
array of vertices coordinates. $\q(\al,j)$ is the $\nu$-th coordinate of the $j$-th vertex,
$\al\in\{1,2,3\}$, $j\in\{1,\hdots,\nq\}.$
The $j$-th vertex will be also denoted by $\q^j$
\end{minipage}&
\begin{minipage}[t]{3cm}
\texttt{q} (transposed)\\
\texttt{q[j-1]} = $\q^j$
\end{minipage}\\
$\me$ & integer & $4 \times \nme$ &
\begin{minipage}[t]{7.9cm}
connectivity array. ${\me}(\jl,k)$ is the storage index of the $\beta$-th vertex
of the $k$-th element, in the array~$q$, for $\jl\in\{1,\hdots,4\}$ and $k\in\{1,\hdots,{\nme}\}$
\end{minipage}&\texttt{me} (transposed)\\
$\rm volumes$ & double & $1\times {\nme}$ &
\begin{minipage}[t]{7.9cm}
array of volumes. ${\rm volumes}(k)$ is the $k$-th tetrahedron volume,
$k\in\{1,\hdots,\nme\}$
\end{minipage}&\texttt{volumes}\\
\hline
\end{tabular}}](_images/math/cc16cf40bee8d694e1d96b522c2dff9e8317f5d2.png)
The
-Lagrange basis functions associated with
are denoted by
for all
and are defined by

We also define the global alternate basis
by

and the global block basis
by
Assembly of the Mass Matrix by
-Lagrange finite elements
using respectively version base, OptV1 and OptV2 (see report).
The Mass Matrix
is given by

Note
generic syntax:
M = MassAssembling3DP1<version>(nq,nme,me,volumes)
,
,
where <version> is base, OptV1 or OptV2
>>> from pyOptFEM.FEM3D import *
>>> Th=CubeMesh(5)
>>> Mbase = MassAssembling3DP1base(Th.nq,Th.nme,Th.me,Th.volumes)
>>> MOptV1= MassAssembling3DP1OptV1(Th.nq,Th.nme,Th.me,Th.volumes)
>>> print(" NormInf(Mbase-MOptV1)=%e " % NormInf(Mbase-MOptV1))
NormInf(Mbase-MOptV1)=1.734723e-18
>>> MOptV2= MassAssembling3DP1OptV2(Th.nq,Th.nme,Th.me,Th.volumes)
>>> print(" NormInf(Mbase-MOptV2)=%e " % NormInf(Mbase-MOptV2))
NormInf(Mbase-MOptV2)=1.734723e-18
We can show sparsity of the Mass matrix :
Note
sources code
Assembly of the Mass Matrix by
-Lagrange finite elements using base version (see report).
Assembly of the Mass Matrix by
-Lagrange finite elements using OptV1 version (see report).
Assembly of the Mass Matrix by
-Lagrange finite elements using OptV2 version (see report).
Assembly of the Stiffness Matrix by
-Lagrange finite elements using respectively version base,
OptV1 and OptV2 (see report).
The Stiff Matrix
is given by

Note
generic syntax
Compute the stiffness sparse matrix where <version> is base, OptV1 or OptV2
| Parameters: |
|
|---|---|
| Returns: | a Scipy CSC sparse matrix of size |
Benchmarks of theses functions are presented in Stiffness Matrix. We give a simple usage :
>>> from pyOptFEM.FEM3D import *
>>> Th=CubeMesh(5)
>>> Sbase = StiffAssembling3DP1base(Th.nq,Th.nme,Th.q,Th.me,Th.volumes)
>>> SOptV1= StiffAssembling3DP1OptV1(Th.nq,Th.nme,Th.q,Th.me,Th.volumes)
>>> print(" NormInf(Sbase-SOptV1)=%e " % NormInf(Sbase-SOptV1))
NormInf(Sbase-SOptV1)=2.220446e-15
>>> SOptV2= StiffAssembling3DP1OptV2(Th.nq,Th.nme,Th.q,Th.me,Th.volumes)
>>> print(" NormInf(Sbase-SOptV2)=%e " % NormInf(Sbase-SOptV2))
NormInf(Sbase-SOptV2)=2.220446e-15
Note
sources code
Assembly of the Stiff Matrix by
-Lagrange finite elements using base version (see report).
Assembly of the Stiff Matrix by
-Lagrange finite elements using OptV1 version (see report).
Assembly of the Stiff Matrix by
-Lagrange finite elements using OptV2 version (see report).
Assembly of the Stiffness Elasticity Matrix by
-Lagrange finite elements using respectively version base,
OptV1 and OptV2 (see report).
The Stiffness Elasticity Matrix
is given by

where
and
are the elastic stress and strain tensors respectively.
Note
generic syntax
Compute the elasticity stiffness sparse matrix where <version> is base, OptV1 or OptV2
| Parameters: |
|
|---|---|
| Returns: | a Scipy CSC sparse matrix of size |
>>> from pyOptFEM.FEM3D import *
>>> Th=CubeMesh(5)
>>> Kbase = StiffElasAssembling3DP1base(Th.nq,Th.nme,Th.q,Th.me,Th.volumes,2,0.5,0)
>>> KOptV1= StiffElasAssembling3DP1OptV1(Th.nq,Th.nme,Th.q,Th.me,Th.volumes,2,0.5,0)
>>> print(" NormInf(Kbase-KOptV1)=%e " % NormInf(Kbase-KOptV1))
NormInf(Kbase-KOptV1)=1.332268e-15
>>> KOptV2= StiffElasAssembling3DP1OptV2(Th.nq,Th.nme,Th.q,Th.me,Th.volumes,2,0.5,0)
>>> print(" NormInf(Kbase-KOptV2)=%e " % NormInf(Kbase-KOptV2))
NormInf(Kbase-KOptV2)=1.332268e-15
We now illustrate the consequences of the choice of the global basis on matrix sparsity
global alternate basis
(Num=0 or Num=2)
>>> from pyOptFEM.FEM3D import *
>>> Th=CubeMesh(5)
>>> K0=StiffElasAssembling3DP1OptV1(Th.nq,Th.nme,Th.q,Th.me,Th.volumes,2,0.5,0)
>>> showSparsity(K0)
global block basis
(Num=1 or Num=3)
>>> K3=StiffElasAssembling3DP1OptV1(Th.nq,Th.nme,Th.q,Th.me,Th.volumes,2,0.5,3)
>>> showSparsity(K3)
Note
sources code
Assembly of the Stiffness Elasticity Matrix by
-Lagrange finite elements using base version (see report).
Assembly of the Stiffness Elasticity Matrix by
-Lagrange finite elements using OptV1 version (see report).
Assembly of the Stiffness Elasticity Matrix by
-Lagrange finite elements using OptV2 version (see report).
Let
be a tetrahedron, of volume
and with
,
,
and
its four vertices. We denote by
,
,
and
the
-Lagrange local basis functions such that
.
We also define the local alternate basis
by

and the local block basis
by
The elasticity tensor,
, obtained from Hooke’s law with an isotropic material,
defined with the Lamé parameters
and
is given by

and, for a function
the strain tensors is given by

The element Stiffness Elasticity matrix,
,
for a given tetrahedron
in the local alternate basis
is defined by

We also have

where
is the elasticity tensor and
is a
matrix defined by

So in
basis we obtain

Note
sources code
Return the element Stiffness Elasticity matrix,
,
for a given tetrahedron
in the local alternate basis 
| Parameters: |
|
|---|---|
| Returns: |
|
| Type : |
|
The element Stiffness Elasticity matrix,
,
for a given triangle
in the local block basis
is defined by

We also have

where
is the elasticity tensor and
is a
matrix defined by

So in
basis we obtain

Note
sources code
Return the element Stiffness Elasticity matrix,
,
for a given tetrahedron
in the local block basis 
| Parameters: |
|
|---|---|
| Returns: |
|
| Type : |
|
By construction, the gradients of basis functions are constants on each element
So, we denote,
by
the
array defined,
by

On
tetrahedra
we set

Then, we have

With these formulas, we obtain the vectorized algorithm given in Algorithm 148.
Algorithm 148
We have

Then with
definition (see Section New Optimized assembling algorithm (version OptV2)) , we obtain

So the vectorized algorithm for
computation is simple and given in Algorithm 149.
Algorithm 149
Note
Compute all the elementaries Mass matrices,
for 
| Parameters: | volumes ( numpy array of floats) – volumes of all the mesh elements. |
|---|---|
| Returns: | a one dimensional numpy array of size ![]() |
We have 

Using vectorized algorithm function
given in Algorithm 148, we obtain
the vectorized algorithm 150 for
computation of the Stiffness matrix in 3d.
Algorithm 150
Note
Compute all the elementaries Stiff matrices,
for 
| Parameters: |
|
|---|---|
| Returns: | a one dimensional numpy array of size |
We define on tetrahedra
the local alternate basis
by

where
With notations of Presentation,
we have 

with,
by

where
and
are the Lame coefficients, and 
For example, we can compute explicitely the first two terms in the first column of
which are given by

and

Using vectorized algorithm function
given in Algorithm 148, we obtain
the vectorized algorithm 151 for
computation of the Elasticity Stiffness matrix in 3d.
Algorithm 151
Note
Compute all the elementaries Stiffness elasticity matrices,
for
in local alternate basis.
| Parameters: | |
|---|---|
| Returns: | a (144*nme,) numpy array of floats. |
We define on
the local block basis
by

where 
For example, using formula (?), we can explicitly compute the first two terms in the first column of
which are given by

and

Using vectorized algorithm function
given in Algorithm 148, we obtain
the vectorized algorithm 152 for
computation of the Elasticity Stiffness matrix in 3d.
Algorithm 152
Note
Compute all the elementaries Stiffness elasticity matrices,
for
in local block basis.
| Parameters: | |
|---|---|
| Returns: | a (144*nme,) numpy array of floats. |
Build meshes of the unit cube
. Class attributes are :
nq, total number of mesh vertices (points), also denoted
.
nme, total number of mesh elements (tetrahedra in 3d),
version, mesh structure version,
q, Numpy array of vertices coordinates, dimension (nq,3) (version 0) or (3,nq) (version 1).
q[j] (version 0) or q[:,j] (version 1) are the three coordinates of the
-th vertex,
me, Numpy connectivity array, dimension (nme,4) (version 0) or (4,nme) (version 1).
me[k] (version 0) or me[:,k] (version 1) are the storage index of the four vertices of the
-th tetrahedron in the array q of vertices coordinates,
.
volumes, Array of mesh elements volumes, (nme,) Numpy array.
volumes[k] is the volume of
-th tetrahedron, k in range(0,nme)
| Parameters: | N – points number on each edges of the cube |
|---|
optional parameter : version=0 or version=1
Read a medit mesh from file meshfile. Class attributes are :
nq, total number of mesh vertices (points), also denoted
.
nme, total number of mesh elements (tetrahedra in 3d),
version, mesh structure version,
q, Numpy array of vertices coordinates, dimension (nq,3) (version 0) or (3,nq) (version 1).
q[j] (version 0) or q[:,j] (version 1) are the three coordinates of the
-th vertex,
me, Numpy connectivity array, dimension (nme,4) (version 0) or (4,nme) (version 1).
me[k] (version 0) or me[:,k] (version 1) are the storage index of the four vertices of the
-th tetrahedron in the array q of vertices coordinates,
.
volumes, Array of mesh elements volumes, (nme,) Numpy array.
volumes[k] is the volume of
-th tetrahedron, k in range(0,nme)
| Parameters: | meshfile – medit mesh file |
|---|
optional parameter : version=0 or version=1