Sie sind auf Seite 1von 50

CI 221 Computational Methods

Introduction to Finite Element Analysis


Dr Andrew TM Phillips
While intended to give an overview of this part of the course these notes are not a complete
record and should not be treated as a substitute for attending lectures and tutorials.
Copyright 2010. All rights reserved.
Aim of this part of the course:
The aim of this part of the course is to introduce the nite element method, and inves-
tigate its application in particular in structural engineering. Emphasis is placed on the
use of Matlab and GSA in achieving this.
No one believes the results of a computational model, except the person who put to-
gether the model. Everyone believes the results of an experimental test, except the person
who put together the experiment.
Recommended reading
The following suggested textbooks may be useful for students looking to do further read-
ing on the subjects introduced in this part of the course.
Kwon and Bang, The Finite Element Method Using MATLAB
Ferreira, MATLAB Codes for Finite Element Analysis
Zienkiewicz, Taylor and Zhu, The Finite Element Method: Its Basics and Funda-
mentals
Zienkiewicz and Morgan, Finite Elements and Approximation
1
1 Introduction
The nite element method is a very powerful mathematical technique that has found
signicant application in structural engineering, as well as other elds of science and
engineering.
The rst recognised use of the Finite Element Method as we know it is that of
Turner et al.
1
who used it to numerically model aircraft wings using a mesh of triangular
elements. In introducing the nite element method we will rst look at the Galerkin
method of weighted residuals for approximating functions, before moving on to look at
strong and weak function formulations.
1.1 Galerkin method of weighted residuals
Although the Galerkin method is not the only method of weighted residuals available for
approximating functions we will investigate it, as we will see later on that it has particular
relevance to the nite element method.
Let us rst consider the following dierential governing equation:
d
2
u
dx
2
u + x = 0 (1.1)
In order to dene the problem let us introduce a domain, 0 < x < 1, and let us also
dene boundary conditions, u(0) = 0, and u(1) = 0. This information can be rewritten
in the form:
_
d
2
u
dx
2
u + x = 0, 0 < x < 1
u(0) = 0, and u(1) = 0
(1.2)
The rst step for any method of weighted residuals is then to determine a trial function
which contains unknown coecients to be determined. Here we will select the trial
function:
1
Turner et al., Stiness and Deection Analysis of Complex Structures, Journal of Aeronautical
Sciences 23(9):805-823,854, 1956
2
u = ax(1 x) (1.3)
where u denotes an approximate solution for u, and a is the unknown coecient. The trial
function, u suggested has been chosen as it satises the boundary conditions specied
for the governing dierential equation ( u(0) = 0, and u(1) = 0). It is observed that the
goodness of t of the approximate solution to the exact solution is dependent on the trial
function. Having selected a a trial function we dene a residual, R by substituting u into
the governing dierential equation:
R =
d
2
u
dx
2
u + x = 2a ax(1 x) + x (1.4)
where because u will be dierent to the exact solution, the residual R will not be equal
to zero for all values of x within the domain. Having dened the residual, R we can now
combine this with a weighting function w in order to determine the value of the coecient,
a such that our chosen trial function provides the best t that can be achieved compared
to the exact solution. To do this we set the integration of the weighted residual over the
domain to zero:
_
1
0
wR dx =
_
1
0
w
_
d
2
u
dx
2
u + x
_
dx
=
_
1
0
w(2a ax(1 x) + x) dx = 0
(1.5)
For Galerkins method we set the weighting function based on the chosen trial function,
such that:
w =
d u
da
= x(1 x) (1.6)
Hence for the chosen trial function, setting the integrated weighted residual over the
domain to zero we have:
_
1
0
x(1 x)(2a ax(1 x) + x) dx = 0 (1.7)
which can be solved to give a = 0.2272.
3
Although not discussed here the governing dierential function can be solved exactly
to give:
u = x
1
(e
1
e
1
)
(e
x
e
x
) (1.8)
Hence we can plot the solution provided by our chosen trial function against our exact
solution, as shown in Figure 1.1.
0 0.2 0.4 0.6 0.8 1
0
0.01
0.02
0.03
0.04
0.05
0.06
x
u
(
s
o
l
i
d
r
e
d
)
,
u
Figure 1.1: u, the exact solution (solid red) and u, the approximate solution (dash-dot
blue) found using the Galerkin weighted residual method
In order to improve the approximation we can change the trial function, and increase
the number of independent coecients. Hence another trial function could be:
u = a
1
x(1 x) + a
2
x
2
(1 x) (1.9)
where a
1
and a
2
are independent coecients. This trial functions gives the residual:
R =
d
2
u
dx
2
u + x = a
1
(2 x + x
2
) + a
2
(2 6x + x
2
+ x
3
) + x (1.10)
In order to nd appropriate values for a
1
and a
2
we dene the same number of weight-
ing functions as we have unknowns. For the Galerkin method these are dened:
4
w
i
=
u
a
i
(1.11)
So for the given trial function we have:
w
1
= x(1 x), w
2
= x
2
(1 x) (1.12)
Hence for the chosen trial function, we can dene two weighted residuals, and set their
integrals to zero over the domain:
_
1
0
w
1
Rdx = 0,
_
1
0
w
2
Rdx = 0 (1.13)
giving simultaneous expressions, that in matrix form can be solved to give a
1
= 0.1457
and a
2
= 0.1628:
_
11/30 11/60
11/60 1/7
__
a
1
a
2
_
=
_
1/12
1/20
_
(1.14)
Hence we can plot the solution provided by our 1st-order and 2nd-order chosen trial
functions against our exact solution, as shown in Figure 1.2. It is observed that the
2nd-order chosen trial function has a very high goodness of t for the exact solution.
1.2 Weak formulation of the Galerkin method
When we were operating on the trial function previously we were using the strong form,
where the evaluation of the integrated weighted residual relied on the highest order of
derivative term in the residual having a non-zero value. This restricted our choice of trial
functions to those where:

2
u
x
2
= 0 (1.15)
We can however apply integration by parts to the strong form, in order dene the
weak form:
5
0 0.2 0.4 0.6 0.8 1
0
0.01
0.02
0.03
0.04
0.05
0.06
x
u
(
s
o
l
i
d
r
e
d
)
,
u
Figure 1.2: u, the exact solution (solid red), 1st-order approximate solution (dash-
dot blue), and 2nd-order approximate solution (dotted black) found using the Galerkin
weighted residual method
_
1
0
w
_
d
2
u
dx
2
u + x
_
dx =
_
1
0
_

dw
dx
d u
dx
w u + wx
_
dx +
_
w
d u
dx
_
1
0
= 0 (1.16)
If we refer back the our original trial function for the governing dierential equation
it can be seen that we will arrive at the same value of a using the weak form as we did
for the strong form:
_
1
0
(w

w u + wx)dx + [w u

]
1
0
= 0
u = ax(1 x), u

= a 2ax, w = x(1 x), w

