starting
length
X
s
y
x
inflow
outflow
surface length
L
= 1
H
i
,0
i
,1
i
,
N
y
Figure 1:
External boundary layer control volume.
4
Mathematica
Code for streamfunction–vorticity CFD
Listed below is a Mathematica code which implements the solution procedure for the flat plate, external
boundary layer problem. The domain consists of a rectangular region show in Fig. (
1
). The mathematical
formulation of the boundary conditions for this flow configuration was discussed in the previous set of notes.
The objective here is to show how it is coded into
Mathematica
.
The code consists of the following basic modules (or elements):
•
A module to numerically solve for stream function values, as a function of the vorticity values and the
stream function boundary conditions. The system of equations that are solved have the form
ψ
i
+1
,j
+
ψ
i

1
,j

2
ψ
i,j
(Δ
x
)
2
+
ψ
i,j
+1
+
ψ
i,j

1

2
ψ
i,j
(Δ
y
)
2
=

ω
i,j
(1)
•
A module to explicitly calculate the values of either
ω
i,j
or
T
i,j
at the
k
time step from the flow
information at the
k

1 time step.
This procedure utilizes the explicit time integration, upwind–
differencing scheme.
•
Associated modules and functions to interpolate the numerical results, compute derivatives of results,
produce plots, and so on.
The code is presented as follows
•
The first lines set up global definitions and define assorted utility functions.
Remove["Global‘*"]
Off[General::"spell1",General::"spell"]
sp[x_]:=Simplify[PowerExpand[x]]
$TextStyle={FontFamily>"Times",FontSize>16};
zeroprint[n_]:=Module[{s},s="";Do[s=s<>"0",{i,1,n}];s];
index[l_]:=Which[l<10,"00",l<100,"0",1==1,""]<>ToString[l];
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
printtodigits[x_,nd_]:=Module[{t,lt,ndot,ndrop,t2,nzero,t3},
t=ToString[x];
lt=SyntaxLength[t];
ndot=StringPosition[t,"."][[1,1]];
ndrop=Max[0,ltndotnd];
t2=StringDrop[t,ndrop];
nzero=Max[0,nd+ndotlt];
t3=t2<>zeroprint[nzero];
t3]
•
The system consists of a rectangular region, with length 1 +
X
s
, where
X
s
is the starting region, and a
height of
H
. The number of
interior
control volumes in the
x
and
y
directions is
nx1
and
ny1
. The
sizes of the control volume,
delx
and
dely
, are
Δ
x
=
1 +
X
s
N
x
,
Δ
y
=
H
N
y
•
The module (or subroutine)
psisoln[omega]
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '10
 Staff
 Heat Transfer, Boundary value problem, NX, stream function, eqns

Click to edit the document details