7/27/2019 MAT FemIngles
1/29
F. Zrate, E. Oate
CIMNE 2007
7/27/2019 MAT FemIngles
2/29
Index:
Introduction 3Data files 4
MAT-fem 7Start 7
Elemental stiffness matrix and it assemble 8Details about the stiffness matrix 10External loads 13Fixed displacements 14Solution of the equation system 14
Reactions 15Stresses 15Writing for Postprocessing 15
About the stress calculus 16
Graphical User Interface 21Process 24Postprocess 24Example 25
2
7/27/2019 MAT FemIngles
3/29
Introduction.
As any other numerical method the Finite Element Method is linked to the
programming algorithms that they define it. In fact, its advantage is in the iteration of
the same calculations on a great amount of elements. Historically the first used
programming language to work with the Finite Element Method was FORTRAN; since
then many routines, algorithms and programs associated to the method have been
programmed in this language. With the development of the computers, new languages
have appeared, each one with capacities and specific tools for diverse fields of
application, all it with the idea to simplify the codification of the algorithms and to
optimize the computer resources.
Although FORTRAN continues being a language of reference in the use of the FEM,
the new languages and programming tools allow the coding simplification in thealgorithms implementation. At the same time uses specific libraries and resources that
optimize the memory and computer resources. This is the tactical mission of MATLAB
that besides to be an investigation tool, allows us to write codes that it interprets at the
moment of the execution. From an optimal programming point of view, the interpretive
languages are very slow, however, MATLAB allows us to make use of all the
implemented matrix routines which allows optimizing the calculations until the point to
compete efficiently with other compiled languages.
MATLAB is a designed tool to work with matrices, facilitating all the matrix algebra,
from the numerical and storage point of view, giving a simple and easy way to handle
complex routines.
Having an efficient calculus program is not the only requirement to be able to work with
the Finite Element Method. It is necessary to count on a suitable interface to prepare the
problem data, to generate meshes adapted to the kind of problem to solve and to display
the results so that the interpretation of these is the main objective. MATLAB is very
efficient in treatment of matrices but very poor program in their graphical capacities.
The ideal complement is the pre/postprocessor program GiD.
GiD is a tool designed to treat any geometry as a CAD and to allocate the materials
properties and boundary conditions of the original problem. Different efforts as the
discretization and data writing in an established format become a practically transparenttask for the user.
The data processing by means of GiD is a simple task, in where the visualization of the
obtained results allows concentrating itself in the interpretation of the results.
MAT-fem has been written thinking about the joint interaction of GiD with MATLAB.
GiD allows manipulating geometries and discretizations, writing the file as MATLAB
need it. Through MATLAB the calculation program is executed, without losing the
MATLAB advantages. Finally GiD gathers the output data files for its graphical
visualization and interpretation.
3
7/27/2019 MAT FemIngles
4/29
This scheme allows understanding in detail the execution a Finite Elements program,
following step by step each one of the code lines if it is desired, to the time that is
possible to heighten examples that by their dimensions would fall outside any program
with educative aims.
Este esquema permite conocer en detalle la ejecucin de un programa de ElementosFinitos, siguiendo, si se desea, paso a paso cada una de las lneas del cdigo, al tiempo
que es posible realzar ejemplos que por sus dimensiones caeran fuera de cualquier
programa con fines educativos.
In the following sections the program is described in detail. It starts with the input data
file, automatically generate by GiD, but it contains information important to understand
the operation of MAT-fem.
Finally the user interface implemented in GiD is described using an application
example.
Data Files.
Before describing the program it is obvious to say that somehow it is necessary to feed
it with the information corresponding to the nodal coordinates, the element
discretization and the boundary conditions. For that reason, the input data file is firstly
described in order to familiarize with the programming style and the variables used in
MATLAB. As we commented, MATLAB is an interpreter and we will use this property
to define the input data. That is to say, that the input data file is in fact one subroutine of
the program in where the values corresponding to the problem are assigned directly to
the variables.
It avoids having to define a special reading syntax for the program and at the time it also
avoids us to implement an I/O interface, concentrating in programming the method.
Therefore, the input data file will use the MATLAB syntax. The variables used by the
program are defined directly in it. It is obvious that the name of this file will have to
take the MATLAB extension .m
Inside the data file we can distinguish three groups of variables: the associates to the
material; those that define the topology of the problem and those that define theboundary conditions. With the intention of simplifying the code, an isotropic linear
elastic material for the whole domain is used, due to that the material section appears
once in the data file.
Figure 1 shows the variables associated to the material: the variable pstrs indicates if it
is a problem of plane stress (pst r s = 1) or plane strain (pst r s = 0). young contains
the elasticity modulus andpoi ss the Poissons coefficient. t hi ck anddenss define the
thickness and the density of the domain respective. It is obvious that in a plan strain
problem the thickness value must be unitary.
4
7/27/2019 MAT FemIngles
5/29
7/27/2019 MAT FemIngles
6/29
case of using quadrilateral elements. Similar to the previous variable, the number of
element corresponds with the number of row that keeps in the defined matrix.
The last group of variables defines the boundary conditions of the problem, as it is
shown in figure 3.
Figure 3: Input data file: Boundary conditions definition
%% Fi xed Nodes%fixnodes = [
1, 1, 0.0 ;1, 2, 0.0 ;
13, 1, 0.0 ;13, 2, 0.0 ];
%% Poi nt l oads%
pointload = [
6, 2, -1.0 ;
18, 2, -1.0 ];
%% Si de l oads%sideload = [
11,12, 2.0, 3.0;
14,15, 2.0, 3.0 ];
The variable f i xnodes corresponds to the degrees of freedom (DOF) restricted in
agreement with the problem to solve. f i xnodes is a matrix where the number of rowscorresponds to the number of prescribed DOF and the number of columns describes in
the following order the restricted node, the fixed DOF code (1 in x direction and2 in y
direction) and the value for this DOF. In this way if a node is prescribed in both
directions two lines are necessary to define this condition.
The poi nt l oad variable is used to define the punctual loads. Like the previous
variables, this is a matrix where the number of rows is the number of defined loads in
the problem and the number of columns corresponds to the number of the loaded node,
the direction in which acts and the value of the load. The loads are referred in the global
system of coordinates. In the case of not existing punctual loads poi nt l oad is defined
as an empty matrix by means of the commandpoi nt l oad = [ ] ;
Finally the variable si del oad contains the information of the loads uniformly
distributed throughout the sides of the elements. The definition of the loads is in the
global reference system. si del oad is a matrix where the number of rows is the number
of element sides with this type of load and the two first columns define the nodes of this
side while columns 3 and 4 correspond to the value of the load distributed by unit of
length in direction x andy respectively. If there is no uniform loads sideload must be
defined as an empty matrix by means of the commandsi del oad = [ ] ;
The name of the data file is up to the user; nevertheless, the extension must be .m inorder that MATLAB can recognize it.
6
7/27/2019 MAT FemIngles
7/29
MAT-fem
MAT-fem is a TOP-DOWN execution program. The program flow chart is shown in
Figure 4. The first part, the input data section, is made in the same file were the data isdefined as it was described in the previous section.
The next task is to evaluate and assemble the elemental stiffness matrix and the
elemental mass load vector
Start
Read input data *.m
Figure 4: MAT-fem flow chart
In the same figure, before eliminating the equations related to the known DOF and
solving the equation system, all the load conditions are applied to the load vector.
Once the unknown DOF are found, the program evaluates the systems reactions and
stresses, finalizing with the data writing to visualize them in GiD.
Compute K(e)
and f(e)
Define f(e) for point and
distributed loads along a side
Solve Ka=f
Compute node reactionsR = Ka - f
Compute smoothed
stresses at nodes
Write results for GiD
Assembling of K(e) and f(e)
Function TrStiffor trianglesFunction QdStinffor quadrilaterals
Function Stress:
Call function TrStrs for trianglesCall function QsStrs for
uadrilaterals
Compute D Function constt
Loop over elements
Function ToGiD
End
7
7/27/2019 MAT FemIngles
8/29
Start
AT-fem begins cleaning all the variables with the cl ear command. Next it asks to the
Figure 5: Program initia zation and data reading
he data reading, as it was said before, is a direct variable allocation in the program.
he total number of equations per element will be the number of nodes by element
is interesting to reflect that these variables are not strictly necessary since they are
hroughout the program the t i mi ng routine is used to calculate the run time between
M
user the name of the input data file that is going to use (the .m extension in not included
in the filename). Figure 5 shows the first lines of the code corresponding to thevariables boot as well as the clock set up, storing in the variable t t i mthe total time of
execution.
%% MAT- f em
r y and var i abl es.
me = input('Enter the file name :','s');
me count er
,1); % Number of nodesOF
l ement
%Cl ear memo%
clear
file_na
tic; % St art c l ockttim = 0; % I ni t i al i ze t i
eval (file_name); % Read i nput f i l e
Fi nds basi cs di ment i ons% npnod = size(coordinates nndof = 2*npnod; % Number of t otal D nelem = size(elements,1); % Number of el ements
e nnode = size(elements,2); % Number of nodes per neleq = nnode*2; % Number of DOF per el ement
ttim = timing('Time needed to read the input file',ttim);
li
TFrom these matrices it is possible to extract the basic dimensions of the problem such as
the number of nodal points npnod which corresponds to the number of lines in the
coor di nat es matrix. The number of total degrees of freedom of the program nndof
will be twice the previous amount (2*npnod). nel emcorresponds to the number of read
elements and is the number of lines contained in the matrix el ement s whereas the
number of nodes that contain each elements is the number of columns of this matrix; in
this way the triangular elements are identified if the number of columns is three whereas
for the quadrilateral elements the number of columns will be of four.
T
nnode multiplied by the number of DOF for each node: two in the case of bidimensional
problems.
It
defined in the data structure, nevertheless, their definition simplify the code
interpretation.
T
two points in the code. In this way the user can observe the programs subroutine that
requires higher computational effort. Inside t i mi ng the t i c and t oc MATLAB
commands are used.
8
7/27/2019 MAT FemIngles
9/29
Elemental stiffness matrix and it assemble.
he code shown in Figure 6 respectively defines the global stiffness matrix and the
Figure 6: Global matrix initialization
ince the programs main purpose is to demonstrate the implementation of the FEM
he subroutine const t starts with the Youngs modulus, the Poissons coefficient and a
x definition.
this program it has been decided to recalculate values instead of storing them. The
igure 8 shows the elemental loop in which the program calculates and assembles the
T
equivalent nodales forces vector as a spar se matrix and vector. MAT-fem uses sparse
matrices to optimize the memory using the MATLABs tools. On this way and without
additional effort MAT-fem makes use of very powerful algorithms without losing thewriting simplicity.
% Di mensi on t he gl obal mat r i ces.); % The gl obal st i f f ness mat r i xStifMat = sparse ( nndof , nndof
force = sparse ( nndof , 1 ); % The gl obal f orce vect or
Mater i al pr oper t i es ( Const ant over t he domai n) .% dmat = constt(young,poiss,pstrs);
S
some simplifications are made like using a unique material in the whole domain, in this
way the constitutive matrix will not vary element to element and it is evaluated before
initiating the element stiffness matrix.
T
flag that allows us to distinguish between a plane stress or plane strain problem. The
constitutive matrix is stored in dmat as it is observed in Figure 6. In Figure 7 the
subroutine const t shows the explicit form for the dmat for an isotropic linear elastic
material.
Figure 7: Constitut e matri
function D = constt (young,poiss,pstrs)
g/(1-poiss^2);
ng*(1-poiss)/(1+poiss)/(1-2*poiss);
[aux1,aux2,0;aux2,aux1,0;0,0,aux3];
Pl ane Sr ess%
if (pstrs==1)aux1 = younaux2 = poiss*aux1;
oiss);aux3 = young/2/(1+p
% Pl ane St r ai nelse
ux1 = youaaux2 = aux1*poiss/(1-poiss);aux3 = young/2/(1+poiss);thick= 1.0;
end
=D
iv
In
computers speed makes this without reduction of the program efficiency. In addition, it
allows having more memory to attack greater problems.
F
stiffness matrix and the equivalent nodal load vector for each element. The cycle begins
recovering the geometric properties of each element. In the vector l nods the elements
nodal connectivity are stored and in the coord matrix the coordinates from these nodes
9
7/27/2019 MAT FemIngles
10/29
are keep.
Figure 8: Elemental stiffness m nd assembling.
the next step the elemental stiffness matrix is calculate. Depending on the element the
efore making the assembly the eqnum vector is defined. It contains the global
he assembly is made by means of two cycles from 1 t onel eq (number of equations
etails about the stiffness matrix
this program two finite elements are used the triangular whose stiffness matrix is
% El ement cycl e.elem
i es% conecti vi t i es
gl e
he equati on number l i st f or t he i - t h el ementr t he l i s t
on
eqnum(j)) + ...
End el ement ci cl e
for ielem = 1 : n
Recover el ement proper t%
lnods = elements(ielem,:); coord(1:nnode,:) = coordinates(lnods(1:nnode),:); % coor di nat es
Eval uates t he el ement al st i f f nes matr i x and mass f orce vect or.%i f (nnode == 3)
or] = TrStif(coord,dmat ,thick,denss); %Tr i an[ElemMat,ElemF else
mMat,ElemFor] = QdStif(coord,dmat ,thick,denss); % Quad.[Ele end
Fi nds t% eqnum = []; % Cl ea for i =1 : nnode % Node ci cl e
quat i eqnum = [eqnum,lnods(i)*2-1,lnods(i)*2]; % Bui l d t he e end % number l i st
Assambl e the f or ce vect or and t he st i f f nes matr i x% for i = 1 : neleq
= force(eqnum(i)) + ElemFor(i);force(eqnum(i))for j = 1 : neleq
),eqnum(j)) = StifMat(eqnum(i),StifMat(eqnum(iElemMat(i,j);
endend
end %
atrix evaluation a
In
subroutine Tr St i f is called for triangular elements and QdSt i f for quadrilateral
elements. The same subroutine evaluates the element stiffness matrix and the element
load vector. The use of the same area integration allows this simplification. The
calculation of the elemental stiffness matrices requires a detailed study made in the
following section.
B
equations number for each one of the equations in the elemental stiffness matrix. The
number conversion is simple because for each node two equations corresponds (one byeach degree of freedom).
T
in each element) assembling in the first cycle the equivalent nodal load vector and in the
second the elemental stiffness matrix term by term. This scheme avoids storing the
element matrices temporarily.
D
In
10
7/27/2019 MAT FemIngles
11/29
calculates in an explicit form and the quadrilateral element calculates by means of
numerical integration. Both routines require exactly the same input data and also return
the same variables: El emMat for the stiffness matrix and El emFor for the nodal
equivalent mass load vector.
TheTr St i f subroutine is defined for triangular elements as it is shown in Figure 9. In it
he elemental stiffness matrix is calculates by means of the classic expression T
he equivalent nodal mass load vector is evaluated distributing equal l y the weight of
Figure 9: Elemental stiffness matrix for the triangular element.
or the quadrilateral element the evaluation of the stiffness matrix is made using a
t this level also the Gaussian-Legendre coordinates values (pospg) and the weights
the Cartesian derivatives of the triangular linear function forms are calculate directly.
Those derivates are constant in the entire element. In this way the bmat matrix is built
simply placing each one of the Cartesian derivatives (b( i ) / ar ea2 andc( i ) / area2) in
the corresponding position of the deformation matrix, without forgetting the common
factor1/ area2.
T B DB
dA. In this line one of the fundamental advantages of MATLAB is observed where themultiplication of matrices is direct with no need to write troublesome cycles.
T
the element in each node (f orce). This load represents a negative force in y direction.
function [M,F] = TrStif ( nodes,dmat,thick,denss)
k
% ci = xk - xj
);
(2), 0 ,b(3), 0 ; % Expl i c i t f orm f or mat ri x B
mat*bmat)*area*thick; % El ement al st i f f nes mat r i x
ce]; % El ement al f orce vect or
b(1) = nodes(2,2) - nodes(3,2); % bi = yj - yb(2) = nodes(3,2) - nodes(1,2);
b(3) = nodes(1,2) - nodes(2,2);
c(1) = nodes(3,1) - nodes(2,1);c(2) = nodes(1,1) - nodes(3,1);c(3) = nodes(2,1) - nodes(1,1);
area2 = abs(b(1)*c(2) - b(2)*c(1)area = area2 / 2;
bmat = [b(1), 0 ,b0 ,c(1), 0 ,c(2), 0 ,c(3);
c(1),b(1),c(2),b(2),c(3),b(3)];bmat = bmat / area2;
M = (transpose(bmat)*dforce = area*denss*thick/3;F = [0,-force,0,-force,0,-for
F
numerical integration. Initially the elements function forms and its natural derivatives
are defined (f f o r m and der i v). This definition is made by means of an intrinsic
function. This facility allowed in MATLAB avoids the use of additional subroutines.
A
(pespg) corresponding to the 2x2 integration rule are defined. Also the boot of the M
matrix for the elemental stiffness matrix and the equivalent nodal load vectorf y is made
on this section. In figure 10 this routine is observed with detail.
11
7/27/2019 MAT FemIngles
12/29
Once the variables are initialized two loops defines the integration along the global
Figure 10: Elemental stiffness matrix for the quadrilateral element.
he deformation matrix is obtained placing properly the Cartesian derivates of the
he equivalent nodal mass load vector also requires integrate over the elements area
o finalize the routine in the F vector all the nodal forces are properly placed having in
axes. The l c f f m vector contains the values of the function form evaluated at the
integration point i , j and the l cder matrix stores the values for the natural derivative
of these functions at the same integration point. The Jacobian matrix (xcj acm) is
evaluated by the simple multiplication of the l cder matrix by the nodales coordinates
of the element. The value of the Cartesian derivates (ct der) in the integration point isobtained multiplying the inverse of the Jacobian matrix by the natural derivates of the
function form. The area differential is not another thing more than the determinant of
the Jacobian matrix by the weight functions of the integration point without forgetting
the element thickness.
function [M,F] = QdStif ( nodes,dmat,thick,denss)
+t+s*t)/4,(1-s+t-s*t)/4];
0 ];
2orm(pospg(i),pospg(j)) ; % FF at gauss poi nt
s
1 : 4 ctder(1,inode), 0 ;
;
+ (transpose(bmat)*dmat*bmat)*darea;
0, -fy(1), 0, -fy(2), 0, -fy(3), 0, -fy(4)];
fform = @(s,t)[(1-s-t+s*t)/4,(1+s-t-s*t)/4,(1+sderiv = @(s,t)[(-1+t)/4,( 1-t)/4,( 1+t)/4,(-1-t)/4 ;
(-1+s)/4,(-1-s)/4,( 1+s)/4,( 1-s)/4 ];
pospg = [ -0.577350269189626E+00 , 0.577350269189626E+0pespg = [ 1.0E+00 , 1.0E+00];
M = zeros(8,8);fy = zeros(1,4);
or i=1 : 2ffor j=1 :
lcffm = ff lcder = deriv(pospg(i),pospg(j)) ; % FF Local der i vat i ve xjacm = lcder*nodes ; % J acobi an mat r i x
i vat es ctder = xjacm\lcder ; % FF Cart esi an der darea = det(xjacm)*pespg(i)*pespg(j)*thick;
mat = [];b
for inode =bmat = [ bmat , [0 ,ctder(2,inode);
ctder(2,inode),ctder(1,inode) ] ]end
= MM
y = fy + lcffm*denss*darea;f
endend
F = [
T
function form in a matrix array, to obtain by means of the classic BTDB expression the
elemental stiffness matrix. Do not forget that to make a numerical integration it is
necessary to evaluate the sum of the variables calculated in all of the Gaussian points.
This sum is made in the same matrix M
T
multiply the function form by the element density.
T
12
7/27/2019 MAT FemIngles
13/29
mind that only the negative y force component exists.
These two routines try to exemplify the two mechanisms for the stiffness matrix
xternal loads.
esides the mass load it is necessary to consider uniformly loads distributed on the
ince both implemented elements have linear functions form, the calculation of the
bserve that the loads are defined in the global coordinate system and it is not
Figure 11: Equivalent nodal force vector for a uniform distributed load.
or the punctual loads, the calculation is as simple as adding the value of the load to the
Figure 12: Equivalent nodal force vector for punctual load.
calculation using the explicit form or a numerical integration.
E
B
sides of the elements and punctual loads in the nodes.
S
nodal contribution for the uniformly distributed loads will be exactly the same for both
cases. The evaluation is made after the assembly of the stiffness matrix, in the main
routine of the MAT-fem program. This code appears in Figure 11 where there is a loop
over the number of loads defined by si del oad. The nodal contribution is evaluated
equality on each node (due the linear function form).
O
necessary to make any rotation or transformation.
% Add si de f orces to t he f orce vect or
dinates(sideload(i,2),:);
node
de
for i = 1 : size(sideload,1)),:)-coorx=coordinates(sideload(i,1
l = sqrt(x*transpose(x)); % Fi nds t he l enght of t he si de ieqn = sideload(i,1)*2; % Fi nds eq. number f or t he f i r st
force(ieqn-1) = force(ieqn-1) + l*sideload(i,3)/2; % add x f or ceforce(ieqn ) = force(ieqn ) + l*sideload(i,4)/2; % add y f or ce
ieqn = sideload(i,2)*2; % Fi nds eq. number f or t he second noforce(ieqn-1) = force(ieqn-1) + l*sideload(i,3)/2; % add x f or ceforce(ieqn ) = force(ieqn ) + l*sideload(i,4)/2; % add y f or ce
end
F
equivalent nodal force vector. A loop over the number of point loads is necessary,
finding for each the equation number associate for adding the value of the load to the
force vector.
% Add poi nt l oads condi t i ons t o t he f orce vect or
% Fi nds eq. numberfor i = 1 : size(pointload,1)
+ pointload(i,2);ieqn = (pointload(i,1)-1)*2force(ieqn) = force(ieqn) + pointload(i,3); % add t he f orce
end
13
7/27/2019 MAT FemIngles
14/29
Fixed displacements
The u vector is defined to hold the DOF of the problem. In Figure 13 the loop over the
prescribed DOF can be observed and how the values defined by the f i xnodes matrix
are assigned to the u vector. Also the f i x vector is defined to keep the equationnumbers of the restricted DOF.
Finally the f orce vector is updated with the product of the St i f Mat matrix ant the u
vector which at this moment contains only the values of those degrees of freedom which
have been restricted.
% Appl i es t he Di r i chl et cou = sparse ( nndof, 1 );
ndi t i ons and adj ust t he r i ght hand si de.
for i = 1 : size(fixnodes,1)ieqn = (fixnodes(i,1)-1)*2 + fixnodes(i,2); %Fi nds t he equat i on numberu(ieqn) = fixnodes(i,3); %and store t he sol ut i on i n ufix(i) = ieqn; % and mark t he eq as a f i x val ue
endforce = force - StifMat * u; % adj ust t he rhs wi t h t he known val ues
Figure13: Update of the force vector due to the known DOF
Solution of the equation system
The strategy used in MAT-fem consists of solving the global equation system without
considering those DOF whose values are known. The Fr eeNodes vector contains the list
of the equations to solve.
The Fr eeNodes vector is used as a DOF index and allows us to write in a simple way
the solution to the equations system. MATLAB takes care to choose the most suitable
algorithm to solve the problem, been totally transparent for the user the solution of the
system. The routines implemented in the MATLAB kernel nowadays compete in speed
and memory optimization with the best existing algorithms, reason why all the power of
calculation available is described in a simple line.
% Comput e the sol ut i on by sol vi ng St i f Mat * u = f orce f or t he
% r emai ni ng unknown val ues of u.FreeNodes = setdiff ( 1:nndof, fix ); % Fi nds t he f r ee node l i st and
% sol ve f or i t .u(FreeNodes) = StifMat(FreeNodes,FreeNodes) \ force(FreeNodes);
Figure 14: Solution of the equation system.
14
7/27/2019 MAT FemIngles
15/29
Reactions
The solution to the equations system is in the u vector, therefore the reaction calculus is
made by means of the expression R = St i f Mat *u - f or ce. It is obvious that the value
of the reaction in those prescribed nodes is not null. In order to avoid unnecessarycalculations we use the vectorf i x which contains the list of the equations associated to
the fixed DOF as it is shown in Figure 15.
% Comput e the r eact i ons on t he f i xed nodes as a R = St i f Mat * u - Freaction = sparse(nndof,1);reaction(fix) = StifMat(fix,1:nndof) * u(1:nndof) - force(fix);
Figure 15: Reactions.
Stresses.
Once the nodal displacements have been found it is possible to evaluate the stresses in
the elements by means of the DBu expression. Since the deformation matrix B is
calculated at the integration points the stresses are referred to these points. In order to
transfer the values of the stresses at the integration points towards the element nodes it
is necessary to review in detail and in a later section the calculation of these values. The
Figure 16 presents the subroutine call for the nodal stresses evaluation which are store
in the St r nod matrix.
% Comput e t he st r essesStrnod = Stress(dmat,poiss,thick,pstrs,u);
Figure 16: Stress evaluation call.
Writing for Postprocessing
Once calculated the nodales displacements, the reactions and the stresses it is come to
overturn these values to the postprocess files from where GiD will be able to
present/display them in a graphical way. This is made in the subroutineToGi D shown in
Figure 17
% Gr aphi c r epr esent at i on.ToGiD (file_name,u,reaction,Strnod);
Figure 17: Postprocess call.
During the program execution will appear in the MATLAB console the total time used
by the program as well as the time consumed in each one of the described subroutines.
It is remarkable to observe that the biggest time consumption is made in the calculation
and assembly of the global stiffness matrix, whereas the solution of the equation system
really represents a small percentage of the consumed time.
15
7/27/2019 MAT FemIngles
16/29
Once the program execution is finish the variables are still alive inside MATLAB
reason why it is possible to experiment with the battery of internal functions of
MATLAB.
About the stress calculus
The stress calculation in the elements requires the use of a specific subroutine, not only
for the calculus itself but also to project the stresses from the integration points towards
the nodes.
The stress subroutine controls the program flow towards the three or four nodes element
routines. In the case of the triangular element the stresses are constant in the element
and the nodal extrapolation is trivial. Not thus it is the case of the quadrilateral element
where the stresses present a bilinear variation and the stress extrapolation is made using
the same elements functions form.
Figure 18 presents the initial part of the stress subroutine were the input data are the
material constitutive matrix dmat , Poissons coefficient poi ss, the thickness thi ck, the
flag for the problem type pstrs and the nodal displacements u. Additionally the nodal
coordinates and the element connectivities will be used (defined as a global variables).
In order to simplify the reading of the routine some variables are extracted like nel emto
indicate the number of elements, nnode to indicate the number of nodes per element and
npnod for the total number of nodes in the domain.
It is important to have into account the number of stresses for plain stress problems (x,
y andxy) and plane strain (x, y, z andxy) were z is a function ofx andy
The nododst r matrix is initialized to zeros to store the value of the nodal stresses; in
the last column the number of elements that concur in the node are counted. This is
necessary to make a nodal stress mean.
function S = Stress (dmat,poiss,thick,pstrs,u)
%% St r ess Eval uates t he st r esses at t he gauss poi nt and smoot h the val ues% t o t he nodes.%global coordinates;
global elements;
nelem = size(elements,1); % Number of el ement snnode = size(elements,2); % Number of nodes per el ementnpnod = size(coordinates,1); % Number of nodes
if (pstrs==1)nstrs= 3; % Number of Str s. Sx Sy Txy
elsenstrs= 4; % Number of Str s. Sx Sy Sz Txy
endnodstr = zeros n nod nstrs+1
Figure 18: Variables boot for stress calculus...
16
7/27/2019 MAT FemIngles
17/29
Like in the stiffness matrix, the stress evaluation requires a loop over the elements,
recovering the elements connectivities (l nods), coordinates for these nodes (coord) as
well as the displacements in di spl as it is shown in Figure 19
for ielem = 1 : nelem
% Recover element propertieslnods = elements(ielem,:);coord(1:nnode,:) = coordinates(lnods(1:nnode),:);eqnum = [];for i =1 : nnodeeqnum = [eqnum,lnods(i)*2-1,lnods(i)*2];
enddispl = u(eqnum);
Figure 19: Recovering of the element coordinates and nodal displacement.
Figure 20 shows the call for the stress calculus in triangular and quadrilateral elements.
In the triangular elements case the routine returns the El emSt r vector that contains the
stresses in the element; these values are accumulated in the nodst r were the last column
is the number of elements that share the node to evaluate later the nodal average.
In the quadrilateral element case the El emSt r variable represents a matrix that contains
the stresses of each one of the elements nodal points. Like in the previous case, the last
column holds the number of elements that share the node. Once all the element stresses
have been calculated and accumulated in nodst r a nodal mean is made to obtain a
smoothed stress field at the nodes.
% St r esses i nsi dif (nnode == 3)e the el ement s.
% Tr i angul ar el ement s const ant s t r essElemStr = TrStrs(coord,dmat,displ,poiss,thick,pstrs);
for j=1 : nstrsnodstr(lnods,j) = nodstr(lnods,j) + ElemStr(j);
endnodstr(lnods,nstrs+1) = nodstr(lnods,nstrs+1) + 1;
else
% Quadr i l ater al el ement s st r ess at nodesElemStr = QdStrs(coord,dmat,displ,poiss,thick,pstrs);
for j=1 : 4for i = 1 : nstrsnodstr(lnods(j),i) = nodstr(lnods(j),i) + ElemStr(i,j);
endendnodstr(lnods,nstrs+1) = nodstr(lnods,nstrs+1) + 1;
endend
% Fi nd t he mean st r ess val ue
S = [];for i = 1 : npnodS = [S ; nodstr(i,1:nstrs)/nodstr(i,nstrs+1)];end
Figure 20: Stress calculus and nodal smooth.
17
7/27/2019 MAT FemIngles
18/29
The stress calculus for each element is in the following figures. For the triangular
element, the B matrix is recalculated as it was done for the stiffness matrix. The stresses
are directly the DBu product
function S = TrStrs (nodes,dmat,displ,poiss,thick,pstrs)b(1) = nodes(2,2) - nodes(3,2);b(2) = nodes(3,2) - nodes(1,2);b(3) = nodes(1,2) - nodes(2,2);
c(1) = nodes(3,1) - nodes(2,1);c(2) = nodes(1,1) - nodes(3,1);c(3) = nodes(2,1) - nodes(1,1);
area2 = abs(b(1)*c(2) - b(2)*c(1));area = area2 / 2;
bmat = [b(1), 0 ,b(2), 0 ,b(3), 0 ;
0 ,c(1), 0 ,c(2), 0 ,c(3);c(1),b(1),c(2),b(2),c(3),b(3)];
se = dmat*bmat*dis l /area2
Figure 21: Stress calculus for the triangular element.
Depending on the problem selected, the stresses that can be calculated are three for
plane stress and four for plane strain (z= - poi ss*(x + y) ) as it is shown in Figure
22.
% Pl ane Sr essif (pstrs==1)
S = se ;
% Pl ane St r ai nelse
S = [se(1),se(2),-poiss*(se(1)+se(2)),se(3)];
end
Figura 22: Plane stress or plane strain stress calculus.
Due the similarly calculus with the stiffness matrix, most of the variables used have
been described in the four nodes stiffness matrix section. Nevertheless, the most
relevant aspect is the stress extrapolation from the Gaussian points towards the nodes.
The stress variation inside the element corresponds to a linear field, therefore, we use
element functions forms to extrapolate the values to the nodes. Considered that points i
and j are in a dominion that goes from - 1/ p to +1/ p were p is the natural coordinate of
the Gaussian points, In the normalized space makes them to be a distance of - 1 and+1
as it is shown in Figure 23 a).
Another consideration consists of establishing a suitable correlation between the nodes
and the Gaussian points numbers, because the order that keep the integration points
does not agree with the element nodal numeration as it is shown in Figure 23 b).
18
7/27/2019 MAT FemIngles
19/29
7/27/2019 MAT FemIngles
20/29
Like in the triangular element case, the stresses are calculate as a plain stress or plane
strain problem as it shows figure to it 24
% Pl ane Sr essif (pstrs==1)
S = se ;% Pl ane St r ai nelse
S = [se(1,:) ; se(2,:) ; -poiss*(se(1,:)+se(2,:)) ; se(3,:)];
end
Figure 24: Stress calculus for plane stress or strain problem
20
7/27/2019 MAT FemIngles
21/29
7/27/2019 MAT FemIngles
22/29
The shown button is used for punctual loads allocation. When selecting, an
emergent window (Figure 26) allows giving the load value in the global
coordinate system. Once it is defined is necessary to select the nodes were to applied it.
Figure 26: Punctual load condition...
The button associated to the uniformly distributed loads permits to assign this
condition on the geometrys lines. The emergent window (Figure 27) allows
introducing the value of the load by length unit referred the global axes system.
Figure 27 Uniform load assignations.
The material properties definition is made trough the following button which
leads to a new emergent window (Figure 28) to define the material variables like
the Youngs modulus, the Poissons coefficient, density and thickness. It is necessary to
assign this material in all the areas that defines the domain. As was mention before, in
MAT-fem, for simplify reasons only one material is allowed.
22
7/27/2019 MAT FemIngles
23/29
Figure 28 Material properties definition.
The general properties button allows acceding to the window shown in Figure 29
where the title of the problem is identified, the problem type (plane stress or
plane strain) the gravity loads and the units for the results.
Figure 29 General properties of the problem.
Once defined the boundary conditions and the material properties it is necessary
to make the domain discretization. The mesh button shown is used to create the
mesh with all the GiDs toolbox facilities.
The data file writing is made when pressing the last button shown in the menu.
All the geometrical properties of the problem, as well as the material are written
to the data file in the specific reading format for MAT-fem. Do not forget the .m
extension for the file name.
23
7/27/2019 MAT FemIngles
24/29
Figure 30 Input data file definition.
Process.
The problem calculation is made with MATLAB. The execution does not have greater
complications than knowing in which directory is the written file. A good practice is to
set this directory the working directory were also the postprocess file will be written.
Postprocess.
Once concluded the problem execution in MATLAB, is necessary to return to GiD for
the file postprocess to analyze the obtained results. It is necessary to open any of the
generated files that contain the extension *.flavia.msh or *.flavia.res.
Figure 31 Postprocess file reading.
The obtained results visualization can be done in a diversity forms, due the GiDs
graphical possibilities which permits to show the results like a colors gradient, iso-lines,
cuts and graphs; allowing the simple interpretation of the obtained results.
In Figure 32 there is an iso-areas example showing the vertical displacement in a test
beam clamped in its left end and point loaded on its right side.
24
7/27/2019 MAT FemIngles
25/29
Figure 32 Beam postprocess.
Example.
The example below is presented to show the programs simplicity of use. The problem
show corresponds to the IC6-NAFEMS benchmark were the stresses and displacement
of a circular wall subjected to a punctual load are calculated.
In this section the input data file of the proposed example is described in detail for
quadrilateral elements. Also the convergence of the results is analyzed changing the
problem discretization with triangular and quadrilateral elements.
The example is the NAFEMSS IC6 benchmark proposed in Linear Static Benchmarks
vol 1. A circular wall loaded with a punctual force. In Figure 33 the complete
geometry of the problem is presented were only one quarter is analyzed due symmetry.
The material properties are described in the same figure. The hypotheses used are the
plane strain ones.
P = 10 MN
E = 210.103 MPa
v = 0.3
t = 1.0 m
Figure 33 circular wall with punctual load. NAFEMS IC6.
The wall is symmetry fixed in both sides (the normal displacement is zero). The
punctual load is applied in the outer middle side at 45. The goal is to determine thestress x at the point A. The exact value is x = 53.2MPa
25
7/27/2019 MAT FemIngles
26/29
The problem definition for MAT-fem is done using the menu described in the GUI
section. The displacement, loads, materials and problem definitions are shown in
Figures 34 and 35.
Figure 34 Boundary conditions and loads over the structure
Figure 35 Material and problem definition.
Finally the mesh discretization and the input data files are created with the last two
buttons of the MAT-fem menu.
All the meshes used are structured. For the simplest quadrilateral element case it
consists of 8 elements and 15 nodes. Figure 36 shows the nodal and element numeration
of the used mesh. In the same figure the code for the input data file is presented using
the mesh described.
26
7/27/2019 MAT FemIngles
27/29
%=======================================================================% MAT- f em 1. 0 - MAT- f em i s a l ear ni ng t ool f or under st andi ng% t he Fi ni t e El ement Method wi t h MATLAB and Gi D%=======================================================================% PROBLEM TI TLE = NAFEMS I C6% Mat er i al Pr oper t i es%
young = 210103000.00000 ;poiss = 0.30000 ;denss = 0.00 ;
pstrs = 0 ;thick = 1 ;
%% Coor di nates%global coordinatescoordinates = [
11.00000 , 0.00000 ;10.50000 , 0.00000 ;10.00000 , 0.00000 ;9.23880 , 3.82683 ;9.70074 , 4.01818 ;
10.16267 , 4.20952 ;7.07107 , 7.07107 ;7.42462 , 7.42462 ;7.77817 , 7.77817 ;3.82683 , 9.23880 ;4.01818 , 9.70074 ;4.20952 , 10.16267 ;0.00000 , 10.00000 ;0.00000 , 10.50000 ;0.00000 , 11.00000 ] ;
%% El ement s%global elements
elements = [2 , 5 , 4 , 3 ;1 , 6 , 5 , 2 ;5 , 8 , 7 , 4 ;6 , 9 , 8 , 5 ;8 , 11 , 10 , 7 ;9 , 12 , 11 , 8 ;11 , 14 , 13 , 10 ;12 , 15 , 14 , 11 ] ;
%% Fi xed Nodes%fixnodes = [
1 , 2 , 0.00000 ;2 , 2 , 0.00000 ;
3 , 2 , 0.00000 ;13 , 1 , 0.00000 ;14 , 1 , 0.00000 ;15 , 1 , 0.00000 ] ;
%% Poi nt l oads%
pointload = [9 , 1 , -7071067.81200 ;9 , 2 , -7071067.81200 ] ;
%% Si de l oads%sideload = [ ];
Figure 36 Input data file for the NAFEMS IC6 benchmark problem.
27
7/27/2019 MAT FemIngles
28/29
As it is observed, the input data file contains all the sections described before, the
nodales coordinates (in sequence consecutive), the material properties, coordinates (in
sequence consecutive), the element connectivities, as well as the boundary conditions,
punctual loads and the uniform loads that are defined by an empty matrix.
The program execution is made trough MATLAB with the MAT-fem command. It ispossible to observe that the greater time consumption is in the stiffness matrix assembly
due to the storage system where the internal indices of the sparse matrix must be
updated. The total running time of this problem is about 0,15 seconds.
>> MATfemEnter the file name :cilQ2Time needed to read the input file 0.003399Time needed to set initial values 0.000912Time to assamble the global system 0.032041Time for apply side and point load 0.000196Time to solve the stifness matrix 0.026293
Time to solve the nodal stresses 0.024767Time used to write the solution 0.066823
Total running time 0.154431>>
Figure 37 MATLAB console for running the NAFEMS IC6 problem.
Some of the facilities given by MATLAB are shown in figure 38 where with the
spy(StifMat) command the profile of the stiffness matrix can be visualized. With the
aid of other command it is possible to know with detail the properties of this matrix, like
the eigenvectors, the rank, its determinant, etc.
Figure 38 Stiffness matrix profile.
In Figure 39 the deformed mesh is presented as well as the x distribution inside thearc.
28
7/27/2019 MAT FemIngles
29/29
Figure 39 Deformed mesh andx stress distribution
In the analyzed case the stress x in the A point reaches the value of 14,186 MPa farfrom the given solution, nevertheless, when the number of DOF are increased the target
solution is reached as it is shown in the table of the Figure 40 where the convergence of
the total displacement and the stress at the point is presented for triangles and
quadrilaterals structured meshes. The corresponding graph is in Figure 41.
TRIANGULOS CUATRILATEROS
NODOS DOF DESP x TR NODOS DOF DESP SQR x SQR
15 30 0,58607 7,8835E+06 15 30 0,80306 1,4186E+07
28 56 0,80865 9,8442E+06 28 56 1,30890 2,1405E+07
45 90 1,06980 1,2561E+07 45 90 1,79900 2,7571E+0766 132 1,34800 1,5697E+07 66 132 2,22210 3,2746E+07
120 240 1,88800 2,2193E+07 120 240 2,84280 4,0014E+07
231 462 2,54040 3,0504E+07 231 462 3,36800 4,5889E+07
1326 2652 3,73390 4,6827E+07 861 1722 3,91130 5,1518E+07
1891 3782 3,84840 4,8496E+07 1891 3782 4,03990 5,2669E+07
3321 6642 3,97260 5,0340E+07 3321 6642 4,09080 5,3056E+07
Figure 40 Convergence
1,00E+05
1,01E+07
2,01E+07
3,01E+07
4,01E+07
5,01E+07
6,01E+07
10 100 1000 10000
T
Q
Solucin : 53.2 MPa
Figure 41 Stress convergence
Top Related