Vous êtes sur la page 1sur 14

Aarhus University

Advance Numerical Methods in Fluid Dynamics


Steady Diffusion Problem (2D Mixed Formulation)
(Pseudo-Spectral Galerkin Method)

Author:
Javier I. Camacho Hernandez
Contents

1 Problem Formulation 2
1.1 Governing Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Mixed Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Analytical Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Discretization 3
2.1 Method of Weighted Residual(MWR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

O
2.2 System of Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

O
2.3 Derivation of the Equation 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

O
2.4 Derivation of the Equation 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.5 Derivation of the Equation 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Representation of the System of Equations 1.6 . . . . . . . . . . . . . . . . . . . . . . . . 8

3 Matlab Implementation 9
3.1 Set-up Grid and Differentiation Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Dirichlet Boundary Condition Implementation . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Direct Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Results 11
4.1 Numerical Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Error Distribution Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2.1 Temperature Error Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2.2 Flux Error Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Convergence Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

1
1. Problem Formulation

The main purpose of this problem is to use Spectral Finite Element Method (Galerkin Method(GM))to
solve a 2-D steady diffusion problem (Elliptic PDE).The nodes for the quadrature rule for GM are the roots
of a Gauss-Lobatto Legendre(GLL) polynomial,which are defined in the domain [1, 1]2 . The problem
is defined in a 2D domain = [1, 1]2 with an homogeneous Dirichlet boundary condition(DBCs),and
it is required to perform a discretization,and MATLAB implementation in order to solve the governing
equation. The particularity of the mixed formulation is that the solution of the scalar temperature field
can be equated at the same time as the solution of the vector field of the heat flux.

1.1 Governing Equation


~ 2 T (x, y) = f (x, y) = sin(x)sin(x) x, y
= [1, 1]2 (1.1)

Dirichlet Boundary Condition


T (x , y ) = 0 x , y (BoundaryDomain) (1.2)

1.2 Mixed Formulation


 
~ T
. ~ (x, y) = .~
~ q (x, y) = f (x, y) (1.3)
2 T (x, y) 2 T (x, y)  T (x, y)   T (x, y) 
+ = + = f (x, y) (1.4)
x2 y 2 x x y y

Heat Flux(assumed k = 1(Thermal conductivity))


~q = q x , q y


T (x, y)
q x = k (1.5)
x
T (x, y)
q y = k
y

Mixed Formulation(System of Equations) (Removing minus sign to have the Poissons Equation )
 x  y
q + q = f (x, y)
x y
T (x, y) T (x, y)
qx = qx =0 (1.6)
x x
T (x, y) T (x, y)
qy = qy =0
y y

1.3 Analytical Solution


1
T (x, y) = .sin(.x).sin(.y)
2. 2 (1.7)
 1   1 
q x (x, y) = .cos(.x).sin(.y) y
q (x, y) = .sin(.x).cos(.y)
2. 2.

2
2. Discretization

2.1 Method of Weighted Residual(MWR)


The Spectral Methods can be viewed as a part of the discretization schemes called Method of Weighted
Residuals(MWR).

L T (x, y) = f (x, y) x, y (2.1)
x y
Expansion of T (x, y),q (x, y),q (x, y)
n
T (x, y)
X
= T (x, y) = Tij .i (x).hj (y) f or i, j = 0, 1, 2, , n (2.2)
i,j=0

n
q x (x, y)
X
= q x (x, y) = x
qij .hi (x).hj (y) f or i, j = 0, 1, 2, , n (2.3)
i,j=0
n
q (x, y)
X y
y
= q y (x, y) = qij .hi (x).hj (y) f or i, j = 0, 1, 2, , n (2.4)
i,j=0

 
L T (x, y) f (x, y) = R(x, y) 6= 0 (2.5)
Z
R(x, y).(x, y) d = 0 (2.6)

n
X
(x, y) = kl .hk (x).hl (y) f or k, l = 0, 1, 2, , n (2.7)
k,l=0

Where:
L:Differential Operator
h(x, y):Basis functions/Trial Functions/Expansions Functions
T (x, y):Linear combinations of the basis functions.

q x (x, y):Linear combinations of the basis functions.


q y (x, y):Linear combinations of the basis functions.
Tij :Temperature scalar field unknown constants.
x
qij :Heat Flux vector field x-component unknown constants.
x
qij :Heat Flux vector field y-component unknown constants.
R(x, y):Residual.
(x, y):Weight functions/Test Functions.(Test function same basis)

kl :Test coefficients.

3
2.2 System of Equations
Applying MWR to the System of Equations Eq.1.6
Z  
1 = x q x (x, y) + y q y (x, y) f (x, y) .(x, y)d = 0
Z  
2 = q x (x, y) x T (x, y) .(x, y)d = 0 (2.8)
Z  
3 = q y (x, y) y T (x, y) .(x, y)d = 0

2.3 Derivation of the Equation 1 O


O
Separation of Eq. 1 into LHS and RHS
Z  
1 = x q x (x, y) + y q y (x, y) f (x, y) .(x, y)d = 0
Z Z Z
x y (2.9)
= x q (x, y).(x, y)d + y q (x, y).(x, y)d = f (x, y).(x, y)d
| {z } | {z } | {z }
LHS1 LHS2 RHS

Applying Integration by Parts (IBP) to LHS

Z+1Z
LHS1 = x q x (x, y).(x, y)dxdy
1
X "  #  Z+1Z
 x=+1
ZX +1XX
x XXX
= q (x,
  y).(x,
XXy) dy q x (x, y).x (x, y)dxdy
1   X x=1
X XXX 1

Z+1Z
(2.10)
LHS2 = y q y (x, y).(x, y)dxdy
1
X " #  Z+1Z
 y=+1
ZX+1XX
y XXX
= q (x,
 y).(x,
XXy) dx q y (x, y).y (x, y)dydx
1  X y=1
X
 XXX 1
Z Z
x
LHS = q (x, y).x (x, y)d q y (x, y).y (x, y)d

Rewriting Eq. 1 O
Z Z Z
1 = q x (x, y).x (x, y)d q y (x, y).y (x, y)d = f (x, y).(x, y)d (2.11)

| {z } | {z } | {z }
1.1 1.2 1.3

4
Expansion of term 1.1 from Eq.(2.11) by substitution of Eq.(2.3) and eq.(2.7).
The test coefficients kl are cancel out since they are present in all the terms.
Z "X n
# " n
X
#
x
1.1 = qij .hi (x).hj (y) .x hZ
Z
kl .hk (x).hl (y) d f or sub index = 0, 1, 2, , n
i,j=0 k,l=0
Z " X
n
#
0
x
= qij .hi (x).hj (y).hk (x).hl (y) d
i,j,k,l=0
(2.12)

Implementing the Gaussian Quadrature(wnn and wmm )Quadrature Weights


n n
X X 0
x
1.1 = qij .hi (xm ).hj (yn ).hk (xm ).hl (yn ).wnn .wmm f or sub index = 0, 1, 2, , n
m,n=0 i,j,k,l=0
(2.13)
Applying Property of the Basis(h(x, y)) and Test Function((x, y))

hi (xm ) = im
(2.14)
x hi (xm ) = Dmi

Performing Summation(index run from k to l)

x
1.1 = qij .im .jn .Dmk .ln .wnn .wmm f or sub index = 0, 1, 2, , n
(2.15)
x
= Dmk .wmm .mi .qij .jn .wnn .nl

Kronecker Product
AXB = C
  (2.16)
B T A .vec(X) = vec(C)

x
Dmk .wmm .mi qij . .wnn .nl (2.17)
| {z } |{z} |jn {z }
A X B
!
y DxT .x .q x (2.18)

Here Dmk is transposed in order to keep the indexes running from k to l.

5
Expansion of term 1.2 from Eq.(2.11) by substitution of Eq.(2.3) and eq.(2.7).
The test coefficients kl are cancel out since they are present in all the terms.
Z "X n
# " n
X
#
y
1.2 = qij .hi (x).hj (y) .y 
H
 kl .hk (x).hl (y) d f or sub index = 0, 1, 2, , n
H
i,j=0 k,l=0
Z " X
n
#
y 0
= qij .hi (x).hj (y).hk (x).hl (y) d
i,j,k,l=0
(2.19)

Implementing the Gaussian Quadrature(wnn and wmm )Quadrature Weights


n n
X X y 0
1.2 = qij .hi (xm ).hj (yn ).hk (xm ).hl (yn ).wnn .wmm f or sub index = 0, 1, 2, , n
m,n=0 i,j,k,l=0
(2.20)
Performing Summation
y
1.2 = qij .im .jn .km .Dnl .wnn .wmm f or sub index = 0, 1, 2, , n
(2.21)
y
= km .wmm .mi .qij .jn .wnn .Dnl

Kronecker Product
y
km .wmm .mi qij . . .wnn .Dnl (2.22)
| {z } |{z} | jn {z }
A X B
!
DyT .y x .q y (2.23)

Expansion of term 1.3 from Eq.(2.11) by substitution of Eq.(2.3) and eq.(2.7).


The test coefficients kl are cancel out since they are present in all the terms.
Z " #" n
X
#
1.3 = f (x, y) . 
H
 kl .hk (x).hl (y) d f or sub index = 0, 1, 2, , n
H
k,l=0
Z " X
n
# (2.24)
= f (x, y).hk (x).hl (y) d
k,l=0

Implementing the Gaussian Quadrature(wn n and wm m)Quadrature Weights


n
X n
X
1.3 = f (xm , yn ).hk (xm ).hl (yn ).wnn .wmm f or sub index = 0, 1, 2, , n
m,n=0 k,l=0
(2.25)
Performing Summation

1.3 = fmn .km .ln .wnn .wmm f or sub index = 0, 1, 2, , n


(2.26)
= km .wmm fnm .nl .wnn
Kronecker Product
.w fnm . nl .wnn (2.27)
|km{z mm} |{z} | {z }
A X B
!
y x .f (2.28)

Collecting terms and Rewriting Eq. 1 O


! ! !
y DxT .x .q x
DyT .y x .q = y
y x .f (2.29)

6
2.4 Derivation of the Equation 2 O
O
Separation of Eq. 2 into terms
Z  
2 = q x (x, y) x T (x, y) .(x, y)d = 0
Z Z
(2.30)
= q x (x, y).(x, y)d x T (x, y).(x, y)d = 0
| {z } | {z }
2.1 2.2

Expansion of Term 2.1 from Eq.(2.30) by substitution of Eq.(2.2) and eq.(2.7).


The test coefficients kl are cancel out since they are present in all the terms.
Z "X n
#" n
X
#
x
2.1 = qij .hi (x).hj (y) . H
 kl .hk (x).hl (y) d f or sub index = 0, 1, 2, , n

H
i,j=0 k,l=0
Z " X
n
#
x
= qij .hi (x).hj (y).hk (x).hl (y) d
i,j,k,l=0
(2.31)

Implementing the Gaussian Quadrature(wnn and wmm )Quadrature Weights


n
X n
X
x
2.1 = qij .hi (xm ).hj (yn ).hk (xm ).hl (yn ).wnn .wmm f or sub index = 0, 1, 2, , n
m,n=0 i,j,k,l=0
(2.32)
Performing Summation

x
2.1 = qij .im .jn .km .ln .wnn .wmm f or sub index = 0, 1, 2, , n
(2.33)
x
= km .wmm .mi qij .jn .wnn .nl

Kronecker Product
x
km .wmm .mi qij . .wnn .nl (2.34)
| {z } |{z} |jn {z }
A X B
!
y x .q x (2.35)

Expansion of Term 2.2 from Eq.(2.30) by substitution of Eq.(2.2) and eq.(2.7).


The test coefficients kl are cancel out since they are present in all the terms.
Z " n #" n #
X X
2.2 = x Tij .hi (x).hj (y) . H
 kl .hk (x).hl (y) d f or sub index = 0, 1, 2, , n

H
i,j=0 k,l=0
Z " X
n
#
0
= Tij .hi (x).hj (y).hk (x).hl (y) d
i,j,k,l=0
(2.36)

Implementing the Gaussian Quadrature(wnn and wmm )Quadrature Weights


n n
X X 0
2.2 = Tij .hi (xm ).hj (yn ).hk (xm ).hl (yn ).wnn .wmm f or sub index = 0, 1, 2, , n
m,n=0 i,j,k,l=0
(2.37)
Performing Summation

2.2 = Tij .Dmi .jn .km .ln .wnn .wmm f or sub index = 0, 1, 2, , n
(2.38)
= km .wmm .Dmi .Tij .jn .wnn .nl

7
Kronecker Product
.km .wmm .Dmi . Tij . .jn .wnn .nl (2.39)
| {z } |{z} | {z }
A X B
!
y .x .Dx .T (2.40)

Collecting terms and Rewriting Eq. 2 O


! !
x
y .x .q y .x .Dx .T = 0 (2.41)

2.5 Derivation of the Equation 3 O


O
The method is the same as in the previous equations.The results are the following:
Collecting terms and Rewriting Eq. 3
! !
y .x .q y y .Dy x .T = 0 (2.42)

2.6 Representation of the System of Equations 1.6


   
0 y DxT .x DyT .y x ~
 
    T y .x f~
y x .Dx y .x 0 q~ = ~0

 x

q~y
  
y .Dy x 0 y .x ~0

8
3. Matlab Implementation

3.1 Set-up Grid and Differentiation Matrix

1 %% 2D Steady Diffusion Problem


2 %% Numerical Solution by Mixed Formulation Spectral Galerking Method
3 % Domain on [1,1]x[1,1] with u=0 on boundary
4 clc;clear;close all
5 addpath 'Auxiliary Files'
6 %% Set up grid
7 N=30;%Polynomial Order
8 n=N+1;
9 % Collocation Points
10 [x,w]=GLLnodes(N);
11 y=x;
12 k=1;
13 [xx,yy] = meshgrid(x,y);
14 xx = xx(:); yy = yy(:); % stretch 2D grids to 1D vectors
15 % Create the LGL differentiation Matrix
16 [,dh] = MimeticpolyVal(x,N,k);
17 D=dh';%
18 % Set small values to zeros
19 D(abs(D)<1e12) = 0;
20 %Weight Matrix
21 Lambda=diag(w);
22 W=kron(Lambda,Lambda);
23 %Coefficients Matrix
24 Z = kron(zeros(n),zeros(n));
25 A = [Z kron(Lambda,D'*Lambda) kron(D'*Lambda,Lambda)
26 kron(Lambda,Lambda*D) W Z
27 kron(Lambda*D,Lambda) Z W];

3.2 Dirichlet Boundary Condition Implementation

1 %% Create a column matrix to hold the RHS


2 f = sin(pi.*xx).*sin(pi.*yy);
3 f w=W*reshape(f,n2,1);%Weighted RHS
4 rhs=[f w;0.* f w;0.* f w];
5 %% Apply the Boundary Conditions
6 % Find the bounday points of the coordinate vectors:
7 bp = [find(abs(xx)==1 | abs(yy)==1);find( abs(yy)==1)]; % boundary pts (T x,T y,q x)
8 % Impose the boundary conditions on the right side vector.
9 rhs(bp) = 0;
10 % Apply the boundary conditions to the coefficient matrix
11 % Zero the rows out
12 A(bp,:) = zeros(length(bp),length(rhs));
13 A(:,bp) = zeros(length(bp),length(rhs))';%keep symmetry
14 % put in 1 for known points
15 A(bp,bp) = eye(length(bp));%L(bp,bp) = eye(4*N);

9
3.3 Direct Solver

1 %% Numerical Solution (Direct Solver)


2 sol= A\rhs;
3 T num = reshape(sol(1:n2),n,n);
4 qx num = reshape(sol(n2+1:2*n2),n,n);
5 qy num = reshape(sol(2*n2+1:3*n2),n,n);
6 Flux num =sqrt(qx num.2+qy num.2);
7 %% Analytical Solution
8 % Temperature
9 T analytic = (1/(2*pi2))*sin(pi.*xx).*sin(pi.*yy);
10 qx analytic = 1/(2.*pi).*cos(pi.*xx).*sin(pi.*yy);
11 qy analytic = 1/(2.*pi).*sin(pi.*xx).*cos(pi.*yy);
12 Flux analytic =sqrt(qx analytic.2+qy analytic.2);
13 % Reshape long 1D results onto 2D grid:
14 TT analytic= reshape(T analytic,n,n);
15 qxx analytic= reshape(qx analytic,n,n);
16 qyy analytic= reshape(qy analytic,n,n);
17 Flux analytic =reshape(Flux analytic,n,n);
18 %% Error Analysis (Analytical vs Numerical)
19 %% Temperature
20 % Error
21 error T=(T numTT analytic);
22 % Norm Error
23 error norm T=norm(error T);
24 %% Flux
25 % Error
26 error flux=(Flux numFlux analytic );
27 % Norm Error
28 error norm flux=norm(error flux);

10
4. Results

4.1 Numerical Solution

11
4.2 Error Distribution Analysis
4.2.1 Temperature Error Distribution

4.2.2 Flux Error Distribution

12
4.3 Convergence Analysis

13

Vous aimerez peut-être aussi