finite equations

advertisement
Numerical Analysis of Potential Flow
about a Cylinder in the Free Stream
Numerical Analysis for Engineering
MEAE 4960H02
Andrew Aggarwala
12/9/1999
Table of Contents:
1.0
2.0
3.0
4.0
5.0
6.0
7.0
Introduction
Problem Formulation
2.1
Derivation of Stream Function
2.2
Analytical Solution to Laplace Equation
Numerical Approach
3.1
General Overview
3.2
Transformation to Finite Difference Form
3.3
Iterative Technique
Experimental Setup
4.1
Boundary Conditions
4.2
Coordinate System
4.3
Experimental Setup
Results
5.1
Grid Density
5.2
Relaxation Parameter
5.3
Geometry
Discussion and Error Analysis
6.1
Grid Density
6.2
Relaxation Parameter
Conclusion
Appendix A:
Appendix B:
Appendix C:
3
3
3
3
4
4
5
5
6
6
7
7
7
7
8
8
8
8
9
9
MATLAB Source Code
Derivation of Finite Difference Equation in Polar Coordinates
Additional Figures
1
List of Symbols:
A:
P:
U :
area
V:
Vfs :
V max :
a:
h:
i:
j:
k:
l2 :
velocity
l :
Infinity norm
m:
n:
r:
u:
v:
w:
:
:
:
:
mesh size in y-direction
approximation to stream function
free stream velocity
free stream velocity
maximum velocity in flow field
length scale
height
index
index
iteration index
Euclidean norm
mesh size in x-direction
radius
x – velocity
y – velocity
z – velocity
realxation parameter
density
angle of polar coordinate mesh
stream function
1.0: Introduction
2
The potential flow about a cylinder in the free stream is a convenient problem with which to investigate
numerical problem solving techniques. The equation describing the potential flow about any body in two
dimension flow reduces to the Laplace partial differential equation. Fortunately, the Laplace equation has a
well known solution and can be solved analytically. This provides a good benchmark to gauge the accuracy
of the numerical approximation. The problem is the simplest form of Computational Fluid Dynamics, but
the general algorithm forms the foundation for the higher fidelity models.
A cylinder was chosen for it's available analytical solution and for it's simple definition. The numerical
'experiments' conducted involved changing grid densities, moving from a Cartesian to a polar coordinate
system, and changing the inlet velocity to cylinder radius ratio
The main criteria examined is the numerical approximations accuracy in calculating the maximum velocity
and its position in the flow field. In addition, each run of the code produces various plots including
streamlines and velocity contours. The algorithm has been coded using MATLAB, which offers excellent
graphing capability.
2.0: Problem Formulation
2.1 - Derivation of Stream Function
Starting from the integral form of mass conservation:

 t dV   V  dA  0 ,
[1]
we can obtain the differential form to be:
 


 u   v   w  0 .
t x
y
z
[2]
Assuming steady, incompressible flow and dropping the z – dimension, equation [2] reduces to
u v

 0.
x y
[3]
We can use a mathematical trick to replace two variables (u and v) in equation [3] with one, higher order
function , (x,y), known as the Stream Function. Continuity can now be written as:
  

x  y
    


and v  
.
   
  0 , where u 
x
y
 y  x 
[4]
Taking the curl of the local velocity vector V,
curl
V
1  v u  1   2  2 
   , where is vorticity.

   
2  x y  2  x 2 y 2 
[5]
Setting vorticity to zero results in the two dimensional Laplace equation:
 2  2

 0.
x 2 y 2
[6]
2.2 - Analytical Solution to Laplace Equation
This equation is valid for 2D, irrotational, incompressible flow which is commonly referred to as Potential
Flow. The advantage of having reduced Continuity to the Laplace equation is that several solutions and
analytical techniques are known with which to solve it.
The Stream Function is not only useful as a mathematical shortcut, as it also has an important
physical interpretation: it can be shown that lines of constant are streamlines (White, 217). Thus, once
3
the solution of the Stream Function is determined, one can easily plot the streamlines in the flow. In
addition, any streamline can be arbitrarily chosen to represent a body surface.
Another feature of Potential Flow is that all flow fields about any surface can be modeled using
any linear combination of three elementary plane potential flows (White, 229-235). The elementary
potential flows are the Uniform Stream, the Source or Sink, and the Vortex. The line doublet, which is the
superposition of a Source and a Sink results in:
 y 
