Professional Documents
Culture Documents
FE - Lectures2019 - 20 - Part 2 - 2 PDF
FE - Lectures2019 - 20 - Part 2 - 2 PDF
FE - Lectures2019 - 20 - Part 2 - 2 PDF
E A 1 1
kb (5.1)
Le 1 1
L1 L2 L3
E is constant
1 2 3 A is constant
1 2 3 4
Every element connected to a node contributes to the stiffness of that node; thus, node 1 has a
contribution from only element 1, whereas node 2 has contributions from both elements 1 and 2 etc.
P1 u1
P u
2 K bg 2
P3 u3
P4 u 4
1 1
L 0 0
L1
1
1 1 1
L
L1 L 2
EA
1
K bg
73
5.2 ASSEMBLING THE GLOBAL STIFFNESS MATRIX FOR CONTINUUM ELEMENTS
Each element stiffness matrix is set up as a local matrix, of size 8x8 in the present case, and an algorithm
is required to assemble the global matrix. Before explaining the algorithm, the assembly process for the
2 element mesh shown below is illustrated in a set of diagrams
2 4 6
1 3 5
74
Element assembly illustrated
_______________________________________________________________________________
Stiffness matrix for element 1
75
EXERCISE 5.2. Exercise on linking local and global degrees of freedom
The link between global and local nodes is provided by the array topo
In the present case
If we loop over the nodes of an element iel i.e. for in=1:nn, then the global node number is
given by topo(iel,in)
Each node has two degrees of freedom id=1:2 OR id=1:nd (1 being associated with the x-direction
and 2 the y-direction)
If we have a list of global displacements (ug) , complete the section of Matlab code that extracts the
the element displacements (ue) from the list, assuming that the value of iel (the element number)
has already been set.
for in=1:nn
for id=1:nd
ie=
ig=
ue(ie)=ug(ig)
end
end
76
EXERCISE 5.3. ALGORITHM FOR ASSEMBLING GLOBAL STIFFNESS MATRIX
function Kg=Kgmatx(nel,ntv,nn,nd,nev,ng,topo,xy,D,t)
end
end
end
end
77
5.3 BOUNDARY CONDITIONS
The global stiffness matrix when assembled is singular because it represents an unrestrained structure
with free body motions. This is readily illustrated for the case of two bar elements.
Hence det(K)=0
Sufficient restraints are always needed to prevent all rigid body translations and rotations. For a 2D
continuous body (with no internal hinges) this means either 2 x-restraints and 1 y-restraint or 2 y-
restraints and 1 x-restraint, the former case being illustrated below.
x fixed
x & y fixed
A convenient way to apply these is to modify the row and column of the assembled stiffness matrix before
solving by making all elements of these row and columns zero, except for the diagonal element associated
with the restrained degrees of freedom. Then the right hand side is modified so it equals the Kdiagures for
the fixed degrees of freedom (rows) and for other rows the appropriate Kijures terms have to be subtracted
from the r.h.s.. Once the solution is complete, the reaction at a fixed degree of freedom may be calculated
by multiplying the row of the original stiffness matrix, associated with that degree of freedom, with the
newly computed displacement vector.
The steps are illustrated for the two element problem of section 5.2 with the restraints shown below.
1 3 5
The modified stiffness matrix and load vector are illustrated below, in which, for example, ux1r denotes
the restrained value of the x displacement at node 1, which here is 0.
78
Modified stiffness and rhs vector. Note only non-zero components in original matrix shown
Restrained degrees of freedom.
1 1 3 Node
x y y Components
k1,1 0 0 0 0 0 0 0 0 0 0 0 u x1r k11u x1r
0 x 1
k 2, 2 0 0 0 0 0 0 0 0 0 0 u y1r k 22u y1r y 1
0 0 k 3,3 k 3, 4 k 3,5 0 k 3,7 k 3,8 0 0 0 0 u x 2 Px 2 k 3,1u x1r k 3, 2 u y1r k 3,6u y3 r
0 0 k 4,3 k 4, 4 k 4,5 0 k 4, 7 k 4,8 0 0 0 0 u y 2 Py 2 k 4,1u x1r k 4, 2 u y1r k 4,6u y3 r
0 0 k 5,3 k 5, 4 k 5,5 0 k 5,7 k 5,8 k 5,9 k 5,10 k 5,11 k 5,12 u x 3 Px 3 k 5,1u x1r k 5, 2 u y1r k 5,6u y3 r
0 0 0 0 0 k 6, 6 0 0 0 0 0 0 u y3 r k66u y3 r
y 3
0 0 k 7 ,3 k 7, 4 k 7 ,5 0 k 7,7 k 7,8 k 7 ,9 k 7,10 k 7,11 k 7,12 u x 4 Px 4 k 7,1u x1r k 7, 2 u y1r k 7,6u y3 r
0 0 k 8,3 k 8, 4 k 8,5 0 k 8,7 k 8,8 k 8,9 k 8,10 k 8,11 k 8,12 u y 4 Py 4 k 8,1u x1r k 8, 2 u y1r k 8,6u y3 r
0 0 0 0 k 9,5 0 k 9, 7 k 9,8 k 9,9 k 9,10 k 9,11 k 9,12 u x 5 Px 5 k 9,6u y3 r
0 0 0 0 k10,5 0 k10 ,7 k10,8 k10,9 k10,10 k10,11 k10 ,12 u y5 Py5 k10,6u y3 r
0 0 0 0 k11,5 0 k11,7 k11,8 k11,9 k11,10 k11,11 k11,12 u x 6 Px 6 k11,6u y3 r
0
0 0 0 k12,5 0 k12 ,7 k12,8 k12,9 k12,10 k12,11 k12 ,12 u y 6 Py 6 k12,6u y3 r
(5.4)
This may be expressed as
Kg u Pg (5.5)
mod mod
Note, it is important to retain the original stiffness matrix, because this is needed to compute the
reactions, thus the matrix should be copied to one with a different name before it is modified.
The final step, the computation of reactions is illustrated below. Here the displacement vector will
include the restrained (or prescribed) values.
Note: These operations are built into many solution routines and are carried out along with the reduction
of the equations.
79
EXERCISE 5.4. HOW THE RESTRAINTS ARE STORED
The restraints are stored in the following section of Matlab code, which has values set for the two
element problem shown below;
1 3 5
-------------------------------------------------------------------------------------------------------------------------------
Show how the fixity data would change if the restraints were altered to those shown below;
x and y restraint at nodes 1 and 3 with zero displacement
a 0.01mm prescribed displacement in the y direction at node 6
2 4 6
1 3 5
80
MATLAB WORKSHEET 5.
Part a
Develop a MATLAB program to compute the global stiffness matrix for a mesh of 4-noded finite elements
and compute the modified stiffness matrix and load vector required to apply fixities (prescribed
displacements).
The master script is similar to that used in Exercise 4 for the element stiffness matrix except that there
is now an element loop inside the function m-file that computes the global stiffness matrix. The program
should use the scripts already developed for the shape functions, D-matrix, B-matrix & Jacobian and Ke
matrices. These will need to be transferred into the folder you create for this week’s exercise.
Templates for the master, global stiffness matrix and boundary condition scripts are given below. Data
for the two element problem shown below are given in the code.
0.8x106
1 3 5
Part b
Modify your code such that it has the option to select a set of loads and boundary conditions that are
amenable to checking with a hand calculation. Undertake the check.
You will be asked to show your hand calculation.
81
%-------------------------------------------------------------------------
% First finite element program
%-------------------------------------------------------------------------
clear ; clc ; % Clear memory
%----------- Set integer constants
nn=4; nd=2; ns=3; ng=4;
%---------- Mesh data
% Set global data
nel=2 ; np=6; npl=2;
% Derived variables
ntv=np*nd; nev=nn*nd;
% Nodal coordinates
xy=[0.0 0.0 ;
0.0 200.0 ;
200.0 0.0 ;
200.0 200.0 ;
400.0 0.0 ;
400.0 200.0 ] ;
% Element topology
topo=[1 3 4 2 ;
3 5 6 4 ] ;
% Material properties and thickness
E=80000.0 ; nu=0.25; t=8.0;
% Set fixity arrays
nf=3; % No of restrained nodes
nof=[1 2 4]; % List of nodes with fixities
ifp(1:nf,1:nd)=[1 1; % 1st fixed node codes, x then y (1 fixed, 0 free)
1 0; % 2nd fixed node codes, x then y
0 1]; % 3rd fixed node codes, x then y
pre(1:nf,1:nd)=0.0; % Prescribed displacements
% Global load array
fxy(1:ntv)=0; % Initialise load array
fxy(9)=0.8e6; fxy(11)=1.0e6; % x force to nodes 5 & 6
% Compute D-matrix
D=dmatx(E,nu);
% Assemble the global stiffness matrix
Kg=Kgmatx(nel,ntv,nn,nd,nev,ng,topo,xy,D,t);
% Apply boundary conditions
[rhsm,Kgm]=BoundC(ntv,nd,nf,nof,ifp,pre,Kg,fxy);
% Solve equations
ug=Kgm\rhsm';
disp('Global displacements')
disp(ug)
82
function Kg=Kgmatx(nel,ntv,nn,nd,nev,ng,topo,xy,D,t)
% Form global stiffness matrix
% Loop elements and extract element stiffness matrix
Kg=zeros(ntv,ntv);
for iel=1:nel
% Extract element nodal coordinates
xyel(1:nn,1:nd)=xy(topo(iel,1:nn),1:nd);
% Compute the current element stiffness matrix
Ke=Ematx(nev,ng,xyel,D,t);
for in=1:nn
for id=1:nd
ie= ???
ig=???
for jn=1:nn
for jd=1:nd
je= ???
jg= ???
Kg(ig,jg)= ???
end
end
end
end
end
---------------------------------------------------------------------
function [rhsm,Kgm]=BoundC(ntv,nd,nf,nof,ifp,pre,Kg,fxy)
% Apply boundary conditions
rhsm=fxy; Kgm=Kg;
% Modify r.h.s. for fixed d.o.f, then zero associated row and column ;
% set diagonal term of fixed dof to original value and modify rhs
for iv=1:nf;
:
:
:
:
end
83
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
84
6. COMPUTING STRESSES. INPUT AND OUTPUT
6.1 COMPUTING STRESSES
EXERCISE 6.1. Write the equation for computing strains from the element nodal displacements (ue);
(6.1)
---------------------------------------------------------------------------------------------------------------------------------------
and the equation for computing stresses from the D-matrix and element nodal displacements (ue)
(6.2)
---------------------------------------------------------------------------------------------------------------------------------------
EXERCISE 6.2.
Write out the steps involved in computing stresses at the Gauss points
It is noted that there is much common between this algorithm and that for computing the element
stiffness matrix (Section 4.4)
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
85
6.2 Extrapolating stresses
In theory, the stresses could be computed anywhere in an element but it so happens that the most
accurate positions to compute stresses are at the Gaussian integration points for two and three
dimensional isoparametric elements (Hinton and Campbell, 1974)*. The reason for this is that the
displacement derivatives, and therefore stresses and strains, can be inaccurate near the boundaries of
elements; therefore, it is normal for stresses to be computed at the Gauss points, extrapolated to the
nodes and then averaged.
The extrapolation procedure involves local least squares smoothing. In this theory it is assumed that the
minimum error occurs when the integral of the weighted ‘smoothed’ stresses across the element matches
the integral of the local stresses across the element.
N1N1 det Jdd ... ... N1N 4 det Jdd 1 N1 det Jdd
n gp
:
: :
: (6.5)
: : : :
n
N 4 N1 det Jdd ... ... N 4 N 4 det Jdd 4 N 4 gp det Jdd
If detJ does not vary across an element, as is the case when 4-noded elements are rectangles or regular
parallelograms, then detJ may be cancelled out of the equations. The integrals and inversion are then
independent of the element size which means that these only have to be undertaken once. This leads to
the following matrix equation;
n1 3 1 3 1 gp1
1 1
2 2 2 2
n 1 3 1 3 gp
2 1 1 2
2 2 2 2 (6.6)
3 1 3 1
n 3 1 1 gp3
2 2 2 2
1 3 1 3
n 1 1 gp
4 2 2 2 2 4
in which gp1 is a stress component at gauss point (e.g. xx@gp1) and n1 is a nodal stress component
(e.g. xx@node1). The matrix equations are solved for all required stress components.
* For quadratic elements it is the points of a reduced integration rule that prove the optimum locations
86
EXERCISE 6.3.
For the two element problem illustrated below, the stresses at the gauss points of element 1 are those
given below;
gp4 gp3
gp1 gp2
Complete the equation below that gives the extrapolated xx-stresses for element 1 at local nodes
1,2,3,4 which correspond with global nodes 1,3,4,2 respectively
1 1 807.653
227.615 1 3 1
3
2 2 2 2
83.496 1 3 1 3
1 1 724.446
2 2 2 2
2972.385 1 3 1 3 1
1 2392.347
2 2 2 2
________
2475.554
1 3 1 3
1 1
2 2 2 2
87
6.3 PREPROCESSING AND DATA INPUT
Thus far, the data required by the MATLAB finite element program has been included in the main script.
However, it is advantageous to be able to prepare the data separately in a text file and then for the
MATLAB program to read that file. This opens the possibility of another program, a pre-processor, being
used to prepare the data.
Data for nearly all commercial finite element analyses are prepared with pre-processors, which are often
integrated with the solution and post-processing routines (see 6.4). There are a number third party pre and
post processors available, that may be linked with a user defined program e.g. http://gid.cimne.upc.es/
Plotting a mesh is essential when finding errors, and therefore a mesh plotter will be developed as part of
the developed program.
88
6.3.1 Form of data file
The structure of the data to be entered is as follows; which serves as a manual for the preparation of the data file.
Line 1 Title
Title: Up to 70 alphanumeric characters including spaces (don’t forget this title line)
89
Example data file
File Explanation
Example finite element data file Title
6 2 2 2 Control data
1 1 3 4 2 Topology (2 elements)
2 3 5 6 4
1 0.0 0.0 Node coordinates (6 nodes)
2 0.0 200.0
3 200.0 0.0
4 200.0 200.0
5 400.0 0.0
6 400.0 200.0
200000.0 0.3 10.0 Material data
1 1 1 0.0 0.0 Fixed node data (2 fixed nodes)
2 1 0 0.0 0.0
5 1.0e6 0.0 Nodal forces (2 loaded nodes)
6 1.5e6 0.0
y
450
400
300
Element number
250
200 2 4 6 1.5x106
150
100 1 2
50
0 1 3 5 1.0x106
-50 x
-50 0 50 100 150 200 250 300 350 400 450
Note:
Element topology: Node numbers should be in an anticlockwise order
90
6.4 RESULTS OUTPUT AND POST-PROCESSING
In any programming it is important to arrange the output in a logical and easy to read format. In the case
of a finite element program, the output file should contain a record of the input data, the nodal
displacements, reactions, gauss point and/or nodal stresses and, for nonlinear problems, state variables at
the same locations as the stresses (e.g. plastic strains). The amount of output arising from a full-scale finite
element analysis is too great to be printed and such output does not provide a cogent description of the
results. Thus, the results are post-processed and results presented graphically. An example from such
output was shown in Lecture 2. Other common features include the ability to plot graphs of variables at a
chosen range of points (nodes or gauss points). A limited post-processor will be included in the program
developed.
In the present case, relatively small meshes will be used and therefore output files will not be too great to
be comprehended in printed form. An example of the output from the program developed is given overleaf.
91
Output from a different two element problem from that given in the previous data file.
_______________________________________________________________________________
Title : Two Element problem
Control data
Number of nodal points = 6
Number of elements = 2
Number of fixed nodes = 3
Number of loaded nodes = 1
Elem Nodes
1 1 2 5 4
2 2 3 6 5
Node Coords
1 0.000 0.000
2 85.000 0.000
3 170.000 0.000
4 0.000 100.000
5 85.000 100.000
6 170.000 100.000
Material properties
Young Poiss Thick
10000.00 0.200 10.000
Node Px Py
6 3000.00 2000.00
Results
Element stresses
Elem G.P. x-coord y-coord xx-stres yy-stres xy-stres princ1 princ2
1 1 17.963 21.132 0.423 1.148 1.036 1.883 -0.312
1 2 67.037 21.132 0.311 0.588 1.224 1.681 -0.782
1 3 67.037 78.868 0.863 0.698 0.960 1.744 -0.183
1 4 17.963 78.868 0.975 1.258 0.773 1.902 0.331
2 1 102.963 21.132 1.201 0.802 1.872 2.884 -0.881
2 2 152.037 21.132 1.333 1.466 2.878 4.279 -1.479
2 3 152.037 78.868 4.293 2.058 3.191 6.557 -0.205
2 4 102.963 78.868 4.161 1.394 2.184 5.363 0.192
_______________________________________________________________________________
92
MATLAB WORKSHEET 6
ASSESSED EXERCISE
Two optional extra pieces of work, which do not carry any marks, are;
a) Work out how to use the same plotting function to display an exaggerated deformed mesh.
b) Implement the stress extrapolation method (this may be quite difficult).
CANTILEVER PROBLEM
Prepare a data file for the cantilever mesh shown below and check how close the answers are to those
from beam theory. Note, the data given are dimensionless and it is up to the user to use a consistent set
of units. Here the values are consistent with N,mm units
Thickness = 50
E = 100 000
1200 = 0.25
Applied end moment
= 20x106
200
93
NOTES ON STRESS COMPUTATION M-FILE.
The algorithm for this function m-file is provided in section 6.1. Many of the steps are common to
the element stiffness matrix m-file. It is necessary now to extract not only the element coordinates
but also the element nodal displacements. There is a loop over all elements and then a loop over the
gauss points within an element. There is a variable which denotes the total gauss point number called
lgp, noting that lgp will finally be equal to nel*ng. The gauss point stress array records the three
Cartesian components and the two principal stress components for each gauss point (lgp) and is thus
a 5 x lgp array.
ifile and ofile then contain numbers which may be used to say which file is being read from or
written to, respectively. It will be necessary for you to change the path to that for your data and
output files.
The ‘wt’ in the 2nd fopen commands indicates that the file will be written to only in text format. If
this parameter is omitted the file may be read from or written to.
C = textscan(fid, 'format', N)
94
An example from the input file that reads the coordinate data is as follows (with print commands
omitted);
for i=1:np;
lcoord=textscan(ifile,'%d %f %f',1);
ip=lcoord{1}; xy(i,1)=lcoord{2}; xy(i,2)=lcoord{3};
end
This will read each line of the coordinate data e.g.
1 0.0 0.0
2 0.0 200.0
3 200.0 0.0
There is a loop over the number of points and then for each point the whole line is read into
lcoord which will then contain 3 cells, the first with an integer number (node number) and the
next two with floating point (or real) numbers (the x and y coordinates of that point)
The cells are then converted to the appropriate variables ip, xy(i,1) and xy(i,2), using curly
brackets. Note that here, i=ip.
General
Look up the syntax of all of these commands using MATLAB help
95
Template for stress calculation function m-file
function [sig,xygp]=Stresses(ns,nd,ng,nn,nev,nel,xy,topo,ug,D)
% Initialise stress and gauss point coordinate arrays
sig(1:nd+ns,1:nel*ng)=0.0;
xygp(1:nd, 1:nel*ng)=0.0;
ue(1:nev)=0.0;
% Set gauss point positions
c=0.577350269189626;
pgp=[-c -c ; c -c ; c c ; -c c] ;
% Initialise global gauss point counter
lgp=0;
% Loop over all elements
for iel=1:nel
% Extract element nodal coordinates
Missing code
% Extract element nodal displacements
Missing code
% Loop over gauss points
for ig=1:ng
lgp=lgp+1;
Missing code
:
:
stn= ??? % Cartesian strains
str=??? % Cartesian stresses
[prs,~] = ??? % Principal stresses
sig(1:ns,lgp)=str(1:ns); % Record stresses global array
sig(ns+1:ns+nd,lgp)=prs; % Record princ stresses in global array
xygp(:,lgp)=shp*xyel; % Compute Gauss point coordinates
end
end
96
Function m-file for reading input data
Function [nd,ns,nn,nev,ng,nel,np,nf,ntv,ngt,topo, …
xy,E,nu,t,xylim,nof,ifp,pre,fxy,ofile]=Readat
%-------------------------------------------------------------------------
% Read and echo data and set key control variables
%-------------------------------------------------------------------------
% Set number of dimensions, nodes per element etc.
nd=2; ns=3; nn=4; nev=nn*nd; ng=4;
% Set path to data file
name=input('input mesh file name (no extension, data should in *.dat)--> ','s');
iname=strcat('Data\',name,'.dat'); % Input file should have an extension .dat
oname=strcat('Data\',name,'.out'); % Output file should have an extension .out
ifile=fopen(iname);
ofile=fopen(oname,'wt');
% ofile=1 ; % Write to screen option
% Read title
mtitle=textscan(ifile,'%s',1,'endofline','\r\n','delimiter','\r\n');
fprintf(ofile,'Title : '); titl=char(mtitle{1}); fprintf(ofile,'%s',titl);
% Read control parameters
nin=textscan(ifile,'%d %d %d %d ',1);
np=nin{1}; nel=nin{2}; nf=nin{3}; npl=nin{4};
fprintf(ofile,'\n\nControl data \n');
fprintf(ofile,'Number of nodal points = %4i\n',np);
fprintf(ofile,'Number of elements = %4i\n',nel);
fprintf(ofile,'Number of fixed nodes = %4i\n',nf);
fprintf(ofile,'Number of loaded nodes = %4i\n',npl);
ntv=np*nd; % Total number of degrees of freedom
ngt=nel*ng; % Total number of gauss points in total mesh
% Initialise various arrays
topo=zeros(nel,nn); xy=zeros(np,nd); xylim(1:4)=0.0; fxy(1:ntv)=0.0;
nof(1:nf)=0.0 ; ifp=zeros(nf,nd) ; pre=zeros(nf,nd) ;
% Read and echo element topology
fprintf(ofile,'\nElem Nodes\n');
for iel=1:nel
Ctopo=textscan(ifile,'%d %d %d %d %d',1);
jel=Ctopo{1} ;
for in=1:nn
topo(jel,in)=Ctopo{in+1};
end
fprintf(ofile,'%3i %8i %4i %4i %4i\n', iel, topo(iel,:));
end
% Read coordinates
fprintf(ofile,'\nNode Coords\n');
for i=1:np;
lcoord=textscan(ifile,'%d %f %f',1);
ip=lcoord{1}; xy(i,1)=lcoord{2}; xy(i,2)=lcoord{3};
fprintf(ofile,'%3i %8.3f %8.3f\n', ip,xy(i,:) );
end
% Set max and min coords
xylim=[min(xy(:,1)) min(xy(:,2)) max(xy(:,1)) max(xy(:,2))];
% Material properties
fprintf(ofile,'\nMaterial properties\n');
fprintf(ofile,'Young Poiss Thick\n');
lmat=textscan(ifile,'%f %f %f',1);
E=lmat{1} ; nu=lmat{2} ; t=lmat{3};
fprintf(ofile,'%9.2f %4.3f %8.3f\n',E,nu,t) ;
% fixed and prescribed nodes, first initialising arrays
fprintf(ofile,'\nNode Codes Prescribed values\n');
for i=1:nf;
lfx=textscan(ifile,'%d %d %d %f %f',1);
nof(i)=lfx{1} ;
ifp(i,1)=lfx{2} ; ifp(i,2)=lfx{3};
pre(i,1)=lfx{4} ; pre(i,2)=lfx{5};
97
fprintf(ofile,'%3i %2i %2i %8.5f %8.5f \n', ...
nof(i),ifp(i,1:nd),pre(i,1:nd));
end
% Read nodal loads and put them in the force array
fprintf(ofile,'\nNode Px Py\n');
for i=1:npl;
lpt=textscan(ifile,'%d %f %f',1);
ip=lpt{1} ; ipx=(ip-1)*nd+1 ; ipy=ipx+1 ;
fxy(ipx) = lpt{2} ; fxy(ipy)=lpt{3};
fprintf(ofile,'%3i %9.2f %9.2f\n',ip,fxy(ipx:ipy));
end
________________________________________________________________________________
98
Function mfile for writing results to output file
________________________________________________________________________________
function Output(ofile,ng,nd,np,nel,ug,sig,xygp)
%--------------------------------------------------------------------------
% write output to file
%--------------------------------------------------------------------------
% Write displacements
fprintf(ofile,'\n\n\nResults');
fprintf(ofile,'\n\nNode x-disp ydisp\n');
for ip=1:np;
ig1=(ip-1)*nd+1 ; ig2=ig1+1;
fprintf(ofile,'%4i %6.3f %6.3f\n',ip,ug(ig1:ig2));
end
% Write stresses
fprintf(ofile,'\nElement stresses\n');
fprintf(ofile,'Elem G.P. x-coord y-coord xx-stres yy-stres xy-stres
princ1 princ2\n');
for iel=1:nel;
for ig=1:ng;
lgp=(iel-1)*ng+ig;
fprintf(ofile,'%4i %2i %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f
%9.3f\n',...
iel,ig,xygp(:,lgp),sig(:,lgp));
end
end
________________________________________________________________________________
function plotmesh(nel,nn,topo,xy,xylim)
%--------------------------------------------------------------------------
% Plot the finite element mesh
%--------------------------------------------------------------------------
scrsz = get(0,'ScreenSize');
bsz=max([xylim(3)-xylim(1) xylim(4)-xylim(2)]) ; % plot box size=max(Dx,Dy)
figure('Position',[scrsz(3)/5 scrsz(4)/5 scrsz(3)/1.5 scrsz(4)/1.5]);
bsz=1.05*bsz ; % add margin
% Centre of mesh
xcen=0.5*(xylim(1)+xylim(3)) ; ycen=0.5*(xylim(2)+xylim(4)) ;
% plot background box
xb=[xcen-bsz/2 xcen+bsz/2] ; yb=[ycen-bsz/2 ycen+bsz/2] ;
rect=[xb(1) yb(1) ; xb(2) yb(1) ; xb(2) yb(2) ; xb(1) yb(2)];
C=[1 1 1] ; % Set backgorund colour
patch(rect(:,1),rect(:,2),C,'edgecolor',C);
% Plot elements
C=[0.9 1.0 0.9] ; % Set colour using RGB cube
for iel=1:nel;
x(1:nn)=xy(topo(iel,1:nn),1) ;
y(1:nn)=xy(topo(iel,1:nn),2) ;
patch(x,y,C) ; % plot element
text(mean(x),mean(y),num2str(iel),'fontsize',9) ; % wrt. elem
for i=1:nn ;
text(x(i),y(i),num2str(topo(iel,i)),'fontsize',8) ; % wrt. node
end
end
99
FEProg.m. Master script for finite element program
________________________________________________________________________________
% PLANE STRESS FINITE ELEMENT CODE.
clear ; clc ;
% Read data file and set local and global variables
[nd,ns,nn,nev,ng,nel,np,nf,ntv,ngt,topo,xy,E,nu,t,xylim,nof,ifp,pre,fxy,ofile]=Read
at;
% Plot the mesh
plotmesh(nel,nn,topo,xy,xylim)
% Compute D-matrix
D=dmatx(E,nu);
% Form stiffness matrix
Kg=Kgmatx(nel,ntv,nn,nd,nev,ng,topo,xy,D,t);
% Apply boundary conditions
[rhsm,Kgm]=BoundC(ntv,nd,nf,nof,ifp,pre,Kg,fxy);
% Solve equations
ug=Kgm\rhsm';
% Compute stresses at gauss points for all elements
[sig,xygp]=Stresses(ns,nd,ng,nn,nev,nel,xy,topo,ug,D);
% Output the results
Output(ofile,ng,nd,np,nel,ug,sig,xygp)
100
6A. APPENDIX TO LECTURE 6. EXPLANATION OF ELEMENT PLOTTING IN MATLAB
MATLAB, and most graphics packages, allow polyhedral shapes to be plotted with a single command,
however, these may not scale evenly in x and y directions or centre objects as required. Therefore a basic
algorithm is presented which achieves both of these conditions.
One way to ensure that x and y are scaled equally in MATLAB is to plot a square box around the object.
With reference to the figure below, Dbx and the coordinates of its corners may be calculated as follows;
W = greater of x and y
xcen=xmin+x/2 and ycen = ymin+y/2 the coordinates of the centre of the mesh plot box
The coordinates of the 4 corners of the plotting box, which ensure the object is central to the window
but retains its original coordinates, are as follows;
where
y
Dbx
(xb1 , yb2) (xb2 , yb2)
(xmax,ymax)
Object window, from
(xmin,ymin) to (xmax,ymax )
Dbx
(xmin,ymin)
101
Once the box is plotted all the elements may be plotted as follows;
for iel=1:nel
Extract the x and y coords of the 4 corners of each element and store in local arrays x and y,
plot the element using the patch function
End
Element numbers and node numbers may be added using the text function. Again, check the syntax
using MATLAB help.
102
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
103
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
104
7. DIFFERENT FORMS OF ELEMENT
Shape functions
1 Local node numbers N1 1
3
N2
N3
1 2
0 1
Triangular elements require different integration rules from quadrilateral elements (see Sec 7.4).
EXERCISE 7.1.
Assuming that the Cartesian and local coordinates are the same, compute the strain in a linear triangle
0 0
if the nodal displacements are e
u 0.001 0
0 0.002
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
105
Why doesn’t it matter where the strains are evaluated within the element ?
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
106
7.2 QUADRATIC ONE-DIMENSIONAL ELEMENT
Quadratic elements allow the simulation of linearly varying strain fields across elements. The shape
functions for a one-dimensional quadratic finite element are given below.
N1 () 1 ; N 2 () 1 1 ; N 3 () 1
2 2
Le
x
-1 0 +1
EXERCISE 7.2.
Sketch the three shape functions.
N1 N2 N3
1
-1 +1 -1 +1 -1 +1
107
EXERCISE 7.3.
Expand the element interpolation to give a single expression for u, the displacement at a point , within
the element and use this to find an expression for the strain , assuming that the element in Cartesian
coordinates is of length Le and that the mid-node is central.
2 2
u=
2 2
u1 1 2 u 2
u
2 2 3
=
--------------------------------------------------------------------------------------------------------------------------------------
7 6 +1 5 1 Local node numbers
5
-1 +1
6 4
8 4
1 2 3
1 -1 2 3 0 1
8 noded element in local domain 6 noded element in local domain
y y
x x
108
Shape functions for 8-noded quadrilateral
Ni
1
1 i1 ii i 1 for nodes i 1,3,5,7
4
2
2
N i i 1 i 1 2 i 1 i 1 2 for nodes i 2,4,6,8
2 2
EXERCISE 7.4.
Write out the full functions for N1 and N2
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
t 1
N1 2t 1t
N 2 4 t
N 3 2 1
N 4 4
N 5 2 1
N 6 4 t
It is worth noting that the way the finite element code in this course has been developed, very few changes
would be required to implement one of the above elements. If the code were generalised to deal with
different sorts of elements, then the number of nodes per element and the Gauss point rules would need to
become variables that depend on element type.
109
7.4 INTEGRATION RULES FOR TRIANGULAR ELEMENTS
The same basic numerical integration procedures used for rectangular elements (Section 3.2) are
applicable to triangular elements, except that the integration rules used are not the Gauss-Legendre rules
but the Radau rules. The sampling points and weights for 1 and 3 point Radau rules are given below (the
next in the series would be the 7 point rule).
σ σ ' pm
1
1
in which (in 3D)
1
m
0
0
0
EXERCISE 7.5.
Why does the m vector only contain non-zero terms for the xx, yy and zz components ?
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
A Darcy-flow analysis is undertaken for the pore fluid and a conventional deformation analysis undertaken
for the soil skeleton. The problem is coupled because the deformations affect the pore pressures and the
pore pressures affect the deformations. A common practice is to use a different order of interpolation for
the pore fluid from that used for the displacements, thus;
n pr nn
pe N pri pi and ue Niui
i 1 i 1
The shape functions used to interpolate the pore pressure (Npr) are normally an order below those used to
interpolate the displacements (Ni). Why ?
110
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
111
COURSEWORK
The coursework will be given on a separate sheet.
An optional extra piece of work is to add a contouring function to your program. This will require the
addition of a Matlab function called fecontour, a call to fecontour in the master program (see below),
plus the replacement of the existing stress and output Matlab files with the revised versions on
Blackboard. All the necessary files are on Learning Central.
---------------------------------------------------------------------------------------------------------------------------------------
% PLANE STRESS FINITE ELEMENT CODE.
clear ; clc ; close('all')
% Read data file and set local and global variables
[nd,ns,nn,nev,ng,nel,np,nf,ntv,ngt,topo,xy,E,nu,t,xylim,nof,ifp,pre,fxy,ofile]=Read
at;
% Plot the mesh
plotmesh(nel,nn,topo,xy,xylim)
% Compute D-matrix
D=dmatx(E,nu);
% Form stiffness matrix
Kg=Kgmatx(nel,ntv,nn,nd,nev,ng,topo,xy,D,t);
% Apply boundary conditions
[rhsm,Kgm]=BoundC(ntv,nd,nf,nof,ifp,pre,Kg,fxy);
% Solve equations
ug=Kgm\rhsm';
% Compute stresses at gauss points for all elements
[sig,xygp,stnod]=Stresses(ns,nd,ng,nn,nev,np,nel,xy,topo,ug,D);
% Output the results
Output(ofile,ng,nd,np,nel,ug,sig,xygp,stnod)
% Plot deformed mesh
plotdmesh(np,nel,nn,nd,topo,xy,xylim,ug)
% Plot contours
fecontour(nn,nd,np,nel,xy,xylim,topo,ug,stnod)
112
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
113
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
114
8. SOLVING LINEAR ALGEBRAIC EQUATIONS
Ku P (8.1)
There are many techniques available for solving these equations but standard direct methods that deal with
the solution of the whole equation system are not used in finite element codes other than for relatively
small problems. The reason for this is that finite element stiffness matrices are sparse, which means that
they contain many more zero entries than non-zero. This issue is discussed further in Section 8.3, but,
largely because of the issue of sparsity, the development of efficient equation solution methods has been
a very active research area for over half a century.
There are two main categories of solution method for linear equation systems
(i) Direct solution methods
Most direct solvers are developments of either Gaussian elimination or LU decomposition
techniques (which are themselves related)
(ii) Iterative solution methods
Many of these are based on Conjugate gradient solution techniques
This process is accomplished by working through each row (i.e. each equation) in turn and eliminating
(i.e. making zero) all entries in the column below the diagonal element. It starts by the terms in the first
column below row 1 being eliminated and then proceeds with the terms below the second row in column
two being eliminated and so on. The process is illustrated below.
115
Elimination process
Ko denotes the matrix at the start of a stage and Kn at the end. Between stages, Ko is replaced with the Kn
that has just computed. At the start of the whole process Ko = K
Kn now has non-zero terms only on or above the diagonal and it is thus termed an upper triangular matrix
(often denoted U). A matrix which only has non-zero terms on or below the diagonal is termed lower
triangular (and is often denoted L).
EXERCISE 8.1.
In stage 1, the individual terms of the matrix become those shown in the equation below.
Fill-in the missing terms.
116
This may be written in matrix form Kn u =Pn, noting that Kn and Pn, here, are the updated matrix and r.h.s
vector, not the final form shown in (8.3)
For stage 2, noting that Ko is equal to Kn just calculated from stage 1 above,
Back substitution
Once the equations are in an upper triangular form, they may be solved by working up from the bottom
equation to the top, because each equation then only introduces one new unknown, which may be solved.
The steps of the back substitution process are illustrated below
117
EXERCISE 8.2.
Write out the calculations required to compute u5, then u4 then u3 etc.
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
______________________________________________________________________________(8.8)
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
EXERCISE 8.3.
Complete the code for the Back substitution phase
Elimination Elimination
for i=1:n-1
for ir=i+1:n Loop the columns to be eliminated (i.e. stages)
K ir ,i
fac Loop rows from i+1 to n
K i,i
Loop over columns of current row (i to n)
for ic=i:n
Kir ,ic Kir ,ic Ki,ic fac Calculate terms on current row
end
Pir Pir Pi fac Calculate modified r.h.s. terms
end
end
end
Back substitution
Pn Back substitution
un Loop backwards through equations from n to 1
K n,n
for i=n-1: (step-1) to 1
Compute the first contribution to u from the diagonal
term and then complete the rest of the terms for the
__________________________ current row
__________________________
__________________________
__________________________
__________________________
__________________________
__________________________
end
118
8.3 SPARSITY
A key issue with the solution of finite element equations is sparsity. The stiffness matrix that arises from
assembling the element stiffness matrices contains many zero entries, and therefore to solve for the full
matrix is wasteful and unnecessary.
EXERCISE 8.4.
For the 9 element problem below, put a * in the positions of the partial global stiffness matrix that have
non-zero entries.
Elem Nodes
1 1 3 4 2
2 3 5 6 4
3 5 7 8 6
4 7 9 10 8
5 9 11 12 10
6 11 13 14 12
7 13 15 16 14
8 15 17 18 16
9 17 19 20 18
1 2 3 4 5 6 7 8 ……
x y x y x y x y x y x y x y x y
Row 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ….
3 x 5 ….
y 6 …..
To solve for the full matrix in large problems is incredibly wasteful in computer time and to do so would
be to make many real problems impossible to solve. Thus a huge research effort over many years has been
made to find efficient solution methods for highly sparse equations. It is worth noting that the same
problem arises in solutions with other numerical techniques, such as finite volume, finite difference and
boundary element methods.
119
8.3.2 Solvers which account for sparsity
. . . . . .
. . . . . .
All non-zero entries in a band
. . . . . . close to the diagonal
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . . Only non-zero’s within the ‘skyline’ need
. . . . . . be considered
. . . . . .
120
8.3.2.5. Conjugate gradient solvers with compressed row storage.
In general, iterative solvers are not as efficient as good direct solvers unless problems become large. A
huge advantage of conjugate gradient type solvers, however, is that they only need to store and work on
the non-zero entries of the matrix. This can result in major storage savings and hence they can become
very competitive for large problems. A method of storage compatible with CG solvers is compressed row
storage, in which the non-zero entries of matrix are stored in a single vector and the associated columns
and rows in the full stiffness matrix recorded in pointer arrays. This type of algorithm is highly suitable
for implementation on parallel computers. (See Appendix B. Also Ref Templates, by Barrett et al).
S = sparse(i,j,v) generates a sparse matrix S from the triplets i, j, and v such that S(i(k),j(k))
= v(k). The max(i)-by-max(j) output matrix has space allotted for length(v) nonzero
elements. sparse adds together elements in v that have duplicate subscripts in i and j.
If the inputs i, j, and v are vectors or matrices, they must have the same number of elements.
Alternatively, the argument v and/or one of the arguments i or j can be scalars.
Using the variable names in the present course and applying this to the global stiffness matrix results in
Kg=sparse(ivc,jvc,Kgvec,ntv,ntv);
in which ivc and jvc give the row and column numbers of each non-zero entry in Kgvec
This code is implemented in a Matlab function KgSparse , which is available on Learning Central. To
use this function, simply replace the function Kgmatx with KgSparse, remembering to change the call in
FEcomp.
Example
The cantilever problem in Lecture 7 will be used here as an example. Three uniform meshes of
rectangular elements are employed to illustrate the performance of the sparse function in solving the
equations. Table 1 shows the average times to solve the equations using a full and a sparse stiffness
matrix respectively:
121
8.4 CONDITIONING
A set of equations, such as those of 8.1, is ill-conditioned if a small change in K, and/or P, results in a
large change in solution u. Ill conditioned equations arise in solid mechanics problems when, for example,
different elements have vastly different stiffnesses, or when boundary conditions do not strongly prevent
rigid body motions.
All numerical calculations are carried out to a certain level of accuracy. Most finite element programs use
double precision arithmetic, which gives typically 16 significant figures or 16 digit precision. When
equations are solved by, for example Gaussian elimination or a derived method, equations are scaled and
subtracted from other equations. If terms have very different magnitudes, the process can break down
because important significant figures are lost.
(10 10 1) 1 0
(8.9)
10 10 (1 1) 10 10
It may be seen that in the first case the small number is lost. If such a small number was significant, as
maybe the case in an ill-conditioned system, the results could be meaningless.
The main lesson from this, in this course, is that having very different sizes of terms in the stiffness matrix
can lead to problems. Also, MATLAB (as do most programming languages) allow variables to be stored
to different accuracies, and it is important to ensure sufficient accuracy is being used.
122
REFERENCES
‘Numerical Recipes’ by W Press, W Teukolsky, W Vetterling and B Flannery (2002)
‘An introduction to finite element computations’ by E Hinton and R Owen(1979) (An old but
excellent text on basic F.E. theory)
‘Finite element programming’ by R Owen and E Hinton
‘Finite element procedures in Engineering Analysis’, by K J Bathe
‘Techniques of finite elements’ by Irons and Ahmed (1983) (A real insightful and amusing text by
Bruce Irons, who contributed so much to the methods of modern F.E. technology)
‘Templates for the solution of linear equations’ by Barrett et al (Available at
http://netlib2.cs.utk.edu/linalg/html_templates/report.html)
A comprehensive set of up to date reports on solvers are available from the numerical group at
Oxford from http://www.numerical.rl.ac.uk, 2017
123
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
124
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
125
9 A BRIEF INTRODUCTION TO NON-LINEAR PROBLEMS.
In order to solve such problems non-linear solution strategies are required, which are generally based on
Newton-Raphson type solutions algorithms.
Plasticity models.
Plastic behaviour is characterised by permanent (plastic) strains and in one dimension an elastic-
perfectly plastic material would follow the path shown in Figure 9.1. The stress strain relationship
in one dimension is as given in equation (9.2);
E p (9.2)
fy
p
Figure 9.1. Typical path for 1D elastic perfectly plastic material
126
These are used for metals, soils and even concrete, although they do not capture well the cracking
behaviour in a material like concrete. These models employ a yield function, which is normally
described in stress space, which bounds the elastic region. If the stress tries to cross this boundary,
plastic behaviour starts and the stress then remains on the yield surface which may expand, contract
or remain the same size depending on a hardening rule. In metal plasticity two commonly used yield
functions are the Von Mises and Tresca yield functions. These are illustrated in the diagram below
(Ref Owen and Hinton, Finite elements in plasticity). The equation for the Von Mises yield function,
in terms of principal stress components, is given below;
f (σ) J 2 f y ( ) (9.3)
J2
1
6
1 2 2 2 3 2 1 3 2
and is a scalar which increases as the plastic (permanent) strains increase
Figure 9.2. Von-Mises and Tresca yield surfaces (After Owen and Hinton)
Damage models
Damage models are based on the idea that materials undergo damage when a certain damage
threshold, or damage surface, is reached. In one dimension, a typical stress strain damage
relationship is as follows;
1 DE (9.4)
D is the damage variable which has a value 0 when there is no damage and 1 when there is complete
damage. Unlike plasticity models, these do not have permanent strains, and thus unloading from a
damaged state follows a secant path, as illustrated in Figure 9.3.
127
Damage
threshold
Figure 9.3. Typical path for 1D damage model
It may be seen here that the material softens. Simulating such behaviour creates a major challenge
in the solution of the non-linear equations.
Damage models are most applicable to so-called quasi brittle materials such as concrete, mortars,
rocks and certain metal-matrix composites.
Hyper-elastic models
In hyper-elastic models the stresses depend only on the strains, and not upon any other state variables,
such as a damage parameter or plastic strain parameter. More formally, hyper-elastic materials are defined
as those for which there exists an elastic potential, which is a scalar function of strain components, whose
derivatives with respect to the strain components are the stress components. The potentials are generally
written in terms of stress invariants, which may be thought of as combinations of principal stresses.
One of the most widely used hyper-elastic models is that for rubber, known as the Mooney Rivlin model.
A hyper-elastic material follows the same path in loading and unloading, as shown in figure 9.4.
Damage
threshold
Figure 9.4. Typical path for 1D hyper-elastic model
128
9.3 Geometric non-linearity.
When the geometry of a structure changes during the course of an analysis, such that the stiffness in the
deformed configuration is significantly different from the stiffness based on the original configuration, it
is necessary to update the geometry and re-compute the stiffness. A simple example of a structure for
which the stiffness in the direction of the load is highly dependent on the deformed configuration is that
shown below.
Bar elements have zero stiffness
in load direction
In many geometrically non-linear problems small strain measures are inadequate and therefore it is
necessary to use higher order strain measures, for example Green’s strains. For a plane stress case these
are as shown below
2
1 u y
2
u 1 u
xx x x
x 2 x 2 x
2 2
u y 1 u y 1 u
yy x (9.5)
y 2 y 2 y
u u y u x u x u y u y
xy x
y x x y x y
ψ
ψ new 0 ψ u g (9.7)
u g
i
in which
ψ K g
K T (9.8)
u g u g
i i
and KT = Tangential stiffness matrix
129
Using (9.7) and (9.8) the displacement increment is
It is normal to divide the applied load into increments and update the displacements until convergence is
achieved, and then apply the next increment. The entire solution algorithm is given below, in which r is a
proportion factor for the load. It is noted that takes the value of the applied load increment at the start
of an increment and thereafter it is evaluated directly from the out of balance forces rather than from (9.6).
The out of balance forces are the difference between the stress resultant nodal forces (R, see below) and
the applied loads
R ΞT B T σ dVe (9.10)
n e el
r 1/ninc ; r0 ; Pr 0 ; u g 0
Loop number of load increments i 1 : ninc
r r r
Pr Pr r Pg
Ψ r Pg
Enter iteration loop it 1 : nit
u g K T 1Ψ
u g u g u g
Ψ Pr R r
If Ψ tolerance Exit iteration loop
Close iteration loop
Trap case of no convergenc e
Close increment loop
130
r Pg
ug
131
APPENDIX B. DIFFERENT FORMS OF SOLVER. (NOT EXAMINABLE)
1
f (u) u T Ku u T P 0
2 (B1)
Given a particular approximation ua, minimizing f(ua) moves towards the exact solution f(u)=0, thus
f
0
u a (B2)
gives the solution to (8.1) when ua=u
The fact that (B1) provides the solution to the equations is readily demonstrated. For example, for a 2x2
set of symmetric equations, for which K12=K21
F
K11u1 K12 u 2 P1 0
u1
F
K12 u1 K 22 u 2 P2 0
u 2
rearrangin g and replacing the 2nd K12 with K 21 gives
K11 K12 u1 P1
K
21 K 22 u 2 P2 (B4a-b)
132
B2 Conjugate gradient solutions
Probably the best and most successful iterative solution algorithms are based upon Conjugate gradient
techniques. The method works by minimising a quadratic function, as described above.
If uj = jth iterate (or jth approximation) to the exact solution (u) and r is a residual (or error) vector such
that
rj Ku j P
(B5)
u j u j1 ipi
(B6)
in which and p are chosen to minimise the error function, the proof of which will not be given here.
Set an initial value for u0, e.g. =Kdiag-1P, where Kdiag contains only the diagonal entries of K
then r0=K u0 - P and p0-=r0
r j1T r j1
j
r jT r j
p j1 r j jp j
u j1 u j jp j
The steps are repeated until the residual becomes acceptably small, i.e. the iteration loop j=1,2,3 … is
continued until a convergence criterion is satisfied.
133
B3 DIRECT SOLUTION WITH LU DECOMPOSITION
LU decomposition is another method that leads to the solution of a triangular set of equations. The basic
idea is that if a lower (L) and an upper (U) triangular matrix could be found, the product of which is the
coefficient matrix of the system (K), the solution could then be found by back and forward substitution
operations alone. It is noted that, although classified differently here, Gaussian elimination may be cast
as a set of LU operations. The operations are as follows;
Assume
LU K (B8)
Then
(LU)u P (B9)
And
L(Uu) P
Solve for y
Ly P
and then for u
Uu y (B10a-c)
Both solutions can be carried out directly by forward and backward substitutions alone.
The question is how to find L and U efficiently. A classical algorithm for nonsymmetric matrices is
Crout’s algorithm, but for symmetric positive definite systems, Cholesky decomposition is a simple and
effective method (Ref Numerical recipes). The Cholesky decomposition method turns out to be very
straight forward, as follows;
for i=1:n
i 1
L ii K ii L ik 2
k 1
for j=i+1:n
i 1
K ji L jk L ik
L ji
k 1
L ii
end
In the loop all required terms are already known by the time they are needed.
134
APPENDIX C. Code optimization with MATLAB. (NOT EXAMINABLE)
C1.1 Sparse solver
Finite element stiffness matrices are sparse and considerable memory can be saved if their sparsity is
exploited. Moreover, solving the equations becomes a lot faster and this is significant for large
problems.
The cantilever problem in Lecture 7 will be used here as an example. Three uniform meshes of
rectangular elements are employed to illustrate the performance of the sparse function in solving the
equations. Table 1 shows the average times to solve the equations using a full and a sparse stiffness
matrix respectively:
It can be observed that solving the equation is orders of magnitude faster when employing a sparse
stiffness matrix rather than a full stiffness matrix.
Note: tic and toc functions are used to measure the elapsed time (in seconds) as shown below:
tic
ug = Kgmod\rhsmod';
tsolve = toc
tsolve = 0.3927
Kg = sparse(I,J,X,ntv,ntv).
The X values of repeated pairs in I,J are added each other in Matlab sparse function, which represents
the assembly procedure. The allocation (with Matlab zeros function) of I, J and X is done before the
finite element loop. Note that the size of these arrays is known a priori.
135
Table C2. Average assembly times
Mesh (nelem/ntotv) Nested for assembly Vectorised assembly Sparse assembly
480/1098 0.379 0.146 0.134
3000/6342 4.502 1.376 0.810
12000/24682 71.658 17.916 3.203
Note: Results presented here were obtained with an Intel® Core™ i5-2450M CPU @ 3.10 GHz, 1333
MHz, 6GB RAM, Windows 7 (64-bit) machine.
136
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
137
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
138
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
139
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
140
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
141
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
142