= 1 2x
a = 0.2272
(1.17)
While for the originally chosen trial function this is not seen to have any immediate
advantage, we can go on to introduce the concept of using piecewise continuous trial
functions.
6
1.3 Piecewise continuous trial functions
It is observed that regardless of whether a strong or weak formulation is adopted the
accuracy of any approximate solutions depends on the chosen trial function. However
selecting a trial function is not always an easy task. The is particularly true if the exact
function varies widely over the problem domain, if the domain has a complex shape in
two or three dimensions, or if the domain, or problem has a complex set of boundary
conditions. The task can be made easier by selecting piecewise continuous trial functions.
Consider piecewise linear functions in a one dimensional domain:

i
(x) =
_

_
(x x
i1
)/h
i
for x
i1
x x
i
(x
i+1
x)/h
i+1
for x
i
x x
i+1
0 for x < x
i1
, or x > x
i+1
(1.18)
The piecewise linear functions can be represented graphically as shown in Figure 1.3.
Figure 1.3: Piecewise linear functions
Let us go on to dene a piecewise linear trial function such that:
u = a
1

1
(x) + a
2

2
(x) (1.19)
where a
1
and a
2
are unknown coecients and
1
and
2
are dened:

1
(x) =
_

_
3x for 0 x 1/3
2 3x for 1/3 x 2/3
0 for 2/3 x 1
(1.20)
7

2
(x) =
_

_
0 for 0 x 1/3
3x 1 for 1/3 x 2/3
3 3x for 2/3 x 1
(1.21)
The trial function, u can then be rewritten as:
u =
_

_
a
1
(3x) for 0 x 1/3
a
1
(2 3x) + a
2
(3x 1) for 1/3 x 2/3
a
2
(3 3x) for 2/3 x 1
(1.22)
and graphically represented as shown in Figure 1.4.
Figure 1.4: Piecewise linear trial functions
The Galerkin method gives the following weighting functions:
w
1
=
_

_
3x for 0 x 1/3
2 3x for 1/3 x 2/3
0 for 2/3 x 1
(1.23)
w
2
=
_

_
0 for 0 x 1/3
3x 1 for 1/3 x 2/3
3 3x for 2/3 x 1
(1.24)
The integrated weighted residuals over the domain are given:
I
wR1
=
_
1
0
(w

1
u

w
1
u + w
1
x)dx = 0 (1.25)
I
wR2
=
_
1
0
(w

1
u

w
1
u + w
1
x)dx = 0 (1.26)
8
where [w
i
u

] is omitted recognising that w


1
(0) = w
1
(1) = w
2
(0) = w
2
(1) = 0.
We can go on to evaluate the weighted integrals:
I
wR1
=
_
1/3
0
[3(3a) 3x(a
1
(3x)) + (3x)x] dx
+
_
2/3
1/3
[3(3a
1
+ 3a
2
) (2 3x)(2a
1
3a
1
x + 3a
2
x a
2
) + (2 3x)x] dx
+
_
1
2/3
0 dx = 0
(1.27)
I
wR2
=
_
1/3
0
0 dx
+
_
2/3
1/3
[3(3a
1
+ 3a
2
) (3x 1)(2a
1
3a
1
x + 3a
2
x a
2
) + (3x 1)x] dx
+
_
1
2/3
[3(3a
2
) (3 3x)(3a
2
3a
2
x) + (3 3x)x] dx = 0
(1.28)
giving simultaneous equations, that in matrix form can be solved to give a
1
= 0.0488 and
a
2
= 0.0569:
_
6.2222 2.9444
2.9444 6.2222
__
a
1
a
2
_
=
_
0.1111
0.2222
_
(1.29)
Hence we can plot the solution provided by our piecewise linear trial functions against
our exact solution, as shown in Figure 1.5. It is observed that although a good t is not
achieved with just two piecewise linear trial functions, a good t could be achieved with
the introduction of additional piecewise linear trial functions. While this will not be done
here, it is clear that computationally the process could quickly be automated.
Exercise: Download the Oasys GSA refresher tutorial from BlackBoard
and remind yourself of how to put together simple truss and frame structures.
GSA is based on the stiness method and you should look in the help documents for
the stiness matrices used for bar and beam elements respectively. When we move on to
the implementation of the nite element method for analysing structures we will rst of
all remind ourselves of the matrix stiness method, which is covered in the second year
structural mechanics course.
9
0 0.2 0.4 0.6 0.8 1
0
0.01
0.02
0.03
0.04
0.05
0.06
x
u
(
s
o
l
i
d
r
e
d
)
,
u
Figure 1.5: u, the exact solution (solid red), u approximate solution (dash-dot blue) using
piecewise linear trial functions
10
1.4 Galerkin Finite Element Formulation
Having introduced the concepts of the Galerkin method, and piecewise continuous trial
functions we can go on to introduce a more formal system of nite elements. Let us
consider an individual nite element as shown in Figure 1.6.
Figure 1.6: Individual nite element with nodes at x
i
and x
i+1
The element shown has two nodes at x
i
and x
i+1
with nodal variables u
i
and u
i+1
at those nodes. We will assume that our unknown trial function is of the form:
u = c
1
x + c
2
(1.30)
This trial function can be expressed in terms of the nodal variables ( u
i
and u
i+1
),
replacing c
1
and c
2
with the nodal variables:
u(x
i
) = c
1
x
i
+ c
2
= u
i
u(x
i+1
) = c
1
x
i+1
+ c
2
= u
i+1
(1.31)
Thus solving simultaneously we obtain:
c
1
=
u
i+1
u
i
x
i+1
x
i
c
2
=
u
i
x
i+1
u
i+1
x
i
x
i+1
x
i
(1.32)
Substituting expressions for c
1
and c
2
back into our unknown trial function we have:
u = N
1
(x) u
i
+ N
2
(x) u
i+1
(1.33)
11
where:
N
1
(x) =
x
i+1
x
h
i
, N
2
(x) =
x x
i
h
i
, h
i
= x
i+1
x
i
(1.34)
and N
1
and N
2
are referred to as linear shape functions.
The shape functions are such that at node n
i
, the shape function N
i
will have a value
of 1, while at all other nodes it will have a value of zero. Thus the linear shape functions,
N
1
and N
2
for a single element can be graphically represented as shown in Figure 1.7.
Figure 1.7: Linear shape functions for a single nite element (e
1
), with two nodes (n
1
and n
2
)
It is noted that in general:
n

i=1
N
i
(x) = 1 (1.35)
We can go on to look at a system of four nite elements as shown in Figure 1.8 which
we will use to nd an approximation to the actual solution using the weak form of the
governing dierential we looked at previously:

I
wR
=
n

i=1
_
x
i+1
x
i
(w

w u + wx)dx + [ u

w]
1
0
= 0 (1.36)
For an individual element e
i
we maintain the relationship:
u = N
1
(x)u
i
+ N
2
(x)u
i+1
(1.37)
12
Figure 1.8: Four nite elements (e
1
to e
4
), with ve nodes (n
1
to n
5
) with linear shape
functions
where from the Galerkin method the weighting functions w
1
and w
2
are based on the
shape functions N
1
and N
2
:
w
1
= N
1
(x)
w
2
= N
2
(x)
(1.38)
and the integrated weighted residual for an individual element e
i
is:
I
wR(e
i
)
=
_
x
i+1
x
i
_