,
 x2  y2 
  U a 2 
[7]
where Uis the free stream velocity and a is the length scale. Linearly combining a line doublet with a
Uniform Stream results in:
 y 
,
 x2  y 2 
[8]
a2 
.
x2  y2 
[9]
  U  y  U a2 
which reduces to:


 ( x , y )  U  1 
If the length scale a is taken to be the radius of the cylinder, and
x 2  y 2  a then [9] is the Potential
Flow solution about a cylinder in the free stream. Using [4] it can be also be found that
 x2  y2 


xy
2



u  U  Ua 2 
and
v


U
a
2 .
2

  x 2  y 2  
  x 2  y 2  
[10]
A more rigorous derivation can be found in (Fay,520-527) and (White, 229-235).
Placing the coordinate system at the center of the cylinder, we can find the velocity at the top of
the cylinder (x = 0, y = a) by using [10] as follows:
  a2 
 0 
u  U   U  a 2  2 2   2U  and v  U  a 2  2 2   0
 a  
 a  
[11]
Further inspection reveals that the maximum velocity in the flow field will occur at the top and bottom
(x = 0, y = a) of the cylinder, while the flow will be stagnated (u = 0, v = 0) at the front and rear
positions (x = a, y = 0).
3.0: Numerical Approach
3.1 - General Overview
The finite difference algorithm for solving partial differential equations combines several different
numerical problem solving techniques. The first step is to transform the differential equation into the finite
difference form. Each method for performing the transformation results in a truncation error, which is an
inherent error in the approximation. Moving to higher fidelity approximations results in lower truncation
errors but at the cost of round-off error. The method described below is known as the Three-Point Formula
for each dimension (there are actually five points because of the two dimensionality of the problem), which
is generally accepted as having 'good' behavior ( Burden & Faires,168-177).
If the function is to be evaluated between [a,b], the finite difference technique breaks [a,b] up into n-1
discrete sections. This results in n nodes being formed; with the finite difference function being evaluated
at each node. In the flow field problem being investigated, we are limiting ourselves to two dimensions
which results in n x m nodes, where n and m are the number of nodes in the x and y directions respectively.
Each node is indexed, with 1 i  n in the x direction and 1  j  m in the y direction, with the finite
difference function being solved for Pi,j.
4
Once the function P is evaluated at each node, we must use a numerical technique to solve the resulting
system of equations. Direct methods are efficient for small dimension systems, but to allow for greater
flexibility in mesh density an indirect method is preferred. The method chosen and detailed below is the
Gauss-Seidel iterative technique. This indirect technique is computationally efficient as it is continuously
updating the system matrix P with the most recently computed values. The Euclidean and Infinity Norms
are useful criteria for terminating the iterative loop. In the code presented here, the Infinity Norm is used as
stopping criteria, although both Norms are plotted versus iteration to give a visual representation of the
convergence.
3.2 - Transformation to Finite Difference Form
The first step is to find the first three terms of the Taylor Series expansion about the point x i with respect to
x as:
2
   1
2   




x

x

i
 x 2 
 x  i 2

i
 ( x )   i  x  xi 
[12]
Equation [12] can be evaluated at xi-1 and xi+1 to yield:
2
   1
2   
 i 1   i  xi 1  xi 
  xi 1  xi   2 
 x  i 2
 x  i
2
   1
2   
   xi 1  xi   2 
 x  i 2
 x  i
 i 1   i  xi 1  xi 
[13]
Equations [13] can then be solved to attain:
  2
 2
 x
  i 1  2 i  i 1
 
.
x 2
i
[14]
The same process is repeated in the y-direction, and then substituted into the Laplace equation [6]:
 i 1, j  2 i , j   i 1, j
x 
2

 i , j 1  2 i , j   i , j 1
y 2
0
[15]
And [15] can now be solved for  i :
 i, j




2



 x 
1
















i

1
,
j
i

