Top Banner
F. Zárate, E. Oñate CIMNE 2007
29

F. Zárate, E. Oñate CIMNE 2007

Dec 29, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: F. Zárate, E. Oñate CIMNE 2007

F. Zárate, E. Oñate CIMNE 2007

Page 2: F. Zárate, E. Oñate CIMNE 2007

Index:

Introduction 3 Data files 4 MAT-fem 7 Start 7 Elemental stiffness matrix and it assemble 8 Details about the stiffness matrix 10 External loads 13 Fixed displacements 14 Solution of the equation system 14 Reactions 15 Stresses 15 Writing for Postprocessing 15 About the stress calculus 16 Graphical User Interface 21 Process 24 Postprocess 24

Example 25

2

Page 3: F. Zárate, E. Oñate CIMNE 2007

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 the algorithms 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 transparent task 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

Page 4: F. Zárate, E. Oñate CIMNE 2007

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 ejecución de un programa de Elementos Finitos, siguiendo, si se desea, paso a paso cada una de las líneas del código, al tiempo que es posible realzar ejemplos que por sus dimensiones caerían 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 the boundary 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 (pstrs = 1) or plane strain (pstrs = 0). young contains the elasticity modulus and poiss the Poisson’s coefficient. thick and denss 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

Page 5: F. Zárate, E. Oñate CIMNE 2007

It is important to observmechanisms, reason why(0 <= poiss < 0.5) ThFEM algorithm. The variables group thaglobal variables to be acdefinition of the coordinand elements.

coordinates is a matrixproblem (dimension of nnodes used in the discrethat keeps their coordinposition 123 in coordina The variable elements drows as number of elennode). In the case of de

% % Material Properties% pstrs = 1; young = 1000.0; poiss = 0.2; thick = 0.1; denss = 1.0;

Figure 1: Input data file: Material definition.

e at this moment that the program is free of data validation any value will not be verify like the Poisson’s coefficient rank e main reason is that this kind of details would hide core of the

t describes the problem topology is defined with the attribute of cessible inside the code by any subroutine. Figure 2 shows the ates and connectivities by means of the variables coordinates

wptiat

emfi

% % Coordinates % global coordinates coordinates = [ 0.00 , 0.00; 0.50 , 0.00; 2.00 , 1.00; 2.50 , 1.00 ]; % % Elements % global elements elements = [ 1, 2, 7 ; 2, 3, 8 ; 17, 16, 11 ; 18, 17, 12 ];

Figure 2: Input data file: topological definition

ith as many rows as nodes and columns as dimensions of the nod x 2). This variable describes the coordinates of all the zation. The number of any node corresponds to the position tes in the defined matrix. I.e. node number 123 keeps the es

fines the number of elements and its connectivities. So many ents and columns as nodes have each element (nelem x ning triangular elements it have three columns and four in the

5

Page 6: F. Zárate, E. Oñate CIMNE 2007

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

% % Fixed Nodes % fixnodes = [ 1, 1, 0.0 ; 1, 2, 0.0 ; 13, 1, 0.0 ; 13, 2, 0.0 ]; % % Point loads % pointload = [ 6, 2, -1.0 ; 18, 2, -1.0 ]; % % Side loads % sideload = [ 11,12, 2.0, 3.0; 14,15, 2.0, 3.0 ];

The variable fixnodes corresponds to the degrees of freedom (DOF) restricted in agreement with the problem to solve. fixnodes is a matrix where the number of rows corresponds 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 and 2 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 pointload 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 pointload is defined as an empty matrix by means of the command pointload = []; Finally the variable sideload 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. sideload 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 and y respectively. If there is no uniform loads sideload must be defined as an empty matrix by means of the command sideload = []; The name of the data file is up to the user; nevertheless, the extension must be .m in order that MATLAB can recognize it.

6

Page 7: F. Zárate, E. Oñate CIMNE 2007

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 is defined 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 system’s 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 reactions R = Ka - f

Compute smoothed stresses at nodes

Write results for GiD

Assembling of K(e) and f(e)

Function TrStif for triangles Function QdStinf for quadrilaterals

Function Stress: Call function TrStrs for triangles

Call function QsStrs for quadrilaterals

Compute D Function constt

Loop over elements

Function ToGiD

End

7

Page 8: F. Zárate, E. Oñate CIMNE 2007

Start

AT-fem begins cleaning all the variables with the clear 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 timing routine is used to calculate the run time between

Muser 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 the variables boot as well as the clock set up, storing in the variable ttim the total time of execution.

%% MAT-fem

ry and variables.

me = input('Enter the file name :','s');

me counter

,1); % Number of nodes OF

