26
CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use 1-D FEM with linear elements. Also, you will only consider the isothermal case with the non-dimensionalized temperature set to 1. A sample program has been provided for you. Among the tasks are: Check the sample program for bugs (especially the matrix element equations). Place the boundary conditions into the matrix. Modify the matrix storage for use of PETSC. Look at different values of dissipation (both varying in time and space) and see how they affect the solution.

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

Embed Size (px)

Citation preview

Page 1: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

HW 5

• Repeat the HW associated with the FD LBI except that you will now use 1-D FEM with linear elements. Also, you will only consider the isothermal case with the non-dimensionalized temperature set to 1. A sample program has been provided for you. Among the tasks are:– Check the sample program for bugs (especially the matrix element

equations).

– Place the boundary conditions into the matrix.

– Modify the matrix storage for use of PETSC.

– Look at different values of dissipation (both varying in time and space) and see how they affect the solution.

Page 2: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

HW 5 (cont’d 2)

The sample code stores the matrix in a banded format:

11 12

21 22 23

32 33 34

4543 44

54 55

0 0 0

0 0

00

0 0

0 0 0

k k

k k k

k k kk

k k

k k

11 12

21 22 23

32 33 34

43 44 45

54 55

k k

k k k

k k k

k k k

k k

Page 3: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Higher Order Elements in 1-D

The Lagrange family provides basis functions to approximatethe solution to any degree polynomial in 1-D. To approximatea kth degree polynomial, we need k+1 nodes:

Element m

1mx 2

mxmkx 1

mkx

1( )

0 at other nodes

mm jj

x xx

Page 4: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Higher Order Elements in 1-D (cont’d 2)

One possibility:

1 2 1 1 1( )( ) ( )( ) ( )m m m m m mj j j kx x x x x x x x x x

The above expression does not satisfy the condition that

1 2 1 1 1

1, at . In fact,

( ) ( )( ) ( )( ) ( )

m mj j

m m m m m m m m m m m mj j j j j j j j j k

x x

x x x x x x x x x x x x

Therefore,

1 2 1 1 1

1 2 1 1 1

( )( ) ( )( ) ( )

( )( ) ( )( ) ( )

m m m m mj j km

j m m m m m m m m m mj j j j j j j k

x x x x x x x x x x

x x x x x x x x x x

Page 5: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Higher Order Elements in 1-D (cont’d 3)

Example for quadratic (k=2)

Page 6: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

2-D Finite Element Methodfor Isothermal Flow of Ionized Gas

Through a Nozzle

Robert Lee

Page 7: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Differences from 1-D Case

• Method of weighted residuals applied over a surface rather than a line.

• Unknowns increase because velocity along two directions.

• Finite element basis functions are 2-D.

• The resulting matrix equation produces general sparse matrices.

Page 8: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Differences from 1-D Case (cont’d 2)

• Gridding of geometry now becomes complicated.• There are numerous choices for element shapes• Errors present in both discretization of unknowns

and the geometry.

Page 9: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Equation of Interest

After application of the method of weighted residuals,the equation of interest is

, , , , ,m

m mm mj jm m i i

j i

d dd df dxdy

dx dx dy dy

Thus, the only thing that we must find is

the basis function ( , ) and its derivative

in and .

mj x y

x y

Page 10: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Review of FEM

• The basis functions j(x)are generated by simple functions defined piecewise (element by element) over the FEM grid.

• The basis must be smooth enough such that their derivatives in the weight residual equation exists (assume nth order derivatives), i.e.,

FEM provides a systematic and very general way ofgenerating the basis functions (usually polynomialapproximations). The criteria are:

2njnxdx

is element of interest 2n

jnydx

Page 11: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Review of FEM (cont’d 2)

• The basis functions are chosen in such a way that the coefficients defining the unknown quantity are precisely the value of the unknown quantity at the nodes.

1( )

0j i

i jx

i j

1( )

0 at other nodesj

j

x xx

There are two ways to find the basis functions over anarbitrary element. We will call them Method 1 and Method 2

Page 12: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 1 for Triangles

Consider a 3-node triangle. With 3 nodes, one has 3 degreesof freedom for the basis functions,

( , )mj j j jx y a b x c y

An obvious choice for the placement of the nodes is at the vertices of the triangle.

The basis functions will be continuous along the edges ofthe triangle as long as the unknowns at the nodes associatedtith that edge are single valued.

Page 13: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 1 for Triangles (cont’d 2)

1

3

21 1( , )x y

2 2( , )x y

3 3( , )x y1 1 1 1 1 1 1 1( , ) 1m x y a b x c y

1 2 2 1 1 2 1 2( , ) 0m x y a b x c y

1 3 3 1 1 3 1 3( , ) 0m x y a b x c y

1 1 1

2 2 1

3 3 1

1 1

1 0

1 0

x y a