1
,
j
i
,
j

1
i
,
j

1
 y 
   x  2   



 21     
   y   

 
[16]
For clarity we will designate the above numerical approximation as P i,j.
3.3 - Iterative Technique
A numerical technique must be used to solve the resulting system AP = b. Direct methods for solving the
system are computationally efficient only for systems of small dimensions (~100). To accurately resolve
the flow field about the cylinder we are required to use relatively high grid counts which can result in a
system containing 1000 or more equations. The indirect or iterative methods appear to be the only course
to follow.
Iterative techniques involve rearranging the system AP = b into P = TP + c for some fixed matrix T and
vector c. The iterative process is started by guessing at the initial value P(0) and solving for P(1) such that:
5
P(k) = TP(k-1) + c
for k = 1,2,3,… until some convergence criteria is met or a maximum iteration count is exceeded. The
(k )
(k )
(k )
Gauss-Seidel iterative technique involves using x1 ,... xi 1 for computing x i
, thus making use of the
most recent calculated values.
In addition, the Gauss-Seidel method can be accelerated by using a relaxation term  > 1. One variable
which will be investigated in Part 4 is the effect that  has on convergence.
Two stopping criteria are used for this algorithm. One is to terminate the loop if the number of iterations
exceeds some upper limit. If this upper limit is reached it may signify that the system will never converge,
or that the convergence rate is too slow to be practical. The other criteria involves checking if the l 2 or l
distances between P(k) and P(k-1) are less then the machine tolerance. The norm of the difference is defined
as:
l2  x
k
x
 k 1
l  x  k   x  k 1
2
1
2
2
n
  x  k   x  k 1 
 i 1




[17]
 max x  k   x  k 1
1i n
4.0: Experimental Setup
4.1 – Boundary Conditions
The first step in running the numerical analysis is to establish boundaries and boundary conditions. The
cylinder must be enclosed in a ‘box’, within which all the calculations are performed. The boundary
conditions are specified by the user at the start and are held throughout the analysis. For the particular
problem being studied here, it makes sense to specify and hold a value for the stream function at the inlet,
exit and along the upper and lower boundaries.
For the cylinder in the free stream, the user inputs a specific free stream velocity. From equation [8] we can
see that in a Uniform Stream,   U  y , where U is the freestream velocity and y is a height. For
convenience, the mean line height y between the upper and lower boundaries is set to zero. Solving then for
 at the upper and lower boundaries yields:
hU 
hU 
, and  lower  
2
2
where h is the total distance between upper and lower boundaries.  can also be solved for value of y.
 upper 