lement

% Clear memo%

clear file_na

tic; % Start clock

ttim = 0; % Initialize ti eval (file_name); % Read input file Finds basics dimentions %

npnod = size(coordinates nndof = 2*npnod; % Number of total D nelem = size(elements,1); % Number of elements

e nnode = size(elements,2); % Number of nodes per neleq = nnode*2; % Number of DOF per element 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 coordinates matrix. The number of total degrees of freedom of the program nndof will be twice the previous amount (2*npnod). nelem corresponds to the number of read elements and is the number of lines contained in the matrix elements 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. Tnnode multiplied by the number of DOF for each node: two in the case of bidimensional problems. Itdefined in the data structure, nevertheless, their definition simplify the code interpretation. Ttwo points in the code. In this way the user can observe the program’s subroutine that requires higher computational effort. Inside timing the tic and toc MATLAB commands are used.

8

Page 9: F. Zárate, E. Oñate CIMNE 2007

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 program’s main purpose is to demonstrate the implementation of the FEM

he subroutine constt starts with the Young’s modulus, the Poisson’s 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

Tequivalent nodales forces vector as a sparse matrix and vector. MAT-fem uses sparse matrices to optimize the memory using the MATLAB’s tools. On this way and without additional effort MAT-fem makes use of very powerful algorithms without losing the writing simplicity.

% Dimension the global matrices. ); % The global stiffness matrix StifMat = sparse ( nndof , nndof

force = sparse ( nndof , 1 ); % The global force vector Material properties (Constant over the domain). %

dmat = constt(young,poiss,pstrs);

Ssome 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. Tflag 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 constt 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];

Plane Sress %

if (pstrs==1) aux1 = youn aux2 = poiss*aux1;

oiss); aux3 = young/2/(1+p% Plane Strain else

ux1 = you a aux2 = aux1*poiss/(1-poiss); aux3 = young/2/(1+poiss); thick= 1.0; end

= D

iv

Incomputer’s speed makes this without reduction of the program efficiency. In addition, it allows having more memory to attack greater problems. Fstiffness matrix and the equivalent nodal load vector for each element. The cycle begins recovering the geometric properties of each element. In the vector lnods the element’s nodal connectivity are stored and in the coord matrix the coordinates from these nodes

9

Page 10: F. Zárate, E. Oñate CIMNE 2007

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 to neleq (number of equations

etails about the stiffness matrix

this program two finite elements are used the triangular whose stiffness matrix is

% Element cycle. elem

ies % conectivities

gle

he equation number list for the i-th element r the list

on

eqnum(j)) + ...

End element cicle

for ielem = 1 : n Recover element propert%

lnods = elements(ielem,:); coord(1:nnode,:) = coordinates(lnods(1:nnode),:); % coordinates Evaluates the elemental stiffnes matrix and mass force vector. %

if (nnode == 3) or] = TrStif(coord,dmat ,thick,denss); % Trian [ElemMat,ElemF

else mMat,ElemFor] = QdStif(coord,dmat ,thick,denss); % Quad. [Ele

end Finds t%

eqnum = []; % Clea for i =1 : nnode % Node cicle

quati eqnum = [eqnum,lnods(i)*2-1,lnods(i)*2]; % Build the e end % number list Assamble the force vector and the stiffnes matrix %

for i = 1 : neleq = force(eqnum(i)) + ElemFor(i); force(eqnum(i))

for j = 1 : neleq ),eqnum(j)) = StifMat(eqnum(i), StifMat(eqnum(i

ElemMat(i,j); end end end %

atrix evaluation a

Insubroutine TrStif is called for triangular elements and QdStif 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. Bequations 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 by each degree of freedom). Tin 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

Page 11: F. Zárate, E. Oñate CIMNE 2007

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: ElemMat for the stiffness matrix and ElemFor for the nodal equivalent mass load vector. The TrStif 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 equally 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)/area2 and c(i)/area2) in the corresponding position of the deformation matrix, without forgetting the common factor 1/area2. T B DBdA. In this line one of the fundamental advantages of MATLAB is observed where the multiplication of matrices is direct with no need to write troublesome cycles. Tthe element in each node (force). 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 ; % Explicit form for matrix B

