Docsity

FE Analysis for Mechanical & Aerospace Design: Solving a 1D Problem using MATLAB - Prof. N, Lab Reports of Mechanical Engineering

Partial preview of the text

Download FE Analysis for Mechanical & Aerospace Design: Solving a 1D Problem using MATLAB - Prof. N and more Lab Reports Mechanical Engineering in PDF only on Docsity!

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

MAE4700/

Finite Element Analysis for

Mechanical and Aerospace Design

Cornell University, Fall 2008

Nicholas Zabaras

Materials Process Design and Control Laboratory

Sibley School of Mechanical and Aerospace Engineering

101 Rhodes HallCornell University Ithaca, NY 14853-

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Problem definition

•^

The problem considered in the MATLAB software 1DBVPsolves the following BVP:– Compute

u(x)

in

[a,b]

such that with appropriate boundary

conditions, the following equation holds:

•^

The particular example provided solves the following BVP:

The analytical solutionis given as:

(^

)^

[ , ]

d

du

p x

q x u x

f^

x^

x^

a b

dx

dx

2

2

2

1)sin 4

,^

[0,1]

cos 4

d u

u x

x x

dx

u du dx

π

π

π

π

sin 4

cos 4

u x

x

du

x

dx

π

π

π

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Introducing the geometry and FE discretization

include_variables;xl = 0.0;

% Introduce here the left location of the 1D domain

xr = 1.0;

% Introduce here the right location of the 1D domain

ElementType = 1;

% Introduce element type^ % Here linear elements are used (two nodes per element)% If quadratic (3 nodes per element), enter 2, etc.

nel = 50;

% number of total elements that you want in your grid

MeshGenerator(xl,xr); % This function will generate the desirable finite element

% grid based on your input information (see next slide)

Function InputGrid.m

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Mesh generator: MeshGenerator.m

if (ElementType==1)

% This part is for linear elements only!

nno = nel+1;

% number of total nodes

nen = 2;

% number of nodes on each element

Elems = zeros(nen,nel);

% initialize

Nodes = linspace(xl,xr,nno);

% set the coordinates of each global node^ % (change this for different type of elements)

for e = 1:nel

% loop over all elements,

Elems(1,e) = e;

% set the global node number for each

Elems(2,e) = e+1;

% local node of the (linear) element

end endif (ElementType==2)

% This is left for you to program….

endif (ElementType==3)

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Preprocessor.m

% Proprocessing introduces input data, creating and discretizing the domain% into finite elements (nodes, elements, etc.) InputGrid;

% Reads geometric information (problem dependent)% and generates the mesh (nodes, elements, connectivities, ..)

neq = nno;

% number of equations

f = zeros(neq,1);

% initialize nodal force vector

d = zeros(neq,1);

% initialize nodal solution vector

I = zeros(nen*neq,1);

% initialize the triplet for assembling the sparse

J = zeros(nenneq,1); % matrix. We assume that the max number ofX = zeros(nenneq,1); % nonzero entries in nen*neqntriplets = 0;InputData;

% Here you need to add your problem dependent input% data (Gauss quadrature, essential, natural or mixed% boundary conditions, etc.)

PlotGrid;

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Element basis functions and their derivatives function [n,dndxi] = FiniteElement_1D(xi);

% Note that they are defined at a given% Gauss point in natural coordinates xi

if ( ElementType == 1 )

% linear element

n = [(1/2)(1 - xi), (1/2)(xi + 1)]; % Calculate the basis functions (row vector)

% at the given integration point

dndxi=[-1/2, 1/2 ];

% Calculate the derivative of the basis functions% at the given integration point (row vector)

end if ( ElementType == 2 )

% quadratic element

% You need to program this part

end

1 2

1

(

)

2 1

(

)

2

N N

ξ^ ξ

=

−

=

1 2

1 2 1 2

dNd dNd

=

− =

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

10

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Stiffness and load calculations at a given Gauss point

ξ

i

function [Ke,fe] = integrands(e, felm, Ke, fe);….. B = felm.dN;Ke = Ke + (pp(felm.x)B'B + qq(felm.x)felm.N'felm.N) * felm.detJxW;fe = fe + ff(felm.x) * felm.N' * felm.detJxW;

(^

( )

)^

( ) ( )

( ),

[ , ]

d^

du

p x

q x u x

f^

x^

x^

a b

dx

dx

−

+^

=^

∈

⇒

e^

e

e^

e

du dw

p x

q x u x

dx

f^

x w x dx

dx dx

Ω

Ω

∑

∑

∫^

∫

⎡^

⎢^

⎣^

T^

T e^

e

dw

w

B

dx

e^

e

du

B u

dx

T^

T^

T^

T

e^

e

e^

e

e^

e^

e^

e^

e^

e^

e^

eT

e^

e

K^

f

w

B

p x B

q x N

N

dxu

w

N

f^

x dx

Ω

Ω

∑

∑

∫^

∫

⎡^

⎣^

.det

(^

) i

i

dx

felm

JxW

W

d

1

2

dN

dN

dx

dx

⎡^

⎢^

⎣^

Struct defined

at each Gauss point

[^

]

1

2

N

