Anda di halaman 1dari 21

MATLAB for Finite Elements

An introduction

[X,Y] = meshgrid(-10:0.25:10,-10:0.25:10);
f = sinc(sqrt((X/pi).^2+(Y/pi).^2));
mesh(X,Y,f);
axis([-10 10 -10 10 -0.3 1])
xlabel('{\bfx}')
ylabel('{\bfy}')
zlabel('{\bfsinc}
({\bfR})')
hidden off
MATlab: It’s all about the MATRIX

But what is the matrix?


Do not fool yourself. Matlab
will not add any magic
ingredient for the assignment
that has not been covered in
the tutorials and lectures.

Neither will ANSYS. Its pretty


interface is the world that has
been pulled over your eyes to
blind you from the truth.

The truth that you are a slave. Like everyone else you were
born into bondage to overpriced commercial software.
""Let me tell you why you're here.
You're here because you know
something. What you know you can't
explain, but you feel it."

"No, I don't believe it. It's not


possible."
FF KK1111 K1212 UU
RR KK2121 K
K 22 00
22

FF KK1111UU
R K U
R K 2121U
"I didn't say it would be easy, Neo. I
just said it would be the truth""
"But I believe that, as a species,
human beings define their reality
through suffering and misery"

T0(1)=100;
%
% INCIDENCE MATRICES AND ASSEMBLY
I=zeros(2,(E+1),(E+1));
for a=1:E
I(1,a,a)=1;
I(2,(a+1),a)=1;
end
I2=zeros(2,(E+1));
for a=1:E
I2(:,:)=I(:,:,a);
K=K+I2'*KE*I2;
M=M+I2'*ME*I2;
end
%
% DOF CONSTRAINTS AND REDUCTION OF GLOBAL MATRICES
%
bcdof(1)=1; %DOF constraint on global DOF 1
bcval(1)=100; % fixed value for DOF constraint no. 1
for ic=1:1 % loop over BCs
id=bcdof(ic);
val=bcval(ic);
for i=1:(E+1) % loop over total DOFs
F(i)=F(i)-val*K(i,id);
K(id,i)=0;
K(i,id)=0;
end
K(id,id)=0;
F(id)=val;
Using Matlab
• Command line

• Text files/m-files

• Everything is a matrix:

A 6
>> A=6
>> A='QWERTY' A QWERTY
>> A=3e5 A 300000
Basics
 Matrix input
• Square brackets
>> A=[1,3,6;2,7,8;0,3,9] • Comma or space separates

1 3 6 • Semicolon separates rows


A 2 7 8 • Semicolon at end suppresses output
0 3 9

 Matrix output >> A [ENTER]


>> A(2,1) [ENTER]
>> A(:,3) [ENTER]
6
A 8
9
 Matrix definition (other ways)
- Element specification >> A(2,2)=7;

- Range specification >> A(2,1:3)=[2 7 8];

- Colons
>> A=1:2:9 A 1 3 5 7 9

- Initialisation
>> A=zeros(3,3) >>A=eye(4)

1 0 0 0
0 0 0
0 1 0 0
A 0 0 0 A
0 0 1 0
0 0 0 0 0 0 1
Matrix Algebra
1 2 5 6
A B
3 4 7 8

>> C=A+B;
- Addition/subtraction
>> C=A-B;
- Matrix multiplication
>> C=A*B;

-Element-by-element operations

>> C=A.*B
5 12
C
21 32
Special Functions
>> A’
- Matrix transpose >> inv(A)
- Matrix inverse >> size(A)
-Matrix size

- Solution of system of linear equations >> x=A\b


Ax=b >> f=cos(0.5)
- Trigonometric functions (in radians) >> a= 2^7
- Exponents

and many more...


>> help
>> why
Programming Constructs
 For loop b=0; RANGE
for a=1:10
INDENT b=b+1 [start]:[increment]:[stop]
end

gives
b=1
b=2
b=3

b=10
Programming Constructs
 If statements
b=input('Give me a number ');
if (b>0)
i_say_that='bigger than zero';
elseif (b<0)
i_say_that ='less than zero';
else
i_say_that ='exactly zero';
end
i_say_that
Less than (b<0)
Greater than (b>0)
Equal to (b==0)
Not equal to (b~=0)
Less than or equal to (b<=0)
etc…
There will always be errors
Matlab is usually quite helpful in reporting errors

Common errors include

• Undefined variables
• Division by zero
• Array indices used wrongly or out of range
• Programme gets stuck in a loop

So...
• Build programmes up gradually, testing after each
change to check there are no errors
• Use comments “% Comment”
• “Hi1, Hi2, Hi3”
STATIC, LINEAR TRUSSES
Materials
1. Number nodes and elements Element section properties

2. For each element
Nodal coordinates
• Calculate K(e) , T(e) and Λ(e) matrices
Element
• Transform K(e) into global coordinates
connectivity
• Expand K(e) with incidence matrices
• Expand F(e) with incidence matrices
Element stiffness
matrix K(e)
3. Sum Ks and Fs to form global stiffness
matrix and global load vector Transformation
matrix T(e)
4. Partition K using BCs
Element
5. Solve for unknown displacements U incidence
matrices Λ(e)
6. Back-substitute to solve for unknown R
Loads
7. Use displacement solution to calculate
element forces/stresses Boundary
conditions
NOTATION

• Element vs. model quantities (one exists for each element?)


• Local vs. global coordinate systems (effects of element orientation)
• Local vs. global DOFs (size of vector/matrix)

Subscripts: x/y = global directions a/t=local axial/transverse directions


(e)
A Element quantity (in local coordinate system) 4x4

Tranformation matrix T(e)


~ (e)
A Element quantity (in global coordinate system) 4x4

Incidence matrix Λ(e)


~~ (e)
A Element quantity (in terms of global DOFs) nxn

Summation over elements

A Model quantity nxn


[NODE,X,Y]
1.NUMBERING
u1x
N1 u1y
NODES

E2 u 2x
1,0,3
u 2y
1m

N2 U 2,2,2
u 3x 3,0,0
u 3y 4,3,0
E1 u 4x
E4
2m

u 4y
E3 1000 N
N3
N4
[ELEMENT,NODE1,NODE2]
E5

2m 1m DOFs
ELEMENTS
Local --> Global
A=0.01m2 1,1,3 ũ1x(1) --> 1
2,1,2 ũ1y (1) --> 2
E=210 GPa
3,2,3 ũ2x (1) --> 5
4,2,4 ũ2y(1) --> 6
5,3,4 …
ũ2y(4) --> 8
LOCAL REPRESENTATION
u2t

u2a
2

1 …for element e
u1t
u1a

Local stiffness matrix using


local DOF convention:

u1a f1a
1 0 1 0
u1t f1t
U (e) F (e)
(e) EA 0 0 0 0
f2a K
u2 a l (e) 1 0 1 0
u2 t f 2t
0 0 0 0
2a. CALCULATING LOCAL MATRICES
• Local stiffness matrix for each • Local transformation matrix for
element depends on length: each element depends on
inclination to positive x-axis:
(e) ( e ) ~ ( e ) (+θ = anti-
1 0 1 0 U T U clockwise )
(e)
(e) EA 0 0 0 0 cos sin ( e ) 0 0
K
l (e) 1 0 1 0 (e) sin (e)
cos ( e ) 0 0
T (e) (e)
0 0 0 0 0 0 cos sin
(e) (e)
0 0 sin cos
• Incidence matrices map the 4 local
to 8 global degrees of freedom:
4x1 = (4x8) x (8x1)
~ (e) ~
~(e)
(e)
U U
1 0 0 0 0 0 0 0 ũ1x(1) --> 1
(1) 0 1 0 0 0 0 0 0 …because ũ1y(1) --> 2
… ũ2x(1) --> 5
0 0 0 0 1 0 0 0
ũ2y(1) --> 6
0 0 0 0 0 1 0 0
2b. TRANSFORM LOCAL STIFFNESS MATRICES
~ (e) T (e)
K T K T
4x4= 4x4 4x4 4x4

2c. EXPAND LOCAL STIFFNESS MATRICES


~
~ (e) T ~ (e)
K K
8x8= 8x4 4x4 4x8

2d. TRANSFORM & EXPAND LOCAL LOAD


MATRICES
~ (e) T (e)
F T F
~~ ( e ) T ~ (e)
F F
3. ASSEMBLE GLOBAL MATRICES
~~ (e)
F F
e
~~ ( e)
K K
e
4-6. PARTITION AND SOLVE MATRICES

F K11 K12 U
R K 21 K 22 0
F K11U
R K 21U
7. CALCULATE ELEMENT FORCES

(e) (e) (e) (e)


F K T U
4x1= 4x4 4x4 4x8 8x1

…for each element e

ALSO…

Note that the transformation and incidence matrices are


orthogonal:
T 1
T T

Anda mungkin juga menyukai