x y b

x y c

1 2 3 3 2 2 3 3 2

1( , )

2m

e

x y x y x y y y x x x yA

Page 14: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 1 for Triangles (cont’d 3)

is the area of the triangle and is given by

1/2 times the determinant of the matrix:eA

12 3 1 2 3 1 1 2 2 3 3 12eA x y x y x y y x y x y x

Note: is positive if nodes numbered clockwiseeA

2 3 1 1 3 3 1 1 3

1( , )

2m

e

x y x y x y y y x x x yA

3 1 2 2 1 1 2 2 1

1( , )

2m

e

x y x y x y y y x x x yA

Page 15: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Higher Order Triangles

Pascal’s triangle: 1x y

2 2x xy y3 2 2 3x x y xy y

Examples:

1x y

1x y

2 2x xy y

does not

fit

Page 16: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Quadrilateral Elements

( , )mj j j j jx y a b x c y d xy

The 4-node quadrilateral has bilinear behavior,

Page 17: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Concept of Master Element

Let us consider the concept of master element for the 1D case.

ˆThe master element defined on the coordinate system,

1 1

1 2

11 2

12 2

1

1

Page 18: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Mapping from Master Element

1 1

m

1mx 2

mx

2

2 1 2 11

1

2m m m m mj j

j

x x x x x x

1mx

2mx

1 1

x

Page 19: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Mapping from Master Element (cont’d 2)

( ) ( ( ))m mj j jx x

e.g., if 2 , ( ) sinmjx x x then 2( ( )) sinm

j jx

2

Note and are not the same functions

( ) sin , sin

mj j

mj jx x x x

m mj j jd d dd d

dx d dx d dx

2 1

2 1

2 m m

m m

x x x

x x

2 1

2m m

d

dx x x

2 1

2

m mx xdxdx d d

d

Page 20: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 2 for Quadrilaterals

The elements formed by method 2 are called isoparametric elements,

m

12

3

4

1 2

34

1 1,x y

4 4,x y 3 3,x y

2 2,x y 1, 1

1,1

1, 1

1,1

4 4

1 1

( , ) ( , ) ( , ) ( , )j j j jj j

x x y y

Note: In general, the inverse map ( ( , ), ( , )) is nonlinearx y x y

Page 21: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 2 for Quadrilaterals (cont’d 2)

The basis functions ( , ) can be written in terms of

the , system,

mj x y

( , ) ( ( , ), ( , )) ,m mj j jx y x y

1 at node ( , )

0 at other nodesj

j

11 4

12 4

13 4

14 4

, 1 1

, 1 1

, 1 1

, 1 1

Page 22: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 2 for Quadrilaterals (cont’d 3)

Finding the derivatives of the basis functions is not

as easy as in the 1-D case. We can write,m m mj j j j jd d d d dd d d d

dx d dx d dx d dx d dx

m m mj j j j jd d d d dd d d d

dy d dy d dy d dy d dy

d dd dx dy

dx dy

d dd dx dy

dx dy

d d

d dxdx dy

d d d dy

dx dy

Page 23: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 2 for Quadrilaterals (cont’d 4)

dx dxdx d d

d d

dy dydy d d

d d

dx dx

dx dd d

dy dy dy d

d d

The 2x2 matrix is referred to as the Jacobian matrix [J]. Thedeterminant of the Jacobian matrix is

dx dy dx dy

d d d d J

Page 24: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 2 for Quadrilaterals (cont’d 5)

1

1

dx dx dy dx

d dx dxd d d d

d dy dy dy dy dx dy

d d d d

J

1 1 1 1d dy d dx d dy d dx

dx d dy d dx d dy d

J J J J

4 4

1 1

4 4

1 1

i ii i

i i

i ii i

i i

d ddx dxx x

d d d d

d ddy dyy y

d d d d

Page 25: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Method 2 for Quadrilaterals (cont’d 6)

4 4

1 1

4 4

1 1

1

1

mj j ji i

i ii i

mj j ji i

i ii i

d d dd dy y

dx d d d d

d d dd dx x

dy d d d d

J

J

dxdy d d J1 1

1 1

( , ) ( ( , ), ( , ))m

f x y dxdy f x y d d

J

Applying Gauss Quadrature,1 1

1 11 1

( , ) ( , )I J

i j i ji j

g d d g ww

Page 26: CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering HW 5 Repeat the HW associated with the FD LBI except that you will now use

CIS 888.11V/EE894R/ME894V A Case Study in Computational Science & Engineering

Accuracy of Mapping

The accuracy of the FEM solution is highly dependent on theelement shape. The best solutions are produced in those gridswhere the element is well-shaped (the best shape being a square)For quadrilaterals with inner angles greater than 180 degrees, themapping may be outside the quadrilateral.

Typically, we would likeno inner angles greaterthan 150 degrees.