mat*bmat)*area*thick; % Elemental stiffnes matrix

ce]; % Elemental force vector

b(1) = nodes(2,2) - nodes(3,2); % bi = yj - y

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

0 ,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)*d

force = area*denss*thick/3;

F = [0,-force,0,-force,0,-for

Fnumerical integration. Initially the element’s function forms and its natural derivatives are defined (fform and deriv). 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 vector fy is made on this section. In figure 10 this routine is observed with detail.

11

Page 12: F. Zárate, E. Oñate CIMNE 2007

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 element’s area

o finalize the routine in the F vector all the nodal forces are properly placed having in

axes. The lcffm vector contains the values of the function form evaluated at the integration point i, j and the lcder matrix stores the values for the natural derivative of these functions at the same integration point. The Jacobian matrix (xcjacm) is evaluated by the simple multiplication of the lcder matrix by the nodales coordinates of the element. The value of the Cartesian derivates (ctder) in the integration point is obtained 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 ];

2 orm(pospg(i),pospg(j)) ; % FF at gauss point

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+s

deriv = @(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+0

pespg = [ 1.0E+00 , 1.0E+00]; M = zeros(8,8);

fy = zeros(1,4);

or i=1 : 2 f for j=1 : lcffm = ff lcder = deriv(pospg(i),pospg(j)) ; % FF Local derivative xjacm = lcder*nodes ; % Jacobian matrix

ivates ctder = xjacm\lcder ; % FF Cartesian 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

= M M

y = fy + lcffm*denss*darea; f end end

F = [

Tfunction 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 Tmultiply the function form by the element density. T

12

Page 13: F. Zárate, E. Oñate CIMNE 2007

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 Bsides of the elements and punctual loads in the nodes. Snodal 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 sideload. The nodal contribution is evaluated equality on each node (due the linear function form). Onecessary to make any rotation or transformation.

% Add side forces to the force vector

dinates(sideload(i,2),:); node

de

for i = 1 : size(sideload,1) ),:)-coor x=coordinates(sideload(i,1

l = sqrt(x*transpose(x)); % Finds the lenght of the side ieqn = sideload(i,1)*2; % Finds eq. number for the first force(ieqn-1) = force(ieqn-1) + l*sideload(i,3)/2; % add x force force(ieqn ) = force(ieqn ) + l*sideload(i,4)/2; % add y force ieqn = sideload(i,2)*2; % Finds eq. number for the second no

force(ieqn-1) = force(ieqn-1) + l*sideload(i,3)/2; % add x force force(ieqn ) = force(ieqn ) + l*sideload(i,4)/2; % add y force end

Fequivalent 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 point loads conditions to the force vector

% Finds eq. number for i = 1 : size(pointload,1)

+ pointload(i,2); ieqn = (pointload(i,1)-1)*2 force(ieqn) = force(ieqn) + pointload(i,3); % add the force end

13

Page 14: F. Zárate, E. Oñate CIMNE 2007

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 fixnodes matrix are assigned to the u vector. Also the fix vector is defined to keep the equation numbers of the restricted DOF. Finally the force vector is updated with the product of the StifMat matrix ant the u vector which at this moment contains only the values of those degrees of freedom which have been restricted.

% Applies the Dirichlet co u = sparse ( nndof, 1 );

nditions and adjust the right hand side.

for i = 1 : size(fixnodes,1) ieqn = (fixnodes(i,1)-1)*2 + fixnodes(i,2); %Finds the equation number u(ieqn) = fixnodes(i,3); %and store the solution in u fix(i) = ieqn; % and mark the eq as a fix value end force = force - StifMat * u; % adjust the rhs with the known values

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 FreeNodes vector contains the list of the equations to solve. The FreeNodes 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.

% Compute the solution by solving StifMat * u = force for the % remaining unknown values of u. FreeNodes = setdiff ( 1:nndof, fix ); % Finds the free node list and % solve for it. u(FreeNodes) = StifMat(FreeNodes,FreeNodes) \ force(FreeNodes);

Figure 14: Solution of the equation system.

14

Page 15: F. Zárate, E. Oñate CIMNE 2007

Reactions The solution to the equations system is in the u vector, therefore the reaction calculus is made by means of the expression R = StifMat*u - force. It is obvious that the value of the reaction in those prescribed nodes is not null. In order to avoid unnecessary calculations we use the vector fix which contains the list of the equations associated to the fixed DOF as it is shown in Figure 15.

% Compute the reactions on the fixed nodes as a R = StifMat * u - F reaction = 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 Strnod matrix.

% Compute the stresses Strnod = 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 subroutine ToGiD shown in Figure 17

% Graphic representation. 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

Page 16: F. Zárate, E. Oñate CIMNE 2007

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 element’s functions form. Figure 18 presents the initial part of the stress subroutine were the input data are the material constitutive matrix dmat, Poisson’s coefficient poiss, the thickness thick, 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 nelem to 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 and γxy) and plane strain (σx, σy, σz and γxy) were σz is a function of σx and σy The nododstr 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) %% Stress Evaluates the stresses at the gauss point and smooth the values % to the nodes. % global coordinates; global elements; nelem = size(elements,1); % Number of elements nnode = size(elements,2); % Number of nodes per element npnod = size(coordinates,1); % Number of nodes if (pstrs==1) nstrs= 3; % Number of Strs. Sx Sy Txy else nstrs= 4; % Number of Strs. Sx Sy Sz Txy end nodstr = zeros(npnod,nstrs+1);

