bilinear interpolationgtryggva/cfd-course/2013-lecture-24.pdf · bilinear interpolation!...
TRANSCRIPT
Computational Fluid Dynamics
Elementary!Grid Generation!
Grétar Tryggvason !Spring 2013!
http://www.nd.edu/~gtryggva/CFD-Course/!Computational Fluid Dynamics
Bilinear Interpolation!
Results for the Vorticity-Streamfunction formulation!
Elliptic grid generation!
Outline!
Computational Fluid Dynamics
Bilinear Interpolation!
Computational Fluid Dynamics
Simples grid generation is to break the domain into blocks and use bilinear interpolation within each block!
As an example, we will write a simple code to grid the domain to the right!
(x1,y1)!
(x2,y2)!(x3,y3)!
(x4,y4)!(x5,y5)!
(x6,y6)!(x7,y7)!
(x8,y8)!
Bilinear Interpolation!
Computational Fluid Dynamics
Start by breaking the domain into blocks!
Then grid each block separately!
(x1,y1)!
(x2,y2)!(x3,y3)!
(x4,y4)!(x5,y5)!
(x6,y6)!(x7,y7)!
(x8,y8)!
Bilinear Interpolation!Computational Fluid Dynamics
P1,0!1!
2!
3!
P1,3!
P1,2=P2,3!
P1,1=P2,0! P2,1=P3,0!
P3,2! P3,1!P2,2=P3,3!
Start by breaking the domain into blocks!
Then grid each block separately!
Bilinear Interpolation!
Computational Fluid Dynamics
2!
P1,0!1!
P1,3!
P1,2!
P1,1!
3!
P3,0!
P3,2! P3,1!
P2,2!
P3,3!
P2,1!P2,0!
P2,3!
Start by breaking the domain into blocks!
Then grid each block separately!
Bilinear Interpolation!Computational Fluid Dynamics
Consider an arbitrary shaped quadrilateral block!1. Select the ξ and ξ direction.!
(x0,y0)!
(x1,y1)!
(x2,y2)!(x3,y3)!
�
ξ
�
η
N!
M!2. Divide the
opposite sides evenly with N points in the ξ direction and !
M in the ξ direction and draw
straights line between the points
on the opposite sides!
Bilinear Interpolation!
Computational Fluid Dynamics
�
x ξ ,1( ) =N −ξN −1
⎛ ⎝
⎞ ⎠ x0 +
ξ −1N −1
⎛ ⎝
⎞ ⎠ x1
Along the edge between points 0 and 1!
Along the edge between points 3 and 2!
�
x ξ ,M( ) =N −ξN −1
⎛ ⎝
⎞ ⎠ x3 +
ξ −1N −1
⎛ ⎝
⎞ ⎠ x2
Then interpolate again for points between the edges!
�
x ξ ,η( ) =M −ηM −1
⎛ ⎝
⎞ ⎠ N −ξN −1
⎛ ⎝
⎞ ⎠ x0 +
ξ −1N −1
⎛ ⎝
⎞ ⎠ x1
⎛ ⎝ ⎜ ⎞
⎠ +
η−1M −1
⎛ ⎝
⎞ ⎠
N −ξN −1
⎛ ⎝
⎞ ⎠ x3 +
ξ −1N −1⎛ ⎝
⎞ ⎠ x2
⎛ ⎝ ⎜ ⎞
⎠
The y-coordinate is found in the same way!
Bilinear Interpolation!Computational Fluid Dynamics
�
x ξ ,η( ) =M −ηM −1
⎛ ⎝
⎞ ⎠ N −ξN −1
⎛ ⎝
⎞ ⎠ x0 +
ξ −1N −1
⎛ ⎝
⎞ ⎠ x1
⎛ ⎝ ⎜ ⎞
⎠ +
η−1M −1
⎛ ⎝
⎞ ⎠
N −ξN −1
⎛ ⎝
⎞ ⎠ x3 +
ξ −1N −1⎛ ⎝
⎞ ⎠ x2
⎛ ⎝ ⎜ ⎞
⎠
�
y ξ ,η( ) =M −ηM −1
⎛ ⎝
⎞ ⎠ N −ξN −1
⎛ ⎝
⎞ ⎠ y0 +
ξ −1N −1
⎛ ⎝
⎞ ⎠ y1
⎛ ⎝ ⎜ ⎞
⎠ +
η−1M −1
⎛ ⎝
⎞ ⎠
N −ξN −1
⎛ ⎝
⎞ ⎠ y3 +
ξ −1N −1
⎛ ⎝
⎞ ⎠ y2
⎛ ⎝ ⎜ ⎞
⎠
(x0,y0)!
(x1,y1)!
(x2,y2)!(x3,y3)!
�
ξ
�
η
N!
M!
For a single block, we therefore have:!
Bilinear Interpolation!
Computational Fluid Dynamics
For many blocks:!1. we must interpolate for each block and !2. ensure that their boundaries are correct!
P1,0!1!
2!
3!
P1,3!
P1,2=P1,2!
P1,1=P2,0! P2,1=P3,0!
P3,2! P3,1!P2,2=P3,3!
Bilinear Interpolation!Computational Fluid Dynamics
Short MATLAB program to generate the grid!
xp(1,1:4)=[0,0,1,2];xp(2,1:4)=[0.5,0.5,1,1.5];!yp(1,1:4)=[1,0,0,0.5];yp(2,1:4)=[1,0.5,0.5,1];!
(0.0,1.0)!
(0.0,0.0)!
(0.5,1.0)!
(1.0,0.5)!
(1.0,0.0)!
(2.0,0.5)!(0.5,0.5)!
(1.5,1.0)!
Bilinear Interpolation!
Computational Fluid Dynamics
xp(1,1:4)=[0,0,1,2];xp(2,1:4)=[0.5,0.5,1,1.5];!yp(1,1:4)=[1,0,0,0.5];yp(2,1:4)=[1,0.5,0.5,1];!
NumBlocks=3;!Nblock(1)=8;Nblock(2)=5;Nblock(3)=12; NTot=0;!Mblock(1)=6;Mblock(2)=6;Mblock(3)=6; MTot=6;!
for l=1:NumBlocks! N=Nblock(l);M=Mblock(l);! x0=xp(1,l);x1=xp(1,l+1);x3=xp(2,l);x2=xp(2,l+1);! y0=yp(1,l);y1=yp(1,l+1);y3=yp(2,l);y2=yp(2,l+1);! Nf=2;if(l == 1),Nf=1;end! for i=Nf:N, for j=1:M !! ii=i+NTot;! x(ii,j)=((M-j)/(M-1))*(((N-i)/(N-1))*x0+((i-1)/(N-1))*x1)+...! ((j-1)/(M-1))*(((N-i)/(N-1))*x3+((i-1)/(N-1))*x2);! y(ii,j)=((M-j)/(M-1))*(((N-i)/(N-1))*y0+((i-1)/(N-1))*y1)+...! ((j-1)/(M-1))*(((N-i)/(N-1))*y3+((i-1)/(N-1))*y2);! end, end;! NTot=NTot+Nblock(l)-1;!end!
axis(’equal'), hold on!for j=1:MTot;plot(x(1:NTot,j),y(1:NTot,j));end;!for i=1:NTot;plot(x(i,1:MTot),y(i,1:MTot));end;!
Bilinear Interpolation!Computational Fluid Dynamics
The grid!
Bilinear Interpolation!
Computational Fluid Dynamics
Sometimes the grid can be improved by smoothing. The simples smoothing is to
replace the coordinate of each grid point by the average of the coordinates around it. This
process can be repeated several times to improve the smoothness.!
Bilinear Interpolation!
�
x i, j( ) = 0.25* x i +1, j( ) + x i −1, j( ) + x i, j +1( ) + x i, j −1( )( )y i, j( ) = 0.25* y i +1, j( ) + y i −1, j( ) + y i, j +1( ) + y i, j −1( )( )
Computational Fluid Dynamics
The grid after two smoothing iterations!
Bilinear Interpolation!
Computational Fluid Dynamics
Bilinear Interpolation can also be used for curved boundaries, if the points on the
boundaries are given.!
Higher order Interpolation functions can also be used to generate stretched grids for
complex boundaries.!
Bilinear Interpolation!Computational Fluid Dynamics
The grid generation results in an array of x and y coordinates for each grid point:!
For simple problems we can include the grid generator in the fluid solver and generate the coordinates before we solve for the fluid motion!
For more complex problems the grid generation step is usually separated from the flow solver and the grid points are read from a file!
For commercial codes you can generally use many different grid generators—as long as the data format is consistent !
Bilinear Interpolation!
�
x ξ,η( ), η ξ,η( )
Computational Fluid Dynamics
%Function gridgen_elbow.m!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!function grid=gridgen_elbow(x,y)!global x y!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!xp(1,1:3)=[0,0,1.5];!xp(2,1:3)=[0.5,0.5,1.5];!yp(1,1:3)=[1,0,0];!yp(2,1:3)=[1,0.5,0.5];!
NumBlocks=2;%3!Nblock(1)=8;!Nblock(2)=14;%5!
NTot=0;!Mblock(1)=8;!Mblock(2)=Mblock(1);!MTot=Mblock(1);!
for l=1:NumBlocks! N=Nblock(l);! M=Mblock(l);! x0=xp(1,l);! x1=xp(1,l+1);! x2=xp(2,l+1);! x3=xp(2,l);! y0=yp(1,l);! y1=yp(1,l+1);! y2=yp(2,l+1);! y3=yp(2,l);! Nf=2;! if(l == 1)! Nf=1;! end!
for i=Nf:N, ! for j=1:M !! ii=i+NTot;! x(ii,j)=((M-j)/(M-1))*(((N-i)/(N-1))*x0+((i-1)/(N-1))*x1)+...! ((j-1)/(M-1))*(((N-i)/(N-1))*x3+((i-1)/(N-1))*x2);! y(ii,j)=((M-j)/(M-1))*(((N-i)/(N-1))*y0+((i-1)/(N-1))*y1)+...! ((j-1)/(M-1))*(((N-i)/(N-1))*y3+((i-1)/(N-1))*y2);! end, ! end;! NTot=NTot+Nblock(l)-1;! %NTot=NTot+Nblock(l);!end!
axis('equal'), hold on!for j=1:MTot;! % plot(x(1:NTot,j),y(1:NTot,j),'linewidth',1);!end;!for i=1:NTot;! %plot(x(i,1:MTot),y(i,1:MTot),'linewidth',1);!end;!axis('square'),axis([-0.10, 2, 0, 2]); hold on!axis off!disp('un-smoothed grid')!
for i=1:3!!for i=2:NTot-1!! for j=2:MTot-1!! x(i,j)=0.25*(x(i+1,j)+x(i-1,j)+x(i,j+1)+x(i,j-1));!
y(i,j)=0.25*(y(i+1,j)+y(i-1,j)+y(i,j+1)+y(i,j-1));!! end;!!end;!
end;!axis('square'),axis([-0.10, 2, 0, 2]); hold on!for j=1:MTot;! plot(x(1:NTot+1,j),y(1:NTot+1,j),'r','linewidth',1);!end;!for i=1:NTot+1;! plot(x(i,1:MTot),y(i,1:MTot),'r','linewidth',1);!end;!axis off!
Function gridgen_elbow.m!use with NS_Vorticity_Stream_Elbow.m!
Computational Fluid Dynamics Bilinear Interpolation!
Flow in an elbow, computed using a body fitted grid, using the streamfunction-vorticity formulation of the Navier-
Stokes equations!
Grid—bilinear interpolation with smoothing!
Streamfunction!
Computational Fluid Dynamics Bilinear Interpolation!
While bilinear interpolation is often the simplest approach for relatively simple domains, it usually
requires fairly large amount of human input.!
Thus, there have been major attempts to make the grid generation more automatic. !
Computational Fluid Dynamics
Elliptic Grid Generation!
Computational Fluid Dynamics
Elliptic Scheme!
“Isotherms” of the conduction equation!
02 =∇ Thave nice properties of smoothness and concentrated !contour spacing where solution has a large spatial gradient.!
è Why not use the solution to the Laplace equation as the new coordinate?!
0,0 22 =∇=∇ ηξ
Elliptic Grid Generation!Computational Fluid Dynamics
Elliptic Grid Generation!
Elliptic Scheme! 0,0 22 =∇=∇ ηξ
�
ξ = 0, ∂η /∂ξ = 0
�
ξ = M, ∂η /∂ξ = 0
�
η = 0∂ξ∂η
= 0
�
η = N∂ξ∂η
= 0
Computational Fluid Dynamics
Few points in regions of interest!
Need more control over the point location!
0,0 22 =∇=∇ ηξ
Elliptic Grid Generation!Computational Fluid Dynamics
Further control can be applied by adding a source term:!
Proper choice of provides the shape of the mesh.!
In practice, instead of solving for in terms of!
, we want to solve for in terms of .!
),(),,( 22 ηξηηξξ QP =∇=∇
QP,
ηξ ,yx, yx, ηξ ,
Transform the Poisson equation into space.!( )ηξ ,
Elliptic Grid Generation!
Computational Fluid Dynamics
Adding the two equations:!
we obtain !�
xξ ∇2ξ + xη∇
2η = xξ P(ξ ,η) + xηQ(ξ ,η)
yξ ∇2ξ + yη∇
2η = yξ P(ξ ,η) + yηQ(ξ ,η)
( )ηξηηξηξξ QxPxJxqxqxq +−=+− 2123 2
( )ηξηηξηξξ QyPyJyqyqyq +−=+− 2123 2
where !
223
2
221
ξξ
ηξηξ
ηη
yxq
yyxxq
yxq
+=
+=
+=
Elliptic Grid Generation!Computational Fluid Dynamics
In discretized form (x-equation):!
�
α xi+1, j − 2xi, j + xi−1, j( ) − 0.5β xi+1, j+1 − xi+1, j−1 − xi−1, j+1 + xi−1, j−1( )
where !
�
γ xi, j+1 − 2xi, j + xi, j−1( ) + 0.5δ P xi+1, j − xi−1, j( ) + Q xi, j+1 − xi, j−1( )[ ] = 0
�
α = 0.25 xi, j+1 − xi, j−1( )2 + yi, j+1 − yi, j−1( )2[ ]
�
β = 0.25 xi+1, j − xi−1, j( ) xi, j+1 − xi, j−1( ) + yi+1, j − yi−1, j( ) yi, j+1 − yi, j−1( )[ ]
�
γ = 0.25 xi+1, j − xi−1, j( )2 + yi+1, j − yi−1, j( )2[ ]
�
δ = 116
xi+1, j − xi−1, j( ) yi, j+1 − yi, j−1( ) − yi+1, j − yi−1, j( ) xi, j+1 − xi, j−1( )[ ]2
Elliptic Grid Generation!
Computational Fluid Dynamics
suggested by Thompson (1977)!
�
P ξ,η( ) = − al sgn ξ −ξ l( )exp −cl ξ −ξ l( )l=1
L
∑
QP,
�
− bm sgn ξ −ξm( )exp −dm ξ −ξm( )2 + η −ηm( )2[ ]1/ 2⎛ ⎝ ⎜
⎞ ⎠ ⎟
m=1
M
∑
�
Q ξ,η( ) = − al sgn η −ηl( )exp −cl η −ηl( )l=1
L
∑
�
− bm sgn η −ηm( )exp −dm ξ −ξm( )2 + η −ηm( )2[ ]1/ 2⎛ ⎝ ⎜
⎞ ⎠ ⎟
m=1
M
∑where are chosen to generate appropriate !
grid clustering.!mlml dcba ,,,
( )⎪⎩
⎪⎨⎧
<−=>
=0if10if00if1
sgnxxx
x
Elliptic Grid Generation!Computational Fluid Dynamics
Selection of!
�
P ξ,η( ) = −al sgn ξ −ξ l( )exp −cl ξ −ξ l( )QP,
Attracts grid lines to the line ξ = ξl.!
al determines how strongly and !
cl determines the “reach” of the attraction!
�
ξ l
Elliptic Grid Generation!
Computational Fluid Dynamics
Selection of! QP,
�
P(ξ,η) = −bm sgn ξ −ξm( )exp −dm ξ −ξm( )2 + η −ηm( )2[ ]1/ 2⎛ ⎝ ⎜
⎞ ⎠ ⎟
Attracts grid lines to the line ξ = ξm, near the point (ξ,η) = ξm, ηm).!bm determines how
strongly and !dm determines the
“reach” of the attraction!
�
ξm�
ηm
Elliptic Grid Generation!Computational Fluid Dynamics
Although mapped grids have severe limitations in terms of the geometric complexity that they can handle, it is nevertheless possible to deal with reasonable complex geometries through the use of branch cuts and blocks.!
This does, however, require significant user input and can be challenging, particularly for three-dimensional geometries.!
Computational Fluid Dynamics
Here the object is introduced in two ways: on the left we bend the grid around the cylinder, turning the corner in front and back into a point on the xi=0 axis. On the right we introduce a branch-cut that preserves the corner but requires us to treat an internal boundary!
From: http://www.hpc.msstate.edu/publications/gridbook/!
Mapped grids for Complex Domains!Computational Fluid Dynamics
To accommodate this complex geometry the regular mapped grid is not a rectangle. However, all boundary conditions are imposed on a grid line !
From: http://www.hpc.msstate.edu/publications/gridbook/!
Mapped grids for Complex Domains!
Computational Fluid Dynamics
More examples of complex geometries handles by either branch cuts or mapping internal boundaries to the outer boundaries of the mapped grid!
From: http://www.hpc.msstate.edu/publications/gridbook/!
Mapped grids for Complex Domains!Computational Fluid Dynamics
From: http://www.hpc.msstate.edu/publications/gridbook/!
A complex geometry handled by the introduction of more than one mapped grid (multi-block grid). The values on the boundaries must be the same to maintain a smooth solution!
Mapped grids for Complex Domains!
Computational Fluid Dynamics
From: http://www.hpc.msstate.edu/publications/gridbook/!
And yet another example!!
Mapped grids for Complex Domains!Computational Fluid Dynamics
When corner points are mapped into a straight boundary, we usually need to treat these points in a special way!
From: http://www.hpc.msstate.edu/publications/gridbook/!
Mapped grids for Complex Domains!
Computational Fluid Dynamics
Accuracy of Generalized Coordinates!
Computational Fluid Dynamics Accuracy of Generalized Coordinates!
Physical Domain !
xΔ xrxΔ
1−if if 1+ifMapped Domain !
ξΔ ξΔ
1−if if 1+if
11
11
−+
−+
−−≈=
∂∂
ii
ii
xxff
xf
xf
ξ
ξ
Considering 1-D Stretching !
Taylor expansion !
fi+1 − fi−1
xi+1 − xi−1
=
fξ 1+ Δξ2
6fξξξfξ
+⎛
⎝⎜
⎞
⎠⎟
xξ 1+ Δξ2
6xξξξ
xξ
+⎛
⎝⎜
⎞
⎠⎟
rx =xi+1 − xixi − xi−1
Computational Fluid Dynamics
fi+1 − fi−1
xi+1 − xi−1
=
fξ 1+ Δξ2
6fξξξfξ
+⎛
⎝⎜
⎞
⎠⎟
xξ 1+ Δξ2
6xξξξ
xξ
+⎛
⎝⎜
⎞
⎠⎟
=
fξxξ
1+Δξ2
6fξξξfξ
+⎛
⎝⎜
⎞
⎠⎟ 1−
Δξ2
6xξξξ
xξ
+⎛
⎝⎜
⎞
⎠⎟ Δξ << 1( )
=
fξxξ
1+Δξ2
6fξξξfξ
−xξξξ
xξ
⎛
⎝⎜
⎞
⎠⎟ +
⎡
⎣⎢⎢
⎤
⎦⎥⎥
It may appear 2nd order accuracy, but…!
Accuracy of Generalized Coordinates!Computational Fluid Dynamics
�
f i+1 − fi−1xi+1 − xi−1
= fx + Δξ 2
6fξξξ xξ( )2 + 3 fxx xξξ[ ] +
Further algebraic expansion gives!
xξ =
x j+1 − x j−1
2Δξ+ O(Δξ2 ) = 0.5 1+ rx( ) Δx
Δξ+ O(Δξ2 )
xξξ =
x j+1 − 2x j + x j−1
Δξ2 + O(Δξ2 ) = rx −1( ) ΔxΔξ2 + O(Δξ2 )
fi+1 − fi−1
xi+1 − xi−1
= fx +16
16
1+ rx
2⎛
⎝⎜⎞
⎠⎟
2
Δx2 fxxx +rx −1
2⎛
⎝⎜⎞
⎠⎟Δxfxx
⎡
⎣⎢⎢
⎤
⎦⎥⎥+
Moral: avoid large changes in ! )1( ≈xi rx
Accuracy of Generalized Coordinates!
Computational Fluid Dynamics
�
∂f∂x
≈ f i+1 − fi−12Δξxξ
= fx + Δξ 2
6fξξξfξ
fx + 3xξξ fxx + xξ( )2 fxxx⎡
⎣ ⎢
⎤
⎦ ⎥ +
If is evaluated exactly!
The use of exact evaluation of introduces an additional!(and dominant) term in the truncation error. !Therefore, numerical evaluation is preferred.!
ξx
ξx
Accuracy of Generalized Coordinates!Computational Fluid Dynamics
How NOT to do uneven grids!
i i +1 i −1
fi+1 = fi +
∂f∂x
Δxi+1/ 2 +∂2 f∂x2
Δxi+1/ 22
2+∂3 f∂x3
Δxi+1/ 23
6+…
fi−1 = fi −
∂f∂x
Δxi−1/ 2 +∂2 f∂x2
Δxi−1/ 22
2−∂3 f∂x3
Δxi−1/ 23
6+…
∂f∂x
=Δxi−1/ 2
2 fi+1 + Δxi+1/ 22 + Δxi−1/ 2
2( ) fi − Δxi+1/ 22 fi−1
Δxi−1/ 2Δxi+1/ 2 Δxi−1/ 2 + Δxi+1/ 2( )
Accuracy of Generalized Coordinates!
Computational Fluid Dynamics
This approximation generally does not have the same symmetry properties as discretizing the mapped derivative and should generally be avoided!
From:!R.W.C.P. Verstappen and A.E.P. Veldman!Symmetry-preserving discretization of turbulent flow JCP187 (2003) 343–368!
Accuracy of Generalized Coordinates!Computational Fluid Dynamics
Working with the mapped derivative also makes it straight forward to obtain higher order approximations. For example:!
∂f∂x
=
∂f∂ξ
∂x∂ξ
∂f∂ξ
=− fi+2 + 8 fi+1 − 8 fi−1 + fi−2
12Δξ+ O Δξ4( )
yields:!
∂f∂x
=− fi+2 + 8 fi+1 − 8 fi−1 + fi−2
−xi+2 + 8xi+1 − 8xi−1 + xi−2
and!
From:!R.W.C.P. Verstappen and A.E.P. Veldman!Symmetry-preserving discretization of turbulent flow JCP187 (2003) 343–368!
Accuracy of Generalized Coordinates!
Computational Fluid Dynamics
By mapping a complex domain can be mapped into a rectangular one, where the techniques that we have covered can be used directly!
The governing equations, however, become more complex!
Although the geometry of the domain can be fairly complex, it must be possible to map it onto a rectangular domain. For more complex domains it is possible to use block-structured grids, but very complex shapes are more easily done by unstructured grids!
Mapped Grids!Computational Fluid Dynamics
http://www.hpc.msstate.edu/publications/gridbook/!
The “classic”!
Here we have examined the elementary aspects of representing the governing equations in a mapped coordinate system. This is a complex topics with its own “language” that needs to be mastered for further studies. !