N

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Assemble process: Local to global DOF mapping function AssembleGlobalMatrix(e,Ae,be);for i = 1 : nen

% local row index

glbi = Elems(i,e);

% global row index

if ( be(i)~=0 )

f(glbi) = f(glbi) + be(i);

% assemble load

endfor j = 1 : nen

% local column index

glbj = Elems(j,e);

% global column index

if ( Ae(i,j) ~= 0)

% set up the list of triplets

ntriplets = ntriplets + 1;len = length(X);

% Manually increase the size of the I, J, X arrays if% needed. All the values of these arrays between

if ( ntriplets > len)

% len and 2*len are set to zero and the length of

I(2len) = 0; J(2len) = 0; X(2*len) = 0; end

% these arrays is increased to 2*len

I(ntriplets) = glbi; J(ntriplets) = glbj;X(ntriplets) = Ae(i,j);

end end end

Stiffness assembly

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Application of boundary conditions: ApplyBC.m debc

= []; ebcVals = [];

% Initialize debc, ebcVals

for i = 1 : 2

% There are two boundary nodes for 1D BVPs

if (BoundaryCondition(i).type == 1) % essential boundary condition

debc = [debc BoundaryCondition(i).glbID];ebcVals = [ebcVals; BoundaryCondition(i).value]; endif (BoundaryCondition(i).type == 2) % natural boundary condition

glbID = BoundaryCondition(i).glbID;val = BoundaryCondition(i).value;if (i==1)

val = -val;

% You need to change the sign in the flux on the 1

st node

endf(glbID) = f(glbID) + val;

% Modify global force vector for nodes with natural BC

end….

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Application of boundary conditions: ApplyBC.m^ if (BoundaryCondition(i).type == 3)

% mixed boundary condition

glbID = BoundaryCondition(i).glbID;val = BoundaryCondition(i).value; % for this boundary condition,

% there are two values.

x = Nodes(index);if ( i==1)

val = -val;

% left boundary

end K(index,index) = K(index,index) - pp(x)val(1); % modify the stiffness matrixf(index) = f(index) - pp(x)val(2);

% modify the load vector

end end

N

N

(1)

(2)

val

val

du

BC

u

dx

|^

(^

)^

|^

(^

)^

b a^

x^

b^

x^

a

du p^

w

p^

u^

w

p^

u^

w

dx

=^

=

=^

−^

Contribution tothe rhs of the

weak form:

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Error estimation: ErrorAnalysis.m (here the

L

2

norm is shown)

function ErrorAnalysis;L2_Norm = 0.0;L2_Norm_Normalize = 0;

[gp,w] = gauss(ngp);for elmID = 1 : nel

glb = Elems(:,elmID);coord = Nodes(glb)';de = d(glb);for i = 1:length(gp)

[n,dndxi] = FiniteElement_1D(gp(i));x = ncoord;dxdxi = dndxicoord;Jacc = dxdxi;detJxW = Jacc * w(i);dN = dndxi/Jacc;[u du] = exact(x);uh = nde;duh = dNde;L2_Norm

= L2_Norm + (u - uh)^2*detJxW;;

L2_Norm_Normalize = L2_Norm_Normalize + u^2*detJxW; end endL2_Norm = sqrt(L2_Norm) / sqrt (L2_Norm_Normalize);

(^

)

(^

)

2 2

1/ 2 2 1/ 2 2

( )

( )

||^

( )

( ) ||

||^

( ) ||

( )

b

h^

exact

h^

exact

L^

a

exact

b

L^

exact u^ a

x^

u^

x^

dx

u^

x^

u^

x

u^

x^

u^

x^

dx

⎛^

⎞

−

⎜^

⎟

−^

⎝^

⎠

=^

⎛^

⎞

⎜^

⎟

⎝^

⎠

(^

)^

(^

)

(^

)

int

2

2

2

1

det

( )

( )

( )

( )

( (

))

( (

))

|

e

i

e b

h^

exact

h^

exact

e

a

N

h^

exact

i^

i^

i

e^

i

JxW

u^

x^

u^

x^

dx

u^

x^

u^

x^

dx

dx

u^

x^

u^

x^

W

d

Ω

=

= Ω

−^

=^

−^

=

−

∑

∫^

∫

∑

∑ ∫^



ξ^

ξ

ξ

ξ^

ξ

(^

) i x

ξ^ |

i

dx d^

= ξ ξ ξ^

|^ det

i^

i JxW dx

W

d^

= 

ξ^ ξ ξ

{^

}

1

2

( (

))

..

h^

e^

e^

e

i

u^

x^

N

N

d

⎡^

⎤

=

⎣^

⎦

ξ

COC

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y

CO^ C

OR

RN

NE

EL

LL

L

U^

N^

I^

V^

E^

R^

S^

I^

T^

Y^

MAE 4700 – FE Analysis for Mechanical & Aerospace DesignN. Zabaras (9/4/2008)

Main program: Main.m

preprocessor;

% Preprocessing

Assemble;

% Loop over all the elements and% assemble the global sparse format of the% stiffness matrix matrix

ApplyBC;

% Apply different boundary conditions

[d,r] = NodalSoln(K ,f, debc, ebcVals); % Solution of linear systems of equationspostprocessor;

% Postprocessor