_
N

1
N

2
_
[N

1
N

2
]
_
N
1
N
2
_
[N
1
N
2
]
_
dx
_
u
i
u
i+1
_
+
_
x
i+1
x
i
_
N
1
N
2
_
x dx
(1.39)
Hence if we have a domain between 0 and 1, with nodes at x = 0, x = 0.25, x =
0.5, x = 0.75 and x = 1, then we can derive the integrated weighted residual for each
element in the form:
I
wR(e
i
)
=
_
1
h
i
+
h
i
3

1
h
i
+
h
i
6

1
h
i
+
h
i
6
1
h
i
+
h
i
3
__
u
i
u
i+1
_
+
_
h
i
6
(x
i+1
+ 2x
i
)
h
i
6
(2x
i+1
+ x
i
)
_
(1.40)
where h
i
= x
i+1
x
i
13
We can then write the integrated weighted residual for each element in matrix form:
I
wR(e
1
)
=
_
4.08333 3.95833
3.95833 4.08333
__
u
1
u
2
_
+
_
0.0104167
0.0208333
_
(1.41)
I
wR(e
2
)
=
_
4.08333 3.95833
3.95833 4.08333
__
u
2
u
3
_
+
_
0.0416667
0.0520833
_
(1.42)
I
wR(e
3
)
=
_
4.08333 3.95833
3.95833 4.08333
__
u
3
u
4
_
+
_
0.0729167
0.0833333
_
(1.43)
I
wR(e
4
)
=
_
4.08333 3.95833
3.95833 4.08333
__
u
4
u
5
_
+
_
0.1041667
0.1145833
_
(1.44)
which can be combined to give:

I
wR
=
_

_
4.08333 3.95833 0 0 0
3.95833 8.16667 3.95833 0 0
0 3.95833 8.16667 3.95833 0
0 0 3.95833 8.16667 3.95833
0 0 0 3.95833 4.08333
_

_
_

_
u
1
u
2
u
3
u
4
u
5
_

_
+
_

_
0.0104167 u

(0)
0.0625
0.125
0.1875
0.1145833 + u

(1)
_

_
= 0
(1.45)
where u

(0) and u

(1) are referred to as the Neumann boundary conditions. In practice we have


what are referred to as the Dirichlet boundary conditions:
u(0) = u
1
= 0, u(1) = u
5
= 0
14
Thus we can alter the integrated weighted residual relationship with the known boundary
conditions:
_

_
1 0 0 0 0
3.95833 8.16667 3.95833 0 0
0 3.95833 8.16667 3.95833 0
0 0 3.95833 8.16667 3.95833
0 0 0 0 1
_

_
_

_
u
1
u
2
u
3
u
4
u
5
_

_
=
_

_
0
0.0625
0.125
0.1875
0
_

_
(1.46)
giving:
u
1
= 0, u
2
= 0.0352, u
3
= 0.0569, u
4
= 0.0505, u
5
= 0
We can substitute back into our unknown trial function for each element to give:
u
_

_
N
1
(x) u
1
+N
2
(x) u
2
= 0.1408x for 0 x 0.25
N
1
(x) u
2
+N
2
(x) u
3
= 0.0352 + 0.0868(x 0.25) for 0.25 x 0.5
N
1
(x) u
3
+N
2
(x) u
4
= 0.0569 0.0256(x 0.50) for 0.5 x 0.75
N
1
(x) u
4
+N
2
(x) u
5
= 0.0505 0.2020(x 0.75) for 0.75 x 1
(1.47)
Hence we can plot the solution provided by the Galerkin nite element formulation against
our exact solution, as shown in Figure 1.9. It is observed that although a reasonable t is
achieved with four elements, a better t could be achieved with the introduction of additional
elements. While this will not be done here, it is clear that computationally the process could
quickly be automated. It should be noted in particular that although the residual (u u) is
zero at the nodes, this is not the case in the length of the element.
So we have demonstrated the application of the Galerkin nite element formulation to a
particular governing dierential relationship. It can be seen that the method is easily applied
to a variety of physical phenomena. We shall look at the nite element method as applied in
structural mechanics.
15
0 0.2 0.4 0.6 0.8 1
0
0.01
0.02
0.03
0.04
0.05
0.06
x
u
(
s
o
l
i
d
r
e
d
)
,
u
Figure 1.9: u, the exact solution (solid red), u approximate solution (dash-dot blue) using
the Galerkin nite element formulation
16
2 Structural Finite Elements
2.1 Axial bar element
Let us rst consider a bar element, that is an element which only resists axial forces. At this
stage we will also introduce a local coordinate system onto the bar such that at the rst node,
n
1
we have = 1, and at the second node, n
2
we have = +1, as shown in Figure 2.1.
Figure 2.1: 1D bar element and associated linear shape functions
If a force per unit length is applied to the bar as shown in Figure 2.2 we can go on to look
at the strain energy and external work associated with axial deformation of the element.
Figure 2.2: 1D bar element with an axial load per unit length, p applied
The total strain energy can be expressed as:
U =
1
2
_
+a
a

x
A dx (2.1)
17
where A is the cross-sectional area of the bar (assumed to be constant). Taking the elastic
modulus of the material to be E we have
x
= E
x
and:
U =
1
2
_
+a
a
EA
2
x
dx (2.2)
with
x
=
du
dx
we have:
U =
1
2
_
+a
a
EA
_
du
dx
_
2
dx (2.3)
The external work associated with the axial deformation of the element is:
W =
_
+a
a
p u dx (2.4)
In the relative coordinate system the axial displacement function can be expressed as:
u = N
1
()u
1
+N
2
()u
2
(2.5)
which can be expressed in matrix form:
u = Nu
e
= [N
1
N
2
]
_
u
1
u
2
_
(2.6)
The strain energy in terms of the relative coordinate system can be expressed:
U =
1
2
_
+1
1
EA
_
1
a
2
__
du
d
_
2
a d (2.7)
du
d
is found from

= J

x
where J is referred to as the Jacobian operator, or derivative
transformation matrix between the global and the local coordinate systems.

x
= J
1

(2.8)
In the case of a bar element J =
x

= a, and J
1
=
1
a
In addition it is noted that x = a.
18
Given
du
d
=
_
dN
1
d
dN
2
d
_
_
u
1
u
2
_
= N

u
e
the strain energy can be expressed:
U =
1
2
u
T
e
_
+1
1
EA
a
N
T
N

d u
e
(2.9)
giving:
U =
1
2
u
T
e
K
e
u
e
(2.10)
where K
e
is the element stiness matrix:
K
e
=
EA
a
_
+1
1
N
T
N

d (2.11)
For the bar element
dN
1
d
=
1
2
and
dN
2
d
= +
1
2
and the element stiness matrix is:
K
e
=
EA
a
_
+1
1
_

