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:
The -Lagrange basis functions associated to
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 base, OptV1 and OptV2 versions respectively (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
source 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 base,
OptV1 and OptV2 versions respectively (see report).
The Stiffness 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
source code
Assembly of the Stiffness Matrix by -Lagrange finite elements using base version (see report).
Assembly of the Stiffness Matrix by -Lagrange finite elements using OptV1 version (see report).
Assembly of the Stiffness Matrix by -Lagrange finite elements using OptV2 version (see report).
Assembly of the Elastic Stiffness Matrix by -Lagrange finite elements using base,
OptV1 and OptV2 versions respectively (see report).
The Elastic Stiffness Matrix
is given by
where and
are the elastic stress and strain tensors respectively.
Note
generic syntax
Compute the elastic 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
source code
Assembly of the Elasticity Stiffness Matrix by -Lagrange finite elements using base version (see report).
Assembly of the Elasticity Stiffness Matrix by -Lagrange finite elements using OptV1 version (see report).
Assembly of the Elasticity Stiffness 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 elastic stiffness 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
source code
Returns the element elastic stiffness matrix
for a given tetrahedron
in the local alternate basis
Parameters: |
|
---|---|
Returns: |
|
Type : |
|
The element elastic stiffness 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
source code
Returns the element elastic stiffness 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 26.
Algorithm 26
We have
Then with definition (see Section New Optimized assembly algorithm (OptV2 version)) , we obtain
So the vectorized algorithm for computation is simple and given in Algorithm 27.
Algorithm 27
Note
Computes all the element Mass matrices for
Parameters: | volumes (![]() |
---|---|
Returns: | a one dimensional numpy array of size ![]() |
We have
Using vectorized algorithm function given in Algorithm 26, we obtain
the vectorized algorithm 28 for
computation for the Stiffness matrix in 3d.
Algorithm 28
Note
Computes all the element stiffness matrices for
Parameters: |
|
---|---|
Returns: | a one dimensional numpy array of size |
We define on the tetrahedron 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 explicitly compute the first two terms in the first column of which are given by
and
Using vectorized algorithm function given in Algorithm 26, we obtain
the vectorized algorithm 29 for
computation for the Elastic Stiffness matrix in 3d.
Algorithm 29
Note
Computes all the element elastic stiffness 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 26, we obtain
the vectorized algorithm 30 for
computation for the Elastic Stiffness matrix in 3d.
Algorithm 30
Note
Compute all the element elastic stiffness matrices, for
in local block basis.
Parameters: | |
---|---|
Returns: | a (144*nme,) numpy array of floats. |
Creates 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 – number of points on each edge of the cube |
---|
optional parameter : version=0 or version=1
Reads 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