21
MATLAB for Finite Elements An introduction [X,Y] = meshgrid(-10:0.25:10,-10:0.25:10); f = sinc(sqrt((X/p i).^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

FINITE ELEMENT matlab[1]

  • Upload
    kabangi

  • View
    267

  • Download
    1

Embed Size (px)

Citation preview

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 1/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

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 2/21

MATlab: It’s all about the MATRIX

But what is the matrix?Do not fool yourself. Matlabwill not add any magicingredient for the assignment

that has not been covered inthe tutorials and lectures.

Neither will ANSYS. Its prettyinterface is the world that hasbeen pulled over your eyes to

blind you from the truth.

The truth that you are a slave. Like everyone else you wereborn into bondage to overpriced commercial software.

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 3/21

U K R

U K F 

K K 

K K 

R

21

11

2221

1211

0

U K R

U K F 

K K 

K K 

R

21

11

2221

1211

0

""Let me tell you why you're here.You're here because you know

something. What you know you can'texplain, but you feel it."

"I didn't say it would be easy, Neo. Ijust said it would be the truth""

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

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 4/21

"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:EI(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;

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 5/21

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 6/21

Using Matlab

• Command line

• Text files/m-files

Everything is a matrix:

>> A=6

>> A='QWERTY'

>> A=3e5

6A

QWERTYA

300000A

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 7/21

Basics

Matrix input

Matrix output

>> A=[1,3,6;2,7,8;0,3,9]

930

872

631

A

• Square brackets

• Comma or space separates

• Semicolon separates rows

Semicolon at end suppresses output

>> A [ENTER]

>> A(2,1) [ENTER]

>> A(:,3) [ENTER]

9

8

6

A

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 8/21

Matrix definition (other ways)

- Element specification

- Range specification

- Colons

- Initialisation

>> A(2,2)=7;

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

000

000

000

A

1000

0100

0010

0001

A

>> A=1:2:9 97531A

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

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 9/21

Matrix Algebra

43

21A

87

65B

- Addition/subtraction- Matrix multiplication

-Element-by-element operations

>> C=A+B;

>> C=A-B;>> C=A*B;

>> C=A.*B

3221

125C

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 10/21

and many more...

Special Functions

- Matrix transpose- Matrix inverse-Matrix size

- Solution of system of linear equationsAx=b

- Trigonometric functions (in radians)- Exponents

>> A’

>> inv(A)>> size(A)

>> x=A\b>> f=cos(0.5)

>> a= 2^7

>> help

>> why

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 11/21

Programming Constructs

For loop

INDENT

gives

b=0;

for a=1:10

b=b+1

end

b=1

b=2

b=3

…b=10

RANGE

[start]:[increment]:[stop]

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 12/21

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_thatLess than (b<0)Greater than (b>0)Equal to (b==0)Not equal to (b~=0)Less than or equal to (b<=0)

etc…

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 13/21

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

• Build programmes up gradually, testing after eachchange to check there are no errors• Use comments “% Comment” • “Hi1, Hi2, Hi3” 

So...

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 14/21

STATIC, LINEAR TRUSSES

Nodal coordinatesElement

connectivity

MaterialsElement section properties

Loads

Element stiffnessmatrix K(e)

Transformationmatrix T(e)

Elementincidence

matrices Λ(e)

1. Number nodes and elements

2. For each element

• Calculate K(e) , T(e) and Λ(e) matrices• Transform K(e) into global coordinates• Expand K(e) with incidence matrices• Expand F(e) with incidence matrices

3. Sum Ks and Fs to form global stiffnessmatrix and global load vector

4. Partition K using BCs

5. Solve for unknown displacements U

6. Back-substitute to solve for unknown R

7. Use displacement solution to calculateelement forces/stresses Boundary

conditions

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 15/21

NOTATION

Element quantity (in local coordinate system) 4x4

Element quantity (in global coordinate system) 4x4

Element quantity (in terms of global DOFs) nxn

Model quantity nxnA

A

A

A

(e)

(e)

(e)

~~

~

• 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

Tranformation matrix T(e)

Incidence matrix Λ(e)

Summation over elements

[NODE X Y]

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 16/21

1.NUMBERINGNODES

1,0,32,2,23,0,04,3,0

N1

N3

N2E2

E3

E1

N4

E4

E5

1000 N

2m 1m

2m

1m

A=0.01m2

E=210 GPa

ELEMENTS

1,1,32,1,23,2,34,2,45,3,4

DOFs

Local --> Globalũ1x

(1) --> 1ũ1y

(1) --> 2ũ2x

(1) --> 5ũ2y

(1) --> 6…

ũ2y

(4)

--> 8

[NODE,X,Y]

[ELEMENT,NODE1,NODE2]

4y

4x

3y

3x

2y

2x

1y

1x

u

u

u

u

u

u

u

u

U

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 17/21

LOCAL REPRESENTATION

u1a

1

2

0000

0101

0000

0101

)(

)(

e

e

l

EAK 

a

a

e

u

u

u

u

2

2

1

1

)(

a

a

e

2

2

1

1

)(

Local stiffness matrix usinglocal DOF convention:

u2a

u1t

u2t

…for element e

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 18/21

2a. CALCULATING LOCAL MATRICES

0000

0101

0000

0101

)(

)(

e

e

l

EAK 

)()(

)()(

)()(

)()(

)(

cossin00

sincos00

00cossin

00sincos

ee

ee

ee

ee

eT 

00100000

00010000

00000010

00000001

)1(

)()()(~~~ eeeU U 

• Local stiffness matrix for eachelement depends on length:

• Local transformation matrix foreach element depends oninclination to positive x-axis:

(+θ = anti-

clockwise )

• Incidence matrices map the 4 localto 8 global degrees of freedom:

…because…

4x1 = (4x8) x (8x1)

)()()( ~ eeeU T U 

ũ1x(1) --> 1

ũ1y(1) --> 2

ũ2x(1) --> 5

ũ2y(1) --> 6

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 19/21

2b. TRANSFORM LOCAL STIFFNESS MATRICES

T K T K eT e )()(~

2c. EXPAND LOCAL STIFFNESS MATRICES

)()( ~~~ eT e

K K 8x8= 8x4 4x4 4x8

4x4= 4x4 4x4 4x4

2d. TRANSFORM & EXPAND LOCAL LOAD

MATRICES

)()(

)()(

~~~

~

eT e

eT e

F F 

F T F 

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 20/21

3. ASSEMBLE GLOBAL MATRICES

e

e

e

e

K K 

F F 

)(

)(

~~

~~

4-6. PARTITION AND SOLVE MATRICES

U K R

U K F 

K K 

K K 

R

21

11

2221

1211

0

8/7/2019 FINITE ELEMENT matlab[1]

http://slidepdf.com/reader/full/finite-element-matlab1 21/21

7. CALCULATE ELEMENT FORCES

U T K F eeee)()()()(

4x1= 4x4 4x4 4x8 8x1

…for each element e

ALSO…

Note that the transformation and incidence matrices areorthogonal:

1T T T