This process is conducted for both the boundary conditions and to get an initial condition of the flow field.
It can easily be seen then that the initial condition is that of undisturbed uniform flow at a free stream
velocity of U.
One assumption that must be made is that the boundaries are far enough away from the disturbance (the
cylinder) to be unaffected by it. A quick look at equation [10] shows that the cylinders affect will only go
to zero as y approaches infinity. Such a boundary condition is obviously impractical; so some criteria must
be developed to determine how far away the boundaries have to be to be ‘acceptable’. By again examining
equation [10], we can see that the delta in velocity due to the cylinder goes as radius squared over y
squared. Assuming that a one percent fluctuation in free stream velocity is acceptable, we can calculate
that:
yupper  10radius  and ylower  10radius 
6
The final boundary condition which must be imposed on the flow is that about the solid body in the free
stream. Recall from Potential Flow theory that any streamline can be considered a solid surface because by
definition no flow is moving normal to the streamline. Using this fact, all the nodes making up the cylinder
surface are given a constant stream function value, thus forming a closed surface in the free stream.
4.2 – Coordinate System
Up to this point all equations have been solved in Cartesian space. Due to the specific geometry being
investigated in this experiment we will also use a mesh using Polar coordinates. As we will see below in the
Results section, the main advantage of the polar coordinate system is that the cylinder’s surface is free from
‘building block’ steps which must occur in Cartesian space when describing a circular object. The results
suggest that such approximations to the shape being studied profoundly influence accuracy and
convergence. The derivation of the finite difference equations in polar coordinates can be found in
Appendix B.
4.3 – Experimental Setup
The main focus of this experiment concerns the effect of numerical approximation on accuracy and speed.
As such, the first experiment involves gradually increasing the grid density in both Cartesian and Polar
coordinates. Once a satisfactory grid count is determined, then the relaxation term in the iterative algorithm
will be tweaked to get the fastest convergence rate. For a given grid count the ratio of velocity to cylinder
radius will also be modified to confirm that the solution is independent of the geometry scale.
5.0: Results
5.1 – Grid Density
Polar Coordinates -  = 1.7
Run
n
m
Grid Count
1
10
10
100
2
20
20
400
3
40
40
1600
4
80
80
6400
5
160
160
25600
6
200
200
40000
Cartesian Coordinates -  = 1.7
Run
n
m
Grid Count
1
10
10
100
2
20
20
400
3
40
40
1600
4
80
80
6400
5
160
160
25600
6
200
200
40000
Vmax/Vfs Analytical = 2.0
Nits
28
33
124
412
1183
Time (min) Vmax/Vfs
0.5
1.6480
0.5
1.8022
1
1.8857
10
1.9466
108
1.9863
r
0.500
0.500
0.500
0.500
0.500
theta
288
270
270
270
270
Nits
2
34
63
219
654
898
Time (min) Vmax/Vfs
0.5
1.0000
0.5
1.1623
0.5
1.4127
4.0
1.6440
47.0
1.8553
100.0
1.9352
x
3.890
-0.263
-0.128
-0.189
-0.157
-0.126
y
2.780
-0.789
-0.641
-0.565
-0.535
-0.527
Analytical Location of max velocity: (0.5,270) or (0.0,-0.5)
7
5.2 – Relaxation Parameter
Relaxation - Polar Coordinates
n
80
80
80
80
80
m
80
80
80
80
80
nXm
6400
6400
6400
6400
6400