1
2
+
1
2
_
[
1
2
+
1
2
]d =
EA
2a
_
+1 1
1 +1
_
=
EA
L
_
+1 1
1 +1
_
(2.12)
The external work in terms of the relative coordinate system can be expressed:
W
e
=
_
+1
1
pua d = u
T
e
a
_
+1
1
pN
T
d (2.13)
giving:
W
e
= u
T
e
f
e
(2.14)
where f
e
is the matrix of nodal forces equivalent to the applied distributed load:
f
e
= a
_
+1
1
pN
T
d =
pL
2
_
1
1
_
(2.15)
19
For a system of elements, as illustrated in Figure 2.3 we can express the strain energy and
work done by the external forces as:
U =
1
2
u
T
n

i=1
K
e
u =
1
2
u
T
Ku (2.16)
W = u
T
n

i=1
f
e
= u
T
f (2.17)
where K and f are the system stiness and force matrices.
Hence we have a global system expressed in matrix form:
Ku = f (2.18)
Figure 2.3: System of 1D bar elements
2.1.1 Numerical integration
Integrals arising from the computational implementation of the nite element method may
be solved using numerical integration, for example Gauss quadrature. Considering a function
f(x), x [1, +1] the integral I =
_
+1
1
f(x) dx may be represented by the weighted sum of the
values of f(x) at the Gauss points. The position and weightings of the Gauss points relate to
the chosen number, as described in Table 1.
Table 1: Gauss point positions and weightings
n x
i
W
i
1 0 2.0
2 1/

