Professional Documents
Culture Documents
Introduction
Finite Element Method is the application of numerical techniques to solve engineering problems. This is done by finding
approximate solutions to partial differential equations and integral equations. For steady state problems this method is
based on eliminating differential equations completely.
The application of this method involves replacing an infinite dimensional linear problem with a finite dimensional
version. By dividing a system into a number of discrete elements the complex system gets broken into a number of
simpler systems. The element that a system is split up into can take a variety of one, two, and three dimensional
shapes. Each elements behaviour is analyzed in terms of the responses at discrete nodes.
In this Project, Finite Element Method will be applied to a one dimensional axial beam deflection problem with the help
of a written program.
Contents
Introduction ............................................................................................................................................................................ 1
List of Tables ........................................................................................................................................................................... 3
List of Figures .......................................................................................................................................................................... 3
Objective ................................................................................................................................................................................. 4
About Python .......................................................................................................................................................................... 4
Results ..................................................................................................................................................................................... 5
Discussion.............................................................................................................................................................................. 14
Conclusion ............................................................................................................................................................................. 15
Program Code ....................................................................................................................................................................... 16
List of Tables
Table 1 - 1 Element, Element Properties ................................................................................................................................ 5
Table 2 1 Element, Equivalent Nodal Forces........................................................................................................................ 5
Table 3 - 1 Element, External Forces ....................................................................................................................................... 5
Table 4 - 1 Element, Global Forces Before BC's ...................................................................................................................... 5
Table 5 - 1 Element, Global Stiffness Matrix ........................................................................................................................... 5
Table 6 - 1 Element, Global Forces After BC's ......................................................................................................................... 6
Table 7- 1 Element, Global Displacements ............................................................................................................................. 6
Table 8 - 2 Elements, Element Properties ............................................................................................................................... 6
Table 9 - 2 Elements, Equivalent Nodal Forces ....................................................................................................................... 6
Table 10 - 2 Elements, External Forces ................................................................................................................................... 6
Table 11 - 2 Elements, Global Forces Before BC's................................................................................................................... 7
Table 12 - 2 Elements, Global Stiffness Matrix ....................................................................................................................... 7
Table 13 - 2 Elements, Global Forces After BC's ..................................................................................................................... 7
Table 14 - 2 Elements, Global Displacements ......................................................................................................................... 7
Table 15 - 4 Elements, Element Properties ............................................................................................................................. 8
Table 16 - 4 Elements, Equivalent Nodal Forces ..................................................................................................................... 8
Table 17 - 4 Elements, External Forces ................................................................................................................................... 8
Table 18 - 4 Elements, Global Forces Before BC's................................................................................................................... 8
Table 19 - 4 Elements, Global Stiffness Matrix ....................................................................................................................... 9
Table 20 - 4 Elements, Global Forces After BC's ..................................................................................................................... 9
Table 21 - 4 Elements, Global Displacements ......................................................................................................................... 9
Table 22 - 8 Elements, Element Properties ........................................................................................................................... 10
Table 23 - 8 Elements, Equivalent Nodal Forces ................................................................................................................... 10
Table 24 - 8 Elements, External Forces ................................................................................................................................. 11
Table 25 - 8 Elements, Global Force Matrix Before BC's....................................................................................................... 11
Table 26 - 8 Elements, Global Stiffness Matrix ..................................................................................................................... 13
Table 27 - 8 Elements, Global Force Matrix After BC's ......................................................................................................... 14
Table 28 - 8 Elements, Global Displacements ....................................................................................................................... 14
Table 29 - Comparison of Element Number and Displacement ........................................................................................... 15
List of Figures
Figure 1 - Problem Schematic ................................................................................................................................................. 4
Figure 2 - Schematic, 1 Element.............................................................................................................................................. 5
Figure 3 - Schematic, 2 Elements ............................................................................................................................................ 6
Figure 4 - Schematic, 4 Elements ............................................................................................................................................ 7
Figure 5 - Schematic, 8 Elements ............................................................................................................................................ 9
Objective
The objective of this project was to use Finite Element Methods to write a program that would be able to compute one
dimensional axial deflection problems. The program was to accommodate uniformly distributed loads, variable cross
sectional areas, given displacements, and varying number of elements.
The provided problem for this project can be seen in Figure 1. The deflection of this beam was to be calculated with a
load F =5000N at node C and a linear load of T(x)= 10x kN applied along the first section. The displacement should be
calculated for 1, 2, 4, and 8 elements per section. Results are then to be recorded and discussed.
About Python
Python was originally chosen for this problem out of curiosity. Although learning a new language syntax somewhat
slowed progress of the project it became quickly apparent that Python had some advantages for computation,
specifically an extension of the language called NumPy.
Python is a general purpose interpreted high-level programming language designed by Guido van Rossum which first
appeared in 1991. The design emphasis behind Python was to develop a powerful language with very good code
readability. Python uniquely supports more than one programming style such as object-oriented, imperative, and
functional programming. The language also features a fully dynamic type system and automatic memory management.
Python is mainly used as a scripting language.
NumPy is an extension of the Python programming language which adds a large support for multidimensional arrays and
matrices, along with a large number of high level functions to operate these arrays. In regards to this project, this
package also added gauss quadrature functions which were vital to finding equivalent nodal forces. NumPy is
5
considered a free open source alternative to MatLab, as they are both interpreted, and allow users to write fast
programs so long as the majority of operations work on arrays or matrices instead of scalars.
Results
The following is the collected results for the sample problem using iterations of 1, 2, 4 and 8 elements. Raw input and
output for each case may be viewed in the Program Input-Output folder of this cd.
1 Element
Element
1
2
Length (m)
1
0.8
Average Area
0.001
0.002
Node
1
2
3
Node
1
2
3
Force (N)
0
0
5000.
Node
1
2
3
Force (N)
1666.66666667
3333.33333333
5000
6
Node
1
2
3
Force (N)
0
3333.33333333
5000
Node
1
2
3
Displacement (m)
0
3.96825397e-05
5.39682540e-05
2 Elements
Element
1
2
3
4
Length (m)
0.5
0.5
0.4
0.4
Node
1
2
3
4
5
Node
1
2
3
4
5
Average Area
0.001
0.001
0.0015
0.0025
7
Node
1
2
3
4
5
Force (N)
416.66666667
2500
2083.3333
0
5000
Node
1
2
3
4
5
Force (N)
0
2500
2083.3333
0
5000
Node
1
2
3
4
5
4 Elements
0.00000000e+00]
0.00000000e+00]
0.00000000e+00]
-8.75000000e+08]
8.75000000e+08]]
8
Element
1
2
3
4
5
6
7
8
Length (m)
0.25
0.25
0.25
0.25
0.2
0.2
0.2
0.2
Node
1
2
3
4
5
6
7
8
9
Node
1
2
3
4
5
6
7
8
9
Node
1
2
3
4
5
6
7
8
9
Force (N)
104.16666667
625
1250
1875
1145.8333
0
0
0
5000
Average Area
0.001
0.001
0.001
0.001
0.00125
0.00175
0.00225
0.00275
9
[[ 8.40000000e+08
[ -8.40000000e+08
[ 0.00000000e+00
[ 0.00000000e+00
[ 0.00000000e+00
[ 0.00000000e+00
[ 0.00000000e+00
[ 0.00000000e+00
[ 0.00000000e+00
Node
1
2
3
4
5
6
7
8
9
Force (N)
0
625
1250
1875
1145.8333
0
0
0
5000
Node
1
2
3
4
5
6
7
8
9
8 Elements
10
Element
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Length (m)
0.125
0.125
0.125
0.125
0.125
0.125
0.125
0.125
0.1
0.1
0.1
0.1
0.1
0.1
0.1
0.1
Node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Area
0.001
0.001
0.001
0.001
0.001
0.001
0.001
0.001
0.001125
0.001375
0.001625
0.001875
0.002125
0.002375
0.002625
0.002875
11
Node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Force (N)
26.04166667
156.25
312.5
468.75
625
781.25
937.5
1093.75
598.95833333
0
0
0
0
0
0
0
5000
-1.68000000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
12
Row 2
[ -1.68000000e+09 3.36000000e+09 -1.68000000e+09 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 3
[ 0.00000000e+00 -1.68000000e+09 3.36000000e+09 -1.68000000e+09
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 4
[ 0.00000000e+00 0.00000000e+00 -1.68000000e+09 3.36000000e+09
-1.68000000e+09 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 5
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.68000000e+09
3.36000000e+09 -1.68000000e+09 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 6
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
-1.68000000e+09 3.36000000e+09 -1.68000000e+09 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 7
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 -1.68000000e+09 3.36000000e+09 -1.68000000e+09
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 8
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 -1.68000000e+09 3.36000000e+09
-1.68000000e+09 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 9
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.68000000e+09
3.25500000e+09 -1.57500000e+09 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 10
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
-1.57500000e+09 3.50000000e+09 -1.92500000e+09 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
13
Row 11
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 -1.92500000e+09
0.00000000e+00 0.00000000e+00
0.00000000e+00]
Row 12
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
-2.62500000e+09 0.00000000e+00
0.00000000e+00]
Row 13
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
5.60000000e+09 -2.97500000e+09
0.00000000e+00]
Row 14
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
-2.97500000e+09 6.30000000e+09
0.00000000e+00]
Row 15
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 -3.32500000e+09
0.00000000e+00]
Row 16
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
-4.02500000e+09]
Row 17
[ 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00
4.02500000e+09]]
0.00000000e+00
0.00000000e+00
4.20000000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
-2.27500000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
-2.27500000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
4.90000000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
-2.62500000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
-3.32500000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
7.00000000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
-3.67500000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
-3.67500000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
7.70000000e+09
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
0.00000000e+00
-4.02500000e+09
14
Node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Force (N)
0
156.25
312.5
468.75
625
781.25
937.5
1093.75
598.95833333
0
0
0
0
0
0
0
5000
Node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Displacement
0
5.93687996e-06
1.17807540e-05
1.74386161e-05
2.28174603e-05
2.78242808e-05
3.23660714e-05
3.63498264e-05
3.96825397e-05
4.28571429e-05
4.54545455e-05
4.76523477e-05
4.95571096e-05
5.12377818e-05
5.27415412e-05
5.41020854e-05
5.53443215e-05
Discussion
Referring to figure 1 the following are the displacements given for common nodes using the varying number of
elements.
15
Node A
Node B
Node C
1 Element
0
3.96825397e-05
5.39682540e-05
2 Elements
0
3.96825397e-05
5.49206349e-05
4 Elements
0
3.96825397e-05
5.52504638e-05
8 Elements
0
3.96825397e-05
5.53443215e-05
As was hoped and expected the end displacement at node C changed with the number of elements and started to
converge towards the exact solution, with changes getting smaller and smaller as the number of elements increased.
What was surprising however was the result that showed no change in the displacement of node B with the increase in
element number. This could be an error in programming or method, however after talking to a fellow classmate who
wrote his own program independently, we found to our surprise that we both had the same result. It was thought that
this displacement should change with node number as the load applied to this section was given as a function of its
length. However now it is my belief that because my program is integrating the known load function over the entire
length of the section no matter the number of elements given, the sum of the forces should not change and therefore
the calculated displacement will not change. I however may very well be wrong in this assumption. In the end my
program predicts a total displacement of 5.53443215e-05m for the given problem.
Conclusion
Overall I found this project to be interesting work, and it quickly became one of my favourite projects. The usefulness
and application of Finite Element Method is now quite apparent, and basic method of computation understood. If I had
further time I would have made some changes to the program. In order to simplify the code I would have liked to make
functions for repeated operations such as creating global matrices. The ability to output data to a text file would have
also been ideal. Lastly it would have been nice to create a GUI interface.
16
Program Code
#
#
#
#
FEM Project
Name: James Mudge
Student ID: 0435508
Date: April 13/11
17
print ''
print '(If section has variable area enter "V")'
while count < int(numSect):
Area = raw_input('Please specify area of section '+str(count+1)+' : ')
count1 = 0
if str(Area) == 'V':
thickness = float(raw_input('Thickness of section: '))
width1 = float(raw_input('Section width at start node: '))
width2 = float(raw_input('Section width at end node: '))
while count1 <= int(numElem)-1:
LocalSecL = LocalSecL + L[count2]
LocalSecL1 = LocalSecL - (L[count2]/2)
Area = (width1*thickness) + ((width2 - width1)/float(SecL[count]))*LocalSecL1*thickness
A.append(Area)
count1 = count1 + 1
# if the area is variable across the section this code calculates
count2 = count2 + 1
# the average cross sectional area for each element and appends it to the area list
count = count + 1
elif str(Area) != 'V':
count1 = 0
while count1 <= int(numElem)-1:
A.append(Area)
# if the sections area does not vary this code appends to the area list
count1 = count1 + 1
# the entered cross sectional area for the number of elements in that section
count2 = count2 + 1
count = count + 1
# generated k matrix to needed size
count1 = 0
while count1 < (int(numSect)*int(numElem)):
stiffness = zeros([(int(numSect)*int(numElem))+1, (int(numSect)*int(numElem))+1])
# creates an empty array of 0's to the global size
count2 = 0
while count2 <= 1:
if count2 == 0:
stiffness[count1][count1] = 1
# uses two counters to count down the diagonal of the matrix and
stiffness[count1][count1+1] = -1
# enter the 1's and -1's seens for each element stiffness matrix
elif count2 == 1:
stiffness[count1+1][count1] = -1
stiffness[count1+1][count1+1] = 1
count2 = count2 + 1
k.append(stiffness)
# enters the entire matrix created into a list in the order of each element
count1 = count1 + 1
# inputs section E to list
print ''
count = 0
while count <= numSect-1:
Elasticity = raw_input('Please specify modulus E for section '+str(count+1)+': ')
count1 = 0
while count1 <= int(numElem)-1:
E.append(Elasticity)
count1 = count1 + 1
count = count + 1
# input external point loads to list
print ''
print '(If no external force is applied at the node enter "0")'
18
force = zeros(shape=((int(numSect)*int(numElem))+1, 1))
count = 0
while count <= (int(numSect)*int(numElem)):
force[count,0] = float(raw_input('Please enter external force applied at node ' +str((count/numElem)+1)+': '))
count = count + int(numElem)
# input boundary conditions
print ''
print '(For a given displacement enter the distance below, otherwise)'
print '(Please use the following codes for boundary conditions)'
print '"F": node is fixed and will not have any displacement'
print '"0": no boundary condition at this node'
count = 0
count1 = 0
count2 = 0
Uint = zeros(shape=((int(numSect)*int(numElem))+1,1))
while count < (int(numSect)+1):
condition = raw_input('Please enter boundary condition at node ' +str(count+1)+ ': ')
BC.append(condition)
if condition != 'F':
Uint[count2,0] = condition
# records boundary conditions to a list and if the boundary condition is a given
count2 = count2 + 1
# nodal displacement it enters the value to a seperate list Uint
if int(count) != int(numSect):
while count1 < numElem-1:
BC.append(0)
count1 = count1 + 1
# enters 0's for elements between the section boundary's
count2 = count2 + 1
count = count + 1
count1 = 0
print ''
print '(Please enter variable axial loads for sections below of the form Tx)'
print '(If section has no variable load enter a value of "0")'
count = 0
count1 = 0
count2 = 0
N = zeros(shape=(int(numSect)*int(numElem)+1, 1))
while count < int(numSect):
forceDist = (raw_input('Please enter variable load for section '+str(count+1)+', T = '))
while count1 < int(numElem):
function_lambda = eval("lambda x: " + forceDist + "*(" + "x" + "+" + str(AbsL[count2]) + ")*(1-(x/" + str(L[count2]) + "))")
function_lambda1 = eval("lambda x: " + forceDist + "*(" + "x" + "+" + str(AbsL[count2])+ ")*(x/" + str(L[count2]) + ")")
N[count2, 0] = N[count2, 0] + delete((quad(function_lambda, 0, L[count2])), 1, axis=0)
N[count2+1, 0] = N[count2+1, 0] + delete((quad(function_lambda1, 0, L[count2])), 1, axis=0)
count1 = count1 + 1
count2 = count2 + 1
# uses quadrature function from Numpy package to integrate over each element and add the
count = count + 1
# results to the array N
count1 = 0
# adds equivalent nodal forces to force matrix
count = 0
Tforce = zeros(shape=((int(numSect)*int(numElem))+1,1))
while count <= int(numSect)*int(numElem):
Tforce[count,0] = Tforce[count,0] + N[count,0] + force[count,0]
count = count + 1
19
20
count = 0
count1 = 0
for x in BC:
if str(x) != '0':
count1 = count1 + 1
count = count + 1
DISP = zeros(shape=(len(BC),1))
count = 0
for x in BC:
DISP[count,0] = BC[count]
count = count + 1
if Tforce.sum() == 0:
Tforce = dot(kg,DISP)
# if given boundary conditions are only displacements the coresponding forces are calculated
21
TTForce.resize((int(numSect)*int(numElem))+1,1)
u.resize((int(numSect)*int(numElem))+1,1)
for x in BCC:
if str(BCC[count]) == 'F':
u[count] == '0'
if str(BCC[count]) != 'F' and str(BCC[count]) != '0':
u[count] = BCC[count]
if Tforce.sum() != 0:
TTForce[count] = Tforce[count1]
count1 = count1 + 1
if str(BCC[count]) == '0':
u[count] = uc[count2]
count2 = count2 + 1
count = count +1
# prints out final results
print ''
print 'Global Force Matrix: '
print TTForce
print ''
print 'Global Displacement Matrix:'
print u
print ''
print 'Nodal Displacements'
count = 0
while count <= (int(numSect)*int(numElem)):
print 'U'+str((count/numElem)+1)+': '+ str(u[count,0])
count = count + numElem