1
1.2
1.4
1.6
1.8
Velocity Time (min)
1.9526
33.0
1.9502
26.0
1.9485
19.0
1.9472
13.0
1.9461
7.0
5.3 – Geometry
Geometry: Polar Coordinates
n
m
80
80
80
80
80
80
nXm
6400
6400
6400
Vel/Radius
2
1
4
Vmax/Vfs
1.9466
1.9459
1.9481
As expected, varying the value of the ratio of freestream velocity to cylinder radius has no significant effect
on the calculation time or accuracy.
6.0: Discussion and Error Analysis
6.1 – Grid Density
The results of the variation in grid density show a clear difference between the coordinate systems. When
solving using the polar coordinates, the accuracy is much higher for a given time. The relative ‘accuracy’ is
based on how well each particular experiment matches the analytical solution for the maximum velocity.
The theoretical maximum velocity should occur at the very top and bottom of the cylinder and be exactly
twice the free stream velocity. Figure 1 shows the plot of Maximum Velocity versus Grid Density for both
the polar and Cartesian solutions.
Figure 1
Figure 2
8
Figure 2 shows Maximum Velocity versus Elapsed Time. (Full size plots are in Appendix C).
The plots clearly indicate that for this particular geometry, the polar coordinate system offers greater speed
and higher accuracy. The main reason for this difference between the two coordinate systems can easily be
seen by glancing at the streamline and velocity contour plots in Appendix C. At the lower grid densities,
the Cartesian grid fails to describe the cylindrical surface with satisfactory accuracy. In fact, at the lowest
grid density tested, the grid spacing is so sparse that it fails to even recognize that the cylinder is present;
and it converges in 2 iterations with the solution for uniform, undisturbed flow.
In addition, the truncation error is dependent on grid density. Specifically, the three point formula used in
creating the finite difference equation has a truncation error of O(x2+y2). As grid density increases the
associated x and y’s get smaller, which causes the truncation error to decrease. However, as grid density
increases not only does the amount of computational time increase but the round off error increases as well.
6.2 – Relaxation Parameter
Varying the relaxation parameter has a drastic effect on the speed of convergence. The experiment was
conducted using polar meshing at one fixed grid density. The results show an elapsed time reduction of
almost 5x when using  with only a 0.33% loss in accuracy as opposed to using the method without
relaxation. Figure 3 shows a plot of Elapsed Time/Velocity versus :
Figure 3
7.0: Conclusions
The numerical investigation was conducted to gain insight into the problems and errors which occur in
using numerical approximations to solve partial differential equations. The study involved forming a mesh
about the solid body, applying boundary conditions and developing and coding the necessary iteration
scheme. In conducting a set of ‘numerical experiments’ we have seen several key qualities of numerical
approximations. Correctly matching all of the boundary conditions (which requires very high density when
using Cartesian grids with this geometry) is of the utmost importance. Choosing a satisfactory mesh density
is complicated by the decreasing importance of truncation and increasing dominance of round off error as
mesh density increases. In closing, I have gained great admiration for those in industry and in the academic
world who develop CFD codes which incorporate turbulence modeling, heat transfer and even time accurate
solutions which converge in half the time that this simplified inviscid, irrotational, potential flow code does.
9
References:
Anderson, Dale et al., Computational Fluid Mechanics and Heat Transfer, McGraw-Hill, New York, 1984.
Burden, Richard L., J. Douglas Faires, Numerical Analysis – 6th Ed., Brooks/Cole, 1997.
Fay, James A., Introduction to Fluid Mechanics, MIT Press, Cambridge, 1994.
Pratap, Rudra, Getting Started with MATLAB, Saunders, New York, 1996.
White, Frank M., Fluid Mechanics – 3rd Ed., McGraw-Hill, New York, 1994.
10
Appendix A:
MATLAB Source Code
1) Cartesian Coordinates
2) Polar Coordinates
11
% CFD3 cartesian coordinates
% Grid Formation
clear
clf
% Inlet Conditions
Vel=1.0;
% velocity at inlet
% Geometry Definition
Diameter=1.0; % diameter of cylinder
% Grid Density
n=200;
% grid count in x dimension (n>1)
m=200;
% grid count in y dimension (m>1)
% Other Options
omega = 1.7; % SOR relaxation parameter 1<omega
TOL=0.00001; % machine tolerance
Nmax=2000; % maximum iterations
Contours=91; % number of streamlines to plot
Grid='on'; % turn cfd grid points on/off
colordef white
%%
%
Radius=Diameter/2.0;
height=Diameter*10;
length=Diameter*10;
Dx=length/(n-1);
Dy=height/(m-1);
B=(Dx/Dy)^2;
%%
% Write time at start
time=fix(clock);
hourstr=int2str(time(4));
minstr=int2str(time(5));
if time(5)<10
minstr=['0',minstr];
end
timex=['Time at start of run: ' hourstr ':' minstr];
disp(timex)
% Center cylinder at (0,0)
xc=0.0;
yc=0.0;
%
% Create x and y arrays
x(1)=-length/2.0;
y(1)=-height/2.0;
for j=2:m
y(j)=y(j-1)+Dy;
end
for i=2:n
x(i)=x(i-1)+Dx;
end
% Boundary Conditions
% & Initial Conditions
for i=1:n
for j=1:m
12
P(i,j)=Vel*y(j);
Z(i,j)=P(i,j)+10*TOL;
end
end
Psurf = 0.0;
% Gauss-Seidel iterative technique
c=0;
Nits=0;
while (c < 1.0) & (Nits<Nmax)
Nits=Nits+1;
itcount=[Nits];
c=1;
norm2(Nits)=0.0;
normi(Nits)=0.0;
lastdiff=0.0;
for i=2:(n-1)
for j=2:(m-1)
Rpoint=((x(i)-xc)^2+(y(j)-yc)^2)^0.5;
%Rpoint, Radius
if Rpoint<=Radius
P(i,j)=Psurf;
Z(i,j)=Psurf;
else
P(i,j)=(1-omega)*P(i,j)+omega*(1/(2+2*B))*(P(i-1,j)+P(i+1,j)+(B)*(P(i,j-1)+P(i,j+1)));
end
norm2(Nits) = ((Z(i,j)-P(i,j))^2)^0.5;
diff=abs(Z(i,j)-P(i,j));
if (diff>lastdiff)
normi(Nits) = diff;
end
lastdiff = diff;
if diff>TOL
c=0;
end
Z(i,j)=P(i,j);
end
end
end
P=rot90(P);
% Calculate velocity in x and y dimensions
for i=1:n
for j=1:m
if ((j==m)|(j==1))
if (j==m)
u(i,j)=(P(i,j)-P(i,j-1))/(Dy);
else
u(i,j)=(P(i,j+1)-P(i,j))/(Dy);
end
else
u(i,j)=(P(i,j+1)-P(i,j-1))/(2*Dy);
end
if ((i==n)|(i==1))
if (i==n)
v(i,j)=(P(i-1,j)-P(i,j))/(Dx);
13
else
v(i,j)=(P(i,j)-P(i+1,j))/(Dx);
end
else
v(i,j)=(P(i-1,j)-P(i+1,j))/(2*Dx);
end
end
end
% Calculate velocity
w = (u.^2+v.^2).^0.5;
% Write time at end
time=fix(clock);
hourstr=int2str(time(4));
minstr=int2str(time(5));
if time(5)<10
minstr=['0',minstr];
end
timex=['Time at end of run: ' hourstr ':' minstr];
disp(timex)
% Calculate maximum velocity and position
wmax=0.0;
xwmax=0;
ywmax=0;
for i=1:n
for j=1:m
if (w(i,j)>=wmax)
wmax=w(i,j);
xwmax=num2str(x(i));
ywmax=num2str(y(j));
end
end
end
ustr=num2str(wmax);
velstring=['Wmax = ' ustr ' at (' ywmax ', ' xwmax ')'];
disp(velstring)
Nits
%
%%
% PLOTTING
plot(1:Nits,norm2)
xlabel('Iterations')
ylabel('Euclidean Norm')
pause
plot(1:Nits,normi)
xlabel('Iterations')
ylabel('Infinity Norm')
pause
%
% Add cylinder to streamline plot
plotcirc=linspace(0,2*pi,100);
xcirc=Radius*cos(plotcirc);
ycirc=Radius*sin(plotcirc);
plot(xcirc,ycirc,'b');
%
xlabel(itcount)
14
ylabel('y (ft)')
title('CFD - Potential Flow')
hold on
if Grid=='on'
for j=1:m
plot(y(j),x,'-')
hold on
end
end
%
hold on
contour(x,y,P,Contours)
title('Streamlines')
grid off
axis([-Radius*5.0 Radius*5.0 -Radius*5 Radius*5])
axis equal
pause
hold off
%
pcolor(x,y,w)
hold on
shading interp
colorbar vert
plotcirc=linspace(0,2*pi,100);
xcirc=Radius*cos(plotcirc);
ycirc=Radius*sin(plotcirc);
plot(xcirc,ycirc,'b');
axis([-Radius*5.0 Radius*5.0 -Radius*5 Radius*5])
axis equal
grid off
title('Velocity')
%
%
hold off
15
% CFD4 cylindrical coords only
clear
clf
% Inlet Conditions
Vel=1.0;
% velocity at inlet
% Geometry Definition
Diameter=1.0; % diameter of cylinder
% Grid Density
nn=200;
% grid count in R-dimension
mm=200;
% grid count in theta
% Other Options
omega = 1.7; % SOR relaxation parameter 1<omega
TOL=0.00001; % machine tolerance
Nmax=2000; % maximum iterations
Contours=91; % number of streamlines to plot
Grid='on'; % turn cfd grid points on/off
colordef white
%%
%
Radius=Diameter/2.0;
maxradius = 10*Radius;
dr=(maxradius-Radius)/nn;
dth=2*pi/mm;
%%
% Write time at start
time=fix(clock);
hourstr=int2str(time(4));
minstr=int2str(time(5));
if time(5)<10
minstr=['0',minstr];
end
timex=['Time at start of run: ' hourstr ':' minstr];
disp(timex)
% Boundary Conditions
% & Initial Conditions
for ii=1:nn
for jj=1:mm
rad(ii,jj)=(((ii-1)/(nn-1))*(maxradius-Radius))+Radius;
theta(ii,jj)=(jj/mm)*2*pi;
x(ii,jj)=rad(ii,jj)*cos(theta(ii,jj));
y(ii,jj)=rad(ii,jj)*sin(theta(ii,jj));
if (ii==1)
Pr(ii,jj)=0.0;
else
Pr(ii,jj)=Vel*y(ii,jj);
end
Zr(ii,jj)=Pr(ii,jj)+10*TOL;
end
end
% Gauss-Seidel iterative technique
c=0;
Nits=0;
while (c < 1.0) & (Nits<Nmax)
Nits=Nits+1;
16
itcount=[Nits];
c=1;
norm2(Nits)=0.0;
normi(Nits)=0.0;
lastdiff=0.0;
for ii=2:(nn-1)
for jj=1:mm
pre=1/(2+2*(dr/(rad(ii,jj)*dth))^2);
if ((jj==mm)|(jj==1))
if (jj==1)
Pr(ii,jj)=(1-omega)*Pr(ii,jj)+omega*pre*(Pr(ii-1,jj)+Pr(ii+1,jj)+(dr/(2*rad(ii,jj)))*(Pr(ii+1,jj)Pr(ii-1,jj))+(dr/(rad(ii,jj)*dth))^2*(Pr(ii,mm)+Pr(ii,jj+1)));
else
Pr(ii,jj)=(1-omega)*Pr(ii,jj)+omega*pre*(Pr(ii-1,jj)+Pr(ii+1,jj)+(dr/(2*rad(ii,jj)))*(Pr(ii+1,jj)Pr(ii-1,jj))+(dr/(rad(ii,jj)*dth))^2*(Pr(ii,jj-1)+Pr(ii,1)));
end
else
Pr(ii,jj)=(1-omega)*Pr(ii,jj)+omega*pre*(Pr(ii+1,jj)+Pr(ii-1,jj)+(dr/(2*rad(ii,jj)))*(Pr(ii+1,jj)-Pr(ii1,jj))+(dr/(rad(ii,jj)*dth))^2*(Pr(ii,jj+1)+Pr(ii,jj-1)));
end
norm2(Nits) = ((Zr(ii,jj)-Pr(ii,jj))^2)^0.5;
diff=abs(Zr(ii,jj)-Pr(ii,jj));
if (diff>lastdiff)
normi(Nits) = diff;
end
lastdiff = diff;
if diff>TOL
c=0;
end
Zr(ii,jj)=Pr(ii,jj);
end
end
end
% Calculate radial and tangential velocities
for ii=1:nn
for jj=1:mm
if (theta(ii,jj)<pi)
if ((ii==1)|(ii==nn))
if ii==1
u(ii,jj)=(Pr(ii,jj)-Pr(ii+1,jj))/(dr);
else
u(ii,jj)=(Pr(ii-1,jj)-Pr(ii,jj))/(dr);
end
else
u(ii,jj)=(Pr(ii-1,jj)-Pr(ii+1,jj))/(2*dr);
end
if ((jj==1)|(jj==mm))
if jj==1
v(ii,jj)=(Pr(ii,jj)-Pr(ii,mm))/(dth*rad(ii,jj));
else
v(ii,jj)=(Pr(ii,1)-Pr(ii,jj))/(dth*rad(ii,jj));
end
else
v(ii,jj)=(Pr(ii,jj+1)-Pr(ii,jj-1))/(2*dth*rad(ii,jj));
end
17
else
if ((ii==1)|(ii==nn))
if ii==1
u(ii,jj)=(Pr(ii+1,jj)-Pr(ii,jj))/(dr);
else
u(ii,jj)=(Pr(ii,jj)-Pr(ii-1,jj))/(dr);
end
else
u(ii,jj)=(Pr(ii+1,jj)-Pr(ii-1,jj))/(2*dr);
end
if ((jj==1)|(jj==mm))
if jj==1
v(ii,jj)=(Pr(ii,jj)-Pr(ii,mm))/(dth*rad(ii,jj));
else
v(ii,jj)=(Pr(ii,1)-Pr(ii,jj))/(dth*rad(ii,jj));
end
else
v(ii,jj)=(Pr(ii,jj+1)-Pr(ii,jj-1))/(2*dth*rad(ii,jj));
end
end
end
end
% Calculate velocity
w = (u.^2+v.^2).^0.5;
% Write time at end
time=fix(clock);
hourstr=int2str(time(4));
minstr=int2str(time(5));
if time(5)<10
minstr=['0',minstr];
end
timex=['Time at end of run: ' hourstr ':' minstr];
disp(timex)
% Calculate maximum velocity and position
wmax=0.0;
rwmax=0;
thwmax=0;
for ii=1:nn
for jj=1:mm
if (w(ii,jj)>=wmax)
wmax=w(ii,jj);
rwmax=num2str(rad(ii,jj));
thwmax=num2str((theta(ii,jj)*180/pi));
end
end
end
ustr=num2str(wmax);
velstring=['Wmax = ' ustr ' at (' rwmax ', ' thwmax ')'];
disp(velstring)
Nits
%%
% PLOTTING
plot(1:Nits,norm2)
xlabel('Iterations')
18
ylabel('Euclidean Norm')
pause
plot(1:Nits,normi)
xlabel('Iterations')
ylabel('Infinity Norm')
pause
%
% Add filled circle to plot
%
% Add cylinder to streamline plot
plotcirc=linspace(0,2*pi,100);
xcirc=Radius*cos(plotcirc);
ycirc=Radius*sin(plotcirc);
plot(xcirc,ycirc,'b');
hold on
xlabel(itcount)
ylabel('y')
title('CFD - Potential Flow')
if Grid=='on'
for ii=1:nn
for jj=1:mm
plot(x(ii,jj),y(ii,jj),'-')
hold on
end
end
end
%
xplot=x;
yplot=y;
Prplot=Pr;
nplot=nn;
for ii=1:nn
Prplot(ii,mm+1)=Pr(ii,1);
xplot(ii,mm+1) = x(ii,1);
yplot(ii,mm+1) = y(ii,1);
end
for ii=1:(nn)
for jj=1:mm+1
Prplot2(ii,jj)=Prplot(ii,jj);
xplot2(ii,jj)=xplot(ii,jj);
yplot2(ii,jj)=yplot(ii,jj);
end
end
hold on
contour(xplot2,yplot2,Prplot2,Contours)
%contour(xplot,yplot,Prplot,Contours)
title('Streamlines')
grid off
%%fill(xcirc,ycirc,'w')
axis([-Radius*5.0 Radius*5.0 -Radius*5 Radius*5])
axis equal
pause
hold off
%
wplot=w;
19
for ii=1:nn
wplot(ii,mm+1)=w(ii,1);
end
pcolor(xplot,yplot,wplot)
shading interp
colorbar
axis([-Radius*5.0 Radius*5.0 -Radius*5 Radius*5])
axis equal
hold on
grid off
title('Velocity')
%fill(xcirc,ycirc,'w')
%
%
hold off
20
Appendix B:
Derivation of Finite Difference Equation in
Polar Coordinates
21
From the Taylor Series expansion and using central differencing it can be shown that:
 2  i 1   i   i 1  2  i 1   i   i 1
,


r 2
 2
r 2
 2
  i 1   i 1   i 1   i 1


,
r
2 r
r
2 r
[B1]
[B2]
and from (White, 725), th eLaplace equation in polar coordinates is given as:
 2 1  1  2


0
r 2 r r r 2  2
[B3]
Plugging [B1] and [B2] into [B3] results in:
 i 1, j  i , j   i 1, j
r 
2
 i 1, j  1  i , j 1  i , j  i , j 1 
1 
  i 1, j
0
  r2 
r
2r
 2



[B4]
And finally solving for  i, j :
 i, j



1


2
 21   r  
   r  

 



2

 r 
 r 
 









  i 1, j

  i , j 1   i , j 1 
i 1, j
i 1, j
i 1, j

 2r 
 r 




22
Appendix C:
Additional Figures
23
Cartesian Coordinates:
Grid Count = 400
Grid Count = 6400
Grid Count = 25600
24
Polar Coordinates:
Grid Count = 400
Grid Count = 6400
Grid Count = 25600
25
Figure 1
Figure 2
26
Figure 3
27
Download