3 1.0
3 0 8/9
_
3/5 5/9
The technique is exact for 2n1 polynomials where n is the chosen number of Gauss points.
20
Exercise:
The MATLAB code over the page, uses the nite element method to analyse
the bar structure shown in Figure 2.4.
Make notes next to the Matlab code and draw a owchart on the blank page following,
using pseudo-code to indicate your understanding of the Matlab code. Experiment with making
changes to the code. In particular develop your understanding of how the stiness and force
matrices are constructed, and how the displacement matrix is derived.
The Matlab code can also be downloaded from BlackBoard.
Figure 2.4: Example Bar Structure
21
1 % Axial bar problem using the Finite Element Method by Andrew Phillips
2 % adapted from Ferreira, MATLAB codes for Finite Element Analysis
3
4 clear all
5 close all
6
7 % E, elastic modulus (N/mm2)
8 % A, area of crosssection (mm2)
9 % L, length of bar (mm)
10
11 E=2.05
*
105;
12 A=pi
*
102;
13 EA=E
*
A;
14 L=900;
15
16 % information on the structure will be kept in a structure array
17 s1 = struct();
18
19 % generating node coordinates and element connectivities
20
21 % setting the number of Elements
22 s1.numElements = 3;
23 % generating equally spaced nodes
24 s1.nodeCoords = 0:L/s1.numElements:L;
25 % setting coords in the x direction
26 s1.nodeXCoord = s1.nodeCoords;
27 % setting the number of Nodes
28 s1.numNodes = size(s1.nodeCoords,2);
29
30 % assigning Nodes to Elements
31 ii = 1:s1.numElements;
32 s1.elementNodes(:,1) = ii;
33 s1.elementNodes(:,2) = ii+1;
34
35 % degrees of freedom (1 at each node for a bar element)
36 s1.globalDOF = s1.numNodes;
37
38 % setting up matrices (K, u, f)
39 s1.stiffness = zeros(s1.globalDOF); % square matrix (n x n)
40 s1.displacements = zeros(s1.globalDOF,1); % column matrix (n x 1);
41 s1.force = zeros(s1.globalDOF,1); % column matrix (n x 1);
42
43 % applied loading (N)
44 s1.force(2) = 1200;
22
45
46 % deriving the system stiffness matrix
47
48 % element degrees of freedom
49 for ee=1:s1.numElements
50 elementDOF = s1.elementNodes(ee,:);
51 nn = size(elementDOF,2);
52 lengthElement = s1.nodeXCoord(elementDOF(2))s1.nodeXCoord(elementDOF(1));
53 detJacobian = lengthElement/2;
54 invJacobian = 1/detJacobian;
55
56 % using a single central Gauss point in each element (xi=0, W=2)
57 xi=0; W=2;
58 shape=struct();
59 shape.shape=[1xi; 1+xi]/2;
60 shape.naturalDerivatives=[1; 1]/2;
61 Xderivatives=shape.naturalDerivatives
*
invJacobian;
62
63 % B matrix (derivates of the shape functions)
64 B=zeros(1,nn); % single row
65 B(1:nn) = Xderivatives;
66
67 % assembling the system stiffness matrix
68 s1.stiffness(elementDOF,elementDOF)=s1.stiffness(elementDOF,elementDOF)...
69 +B'
*
B
*
W
*
detJacobian
*
EA;
70 end
71
72 % prescribed global degrees of freedom
73 s1.prescribedDOF = [1 4];
74
75 % solution
76 activeDOF=setdiff([1:s1.globalDOF]', [s1.prescribedDOF]);
77 U=s1.stiffness(activeDOF,activeDOF)\s1.force(activeDOF);
78 s1.displacements(activeDOF)=U;
79
80 % output displacements and reactions
81 disp('Displacements')
82 [(1:s1.globalDOF)' s1.displacements]
83
84 F=s1.stiffness
*
s1.displacements;
85 reactions=F(s1.prescribedDOF);
86 disp('Reactions')
87 [s1.prescribedDOF' reactions]
23
Blank page for pseudo-code owchart for the bar structure example.
24
2.1.2 Rotational transformation
In introducing the nite element formulation for an axial bar element we implicitly dealt with
transformation between a global (x) and a relative () coordinate system in one-dimension. If
we are to use bar elements in two-dimensional or three-dimensional problems we must also be
able to deal with transforming between the relative coordinate system, and a x, y or x, y, z
coordinate system. We will limit ourselves here to transforming between the one-dimensional
relative () system and a two-dimensional global (x, y) system.
Referring to the global system of equations:
Ku = f (2.19)
We can recall the system of equations for an individual bar element:
K
e
u
e
= f
e

EA
L
_
+1 1
1 +1
__
u
1
u
2
_
=
_
f
1
f
2
_
(2.20)
It is noted that in the above equation u
1
and u
2
are one-dimensional deformation values at
nodes n
1
and n
2
, and f
1
and f
2
are the associated applied forces. Going to a two-dimensional
coordinate system u
e
and f
e
will expand to 4 1 matrices and the element stiness matrix K
e
will expand to a 4 4 matrix:
K
e
u
e
= f
e

EA
L
_

_
+1 0 1 0
0 0 0 0
1 0 +1 0
0 0 0 0
_

_
_

_
u
x1
u
y1
u
x2
u
y2
_

_
=
_

_
f
x1
f
y1
f
x2
f
y2
_

_
(2.21)
It is observed that K
e
is similar to second order strain and stress tensors that we have
encountered before. As such it transforms in the same way as every second order tensor. That
is if we have an element at an angle in the x, y system as shown in Figure 2.5 we can transform
the element stiness matrix in the relative system into the element stiness matrix in the global
system, required in order to allow us for a structural system to combine all of the element
stiness matrices to give us a system stiness matrix.
25
Figure 2.5: Bar element at an angle with respect to the x, y coordinate system
K

G
e
= L

T
e
K

e
L

e
(2.22)
K

G
e
=
_

_
cos sin 0 0
sin cos 0 0
0 0 cos sin
0 0 sin cos
_

_
EA
L
e
_

_
+1 0 1 0
0 0 0 0
1 0 +1 0
0 0 0 0
_

_
_

_
cos sin 0 0
sin cos 0 0
0 0 cos sin
0 0 sin cos
_

_
(2.23)
K

G
e
=
EA
L
e
_

_
cos
2
cos sin cos
2
cos sin
cos sin sin
2
cos sin sin
2

cos
2
cos sin cos
2
cos sin
cos sin sin
2
cos sin sin
2

_
(2.24)
where K

G
e
is the element stiness matrix in the global system, K

e
is the element stiness matrix
in the relative system, L

e
is the directional cosine matrix, and L
e
is the length.
26
Truss Example
We can now adapt the Matlab code developed for our rst bar element example
in order to analyse the truss system shown in Figure 2.6.
Figure 2.6: Example Truss Structure
You should check the results that you nd using Oasys GSA. You should nd a close match
between the stiness method and the nite element method when using bar elements, as imple-
mented here.
27
1 % Axial bar truss problem using the Finite Element Method by Andrew Phillips
2 % adapted from Ferreira, MATLAB codes for Finite Element Analysis
3
4 clear all
5 close all
6
7 % E, elastic modulus (N/mm2)
8 % A, area of crosssection (mm2)
9 % L, length of bar (mm)
10
11 E=2.05
*
105;
12 A=pi
*
102;
13 EA=E
*
A;
14
15 % information on the structure will be kept in a structure array
16 s1 = struct();
17
18 % generating node coordinates and element connectivities
19
20 % generating the node coordinates (6 nodes)
21 s1.nodeCoords = [0 0; 0 3000; 3000 0; 3000 3000; 6000 0; 6000 3000];
22 % setting coords in the x and y directions
23 s1.nodeXCoord = s1.nodeCoords(:,1);
24 s1.nodeYCoord = s1.nodeCoords(:,2);
25 % setting the number of Nodes
26 s1.numNodes = size(s1.nodeCoords,1);
27
28 % assigning Nodes to Elements (11 elements)
29 s1.elementNodes = [1 2; 1 3; 2 3; 2 4; 1 4; 3 4; 3 6; 4 5; 4 6; 3 5; 5 6];
30 % setting the number of Elements
31 s1.numElements = size(s1.elementNodes,1);
32
33 % degrees of freedom (2 at each node for a bar element in 2D space)
34 s1.globalDOF = s1.numNodes.
*
2;
35
36 % setting up matrices (K, u, f)
37 s1.stiffness = zeros(s1.globalDOF); % square matrix (n x n)
38 s1.displacements = zeros(s1.globalDOF,1); % column matrix (n x 1);
39 s1.force = zeros(s1.globalDOF,1); % column matrix (n x 1);
40
41 % applied loading (N)
42 s1.force(4) = 50000; % node 2, DOF 2
43 s1.force(8) = 100000; % node 4, DOF 2
44 s1.force(12) = 50000; % node 6, DOF 2
28
45
46 % deriving the system stiffness matrix
47
48 % element degrees of freedom
49 for ee=1:s1.numElements
50 indice = s1.elementNodes(ee,:);
51 % assigns Global DOF to the element
52 elementDOF = [indice(1)
*
21 indice(1)
*
2 indice(2)
*
21 indice(2)
*
2];
53 % length of each element in the x and y directions
54 xa = s1.nodeXCoord(indice(2))s1.nodeXCoord(indice(1));
55 ya = s1.nodeYCoord(indice(2))s1.nodeYCoord(indice(1));
56 lengthElement = sqrt(xa.2+ya.2);
57 thetaElement = atan(ya/xa);
58 % Ke in the relative system
59 Ke Relative = [1 0 1 0; 0 0 0 0; 1 0 1 0; 0 0 0 0];
60 % Setting up the transformation to the global system
61 C = cos(thetaElement);
62 S = sin(thetaElement);
63 L element = [C S 0 0; S C 0 0; 0 0 C S; 0 0 S C];
64 % Ke in the global system
65 Ke Global = EA./lengthElement.
*
(L element'
*
Ke Relative
*
L element);
66 % assembling the system stiffness matrix
67 s1.stiffness(elementDOF,elementDOF) =...
68 s1.stiffness(elementDOF,elementDOF)+Ke Global;
69 end
70
71 % prescribed global degrees of freedom
72 s1.prescribedDOF = [1 2 10];
73
74 % solution
75 activeDOF=setdiff([1:s1.globalDOF]', [s1.prescribedDOF]);
76 U=s1.stiffness(activeDOF,activeDOF)\s1.force(activeDOF);
77 s1.displacements(activeDOF)=U;
78
79 % output
80 fprintf('Solution\n\n')
81
82 % output displacements and reactions
83 disp('Displacements:')
84 for n=1:s1.globalDOF
85 fprintf('Global DOF %02d, %+1.4e \n',n,s1.displacements(n));
86 end
87 fprintf('\n');
88
29
89 F=s1.stiffness
*
s1.displacements;
90 reactions=F(s1.prescribedDOF);
91 disp('Reactions:')
92 for n=1:size(s1.prescribedDOF,2);
93 fprintf('Global DOF %02d, %+1.4e \n',s1.prescribedDOF(n),reactions(n));
94 end
95 fprintf('\n');
96
97 % output axial strains
98 for n=1:s1.numElements
99 indice = s1.elementNodes(n,:);
100 xa = s1.nodeXCoord(indice(2))s1.nodeXCoord(indice(1));
101 ya = s1.nodeYCoord(indice(2))s1.nodeYCoord(indice(1));
102 s1.originallengthElement(n) = sqrt(xa.2+ya.2);
103 xanew = (s1.nodeXCoord(indice(2)) + s1.displacements(indice(2)
*
21))...
104 (s1.nodeXCoord(indice(1))+ s1.displacements(indice(1)
*
21));
105 yanew = (s1.nodeYCoord(indice(2)) + s1.displacements(indice(2)
*
2))...
106 (s1.nodeYCoord(indice(1))+ s1.displacements(indice(1)
*
2));
107 s1.finallengthElement(n) = sqrt(xanew.2+yanew.2);
108 s1.strainsElement(n) = (s1.finallengthElement(n)s1.originallengthElement(n))...
109 ./s1.originallengthElement(n);
110 end
111
112 disp('Strains:')
113 for n=1:s1.numElements
114 fprintf('Element %02d, %+1.4e \n',n,s1.strainsElement(n));
115 end
116 fprintf('\n');
117
118 % output axial stresses
119 s1.stressesElement = E.
*
s1.strainsElement;
120 disp('Stresses:')
121 for n=1:s1.numElements
122 fprintf('Element %02d, %+1.4e \n',n,s1.stressesElement(n));
123 end
124 fprintf('\n');
30
2.2 Euler-Bernoulli beam element
The Euler-Bernoulli beam element is based on standard or engineering beam bending theory.
The assumptions used in formulating standard beam bending theory are:
Plane sections remain plane after deformation.
Plane sections remain perpendicular to the neutral axis after deformation.
These assumptions are illustrated in Figure 2.7.
Figure 2.7: Euler-Bernoulli Beam Bending
Based on Figure 2.7 and the standard denition of strain we have the relationship:

11
(x
2
) =
du
1
dx
1
=
d
dx
1
_
x
2
du
2
dx
1
_
= x
2
d
2
u
2
dx
2
1
= x
2

Where is the curvature. The curvature of the beam is taken as:


=
1
R
=
d
ds
=
d
2
u
2
dx
2
1
31
Where R is the radius of curvature, and ds is the distance along the curve as illustrated in
Figure 2.8, which for small deections can be considered equal to dx
1
.
Figure 2.8: Beam curvature
With regards to a nite element formulation for a two noded element we can specify two
degrees of freedom at each node, as shown in Figure 2.9.
Figure 2.9: Degrees of freedom for a two noded Euler-Bernoulli beam element
We can dene four shape functions as illustrated in Figure 2.10 and given:
N
1
() = +
1
4
(1 )
2
(2 +) (2.25)
N
2
() = +
1
8
L(1 )
2
(1 +) (2.26)
N
3
() = +
1
4
(1 +)
2
(2 ) (2.27)
N
4
() =
1
8
L(1 +)
2
(1 ) (2.28)
32
1 0.5 0 0.5 1
0.4
0.2
0
0.2
0.4
0.6
0.8
1

N


N
1
N
2
N
3
N
4
Figure 2.10: Hermite cubic shape functions for an Euler-Bernoulli beam element
The adopted hermite shape functions are said to have C
1
continuity, whereas our original
linear shape functions had C
0
continuity. That is to say that C
1
shape functions are continuous
across nodes for the rst derivative, while C
0
shape functions are continuous for the value only.
It is noted that N
2
() and N
4
() do not reach values of 1 or zero at the relevant nodes. However
these shape functions relate to the angle of rotation, , or the slope at each of the nodes, =
du
2
dx
1
.
Thus the relationship is true for
dN
2
d
and
dN
4
d
as shown in Figure 2.11 and given:
dN
2
d
=
1
4
(1 2 + 3
2
) (2.29)
dN
4
d
=
1
4
(1 + 2 + 3
2
) (2.30)
The strain energy associated with bending of the element can be obtained as:
U =
1
2
_
V
E
2
11
dV (2.31)
Where dV = dAdx
1
, thus:
U =
1
2
_
+a
a
EI
_

2
u
2
x
2
1
_
2
dx
1
=
1
2
_
+1
1
EI
a
4
_

2
u
2
x
2
1
_
2
a d (2.32)
33
1 0.5 0 0.5 1
0.4
0.2
0
0.2
0.4
0.6
0.8
1

d
N


dN
2
dN
4
Figure 2.11: dN
2
and dN
4
for an Euler-Bernoulli beam element
From the chain rule it is found that
d
2
u
2
d
2
=
1
a
2
d
2
u
2
dx
2
1
=
4
L
2
d
2
u
2
dx
2
1
. In addition it is noted that
x = a =
L
2
.
Given
d
2
u
2
d
2
=
d
2
N
d
2
u
e
= N

u
e
the strain energy can be expressed:
U =
1
2
u
T
e
EI
a
3
_
+1
1
N
T
N

du
e
(2.33)
giving
U =
1
2
u
T
e
K
e
u
e
(2.34)
where K
e
is the element stiness matrix:
K
e
=
EA
a
3
_
+1
1
N
T
N

d (2.35)
and:
N

=
1
L
_
6

L
3 1 6

L
3 + 1
_
(2.36)
Using the Hermite shape functions the element stiness matrix is found as:
34
K
e
=
EI
L
3
_

_
12 6L 12 6L
6L 4L
2
6L 2L
2
12 6L 12 6L
6L 2L
2
6L 4L
2
_

_
(2.37)
It is observed that this is the same as the matrix derived using a virtual work approach,
therefore an exact match should be found between the stiness method and the nite element
method when using Euler-Bernoulli beam elements as formulated here.
If we apply a uniform load to the element as shown in Figure 2.12 we can state the work
done by the external forces in deforming the element as:
W =
_
+a
a
pu dx = u
T
e
a
_
+1
1
pN
T
d (2.38)
Figure 2.12: Uniformly distributed loading for an Euler-Bernoulli beam element
The vector of nodal forces and moments is then found as:
f
e
= a
_
+1
1
pN
T
d = pL
_

_
1/2
L/12
1/2
L/12
_

_
(2.39)
It is observed that these have the same magnitude as the xed end reactions and moments
for a uniformly loaded xed end beam, which you will have encountered when using the stiness
method.
35
Euler Bernoulli Beam Example
The Matlab code below can be used to model the simply supported and xed
end beams shown in Figure 2.13 using Euler-Bernoulli beam elements.
Adapt the code for the dierent boundary conditions, and perform a convergence study
(increasing the number of elements, and recording the predicted deection at midspan) to nd
the number of Euler-Bernoulli beam elements required to nd the analytical midspan deections.
You will recall that these are

max
=
5pL
4
384EI
for a simply supported beam, and

max
=
pL
4
384EI
for a xed end beam.
Note the eect that using the nodal force vector has on the reported reaction values. Plot
the nodal displacements for 2, 4, 8, 16, 32 and 64 elements for both the simply supported and
xed end beams and comment on what you think is a sensible mesh density with regards to
accurately reproducing the displaced shapes of the beams.
Figure 2.13: Example Truss Structure
36
1 % EulerBernoulli beam problem using the Finite Element Method
2 % by Andrew Phillips
3
4 clear all
5
6 % comment to show successive plots on the same graph
7 close all
8
9 % E, elastic modulus (N/mm2)
10 % I, second moment of area of crosssection (mm4)
11 % L, length of beam (mm)
12
13 E=2.05
*
105;
14 I=8.249
*
107;
15 EI=E
*
I;
16 L=10000;
17
18 % information on the structure will be kept in a structure array
19 s1 = struct();
20
21 % generating node coordinates and element connectivities
22
23 % setting the number of Elements
24 % asking the user for the number of elements
25 s1.numElements = input('How many elements do you wish to use? ');
26 % generating equally spaced nodes
27 s1.nodeCoords = 0:L/s1.numElements:L;
28 % setting coords in the x direction
29 s1.nodeXCoord = s1.nodeCoords;
30 % setting the number of Nodes
31 s1.numNodes = size(s1.nodeCoords,2);
32
33 % assigning Nodes to Elements
34 ii = 1:s1.numElements;
35 s1.elementNodes(:,1) = ii;
36 s1.elementNodes(:,2) = ii+1;
37
38 % degrees of freedom (2 at each node for an EB beam element)
39 s1.globalDOF = s1.numNodes.
*
2;
40
41 % setting up matrices (K, u, f)
42 s1.stiffness = zeros(s1.globalDOF); % square matrix (n x n)
43 s1.displacements = zeros(s1.globalDOF,1); % column matrix (n x 1);
44 s1.force = zeros(s1.globalDOF,1); % column matrix (n x 1);
37
45
46 % applied loading
47 % load per unit length
48 % (kN/m to N/mm)
49 p = 5;
50
51 % deriving the system stiffness matrix
52
53 % element degrees of freedom
54 for ee=1:s1.numElements
55 indice = s1.elementNodes(ee,:);
56 % assigns Global DOF to the element
57 elementDOF = [indice(1)
*
21 indice(1)
*
2 indice(2)
*
21 indice(2)
*
2];
58 % length of the element
59 lengthElement = s1.nodeXCoord(indice(2))s1.nodeXCoord(indice(1));
60 Le = lengthElement;
61 % Ke
62 Ke = EI./(Le.3)
*
[...
63 12 6.
*
Le 12 6.
*
Le;...
64 6.
*
Le 4.
*
Le.2 6.
*
Le 2.
*
Le2;...
65 12 6.
*
Le 12 6.
*
Le;...
66 6.
*
Le 2.
*
Le.2 6.
*
Le 4.
*
Le.2];
67 % fe
68 fe = p.
*
[Le./2; Le.2./12; Le./2; Le.2./12];
69 % assembling the system stiffness matrix
70 s1.stiffness(elementDOF,elementDOF) =...
71 s1.stiffness(elementDOF,elementDOF)+Ke;
72 % assembling the nodal force vector
73 s1.force(elementDOF)=s1.force(elementDOF)+fe;
74 end
75
76 % prescribed global degrees of freedom
77
78 % simply supported
79 s1.prescribedDOF = [1 s1.globalDOF1];
80
81 % fixed end
82 % s1.prescribedDOF = [1 2 s1.globalDOF1 s1.globalDOF];
83
84 % solution
85 activeDOF=setdiff([1:s1.globalDOF]', [s1.prescribedDOF]);
86 U=s1.stiffness(activeDOF,activeDOF)\s1.force(activeDOF);
87 s1.displacements(activeDOF)=U;
88
38
89 % output
90 fprintf('Solution\n\n')
91
92 % output displacements and reactions
93 disp('Displacements:')
94 for n=1:s1.globalDOF
95 fprintf('Global DOF %02d, %+1.4e \n',n,s1.displacements(n));
96 end
97 fprintf('\n');
98
99 F=s1.stiffness
*
s1.displacements;
100 reactions=F(s1.prescribedDOF);
101 disp('Reactions:')
102 for n=1:size(s1.prescribedDOF,2);
103 fprintf('Global DOF %02d, %+1.4e \n',s1.prescribedDOF(n),reactions(n));
104 end
105 fprintf('\n');
106
107 % plot the vertical displacements
108 fig1=figure(1);
109 plot(s1.nodeXCoord,s1.displacements(1:2:s1.globalDOF),'x r');
110 grid on
111 title('EulerBernoulli Beam Example');
112 xlabel('Horizontal Distance');
113 ylabel('Vertial Deflection');
114 hold on
39
2.3 Timoshenko beam element
Alternative beam bending theories to the standard beam bending theory exist, and the formu-
lation of the Timonshenko beam element is an example of the application of one of these.
Timoshenko beam bending theory can be considered as an extension of standard beam
bending theory, in which deections due to shear strains are also taken into account. The
assumptions used in formulating Timoshenko beam theory are:
Plane sections remain in plane after deformation.
Plane sections need not remain perpendicular to the neutral axis.
The rst of these assumptions in particular will be looked at with regards to compatibility.
The additional contribution to deformation due to considering shear strains is illustrated in
Figure 2.14. The contribution of shear strains to deformation of a beam is seen to increase as
the depth:span ratio increases.
Figure 2.14: Timoshenko Beam Bending
40
It is seen in Figure 2.14 that the assumption of plane sections remaining in plane after
deformation doesnt t with what we know about the shear distribution within a section. This
can to some extent be taken account of through the introduction of a shear correction coecient,
or shape factor, in our shear deformation relationship:

12
=
V
GA
(2.40)
Where V is the shear force acting across the section in the x
2
direction, G is the shear
modulus, normally taken as E/2(1 + ) where is Poissons ratio, and A is the area of the
cross-section. Various values of have been put forward for cross-sections of dierent shapes,
although 5/6 is often used.
The nite element formulation for a Timoshenko beam element is dierent to the formulation
for an Euler-Bernoulli beam element. Expressions for the curvature, , caused by bending
moments, and the angle, , caused by shear forces can be written in matrix form as:
_

_
=
_
0
d
dx
1

d
dx
1
1
__
u
2

_
(2.41)
Expressions for the bending moment, M, and the shear force, V can be written in matrix
form as:
_
M
V
_
=
_
EI 0
0 GA
__

_
(2.42)
We can dene a Timoshenko beam element using the same degrees of freedom at each node
as we had for the Euler-Bernoulli beam element, as shown in Figure 2.9. For the formulation
presented here we will use linear shape functions.
_
u
2

_
=
_
1
2
(1 ) 0
1
2
(1 +) 0
0
1
2
(1 ) 0
1
2
(1 +)
_
_

_
u
2(n
1
)

(n
1
)
u
2(n
2
)

(n
2
)
_

_
(2.43)
We can dene the B matrix as:
41
B = dN =
_
0
d
dx
1

d
dx
1
1
__
1
2
(1 ) 0
1
2
(1 +) 0
0
1
2
(1 ) 0
1
2
(1 +)
_
(2.44)
The element stiness matrix can then be dened as:
K
e
=
_
V
B
T
DB dV (2.45)
where D =
_
EI 0
0 GA
_
While the equivalent nodal force vector can be dened as:
f
e
=
_
V
N
T
p dV (2.46)
where p is a uniformly distributed load.
It is observed that the expressions for K
e
and f
e
are general relationships, such that we
could have used them in the development of the axial bar element, and the Euler-Bernoulli
beam element formulations. They are easy to implement using short blocks of code within a
numerical program such as Matlab, and also form the basis of other structural and continuum
nite element formulations that you will investigate in future years.
42
Timoshenko Beam Example
The Matlab code below can be used to model the simply supported and xed
end beams shown in Figure 2.13 (for the Euler-Bernoulli beam element example)
using Timoshenko beam elements.
Instead of using the previous section you should calculate I and A values for a cross-section
300mm in depth and 30mm in width. You may take as 5/6.
As you did for the Euler-Bernoulli beam example adapt the code for the dierent boundary
conditions, and perform a convergence study (increasing the number of elements, and recording
the predicted deection at midspan) to nd the minimum number of Timoshenko beam elements
required to nd consistent values for the midspan deection. You will see that the code makes
use of numerical integration, with two gauss points per element used for the integration related
to curvature, and a single gauss point used per element for the integration related to shear.
Repeat the convergence study for beam depths of 100mm and 900mm.
The analytical values for midspan deection using the Timoshenko formulation are:

max
=
5pL
4
384EI

pL
2
8GA
(2.47)
for a simply supported beam, and

max
=
pL
4
384EI

pL
2
8GA
(2.48)
for a xed end beam.
Repeat the exercise using Euler-Bernoulli beam elements for the new cross-sections and nd
the percentage increase in the midspan deections found using Timoshenko beam elements.
Discuss when you think the use of Timoshenko, as opposed to Euler-Bernoulli beam elements
could be important.
43
1 % Axial bar problem using the Finite Element Method by Andrew Phillips
2 % adapted from Ferreira, MATLAB codes for Finite Element Analysis
3
4 clear all
5 close all
6
7 % E, elastic modulus (N/mm2)
8 % A, area of crosssection (mm2)
9 % I, second moment of area (mm4)
10 % L, length of bar (mm)
11
12 E=2.05
*
105; %elastic (Young's) modulus
13 G=E/(2
*
(1+0.3)); %shear modulus
14 k=5/6; % shear correction factor%
15 b=30;
16 d=300;
17 A=b
*
d;
18 I=b
*
d3/12;
19 EI=E
*
I; %curvature%
20 kGA=k
*
G
*
A; %shear%
21 L=10000;
22
23 % D matrix
24 D=[EI 0; 0 kGA];
25
26 % information on the structure will be kept in a structure array
27 s1 = struct();
28
29 % generating node coordinates and element connectivities
30
31 % setting the number of Elements
32 % asking the user for the number of elements
33 s1.numElements = input('How many elements do you wish to use? ');
34 % generating equally spaced nodes
35 s1.nodeCoords = 0:L/s1.numElements:L;
36 % setting coords in the x direction
37 s1.nodeXCoord = s1.nodeCoords;
38 % setting the number of Nodes
39 s1.numNodes = size(s1.nodeCoords,2);
40
41 % assigning Nodes to Elements
42 ii = 1:s1.numElements;
43 s1.elementNodes(:,1) = ii;
44 s1.elementNodes(:,2) = ii+1;
44
45
46 % degrees of freedom (2 at each node for a T beam element)
47 s1.globalDOF = s1.numNodes.
*
2;
48
49 % setting up matrices (K, u, f)
50 s1.stiffness = zeros(s1.globalDOF); % square matrix (n x n)
51 s1.displacements = zeros(s1.globalDOF,1); % column matrix (n x 1);
52 s1.force = zeros(s1.globalDOF,1); % column matrix (n x 1);
53
54 % applied loading
55 % load per unit length
56 % (kN/m to N/mm)
57 p = 5;
58
59 % deriving the system stiffness matrix
60
61 % element degrees of freedom
62 for ee=1:s1.numElements
63 indice = s1.elementNodes(ee,:);
64 % assigns Global DOF to the element
65 elementDOF = [indice(1)
*
21 indice(1)
*
2 indice(2)
*
21 indice(2)
*
2];
66 % length of the element
67 lengthElement = s1.nodeXCoord(indice(2))s1.nodeXCoord(indice(1));
68 Le = lengthElement;
69 detJacobian = Le/2;
70 invJacobian = 1/detJacobian;
71
72 % two point gauss integration
73 xi=[+1/sqrt(3) 1/sqrt(3)]; W=[1 1];
74
75 for n=1:size(W,2)
76
77 shape=struct();
78 shape.shape=[1xi(n); 1+xi(n)]/2;
79 shape.naturalDerivatives=[1; 1]/2;
80 Xderivatives=shape.naturalDerivatives
*
invJacobian;
81
82 %%%% theta contribution
83 % B matrix (derivates of the shape functions)
84 B=zeros(2,4);
85 B(1,2) = Xderivatives(1);
86 B(1,4) = Xderivatives(2);
87 % assembling the system stiffness matrix
88 s1.stiffness(elementDOF,elementDOF)=s1.stiffness(elementDOF,elementDOF)...
45
89 +B'
*
B.
*
W(n).
*
detJacobian.
*
D(1,1);
90 %%%%
91
92 % assembling the nodal force vector
93 s1.force(elementDOF)=s1.force(elementDOF)+...
94 p
*
[shape.shape(1) 0 shape.shape(2) 0]'.
*
W(n).
*
detJacobian;
95
96 end
97
98 % avoiding a problem described as 'shear locking'
99 % one point gauss integration when looking at shear
100 xi=[0]; W=[2];
101 for n=1:size(W,2)
102
103 shape=struct();
104 shape.shape=[1xi(n); 1+xi(n)]/2;
105 shape.naturalDerivatives=[1; 1]/2;
106 Xderivatives=shape.naturalDerivatives
*
invJacobian;
107
108 %%%% gamma contribution
109 % B matrix (derivatives of shape functions and shape functions)
110 B=zeros(2,4);
111 B(2,1) = Xderivatives(1);
112 B(2,3) = Xderivatives(2);
113 B(2,2) = shape.shape(1);
114 B(2,4) = shape.shape(2);
115 % assembling the system stiffness matrix
116 s1.stiffness(elementDOF,elementDOF)=s1.stiffness(elementDOF,elementDOF)...
117 +B'
*
B.
*
W(n).
*
detJacobian.
*
D(2,2);
118 %%%%
119
120 end
121 end
122
123 % prescribed global degrees of freedom
124
125 % simply supported
126 s1.prescribedDOF = [1 s1.globalDOF1];
127
128 % fixed end
129 % s1.prescribedDOF = [1 2 s1.globalDOF1 s1.globalDOF];
130
131 % solution
132 activeDOF=setdiff([1:s1.globalDOF]', [s1.prescribedDOF]);
46
133 U=s1.stiffness(activeDOF,activeDOF)\s1.force(activeDOF);
134 s1.displacements(activeDOF)=U;
135
136 % output
137 fprintf('Solution\n\n')
138
139 % output displacements and reactions
140 disp('Displacements:')
141 for n=1:s1.globalDOF
142 fprintf('Global DOF %02d, %+1.4e \n',n,s1.displacements(n));
143 end
144 fprintf('\n');
145
146 % midspan displacements
147 disp('Midspan Displacement:')
148 fprintf('%+1.4e \n\n',s1.displacements(s1.globalDOF/2));
149
150 F=s1.stiffness
*
s1.displacements;
151 reactions=F(s1.prescribedDOF);
152 disp('Reactions:')
153 for n=1:size(s1.prescribedDOF,2);
154 fprintf('Global DOF %02d, %+1.4e \n',s1.prescribedDOF(n),reactions(n));
155 end
156 fprintf('\n');
157
158 % plot the vertical displacements
159 fig1=figure(1);
160 plot(s1.nodeXCoord,s1.displacements(1:2:s1.globalDOF),'x r');
161 grid on
162 title('Timoshenko Beam Example');
163 xlabel('Horizontal Distance');
164 ylabel('Vertial Deflection');
165 hold on
47
- Blank page for notes -
48

Das könnte Ihnen auch gefallen