Appendix D Finite Element Analysis Using MATLAB Toolbox In this section, a MATLAB 3 toolbox CALFEM 4 is introduced. This toolbox is developed by Lund University in 1999 and can be downloaded free of charge from http://www .byggmek.lth.se/Calfem. CALFEM provides functions that can be used for finite element analysis of a variety of structures. Compared to other finite element programs, this tool- box has many advantages for education. Many commercial programs automatically per- form finite element process. Thus, the users do not understand the process of constructing element stiffness matrices, assembling them, and applying boundary conditions. In this toolbox, however, the users must provide every step of finite element process. The tool- box then provides functions that can perform particular step of finite element process. In general, MATLAB toolboxes are stored in the toolbox folder in MATLAB instal- lation folder. In order to access the toolbox, the user must provide path information using File, Set Path . . . command from the main menu. Once the CALFEM folder location is stored in MATLAB paths, the user can access CALFEM functions anywhere. Type ‘‘help spring1e’’ in MATLAB window in order to test accessibility. If the path is properly assigned, then MATLAB should return help content of ‘‘spring1e’’ function, as shown in Figure D.1. D.1 FINITE ELEMENT ANALYSIS OF BAR AND TRUSS Three Uniaxial Bar Elements In this section, the uniaxial bar problem in Example 2.3 will be solved using the MATLAB toolbox. The problem consists of four nodes and three elements, as shown in Figure D.2. In one–dimensional problems, each node has a single DOF, and nodes are Ke=spring1e(ep) ———————————————————————————————————————————————————— PURPOSE Compute element stiffness matrix for spring element. INPUT: ep = [k]; spring stiffness or analog quantity OUTPUT: Ke : stiffness matrix, dim(Ke)= 2 x 2 ———————————————————————————————————————————————————— Figure D.1 Help content of spring1e function 3 MATLAB is the trademark of The MathWorks, Inc. 4 CALFEM A finite element toolbox for MATLAB, Lund University, 1999, Web: http://www.byggmek.lth.se/ Calfem 391
25
Embed
Finite Element Analysis Using MATLAB Toolbox · properly assigned, then MATLAB should return help content of ‘‘spring1e’’ function, as shown in Figure D.1. D.1 FINITE ELEMENT
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Appendix D
Finite Element Analysis Using
MATLAB Toolbox
In this section, a MATLAB3 toolbox CALFEM4 is introduced. This toolbox is developed
by Lund University in 1999 and can be downloaded free of charge from http://www
.byggmek.lth.se/Calfem. CALFEM provides functions that can be used for finite element
analysis of a variety of structures. Compared to other finite element programs, this tool-
box has many advantages for education. Many commercial programs automatically per-
form finite element process. Thus, the users do not understand the process of constructing
element stiffness matrices, assembling them, and applying boundary conditions. In this
toolbox, however, the users must provide every step of finite element process. The tool-
box then provides functions that can perform particular step of finite element process.
In general, MATLAB toolboxes are stored in the toolbox folder in MATLAB instal-
lation folder. In order to access the toolbox, the user must provide path information using
File, Set Path . . . command from the main menu. Once the CALFEM folder location is
stored in MATLAB paths, the user can access CALFEM functions anywhere. Type
‘‘help spring1e’’ in MATLAB window in order to test accessibility. If the path is
properly assigned, then MATLAB should return help content of ‘‘spring1e’’ function,
as shown in Figure D.1.
D.1 FINITE ELEMENT ANALYSIS OF BAR AND TRUSS
Three Uniaxial Bar Elements
In this section, the uniaxial bar problem in Example 2.3 will be solved using the
MATLAB toolbox. The problem consists of four nodes and three elements, as shown in
Figure D.2. In one–dimensional problems, each node has a single DOF, and nodes are
Ke=spring1e(ep)————————————————————————————————————————————————————PURPOSECompute element stiffness matrix for spring element.
INPUT: ep = [k]; spring stiffness or analog quantityOUTPUT: Ke : stiffness matrix, dim(Ke)= 2 x 2————————————————————————————————————————————————————
Figure D.1 Help content of spring1e function
3 MATLAB is the trademark of The MathWorks, Inc.4 CALFEM A finite element toolbox for MATLAB, Lund University, 1999, Web: http://www.byggmek.lth.se/
Calfem
391
connected by elements. The information of the connectivity is defined by the following
array:
Edof=[1 1 2;2 2 3;3 2 4];
(P.1)
The first column of Edof array represents element numbers, and the second and third
columns represent the DOF of Nodes i and j, respectively. For example, Element 2 (the
second row) connects Nodes 2 and 3.
Next, the global stiffness matrix and force vector are defined:
K=zeros(4,4);F=zeros(4,1);F(1)=40;
(P.2)
Since there are four nodes and each node has a single DOF, the dimension of the global
stiffness matrix is 4� 4. Initially, components of the stiffness matrix and force vector are
set to zero. In the last line of (P.2), the external force 40 N is applied to Node 1. Note that
the reaction forces are not specified in the global force vector.
Next, the element stiffness matrices are constructed using the given spring constants.
For this purpose, ‘‘spring1e’’ function is used:
ep1=50;ep2=30;ep3=70;
Ke1=spring1e(ep1);
Ke2=spring1e(ep2);
Ke3=spring1e(ep3);
(P.3)
The three variables, ep1, ep2, and ep3, represent the axial rigidity (or, spring constants)
of each element. When a uniaxial bar with constant cross-section is used, the axial
rigidity, EA=L, can be used as the spring constant. Using these spring constants, the
‘‘spring1e’’ function calculates the 2�2 stiffness matrix that corresponds to Eq. (2.6)
in Chapter 2. For example, Ke3 contains the 2�2 stiffness matrix for Element 3. This
step must be repeated for all elements. When the material properties are the same, the
program can be simplified by using the for–end loop command in MATLAB.
Once the element stiffness matrices are obtained, they are assembled to form the
global stiffness matrix using ‘‘assem’’ function:
K=assem(Edof(1,:),K,Ke1);
K=assem(Edof(2,:),K,Ke2);
K=assem(Edof(3,:),K,Ke3);
(P.4)
Figure D.2 One–dimensional structure with three uniaxial bar elements
392 Chapter D Finite Element Analysis Using MATLAB Toolbox
In order to assemble the element stiffness matrix into the global stiffness matrix, it is
necessary to specify the relation between the local DOFs in the global DOFs. This infor-
mation is stored in Edof array. Thus, the first argument of ‘‘assem’’ function is the row
of Edof array. Then, the first line of (P.4) will copy 2�2 matrix Ke1 into the global
stiffness matrix K in the location that is specified in the first row of Edof array. The result
is returned to the global stiffness matrix K so that the matrix K contains the accumulated
data from all elements.
The global stiffness matrix K in (P.4) is singular because there is a rigid body motion
in the system. In order to remove the rigid body motion, the boundary condition must be
applied. The displacement boundary condition is specified by
bc=[3 0;4 0];
(P.5)
The first column of bc array represents the DOF number and the second column is the
prescribed value of the DOF. Since Nodes 3 and 4 are fixed, zero values are provided for
both nodes.
Using the global stiffness matrix and global force vector, the unknown DOF can be
solved using ‘‘solveq’’ function:
Q=solveq(K,F,bc); (P.6)
In this particular implementation, the reduced stiffness matrix is not constructed explic-
itly. The prescribed DOFs are deleted during the matrix solution phase. The results of
the matrix solution (nodal displacement) are stored in the variable Q. For this problem,
the stored nodal displacements are Q ¼ f1:2; 0:4; 0:0; 0:0g. Note that Nodes 3 and 4
have zero displacement.
The nodal displacement that is calculated in (P.6) can be used to calculate the ele-
ment force. For that purpose, the element displacement needs to be extracted from the
global displacement Q, as
ed1=extract(Edof(1,: ),Q);
ed2=extract(Edof(2,: ),Q);
ed3=extract(Edof(3,:),Q);
(P.7)
The array Edof is used to find the location of those nodes in the element from the global
node numbers. For example, ed2 contains the displacement of Nodes 2 and 3. Using the
element nodal displacements and spring constant for the element, the element force can
be calculated by calling ‘‘spring1s’’ function:
es1=spring1s(ep1,ed1);
es2=spring1s(ep2,ed2);
es3=spring1s(ep3,ed3);
(P.8)
The element force corresponds to that in Eq. (2.4). It is positive when the force is tension
and negative when compression. For this problem, the element forces are es1 ¼�40 N; es2 ¼ �12 N, and es3 ¼ �28 N.
Table D.1 provides the list of MATLAB program that can solve the same problem in
Example 2.3.
D.1 Finite Element Analysis of Bar and Truss 393
The above example is the classical finite element analysis procedure. As can be seen,
the formulation is based on the general force–displacement equations of a single one–
dimensional truss element. The two–force member element or truss element is the sim-
plest type of element used in finite element analysis. The procedure to formulate and
solve the force–displacement equation is straightforward, but somewhat tedious. In real
life applications, the use of one–dimensional truss element is rare. In the next section, we
will expand the procedure to solving two–dimensional truss.
Plane Truss Example
In this section, the two–bar truss structure in Example 2.4 is solved using the MATLAB
finite element program. Unlike one–dimensional problem, there are two DOFs at each
node. Two DOFs are assigned at each node in a sequence along with the node numbers,
as illustrated in Figure D.3.
The element connectivity array now contains four DOFs:
Edof=[1 1 2 3 4;
2 3 4 5 6];(P.9)
The first element connects Node 1 (DOF 1 and 2) and Node 2 (DOF 3 and 4), while the
second elements connects Node 2 (DOF 3 and 4) and Node 3 (DOF 5 and 6).
Table D.1 MATLAB Commands for
Spring Finite Elements
Edof=[1 1 2;2 2 3;3 2 4];
K=zeros(4,4);
F=zeros(4,1); F(1)=40;
ep1=50;ep2=30;ep3=70;
Ke1=spring1e(ep1);
Ke2=spring1e(ep2);
Ke3=spring1e(ep3);
K=assem(Edof(1,:),K,Ke1);
K=assem(Edof(2,:),K,Ke2);
K=assem(Edof(3,:),K,Ke3);
BC=[3 0;4 0];
Q=solveq(K,F,bc);
ed1=extract(Edof(1,:),Q);
ed2=extract(Edof(2,:),Q);
ed3=extract(Edof(3,:),Q);
es1=spring1s(ep1,ed1);
es2=spring1s(ep2,ed2);
es3=spring1s(ep3,ed3);
394 Chapter D Finite Element Analysis Using MATLAB Toolbox
The size of global stiffness matrix and force vector can be determined based on the
total number of DOFs, as
K=zeros(6);
F=zeros(6,1);
F(3)=50;
(P.10)
Note that the applied force at Node 2 in the x–direction, it must be assigned in the DOF 3.
In the two–dimensional problem, two properties are required for the element:
ep=[3e7 :125�:125�pi]; (P.11)
The first represents the Young’s modulus, while the second for the cross-sectional area.
The length of the element will be calculated based on the coordinates of the two nodes.
Unlike one-dimensional problem, the coordinates of nodes are required in order to
calculate the length of the element and the coordinate transformation matrix.
ex1=[0 12];ey1=[0 8];
(P.12)
For example, ex1 array includes the x–coordinates of two nodes of Element 1, while ey1contains y–coordinates.
The element stiffness matrix can be obtained using ‘‘bar2e’’ function, as
Ke1=bar2e(ex1,ey1,ep); (P.13)
The first two arguments are nodal coordinates of x– and y–directions, respectively, and
the last argument is the property of the element.
Assembly, boundary conditions, solving the matrix equation, and extracting element
displacements are the same with that of one–dimensional case.
Once the element displacements are available, the element forces can be calculated
using ‘‘bar2s’’ function:
N1=bar2s(ex1,ey1,ep,ed1); (P.14)
The first two arguments are nodal coordinates of x– and y–directions, respectively, and
the last arguments are the element displacements.
Figure D.3 Degrees–of–freedom of two–bar truss
D.1 Finite Element Analysis of Bar and Truss 395
One of the most advantageous features of the two–dimensional program is that it can
provide the geometry of the elements graphically. First, ‘‘eldraw2’’ function plots the
undeformed geometry of the element.
eldraw2(ex1,ey1); (P.15)
This function should be called twice for Elements 1 and 2.
Next, ‘‘eldisp2’’ function plots the deformed geometry of the element using the
element displacement:
eldisp2(ex1,ey1,ed1,plotpar,scale); (P.16)
The variable ‘‘plotpar’’ specifies the property of the deformed geometry plot.
For example, plotpar=[1 3 1] plots the deformed geometry using a solid line, ma-
genta color, and circle mark for the node. Since the actual displacement is usually very
small, it is often difficult to identify the deformed geometry from the undeformed one. Thus,
the ‘‘scale’’ is multiplied with the actual displacement in order to magnify the deforma-
tion. It is important to specify the value of ‘‘scale’’ so that the actual magnitude of dis-
placements can be estimated.
Since the above ‘‘eldraw2’’ and ‘‘eldisp2’’ functions plot a single element,
they must be repeated for all elements in order to plot the entire structure. Table D.2 lists
the program for the two–bar truss. Since the deformation is relatively large, a unit scale is
used for plotting the deformed geometry. Figure D.4 shows the initial geometry of the
truss and deformed geometry with the scale of 1,000. Different values for plotpar are
used to distinguish the deformed geometry from the undeformed one.
Plane Truss Example 2
Determine the normal stress in each member of the truss shown in Figure D.5. Compare
the finite element result with that from the analytical calculation.
When Ex and Ey contains the nodal coordinates of all elements, ‘‘eldraw2’’ and
‘‘eldisp2’’ functions can plot the entire geometry by a single call.
eldraw2(Ex,Ey);
eldisp2(Ex,Ey,Ed,plotpar,scale);(P.20)
The element displacement Ed also contains all element displacements. Figure D.7 shows
the deformed and undeformed geometry of the truss. Due to relatively large deformation,
scale=1 is used in plotting Figure D.7.
Space Truss Example
In the case of space truss, each node has three DOFs: ux, uy, and uz. Consider the space
truss shown in Figure D.8. The Young’s modulus E ¼ 210 GPa, and dimensions of the
cross–section are a ¼ b ¼ 7:5 mm. Solve the problem using MATLAB toolbox and com-
pare the results with analytical calculation.
Let us solve the problem using the conventional vector algebra to solve the space
truss problem. The coordinates of the nodes are given as Að5; 4; 3Þ; Bð0; 2; 3Þ;Cð5; 0; 0Þ;Dð5; 0; 6Þ; Eð0; 0; 3Þ. Since the space truss consists of two-force members,
we can obtain equilibrium relation at Node A using the Free-Body-Diagram as
First, we want to calculate the direction of each member force using the position
vectors AB, AC, and AD:
Figure D.7 Deformed geometry of the nine-bar truss model
Figure D.8 Space truss model
400 Chapter D Finite Element Analysis Using MATLAB Toolbox
D.2 Finite Element Analysis Using Frame Elements 405
Portal Frame Analysis
Consider the plan frames in Figure D.12. All frames have the same material properties.
The horizontal frame has different cross-sectional geometry from two vertical frames. All
frames are made of the same material with Young’s modulus E ¼ 210 GPa. Two vertical
frames have area A1 ¼ A2 ¼ 4:53� 10�3 and moment of inertia I1 ¼ I2 ¼ 2:51�10�5 m4. The horizontal frame has area A3 ¼ 1:43� 10�2 m2 and moment of inertia
I3 ¼ 3:309� 10�4 m4. Uniformly distributed load p ¼ 75 kN=m is applied at the horizon-
tal frame, and a concentrated force F ¼ 1 kN is applied in the horizontal direction at Node
2. Plot the axial force, shear force, and bending moment diagram of the frame. Use three
frame elements to model the structure.
The ‘‘beam2e’’ function can be used for the frame element. The ‘‘beam2e’’ func-
tion also has a capability of calculating the equivalent nodal forces from the distributed
load. eq3=½0 -75000 � represents the distributed load for Element 3 in the local x–
and y–directions. Since the distributed load p is applied downward, it is negative in local
y-direction. In this case, the ‘‘beam2e’’ function has additional parameter and additional
D.2 Finite Element Analysis Using Frame Elements 407
Figure D.13, Figure D.14, and Figure D.15 show the axial force, bending moment,
shear force diagrams, respectively, plotted using ‘‘eldia2’’ function. The complete list
of the MATLAB program that can solve the portal frame problem is shown in Table D.8.
D.3 FINITE ELEMENT ANALYSIS USING PLANESOLID ELEMENTS
Bending analysis of a cantilever beam using CST element
Consider a beam under a pure bending moment, as shown in Figure D.16. Using ten CST
elements, calculate the stress of the beam along the neutral axis and top and bottom surfa-
ces using the MATLAB finite element toolbox. For material properties, use E ¼ 200GPa
and n ¼ 0:3. The thickness of the beam is 0.01 m. Since CST element does not have rota-
tional DOF, the bending moment can be produced by applying an equal and opposite
force F ¼ �100; 000 N at the end of the beam. Compare the numerical results with the
elementary theory of beam. Provide an element stress contour plot for sxx.
The complete list of the MATLAB program that can solve the portal frame problem
is shown in Table D.10. Plane solid elements have two DOFs at each node: ux and uy.
Figure D.13 Axial force diagram for the plane
frame structure Figure D.14 Bending moment diagram for the plane
frame structure
Figure D.15 Shear force diagram for the plane frame structure
408 Chapter D Finite Element Analysis Using MATLAB Toolbox
Thus, the plane beam in Figure D.16 has 24 DOFs. First, the coordinates of nodes and
element connectivity are produced using the following program:
Edof=[ 1 1 2 3 4 13 14;
2 3 4 15 16 13 14;
3 3 4 5 6 15 16;
4 5 6 17 18 15 16;
5 5 6 7 8 17 18;
6 7 8 19 20 17 18;
7 7 8 9 10 19 20;
8 9 10 21 22 19 20;
9 9 10 11 12 21 22;
10 11 12 23 24 21 22];
Coord=[0 0;1 0;2 0;3 0;
4 0;5 0;0 1;1 1;
2 1;3 1;4 1;5 1];
dof=[1 2; 3 4; 5 6; 7 8;
9 10; 11 12; 13 14; 15 16;
17 18; 19 20; 21 22; 23 24];
[Ex,Ey]=coordxtr(Edof,Coord,dof,3);
(P.27)
Since Element 1 connects Nodes 1, 2 and 7, the first row of Edof array has the following
DOFs: 1, 2, 3, 4, 13, and 14. The last parameter of ‘‘coordxtr’’ is 3 because the CST
element has three nodes. For material properties, we need to build the stress-strain matrix
in Eq. (6.5) for plane stress problems. This can be done using the following program:
ep=[1 0:01];
E=200E9;
nu=0:3;
D=hooke(1,E,nu);
(P.28)
In arracy ep, the first column specifies problem type: (1) plane stress, (2) plane strain, (3)
axisymmetric, and (4) three-dimension. The second column stands for the thickness of the
plane solid element. The ‘‘hooke’’ function calculates the stress-strain matrix D.
The first parameter in the ‘‘hooke’’ function specifies problem type. For plane problems,
the size of stress-strain matrix becomes 3� 3.
Figure D.16 CST elements for cantilever beam bending analysis
D.3 Finite Element Analysis Using Plane Solid Elements 409
In order to construct the element stiffness matrix for the i-th element, the ‘‘plante’’
function is called with i-th row of Ex and Ey arrays along with thickness in ep and stress-
strain matrix D:
fori=1 : 10
ke=plante(Ex(i,: ),Ey(i, : ),ep,D);
K=assem(Edof(i, :),K,ke);
end
(P.29)
Applying boundary conditions and solving the matrix equation are identical to the
previous examples. After solving for the nodal DOFs, the element stress can be calculated
using ‘‘plants’’ function:
[es,et]=plants(Ex,Ey,ep,D,ed); (P.30)
Arrays es and et contain element stresses and strains, respectively. The array es is 10�3 dimension. The i-th row represents i-th element resutls. The first column is sxx, the
second column syy, and the third column txy. The same convention for et. Table D.9
shows element stresses and strains for the cantilevered beam model.
Since element stresses are constant in CST elements, the stress along the neutral
axis will be oscillating as illustrated in Figure D.17. From the classical beam theory,
the stress along the bottom surface will be 60 MPa, while along the top surface be
�60 MPa. The stress results from CST elements are about four times smaller than that
of the classical results. This happens due to the inability of the elements in representing
linearly varying stress. Also note that syy and txy are not zero in CST elements. The
stress contour can be plotted using ‘‘plcontour2’’ function, which is not a standard
function in the MATLAB toolbox. The program list of ‘‘plcontour2’’ can be found
in Table D.11.
plcontour2(Ex,Ey,es( : ,1),ed;500); (P.31)
In (P.31), the displacement is magnified by 500 times.
Table D.9 Element Stresses and Strains for the Cantilevered Beam (stress unit is MPa and
strain unit is micro-strain)
Elem sxx syy txy exx eyy gxy
1 15.69 �4.32 4.32 84.9 �45.1 56.1
2 �15.69 �5.00 �4.32 �70.9 �1.5 �56.1
3 14.84 4.16 5.16 68.0 �1.5 67.0
4 �14.84 �4.46 �5.16 �67.5 �0.1 �67.0
5 14.82 4.44 5.18 67.4 �0.1 67.4
6 �14.82 �4.44 �5.18 �67.4 0.1 �67.4
7 14.84 4.46 5.17 67.5 0.1 67.0
8 �14.84 �4.16 �5.17 �78.0 1.5 �67.0
9 15.69 5.00 4.32 70.9 1.5 56.1
10 15.69 4.32 �4.32 �84.9 45.1 �56.1
410 Chapter D Finite Element Analysis Using MATLAB Toolbox
Bending Analysis of a Cantilever Beam Using Rectangular Element
Solve bending of the cantilevered beam in Figure D.16 using five rectangular elements.
Compare the numerical results with the elementary theory of beam. Is the rectangular ele-
ment stiff or soft? Compared to the CST element, is the rectangular element stiffer or softer?
The element numbers and node numbers are shown in Figure D.18. The complete list
of program that can analyze the cantilevered bean bending analysis is shown in Table
D.13. Compared to CST elements, the main difference is the function that calculates the
element stiffness matrix. In the case of rectangular elements, ‘‘planei4e’’ function is
used to construct the element stiffness matrix:
ke=plani4e(Ex(i, : ),Ey(i, :),ep,D); (P.32)
After solving the matrix equation, the element stress are obtained by calling the fol-