Professional Documents
Culture Documents
Finite Element
Finite Element
Weighted residual methods (WRM) assume that a solution can be approximated analytically or piecewise analytically. In general a solution to a PDE can be expressed as a superposition of a base set of functions
N
T (x, t) =
j=1
aj (t)j (x)
where the coefcients aj are determined by a chosen method. The method attempts to minimize the error, for instance, nite differences try to minimize the error specically at the chosen grid points. WRMs represent a particular group of methods where an integral error is minimized in a certain way and thereby dening the specic method. Depending on the maximization WRM generate the nite volume method, nite element methods, spectral methods, and also nite difference methods.
T (x, y, z, t) = T0 (x, y, z, t) +
j=1
aj (t)j (x, y, z)
(6.1)
81
82
with the trial functions j (x, y, z). T0 (x, y, z, t) is chosen to satisfy initial or boundary conditions and the coefcients aj (t) have to be determined. possible trial functions are j (x) = xj1 or j (x) = sin(jx). The expansion is chosen to satisfy a differential equation L(T ) = 0 (where T is the exact solution), e.g., L(T ) = T 2T 2 =0 t x
However, the numerical solution is an approximate solution, i.e., T = T such that the operator L applied to T produces a residual L(T ) = R The goal of WRMs is to choose the coefcients aj such that the residual R becomes small (in fact 0) over a chosen domain. In integral form this can be achieved with the condition Wm (x, y, z)Rdxdydz = 0 (6.2)
where Wm is a set of weight functions (m = 1, ...M ) which are used to evaluate (6.2). The exact solution always satises (6.2) if the weight functions are analytic. This is in particular true also for any given subdomain of the domain for which a solution is sought. There are four main categories of weight or test functions which are applied in WRMs. i) Subdomain method: Here the domain is divided in M subdomains Dm where Wm = 1 in Dm 0 outside (6.3)
such that this method minimizes the residual error in each of the chosen subdomains. Note that the choice of the subdomains is free. In many cases an equal division of the total domain is likely the best choice. However, if higher resolution (and a corresponding smaller error) in a particular area is desired, a non-uniform choice may be more appropriate. ii) Collocation method: tions In this method the weight functions are chosen to be Dirac delta func-
(6.4)
83
Wm (x) = The motivation for this choice is to minimize that this choice of the weight function implies am for all values of am . iv) Galerkin method: functions.
R . am
(6.5)
R2 dxdydz = 0
In this method the weight functions are chosen to be identical to the base
Wm (x) = m (x) In particular if the base function set is orthogonal ( m (x)n (x) = 0 if m = n), this choice of weight functions implies that the residual R is rendered orthogonal with the condition (6.2) for all base functions. Note that M weight functions yield M conditions (or equations) from which to determine the N coefcients aj . To determine these N coefcients uniquely we need N independent condition (equations). Example: Consider the ordinary differential equation dy y =0 dx (6.6)
for 0 x 1 with y(0) = 1. Let us assume an approximate solution in the form of polynomials
N
y =1+
j=1
a j xj
(6.7)
where the constant 1 satises the boundary condition. Substituting this expression into the differential equation (6.6) gives the residual
N
R = 1 +
j=1
aj jxj1 xj
(6.8)
84
x
0
m1
1 +
j=1
aj jxj1 xj
dx = 0
or
1 N 1 1 m1
dx +
j=1
aj j
0
xm1 xj1 dx
0
xm1 xj dx
=0
aj
j=1
j 1 =0 m+j1 m+j
j m+j1
(6.9)
1 ) m+j
SA = D The solution A of this set of equations requires to invert S. For N = 3 the system becomes 1/2 2/3 3/4 a1 1 1/6 5/12 11/20 a2 = 1/2 1/12 3/10 13/30 a3 1/3 y = 1 + 1.0141x + 0.4225x2 + 0.2817x3 Least squares method: Here the weight functions are Wm (x) = This gives the residual condition
1 N
(6.10)
R = mxm1 xm am
mxm1 xm
0
1 +
j=1
aj jxj1 xj
dx =
1 +
1 + m+1
aj
j=1 0
mxm1 xm
jxj1 xj dx
= 0
85
aj
j=1
1 x ( m1 , m ] N N 0 outside
1 +
j=1
aj jxj1 xj
dx = 0
Collocation method: Collocation point (for the Dirac delta function): xm = Condition for the residual error:
1 N m1 . N
(x xm ) 1 +
0 j=1
aj jxj1 xj
dx = 0
which is to be solved with the subdomain method on a domain given by coordinate line (j, k) describing a curved coordinate system. This equation is a typical continuity equation like the equations for conservation of mass, momentum etc.
86
j-1
k-1
Figure 6.1: Illustration of the coordinate system to solve equation (6.11) with the nite volume method. Equation (6.11) is to be solved as an integral over any area ABCDas illustrated in Figure 6.1 => q F G dxdy = 0. + + t x y
ABCD
With H = (F, G) such that F/x + G/y = H this equation becomes (using Gausss theorem) d qdV + H nds = 0 dt ABCD ABCD In Cartesian coordinates the surface element vector ds = (dx, dy) such that the normal vector nds = (dy, dx) and H nds = F dy Gdx. Thus the integral of (6.11) For the area ABCD becomes d (Ar qjk ) + (F y Gx) = 0 dt ABCD with Ar =area of ABCD. Using the notations yAB = yB yA , xAB = xB xA , and the averages FAB = 0.5 (Fj,k1 + Fj,k ), GAB = 0.5 (Gj,k1 + Gj,k ) and applying these to all sections of ABCDwe obtain Ar
dqjk dt
+0.5 (Fj,k1 + Fj,k ) yAB +0.5 (Fj,k + Fj+1,k ) yBC +0.5 (Fj,k + Fj,k+1 ) yCD +0.5 (Fj1,k + Fj,k ) yDA
0.5 (Gj,k1 + Gj,k ) xAB 0.5 (Gj,k + Gj+1,k ) xBC 0.5 (Gj,k + Gj,k+1 ) xCD 0.5 (Gj1,k + Gj,k ) xDA = 0
(6.12)
87
In case of a uniform grid parallel to the x, and the y axes the area is A r = xy and equation (6.12) reduces to dqjk Fj+1,k Fj1,k Gj+1,k Gj1,k + + =0 dt 2x 2y where the spatial derivative is equal to that for the centered space nite difference approximation.
(6.13)
k+1
(A)
j-1
Y
rXY
D
D
B B
k-1
A A
rWZ
(B)
W X
x
Figure 6.2: Illustrations of the domain for the solution of Laplaces equation (A), and of the grid geometry to evaluate the second derivatives for the nite volume method. We are seeking a solution for this equation in a domain as illustrated by the shaded area in Figure~6.2. The appropriate coordinate system for this domain is a polar coordinate system with the variable r and . The boundary conditions are = 0 at boundary W X, = sin /rxy at boundary XY , = 1/ryz at boundary Y Z, = sin /rwz at boundary W Z.
88
To apply the nite volume method we determine the integral of the residual in the area given by ABCD in Figure 6.2 2 2 + 2 dxdy = x2 y H nds = 0
ABCD
(6.14)
ABCD
with H nds = dy dx. Note that H = (/x, /y) and that the direction normal to x y ds = (dx, dy) is nds = (dy, dx). Using the geometry shown in Figure 6.2 equation (6.14) is approximated with x + + x + y
yAB
j,k1/2
xAB
j,k1/2
yBC
j+1,k
xBC
j+1,k
yCD
j,k+1/2
xCD
j,k+1/2
yDA
j1,k
xDA = 0
j1,k
(6.15)
The derivatives /x and /y at the midpoints of each section AB, BC, etc are determined through averages over the appropriate section. For instance along AB the derivatives are x y =
j,k1/2
1 SAB 1 SAB
ABC D ABC D
dy
A B C D
=
j,k1/2
dx
A B C D
dx = j,k1xA B + B xB C + j,k xC D + A xD A
A B C D
89
Figure 6.3: Illustration of the geometry of the elements ABCD. and similar for x. Figure 6.3 shows that the area is approximated by SAB = SA B C D = (xAB xk1,k )(yAB + yk1,k ) xAB yAB + xk1,k yk1,k = xAB yk1,k yAB xk1,k
yAB (j,k1 j,k ) + yk1,k (B A ) SAB xAB (j,k1 j,k ) + xk1,k (B A ) SAB
=
j,k1/2
%
'& %
#! $"
90
yBC (j+1,k j,k ) + yj+1,j (C B ) SBC xBC (j+1,k j,k ) + xj+1,j (C B ) SBC
=
j+1/2,k
=
j,k+1/2
yCD (j,k+1 j,k ) + yk+1,k (D C ) SCD xCD (j,k+1 j,k ) + xk+1,k (D C ) SCD
=
j,k+1/2
=
j1/2,k
yDA (j1,k j,k ) + yj1,j (A D ) SDA xDA (j1,k j,k ) + xj1,j (A D ) SDA
=
j1/2,k
Substitution back into equation (6.15) gives QAB (j,k1 j,k ) + QBC (j+1,k j,k ) + QCD (j,k+1 j,k ) + QDA (j1,k j,k ) +PAB (B A ) + PBC (C B ) + PCD (D C ) + PDA (A D ) = 0 with QAB = QBC = QCD = QDA =
2 x2 + yAB AB 2 x2 + yBC BC 2 x2 + yCD CD 2 x2 + yDA DA
, , , ,
PAB = (xAB xk1,k + yAB yk1,k ) /SAB PBC = (xBC xj+1,j + yBC yj+1,j ) /SBC PCD = (xCD xk+1,k + yCD yk+1,k ) /SCD PDA = (xDA xj1,j + yDA yj1,j ) /SDA
Finally we evaluate A , xA , and yA as the average over the surrounding nodes, e.g., A = 0.25(j,k + j1,k + j1,k1 + j,k1 ) Substitution into our main equation then yields 0.25 (PCD PDA ) j1,k+1 + 0.25 (PBC PCD ) j+1,k+1 +0.25 (PAB PBC ) j+1,k1 + 0.25 (PDA PAB ) j1,k1 + [QCD + 0.25 (PBC PDA )] j,k+1 + [QDA + 0.25 (PCD PAB )] j1,k + [QAB + 0.25 (PDA PBC )] j,k1 + [QBC + 0.25 (PAB PCD )] j+1,k (QAB + QBC + QCD + QDA ) j,k = 0 (6.16) Here the coefcients can be determined initially and then used during the computation. Equation (6.16) is solved in the program FIVOL using successive over-relaxation (SOR). The estimate for is determined from (6.16)
91
j,k = {0.25 (PCD PDA ) j1,k+1 + 0.25 (PBC PCD ) j+1,k+1 (6.17) +0.25 (PAB PBC ) j+1,k1 + 0.25 (PDA PAB ) j1,k1 + [QCD + 0.25 (PBC PDA )] j,k+1 + [QDA + 0.25 (PCD PAB )] j1,k + [QAB + 0.25 (PDA PBC )] j,k1 + [QBC + 0.25 (PAB PCD )] j+1,k }n / (QAB + QBC + QCD + QDA ) The iteration step is completed with n+1 = n + (j,k n ) j,k j,k j,k (6.18)
Note that the discretized equation (6.16) reduces to centered nite differences on a uniform rectangular grid j1,k 2j,k + j+1,k j,k1 2j,k + j,k+1 + =0 x2 y 2 (6.19)
92
SOR is called until the iterated solution tolerance is reached. The result is written to a binary le which can serve as input for the plotting routine plovol. The solution error for the nite volume method is listed in Table (6.2) for different number of grid points in the same domain. The table illustrates that the solution error is second order. This is to be expected from the centered differences to which the nite volume method reduces on a uniform rectangular grid. However, for strongly distorted grids the solution error is larger than second order. Table 6.2: Solution errors for the nite volume method in program Fivol2.f Grid | exact |rms No of iterations 66 0.1326 15 1111 0.0471 19 2121 0.0138 51 The nite volume method is well suited for for somewhat irregular grid domains and does not require an orthogonal grid. The number of iterations for convergence depends on the domain size.
T =
j=1
Tj j (x, y, z)
(6.20)
Where for a suitable set of functions the local domains can be of any shape. Since the nite element method is used with local coordinates the domains can be subdivided (into same shape domains) to increase the resolution where it is desired. The interpolating functions are called trial or shape functions.
93
j =
and j = 0 outside of elements A and B. The shape function j overlaps only with its direct neighbors and the superposition of elements between nodal points yields a linear function in these regions in A : in B : T = Tj1 j1 + Tj j T = Tj j + Tj+1 j+1 (6.22) (6.23)
In any given element only two shape functions overlap. In element A j is given element by (6.21) and j1 is given by j1 = xj x xj xj1
Similar for any element B j is given element by (6.21) and j+1 is given by j+1 = x xj . xj+1 xj
The particular form of the trial functions makes it straightforward to use them to approximate any given function f (x). Since the trial functions are 1 at the nodal points and all except for one trial functions are 0 at any nodal point Thus the expansion of a function f (x) in terms of the shape functions is given by
N
f (x) =
j=1
fj j (x)
!
"
(6.21)
(6.24)
94 fj j (xk ) = fk
(6.26)
f
2.0
quadratic interpolation
1.0
linear interpolation
0.5
1.0
Figure 6.5: Linear (dashed)and quadratic (dotted) nite element approximation of function (6.26). in the range [0, 1]. With two elements and nodal points at (0, 0.5, 1.0) the expansion coefcients are f1 = 2, f2 = 2.7071, and f3 = 0. Figure (6.5) shows the function f (x) and the nite element interpolation for linear and quadratic elements. b) Quadratic interpolation Quadratic interpolation requires simple quadratic polynomials for trial function. Again a trial function should be 1 only at the corresponding nodal point and 0 at all other nodes.
( )
"
Figure 6.6: Illustration of one-dimensional linear nite elements. Following the illustration 6.6 the trial functions are dened by 0
xxj2 xj xj2 xxj+2 xj xj+2 xxj1 xj xj1 xxj+1 xj xj+1
j =
With this form j (xj ) = 1 and j (xj2 ) = j (xj1 ) = j (xj+1 ) = j (xj+1 ) = 0. The trial functions of this form extend over 5 nodes. such that in a given interval 4 trial functions overlap
& '$
%$ #
#
!
& 1
0$
(6.27)
95
if they were all chosen of the same form. This is improved by choosing different trial functions at xj1 and at xj+1 of the form: j = x xj1 x xj+1 f or xj2 x xj xj xj1 xj xj+1 (6.28)
and 0 otherwise. Note that this creates a structure where all odd nodes have elements of the form of (6.27) and all even elements are of the form (6.28) where we start with an index of 1 for the rst node (xmin boundary). Similar to the linear elements it is straightforward to expand any given function in term of these shape functions
N
f (x) =
j=1
fj j (x)
with the coefcients fk = f (xk ) as in the case of the linear elements. with Tj = f (xj ). With these functions the interpolation in elements A and B take the following form T = Tj2 j2 + Tj1 j1 + Tj j in element A Tj j + Tj+1 j+1 + Tj+2 j+2 in element B
The specic form of the shape functions which are nonzero in any element A is
j2 = j1 = j =
x xj x xj1 xj2 xj xj2 xj1 x xj x xj2 xj1 xj2 xj1 xj x xj2 x xj1 xj xj2 xj xj1
For the special function (6.26) with only three nodes we have only one element A and no element B. As before the expansion coefcients are f1 = 2, f2 = 2.7071, and f3 = 0. The errors for the linear and quadratic nite element approximation of function (6.26) is listed in Table 6.3. While the linear approximation scales quadratic in the error the quadratic interpolation scales cubic in the resolution (inverse number of nodes). c) Two-dimensional interpolation Linear elements: The particular strength of nite elements is there exibility in two and three dimensions. Based on the previous introduction we want to illustrate the use of linear and quadratic
96
Table 6.3: Error for linear and quadratic nite element interpolation for the function in (6.26). Linear Interpolation No of elements RMS error 2 0.18662 4 0.04786 6 0.02138 8 0.01204 Quadratic interpolation No of elements RMS error 1 0.04028 2 0.01599 3 0.00484 4 0.00206
nite elements in two and three dimensions. In two dimensions a trial function centered at (x j , yj ) spans four elements A, B, C, and D. The approximate solution in this region can be conveniently written with local element based coordinates (, ) as
4
T =
l=1
Tl l (, )
(6.29)
with 1 1 and 1 1. The approximating functions l (, ) in each element are of the form l (, ) = 0.25(1 + l )(1 + l ) (6.30) with l = 1 and l = 1 or explicit 1 2 3 4 = = = = 0.25(1 )(1 ) 0.25(1 + )(1 ) 0.25(1 + )(1 + ) 0.25(1 )(1 + )
The nodal geometry and local coordinate systems are illustrated in Figure 6.7.
=1
=1 =1
# ! $"
=1
Figure 6.7: Illustration of the nodal geometry and sketch of the two-dimensional linear trial functions.
97
A solution is constructed separate in each element A, B, C, and D where continuity is provided by the overlapping shape functions. For instance a solution in element A implies that shape functions with values of 1 along the boundary to element B overlap into the region of element B and similar for all other boundaries of element A. Bi-quadratic elements: Similar to the bilinear elements the approximate solution for bi-quadratic elements in this region can be conveniently written with local element based coordinates (, ) as
9
T =
l=1
Tl l (, )
(6.31)
with 1 1 and 1 1. The approximating functions l ( ) in each element depend on the location.
Figure 6.8: Illustration of the nodal geometry for bi-quadratic elements. Specically the form of the shape function depends on how they are centered, i.e., where they assume a value of 1.
Again solutions are constructed in each element A, B, C, and D where the shape functions on the side and corner nodes overlap into the adjacent region. Note that quadratic elements require at 3 nodes in each direction and the total number of nodes has to be odd to accommodate quadratic elements.
98
(6.36)
F (x) =
l=1
(6.37)
y(x) =
l=1
(6.38)
y j j .
j=1
Linear Interpolation: In an element based coordinate system we use local coordinates with j = 0.5(1 + ) and = j = 0.5(1 ) and =
x +x 2 x j1 j 2 2 x xj
xj +xj+1 2
f or element A f or element B
xj+1
and the weight function for the weighted residual is wm = m which yields the equation
1
m (x)
0
d2 y + y F (x) dx = 0 dx2
d2 y dy m 2 dx = m dx dx
0 0
dm dy dx dx dx
99 = 0 such
yj
j=1 0
dm dj + m j dx = dx dx
m F (x)dx
0
bmj =
0 1
dm dj + m j dx dx dx
gm =
0
m F (x)dx.
In the computation of these elements it is convenient to make use of the local coordinates. It should also be noted that the residual equation only has contributions for j = m 1, j = m, and m = j + 1. With the transformation to local coordinates we have in element A d d d 2 d = = dx dx d xj d xj dx dx = d = d d 2 and in element B d d d 2 d = = dx dx d xj+1 d xj+1 dx d = d dx = d 2 with xj = xj xj1 and xj+1 = xj+1 xj . Element bm,m1 : A contribution exists only in region A for node m (corresponding to a region B for node m 1). Thus dm dm1 + m m1 dx dx dx 0 1 dA dA dB dx = + A B d dx d d dA 1 1 xm 1 1 d + (1 2 )d = 2xm 1 8 1 1 xm = + xm 6
1
bm,m1 =
100
Similar the element bm,m+1 involves only overlap in region B of element m with region A of element m+1 . The expression is the same only that it regards the interval xm+1 . Thus bm,m+1 = xm+1 1 + xm+1 6
bm,m =
0 1
dm dm + m m dx dx dx dA d 1 2
2
=
1 1
d dx 2 xm
dx + 2 d A + xm 2
2
d +
A 1 2
d dx d
dB d
dx 2 d B
d
B
=
1 1
1+ 2
+
1
2 xm+1
1 2
xm+1 + 2
1 2
d
A 1
1 xm 1 1 xm+1 = + (1 + )2 d + xm xm+1 8 8 1 1 xm + xm+1 1 + = xm xm+1 3 In summary the nonzero elements bmj for 2 m N 1 are
(1 )2 d
1
xN 1 + xN 6 xN 1 + = xN 6 = 0.
101
The inhomogeneity F (x) is known analytically such that one can evaluate 0 m F (x)dx directly. However, in more complex situations it is more convenient to interpolate F (x) through the trial functions
N
F (x) =
j=1
F j j .
such that
N 1
gm =
j=1
Fj
0
m j dx
For the linear interpolation this yields gm = xm + xm+1 xm+1 xm Fm1 + Fm + Fm+1 6 3 6
Finally consider the special case of a uniform grid with xm = xm+1 = x. In this case the equation for the coefcients becomes ym1 2ym + ym+1 + x2 1 2 1 ym1 + ym + ym+1 6 3 6 = 1 2 1 Fm1 + Fm + Fm+1 6 3 6
Exercise: Determine the elements at the min and max boundary, i.e., b 1,1 , b1,2 , and b2,1 . Elements with m = 1 (y1 = 0): There is no equation for y1 needed because y1 = 0 such that the indices for the array dimensions decrease by 1. Elements with m = 2
1
y2
0
d2 d2 + 2 2 dx + y3 dx dx
d2 d3 + 2 3 dx = dx dx
2 F (x)dx
0
Elements with m = N
1 1 1
yN 1
0
dN dN 1 + N N 1 dx + yN dx dx
dN dN + N N dx dx
dx =
0
N F (x)dx
Quadratic interpolation: The program offers the possibility to use a linear or quadratic nite element interpolation. For the second case the equations for the bmj are
102
xm 1 6xm 15 4 2xm + 3xm 15 1 1 7 4 + (xm + xm+1 ) + 6 xm xm+1 15 4 2xm+1 + 3xm+1 15 1 xm+1 + 6xm+1 15
gm =
4 2xm + 3xm 15 8 16xm = + 3xm 15 4 2xm+1 = + 3xm+1 15 16xm 2xm 2xm Fm1 + Fm + Fm+1 = 15 15 15
103
The program Sturm solves the Sturm-Liouville equation (6.36) for the boundary condition and the inhomogeneity dened at the beginning of this section. The parameter int determines linear or quadratic nite element interpolation. The matrix inversion forBY = G is solved with the Thomas algorithm (explained in Chapter 7) which is a special case of Gauss elimination for the case of tridiagonal banded matrices. The subroutines Bianca and ban sol factorize and solve banded matrices (tridiagonal or pentadiagonal;. The program can be downloaded from the website. For the program the following values for ai were chosen: a1 = 1.0, a2 = 1.3, a3 = 0.8, a4 = 0.2, a5 = 1.6 The RMS error is dened as 1 ||y yexact || = N 1
N 1 1/2
(yi yexact,i )
i=1
Table summarizes the solution error for the Sturm-Liouville equation. Table 6.4: RMS solution error for the Sturm Liouville equation. Grid x Linear interpolation Quadratic interpolation 1/4 0.014 0.30 1/8 0.0039 0.0017 1/16 0.00093 0.000072 1/24 0.00040 0.000022 Notes: Higher order interpolation on a coarse grid is not much better or can be worse than linear interpolation. The solution error for linear interpolation decreases approximately with x 2 and for quadratic interpolation it decreases with x3 . Smaller grid spacing than listed in the table requires higher machine accuracy (i. e., variables need to be dened as double precision. Sturm-Liouville problem, fem: quadratic interpolation nx= 9 a= 0.10E+01 -0.13E+01 0.80E+00 -0.20E+00 0.16E+01 i= 2 x=0.12500 y=0.11654 yex+0.11611 dy=0.00044 i= 3 x=0.25000 y=0.21361 yex+0.21262 dy=0.00099 i= 4 x=0.37500 y=0.31541 yex+0.31575 dy=-.00034 i= 5 x=0.50000 y=0.43428 yex+0.43608 dy=-.00180 i= 6 x=0.62500 y=0.54579 yex+0.54528 dy=0.00051 i= 7 x=0.75000 y=0.64174 yex+0.63904 dy=0.00270 i= 8 x=0.87500 y=0.72503 yex+0.72543 dy=-.00040 i= 9 x=1.00000 y=0.76235 yex+0.76568 dy=-.00333 rms= 0.171E-02 nx= 9
104
2 dT 3 dt
+
i
1 dT 6 dt
Here the form of the time derivative has not yet been specied. Also this form allows the freedom to evaluate the second derivative at a suitable time level. Dening T n+1 = T n+1 T n and time derivatives as dT /dt = T n+1 /t and using a parameter to control the time level at which the second derivative is evaluated we obtain
n+1 n+1 1 Ti1 2 Tin+1 1 Ti+1 + + 6 t 3 t 6 t n+1 n+1 n n n Ti1 2Tin+1 + Ti+1 Ti1 2Ti + Ti+1 (1 ) + x2 x2
= 0
(6.39)
Dening operators
105
1 2 , , 6 3 1 , x2
1 6 2 1 , 2 x2 x
(6.40)
Comparison with the nite difference method suggests that the main difference to the nite element method is the distribution of the time derivative over adjacent nodes. The above equation is reminiscent of the general two-level scheme introduced earlier. This scheme is recovered by using the nite difference mass operator
f Mx d = (0, 1, 0)
Finally (6.40) can be cast into the equation (Mx tLxx ) Tin+1 = [Mx t (1 ) Lxx ] Tin which is an implicit equation for T n+1 . Note for = 0 the nite difference method generates an explicit method while the nite element method yields an implicit algorithm; the matrix dened by Mx tLxx is tridiagonal and can be solved by the Thomas algorithm (as in the case of Sturm.f); the symmetry of Mx and Lxx allows to construct an explicit scheme for t = x2 / (6); equation (6.41) is consistent with the diffusion equation and unconditionally stable for 0.5. Viscous ow Stationary viscous ow through a rectangular cross section (in the x, y plane, Figure ) can be described by the the z component of the momentum equation p = z 2w 2w + x2 y 2 (6.42) (6.41)
where the rst term is the pressure gradient which drives the ow and w is the velocity prole of the ow. The problem is actual three-dimensional but is the pressure gradient is known or can be
106
prescribed one can use (6.42) to determine the ow prole in the cross section of the duct. In many problems it is an advantage to normalize the basic equation. Since x [a, a] and y [b, b] we use as normalization x= substitution in (6.42) yields p w0 = 2 z b b a
2
x , a
y y= , b
w=
w w0
2w 2w + x2 y 2
2w 2w + +1=0 x2 y 2
(6.43)
Similar to the procedure for the Sturm-Liouville equation and the diffusion equation we introduce the solution
N
w=
i=1
wi i (x, y)
N i=1
1 1 x=1
wi
i=1 N 1 1 2
b a
2 i 2 i + x2 y 2
1
m dxdy =
1 1
wi
i=1 1 N
b a
1
i m x
1 1
dy +
x=1 1
i m y
y=1
dx
y=1 1 1
i=1
wi
1
b a
i m i m + x x y y
dxdy =
1 1
m dxdy
or
m dxdy.
107
For the chosen boundary conditions the rst two integral are zero such that the resulting equation can be written as BW = G with
1 1 1 1
(6.44)
bmi =
1 1
b a
i m i m + x x y y
dxdy
(6.45) (6.46)
gm =
1 1
m dxdy
In the following we replace the single index i with a pair k, l representing the x and y coordinates. The indices k and l range from 2 to nx1 and from 2 to ny1 respectively because the boundary condition imply that the coefcient of the shape function at the boundaries is zero. The x integration of the rst term in (6.45) yields the operator Lxx and the y integration of this term yield the operator My with wk1,l 2wk,l + wk+1,l x2 2 1 1 wk,l1 + wk,l + wk,l+1 = 6 3 6
(6.47) (6.48)
such that equation (6.44) assumes the form b a with 1 wk1,l1 2wk,l1 + wk+1,l1 + 6 x2 1 wk1,l+1 2wk,l+1 + wk+1,l+1 + 6 x2 1 wk1,l1 2wk1,l + wk1,l+1 + = 6 y 2 1 wk+1,l1 2wk+1,l + wk+1,l+1 + 6 y 2 2 wk1,l 2wk,l + wk+1,l 3 x2 (6.50) 2 wk,l1 2wk,l + wk,l+1 3 y 2 (6.51)
2
(6.49)
My Lxx wk,l =
Mx Lyy wk,l
and similar for Mx Lyy wk,l . In a corresponding nite difference approach we would have M x,f d = (0, 1, 0). Notes:
108
The operator Lxx and My are commutative. The result does not depend on the order the integration in (6.47) is executed. The method provides a straightforward way to employ nite element methods similar to nite difference methods. The result provides a simple equation which can be used with SOR to solve the coefcients for the shape functions. Solving equation (6.49) for wk,l yields 3 [1. + c1 (wk1,l1 + wk+1,l1 + wk1,l+1 + wk+1,l+1 ) 4c0 + c2 (wk1,l + wk+1,l ) + c3 (wk,l1 + wk,l+1 )]
wk,l =
with
c0 = c1 = c2
b a
1 1 + 2 x y 2
1 c0 6 b = a
2 1 2 3x 3y 2
2
c3 =
b a
2 1 + 3x2 3y 2
The program duct.f can be found on the course web page. To provide a reference for the approximate solution the exact solution is given by 8 2
2 (i+j)/21 (1) cos ib 2 + j2 i=1,3,5.. j=1,3,5.. ij a N N
w=
ix 2
cos
A second important measure for this problem is the total ow rate q, i.e., the ow integrated over the cross sectional area 8 2
3 N N
jy 2
q=2
i=1,3,5.. j=1,3,5..
1 i2 j 2
ib 2 a
j2
109
The structure is similar to that of Fivol.f. The program package uses an include le ductin which declares all variables and common blocks and it make use of a parameter le duct.dat. Variables declared in the parameter le are summarized in Table 6.6. Additional variables used in the program are listed in Table 6.7. Table 6.7: Other variables used in the program duct.f Variable Description nx, ny Number of nodes in the x and y directions x, y x and y coordinates dx, dy grid separation in the x and y directions ow, owex iterated ow rate and exact ow rate f, fexact iterated and exact solutions rms RMS error The program generates an ASCII output le which lists basic parameter and results including the iterated solution and the exact solution and the correspond ow rates and errors. In addition the program generates a binary le which can be used as input for graphics routines. The supplied IDL program product.pro reads this this le and plots the iterated and exact solutions. The results of this program indicate that the error decreases with x2 and y 2 . The result for using the nite element method (fem) are very similar to those of the nite difference method (fdm). The error is very similar with slightly smaller errors for fdm while the ow rate is slightly closed to the exact ow rate for fem. Distorted computational domains - Isoparametric mapping The nite element method is very comparable to nite differences for Cartesian grids. However the strength or the nite element method is the ease to apply it to distorted domains and complicated geometries. It is illustrated that the introduction of local coordinates is a particular strength to evaluate the integrals involving shape functions. There are various geometries to choose basic elements such as triangular, rectangular, or tetrahedral. The various method allow a simple grid renement technique by just dividing a basic element into several new element of the same geometry.
110
The advantage of the nite element method is that the coordinates themselves can be described by the shape functions. Figure shows a distorted grid with rectangular elements and the mapping into a local (, ) coordinate system.
=+1
Figure 6.9: Isoparametric mapping. The transformation between (x, y) coordinates and (, ) can be dened by
x=
l=1
l (, ) xl and y =
l=1
l (, ) yl
with (xl , yl ) as the x, y coordinates of the corner numbered l and l (, ) is the shape function with the value of 1 at the corner l. The transformation affects the evaluation of the weighted residual integral. Consider Laplaces equation = 0 as an example. The Galerkin fem produces a system of linear equations BW = G with bm,i =
area
i m i m + x x y y
dxdy
Let us consider the rst term I= The derivative /x can be computed as x y = + x y i m dxdy x x
=1
=1
=+1
(6.52)
111
/ / with
= [J] [J] =
/x /y x/ y/ x/ y/
(6.53) (6.54)
where [J] is the Jacobian. The derivatives in the Jacobian can easily be computed from the mapping (6.52), e.g., y =
4
l=1
l (, ) yl
From (6.53) one can determine the following explicit formulation for /x i 1 = x det J Exercise: Derive equation (6.55). Using dxdy = det J dd one obtains
1 1 1
y i y i
(6.55)
I=
1
1 det J
y i y i
y m y m
dd
All derivatives in this formulation are known because of the simple form that the l assume. The integral can evaluated numerically or analytically.
Example for such functions are Fourier series, Legendre, or Chebyshev polynomials. In this sense the spectral methods can be considered global methods rather than local as in the case of nite differences or nite elements.
112
T = sin (x) + x +
j=1
where the aj (t) are the unknown coefcients which need to be determined. This yields the residual
N
R=
j=1
j=1
daj + (j)2 aj dt
113
a1 = e t 1 am = 0 The solution for T is therefore T = sin (x) e t + x This is in fact the exact solution, however, this has been obtained for this particular set of initial and boundary conditions. For a more realistic case of T (x, 0) = 5x 4x2 and replacing sin (x) + x with 5x 4x2 in the trial solution one obtains rm =
16 m
2
With forward time differencing dam /dt = (an+1 an ) /t one obtains m m an+1 = an t (j)2 an + rm m m m Table 6.8: Value of the solution at x = 0.5 for different times t N=1 N=3 n=5 Exact solution 0 1.5 1.5 1.5 1.5 0.1 0.851 0.889 0.881 0.885 0.2 0.610 0.648 0.640 0.643 Table 6.8 shows the value of T for selected times and different values of N at x = 0.5. Note that the error is caused by two sources one of which is the limited accuracy of the representation in terms of the base functions and the other is the error in the temporal integration. Notes: The spectral method achieves relatively high accuracy with relatively few unknowns. For Dirichlet conditions the method reduces the problem to a set of ordinary differential equations Treatment of nonlinear terms is not yet clear (and can be difcult)
114
T (x, 0)
3 2x 2x2 + 2x3 ,
T (0, t) = 2.0 and T (1, t) = 1.0 x Different from the prior example it is not attempted to incorporate the initial and boundary conditions into the approximate solution. Rather a general trial solution is used
N
T (x, t) = b0 (t) +
j=1
The boundary conditions require the following relations for the coefcients
aj 2j = 2 ,
j=1 j=0
bj = 1
which can be used to eliminate aN and bN from the the approximate solution:
N 1 N 1
j=1
j aj N
, bN = 1
j=0
bj
N 1
j sin (N 2x) N
+
j=0
This implies that the terms in square brackets now need to be considered as the base functions or m sin (N 2x) , 1 m N 1 N = cos (m2x) + cos (N 2x) , 0 m N 1
115
R =
j=1 N 1
daj j daj + (2j)2 aj sin (2jx) + (2N )2 aj sin (2N x) dt dt N dbj dbj + (2j)2 bj cos (2jx) + + (2N )2 bj cos (2N x) dt dt
+
j=0
+ (2N )2 cos (2N x) 4N sin (2N x) Evaluating the weighted residuals yields
N 1
m dam + (2m)2 am + dt N
j=1
j N
= 4N = (2N )2 = (2N )2
(6.56)
N 1
(6.57)
j=0 N 1 j=0
(6.58)
Equations (6.56) for am are linearly independent from equations (6.57) and can be solved independently. To solve for the time integration it is necessary, however, to factorize the the system and carry out a matrix multiplication for each time step. Start values for am and bm are easily obtained using the trial solution for the initial condition. Note, since the problem is linear the factorization is only needed once because the subsequent time steps always use the same matrix (coefcients in equations (6.56) to (6.58) are constant).
116
When compared to the spectral method, the pseudospectral method does not determine the solution entirely in spectral space. Recall that the solution for the Galerkin spectral method is found by integrating the spectral coefcients. For a linear problem this is feasible but a nonlinear problem requires the inversion of a large matrix for each time step. The pseudo spectral method often uses an expansion
N +1
u (x, t) =
k=1
consists of three basic steps: Given a solution un one determines the spectral coefcients ak . This transforms the problem j from physical to spectral space. Using Chebichev Polynomials the step can be done with a fast Fourier Transform (FFT) if the collocation points are xj = cos (j1) (time efcient N with number of operations proportional to N log N ). The next step is to evaluate the second derivative 2 u/x2 from the coefcients ak which makes use of recurrence relations and is also very efcient:
u = x 2u = x2
N +1
ak Tk1 (x)
k=1 N +1
(1)
ak Tk1 (x)
k=1
(2)
The nal step then is to integrate in time. Different from the Galerkin spectral method this is n 2 done in real space directly for u: un+1 = un + t u thereby avoiding to have to solve j j x2
j
117
Pseudospectral method employs spectral space only to determine spatial derivatives (much more efcient)