Figure 18: Variables boot for stress calculus...

16

Page 17: F. Zárate, E. Oñate CIMNE 2007

Like in the stiffness matrix, the stress evaluation requires a loop over the elements, recovering the element’s connectivities (lnods), coordinates for these nodes (coord) as well as the displacements in displ as it is shown in Figure 19

for ielem = 1 : nelem % Recover element properties lnods = elements(ielem,:); coord(1:nnode,:) = coordinates(lnods(1:nnode),:); eqnum = []; for i =1 : nnode eqnum = [eqnum,lnods(i)*2-1,lnods(i)*2]; end displ = 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 ElemStr vector that contains the stresses in the element; these values are accumulated in the nodstr 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 ElemStr variable represents a matrix that contains the stresses of each one of the element’s 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 nodstr a nodal mean is made to obtain a smoothed stress field at the nodes.

% Stresses insid if (nnode == 3)

e the elements.

% Triangular elements constant stress ElemStr = TrStrs(coord,dmat,displ,poiss,thick,pstrs); for j=1 : nstrs nodstr(lnods,j) = nodstr(lnods,j) + ElemStr(j); end nodstr(lnods,nstrs+1) = nodstr(lnods,nstrs+1) + 1; else % Quadrilateral elements stress at nodes ElemStr = QdStrs(coord,dmat,displ,poiss,thick,pstrs); for j=1 : 4 for i = 1 : nstrs nodstr(lnods(j),i) = nodstr(lnods(j),i) + ElemStr(i,j); end end nodstr(lnods,nstrs+1) = nodstr(lnods,nstrs+1) + 1; end end % Find the mean stress value S = []; for i = 1 : npnod S = [S ; nodstr(i,1:nstrs)/nodstr(i,nstrs+1)]; end

Figure 20: Stress calculus and nodal smooth.

17

Page 18: F. Zárate, E. Oñate CIMNE 2007

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*displ)/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 = -poiss*(σx + σy) ) as it is shown in Figure 22.

% Plane Sress if (pstrs==1) S = se ; % Plane Strain else 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

Page 19: F. Zárate, E. Oñate CIMNE 2007

3

2 4

1

3

1 2

b) a)

σi

σjσqσp

i p q

j

4

+1-1

Figure 23: Stress extrapolation

These considerations are part of the code shown in Figure 24 where the deformation matrix B is calculated and the stresses are extrapolated to the nodes of the element.

function S = QdStif (nodes,dmat,displ,poiss,thick,pstrs) fform = @(s,t)[(1-s-t+s*t)/4,(1+s-t-s*t)/4,(1+s+t+s*t)/4,(1-s+t-s*t)/4]; deriv = @(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+00 ]; pespg = [ 1.0E+00 , 1.0E+00]; strsg = []; extrap = []; order = [ 1 , 4 ; 2 , 3 ]; % Align the g-pts. with the element corners for i=1 : 2 for j=1 : 2 lcder = deriv(pospg(i),pospg(j)) ; % FF Local derivatives ctder = xjacm\lcder ; % FF Cartesian derivates

xjacm = lcder*nodes ; % Jacobian matrix

bmat = []; for inode = 1 : 4 bmat = [ bmat , [ctder(1,inode), 0 ; 0 ,ctder(2,inode); ctder(2,inode),ctder(1,inode) ] ] ; end strsg(:,order(i,j)) = (dmat*bmat*displ) ; a = 1/pospg(i); b = 1/pospg(j); extrap(order(i,j),:) = fform(a,b) ; end end se = transpose(extrap*transpose(strsg));

Figure 23: Stress extrapolation code

19

Page 20: F. Zárate, E. Oñate CIMNE 2007

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

% Plane Sress if (pstrs==1) S = se ; % Plane Strain else S = [se(1,:) ; se(2,:) ; -poiss*(se(1,:)+se(2,:)) ; se(3,:)]; end

Figure 24: Stress calculus for plane stress or strain problem

20

Page 21: F. Zárate, E. Oñate CIMNE 2007

Graphical User Interface In this section the Graphical User Interface (GUI) implemented in GiD is reviewed with detail. In order to accede to GUI is necessary to select from the DATA menu in the option PROBLEM TYPE the module corresponding to MAT-fem. When selected, the image shown in Figure 25 will appear. All the GiD characteristics are part of the MAT-fem module: geometry generation, import and handling, as well as the discretización techniques provide to MAT-fem capacities difficult to surpass for an educative code.

Figure 24: MAT-fem GUI Start up. There is a lot of GiD information available in Internet; we recommended visiting the GiD’s main page in www.gidhome.com. However, solving a problem with MAT.-fem is a very simply thing once the geometry have been defined. Just follow the icons of the MAT-fem’s graphical menu

The first button is for identify those geometric elements that present movements restriction. When pressing on, an emergent window (Figure 25) will appear to

select the nodes or lines were the displacements are restricted. The check boxes identify the fixed direction. Also it is possible to give a non-zero value to constrain.

Figure 25: Fixed movement condition.

21

Page 22: F. Zárate, E. Oñate CIMNE 2007

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 geometry’s 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 Young’s modulus, the Poisson’s 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

Page 23: F. Zárate, E. Oñate CIMNE 2007

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 GiD’s 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

Page 24: F. Zárate, E. Oñate CIMNE 2007

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 GiD’s 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

Page 25: F. Zárate, E. Oñate CIMNE 2007

Figure 32 Beam postprocess. Example. The example below is presented to show the program’s 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 NAFEMS’S 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 the stress σx at the point A. The exact value is σx = 53.2MPa

25

Page 26: F. Zárate, E. Oñate CIMNE 2007

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

Page 27: F. Zárate, E. Oñate CIMNE 2007

%======================================================================= % MAT-fem 1.0 - MAT-fem is a learning tool for understanding % the Finite Element Method with MATLAB and GiD %======================================================================= % PROBLEM TITLE = NAFEMS IC6 % Material Properties % young = 210103000.00000 ; poiss = 0.30000 ; denss = 0.00 ; pstrs = 0 ; thick = 1 ; % % Coordinates % global coordinates coordinates = [ 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 ] ; % % Elements % 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 ] ; % % Fixed 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 ] ; % % Point loads % pointload = [ 9 , 1 , -7071067.81200 ; 9 , 2 , -7071067.81200 ] ; % % Side loads % sideload = [ ];

Figure 36 Input data file for the NAFEMS IC6 benchmark problem.

27

Page 28: F. Zárate, E. Oñate CIMNE 2007

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 is possible 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.

>> MATfem Enter the file name :cilQ2 Time needed to read the input file 0.003399 Time needed to set initial values 0.000912 Time to assamble the global system 0.032041 Time for apply side and point load 0.000196 Time to solve the stifness matrix 0.026293 Time to solve the nodal stresses 0.024767 Time 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 the arc.

28

Page 29: F. Zárate, E. Oñate CIMNE 2007

Figure 39 Deformed mesh and σx stress distribution

In the analyzed case the stress σx in the A point reaches the value of 14,186 MPa far from 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+07

66 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

Solución : 53.2 MPa

Figure 41 Stress convergence

29