Você está na página 1de 38

Finite Volume Code for Compressible Flows

Matt Stegmeir
May 16, 2005
AEM8251: Finite Volume Methods
1
2 NUMERICAL METHOD: MODIFIED STEGER-WARMING FLUX VECTOR SPLITTING 1
Abstract
This paper documents the nal project for AEM8251:
Finite Volume methods in Fluid Mechanics, a code to
simulate compressible ows. A nite volume code
was created to study 3 problems, ow through a
channel with slip boundaries, ow through a chan-
nel with a ramp constriction in its middle section,
and ow around a sphere, all with supersonic bound-
aries. The code is able to load a properly formatted 2-
dimensional structured curvilinear grid and calculate
compressible ows, provided with the correct bound-
ary conditions. The results of applying this code are
included in the main report. The appendices contain
reference information including results of previous as-
signments.
1 Introduction
2 Numerical Method: Mod-
ied Steger-Warming Flux
Vector Splitting
2.1 Spatial
In order to promote stability and enhance accuracy
by using information from physically meaningful lo-
cations, it is desirable to employ a scheme that can
sense the direction of the ow of information and
bias itself in the appropriate direction. One tech-
nique which accomplishes this is nite volume Steger-
Warming ux vector splitting for conservation laws.
To employ this method, the vector of ux of con-
served variables must be homogeneous. This allows
the ux to be written as a product of a Jacobian
matrix and the vector of conserved quantities. Fur-
thermore, this Jacobian (A

) can be rearranged into


an easily diagonalizable form based on the conserved
variables U, the primitive variables V, and the ux
(in terms of an arbitrary coordinate system) F

.
F

=
_
_
_
_
u

uu

+ ps

x
vu

+ ps

y
(E + p)u

_
_
_
_
(1)
s

x
and s

y
are the direction cosines in the x and y
directions and u

is the normal velocity us

x
+ us

y
.
U =
_
_
_
_

u
v
E
_
_
_
_
(2)
V =
_
_
_
_

u
v
p
_
_
_
_
(3)
A

=
F

U
=
U
V
V
U
F

V
V
U
(4)
Thus, F

= A

U. For convenience we dene S =


V
U
and S

=
U
V
in the development of the method.
In addition,
V
U
F

V
is easily diagonalized. We shall
denote the result of this diagonalization as C

C. C

is the matrix of eigenvectors and is the eigenvalue


matrix with eigenvalues (u

, u

+ a, u

, u

a). The
positive eigenvalues compose the positive ux and
the negative eigenvalues compose the negative ux.
Separating the positive and negative uxes allows
us to use physically meaningful locations when
computing total ux across boundaries. Upwinding
in this manner forms the base of the Steger-Warming
method. Flux across each face of a cell is computed
by summing the positive ux from the lower-indexed
direction and the negative ux from the higher
indexed direction:
F

i+
1
2
,j
= F

+i,j
+ F

i+1,j
= A

+i,j
U
i,j
+ A

i+1,j
U
i+1,j
(5)
A
+
is the portion of the Jacobian arising from
positive eigenvalues and A

is the portion arising


from negative eigenvalues. This method works, but
3 TIME ADVANCEMENT 2
has the distinct disadvantage of being extremely dis-
sipative. Because of the high numerical dissipation
inherent in applying this method, it is not used for
solving real problems. However, a small modication
to the method removes this problem. Instead of
using A

+i,j
and A

i,j+1
an averaged Jacobian is
computed.
A

i+
1
2
,j
= A

(
1
2
(U
i,j
+ U
i+1,j
) (6)
and used as follows:
F

i+
1
2
,j
= F

+i,j
+ F

i+1,j
= A

+i+
1
2
,j
U
i,j
+ A

i+
1
2
,j
U
i+1,j
(7)
This Modied Steger-Warming method is much
less dissipative and is a superior general-purpose
method. However, it does have a weakness in that
it is not a good method for use in regions of strong
shocks, large gradients, and similar sharp discontinu-
ities. In such situations it may be desirable to locally
revert to the pure Steger-Warming approach for
increased dissipation and hence stability. Another
situation where errors may occur is in regions where
eigenvalues approach zero, either in the form of
a sonic glitch at speeds near the sound speed or
carbuncle problems around ow stagnation. This
may be avoided by making a modication to the
value of u

used in calculating them.

1,
=
1
2
(u

_
u
2
+
2
) (8)
is commonly dened as some small fraction of
sound speed, for example 0.1a. The other corrected
eigenvalues are calculated similarly.
Summarizing the previous statements, we have ar-
rived at a scheme to compute the local time deriva-
tive at a point, using calculated uxes through the
surfaces surrounding that point. This scheme can be
written as follows:
U
t
=
1
V
i,j
_
F

i+
1
2
,j
S
i+
1
2
,j
F

i
1
2
,j
S
i
1
2
,j
+F

i,j++
1
2
S
i,j+
1
2
F

i,j
1
2
S
i,j
1
2
_
(9)
V
i,j
is the cell volume.
In order to implement this method, a reason-
able method of calculating the matrix products
was needed, balancing computational eciency and
ease of debugging. It was decided that the best
course was to follow was to compute and store the
two matrix products S

and CS as well as the


eigenvalue matrices. These three pieces of data,
along with the velocity, were used to compute the
ux. This approach allowed for simple enough
expressions to be easily proofed and debugged,
but still avoided excessively complicated matrix
multiplications or obscene numbers of data elements.
The code multiplies from right to left, so all matrix
multiplication operations performed are a 4x1 vector
right-multiplied by a 4x4 matrix to yield another
4x1 vector. Appendix B contains the calculated
values for S

and CS. They were computing


MATLAB symbolic routines combined with manual
substitution based on known relationships between
the variables used.
3 Time Advancement
For this assignment time advancement was accom-
plished through explicit Euler time integration. A
timestep t was calculated based on a specied
Courant number and the maximum value of a spa-
tial function:
t =
CFL
MAX
_
|u|
x
+
|v|
y
+ a
_
1
x
2
+
1
y
2
_ (10)
This time step was used to obtain a change U in the
value of the vector of conserved variables:
U
n
i,j
=
t
V
i,j
_
F

i+
1
2
,j
S
i+
1
2
,j
F

i
1
2
,j
S
i
1
2
,j
+F

i,j++
1
2
S
i,j+
1
2
F

i,j
1
2
S
i,j
1
2
_
n+1
(11)
This U is then used to compute a new U.
U
n+1
i,j
= U
n
i.j
+ U
n
i,j
(12)
5 RAMP CHANNEL FLOW 3
This method of time advancement has advantages
and disadvantages. Its primary advantages are that
it is easy to implement (reliable, easy to troubleshoot,
etc) and it provides a time accurate (although only
rst order accurate) solution. Its main disadvantage
is that its not an especially ecient way to advance
time, and it scales poorly. When decreasing grid sizes
is needed to resolve smaller ow features the allow-
able time step becomes smaller as well. As grid sizes
get small enough, this becomes a prohibitive expense.
The higher-performing alternative is implicit time ad-
vancement, which is not time accurate but is much
more ecient.
4 Plain Channel Flow
The rst ow that the scheme was tested on was
a simple straight channel ow with slip boundaries.
This was a simple validation of the ability of the
method to correctly maintain a steady ow in various
directions. The ow was initialized in positive and
negative x and y directions and time was advanced
to ensure that there were no steady state errors. Per-
turbations were introduced to see if the ow would
still correctly stabilize. All of these tests were suc-
cessful. If illustration of ow properties is required,
refer to the left third of the ramp ow images. The
code for this problem is part of the nal project code
included in Appendix D.
5 Ramp Channel Flow
For this section of the project, the task was to
simulate a Mach 2.5 ow entering a channel, with
a 15
o
ramp located through the middle third of
the channel. The top and bottom boundaries are
slip boundaries, and the outlet is supersonic. The
results given were obtained using the Modied
Steger-Warming method. A sonic glitch factor of
0.1a was employed in the mean ow direction to
avoid instabilities stemming from a subsonic ow
region which develops near the upper channel wall.
The resulting ow contains a number of distinctive
features, most prominent being a shock that is
Figure 1: Grid for Channel With Ramp
generated at the base of the ramp and reected o
of the opposite wall. In addition, an expansion fan
is visible at the top of the ramp.
As a simple validity check, the ow eld after
the rst shock may be determined by using basic
shock relationships and the result can be compared
to the simulation data. First, the shock angle
is calculated using the - equation. For a 15
o
deection a shock angle of approximately 37 is
expected. However, closer examination of the grid
reveals that the 15 specication is not quite correct,
the actual angle of the ramp is closer to 18
o
. This
yields a 40
o
shock angle. Dividing the channel height
by the tangent of this angle gives the location the
shock should hit the opposite wall, a good rst check
of simulation validity. Using the grid provided, this
collision should occur at x=0.12. Figure 2 shows the
shock (and where it collides with the opposite wall).
The angle of the shock and hence the location of the
interaction match the expected result.
A second point of comparison is the pressure ratio
5 RAMP CHANNEL FLOW 4
Figure 2: Mach Number Contours
across the shock. Using shock relations, an expected
pressure ratio of 2.9 is obtained for an 18
o
shock. Fig-
ure 3 shows the pressure contours generated by the
simulation. The simulations pressure values match
up reasonably well with the expected ones, although
the pressure rise is overpredicted to a value of ap-
proximately 3.0. As shown in gure 4, temperature
behind the lead shock increased by a factor of 1.45.
This is close to the predicted value of 1.4, with a slight
overprediction once again. Figure 5 shows stream-
lines plotted by MATLAB (using interpolated values
on an interpolated grid for technical reasons). They
behave as expected, although their direction changes
are smoothed out by the calculation process. Figure
6 shows the raw velocity vectors for a more accurate
representation. The code for this problem is part of
the nal project code included in Appendix D.
Figure 3: Pressure Contours
Figure 4: Temperature Contours
5 RAMP CHANNEL FLOW 5
Figure 5: Streamlines
Figure 6: Velocity Vectors
7 CONCLUSION 6
6 Mach 5 Flow Around a Half-
Cylinder
This was the most computationally demanding sec-
tion of the project. In this ow a high Mach num-
ber ow is brought to a halt at the leading edge of
a blunt body, namely a half-cylinder. The Modi-
ed Steger-Warming method used for the previous
examples could not handle the sharp gradients that
this type of ow generates, and would crash within
a few time steps of ow initialization. It was unable
to develop a reasonable solution. Switching to the
more dissipative pure Steger-Warming method with
a small time step helped and kept the solution stable
enough to establish ow parallel to the surface of the
half-cylinder. Even in this case, the carbuncle prob-
lem was eventually encountered. Due to these issues
it was not possible to obtain steady-state results for
the cylinder problem. The following results show the
state of the solution shortly before the code crashed.
I make no representation of their accuracy, they are
included only to provide information on the state of
this portion of the code. The code for this problem
is part of the nal project code included in Appendix
D.
Figure 7: Grid for Channel With Ramp
Figure 8: Velocities at Cylinder Surface
Figure 9: Velocities at Entrance and Exit
7 Conclusion
A code to implement the Steger-Warming and Mod-
ied Steger-Warming ux vector splitting methods
with and without sonic glitch correction in two di-
mentions on curvilinear grids has been successfully
written and used on channel and ramped channel
moderate Mach number ows. In addition, the code
was applied with limited success to a semi-cylindrical
body in ow. The code is amenable to future im-
provements discussed below. For the channel ows
agreement with predicted results was acceptable.
8 FUTURE WORK 7
Figure 10: Mach Number Contours
Figure 11: Pressure Contours
8 Future Work
There is still a substantial amount of work that may
be done in the area of this project. Implicit time ad-
vancement will be implemented in order to more e-
ciently advance time, both approximately (Yoon and
Jameson LU-SGS) and exactly (Gauss-Seidel Line
Relaxation). Second-Order accurate ux calculations
will be introduced, as will an intelligent way of de-
tecting and switching to a safe method near strong
gradients. Viscous terms may also be considered.
Figure 12: Temperature Contours
Figure 13: Streamlines
8 FUTURE WORK 8
Figure 14: Velocity Vectors
A PREVIOUS WORK 9
A Previous Work
A.1 Assignment 2: 1-D Steger-Warming
Previous work completed in order to accomplish this task included a 1-D problem solved using a pure Steger-
Warming method. The task was to simulate the behavior of a ow with a velocity discontinuity after 0.05s
had passed. The left side of the ow had an initial velocity of 1000 m/s, and the right side a velocity of 500
m/s. Density was 1.0 kg/m
3
on the left and 0.5kg/m
3
on the right. Temperature on the left was 300K and
on the right was 600K. Figures 15, 16, and 17 demonstrate the eect of changing grid size on the solution.
The dissipative nature of pure Steger-Warming is clear in these results. Note how the steepness of the
Figure 15: 71 Grid Points Used
shock varies heavily with grid size, and even the peak value changes depending on the grid used. While the
solution remains stable at higher grid spacings, accuracy suers.
A PREVIOUS WORK 10
Figure 16: 141 Grid Points Used
A PREVIOUS WORK 11
Figure 17: 281 Grid Points Used
A PREVIOUS WORK 12
The code for this problem is part of the nal project code included in Appendix C.
A.2 Assignment 3 - Single 2-D Flux
Homework Assignment 2 was computing a single 2-dimensional ux across a given face from known conditions
using 4 dierent methods. This was implemented and the results were as follows:
Simple Averaging : F
av
=
_
_
_
_
0.3082046580117479E + 03
0.1850932310996726E + 06
0.4563609822582072E + 05
0.1135750151493932E + 09
_
_
_
_
Pure Steger Warming : F
SW
=
_
_
_
_
0.3100862388776151E + 03
0.2010361951702728E + 06
0.4644602567565192E + 05
0.1183359269341165E + 09
_
_
_
_
Modified Steger Warming : F
MSW
=
_
_
_
_
0.3307416709140678E + 03
0.2002338151898726E + 06
0.4328714021715256E + 05
0.1236992782944958E + 09
_
_
_
_
Modified Steger Warming with = 0.1a : F
MSW
=
_
_
_
_
0.3307416709140678E + 03
0.2002338151898726E + 06
0.4328714021715256E + 05
0.1236992782944958E + 09
_
_
_
_
It is
apparent that the results are correct. The code used to generate these results has been merged with the
code for the nal project and can be found in appendix D.
B MATRIX CALCULATIONS 13
B
M
a
t
r
i
x
C
a
l
c
u
l
a
t
i
o
n
s
C
S
_ _
1

1 2
(

1
)
(
u
2
+
v
2
)
a
2
(

1
)
u
a
2
(

1
)
v
a
2

1
)
a
2

1 2
s
x
u
a

1 2
s
y
v
a

+
1 4
(

1
)
(
u
2
+
v
2
)

a
2
1 2
s
x
a

1 2
(

1
)
u

a
2
1 2
s
y
a

1 2
(

1
)
v

a
2
1 2
(

1
)

a
2
s
y
u

s
x
v

s
y

s
x

0
1 2
s
x
u
a

+
1 2
s
y
v
a

+
1 4
(

1
)
(
u
2
+
v
2
)

a
2

1 2
s
x
a

1 2
(

1
)
u

a
2

1 2
s
y
a

1 2
(

1
)
v

a
2
1 2
(

1
)

a
2
_ _
S

_ _
1

u
+

a
s
x

s
y

a
s
x
v

v
+

a
s
y

s
x

a
s
y
1 2
u
2
+
1 2
v
2
_
1 2
u
2
+
1 2
v
2
_

u
a
s
x
+

v
a
s
y
+

a
2
(

1
)

u
s
y
+

v
s
x
_
1 2
u
2
+
1 2
v
2
_

u
a
s
x

v
a
s
y
+

a
2
(

1
)
_ _
C CODE FOR ASSIGNMENT 2 14
C Code for Assignment 2
PROGRAM ASS2
i mpl i ci t none
! Si mul at i on s e t t i n g s
INTEGER, PARAMETER : : g r i d s i z e =71
REAL8 , PARAMETER : : tmax=0. 005;
REAL8 , parameter : : CFL=0. 3;
REAL8 , PARAMETER : : l engt h =.1141
! phy s i c al cons t ant q u a nt i t i e s
REAL8 , PARAMETER : : gamma=1.4
REAL8 , PARAMETER : : R=287;
! computed v a r i a b l e s
REAL8 ,PARAMETER : : dx=l engt h / g r i d s i z e
INTEGER i
REAL8 t , dt
REAL8 , DIMENSION( 3 , g r i d s i z e ) : : U, Fplus , Fminus !U=rho , rhou , E, u
REAL8 , dimension( g r i d s i z e ) : : uu , TT, x
write ( , ) dx , dx
t=0
cal l s et I Cs (U, gamma, R, g r i d s i z e )
uu=U( 2 , : ) /U( 1 , : ) ! c a l c ul a t e u from rhou and rho
cal l get dt ( uu , g r i ds i z e , CFL, dx , dt )
! t=tmaxdt
write ( , ) t , tmax , dt
DOWHILE ( t < tmax)
write ( , ) t
cal l get dt ( uu , g r i ds i z e , CFL, dx , dt )
! wr i t e ( , ) t , dt
t=t+dt
cal l getF(U, uu , Fplus , Fminus , TT, gamma, R, g r i d s i z e )
DO i =2, g r i ds i z e 1
U( : , i )=U( : , i )dt /dx( Fpl us ( : , i )+Fminus ( : , i +1)Fpl us ( : , i 1)Fminus ( : , i ) )
ENDDO
uu=U( 2 , : ) /U( 1 , : )
ENDDO
! do i =1, g r i d s i z e
! wr i t e ( , ) i
! wr i t e ( , ) Fpl us ( : , i )
C CODE FOR ASSIGNMENT 2 15
! wr i t e ( , ) Fminus ( : , i )
! wr i t e ( , )
! end do
x=0
do i =2, g r i d s i z e
x( i )=x( i 1)+dx
ENDDO
open( unit =911, f i l e=U. out )
write ( 911 , ) U
cl ose ( 911)
open( unit =911, f i l e=x . out )
write ( 911 , 1 F10 . 1 ) x
cl ose ( 911)
ENDPROGRAM
SUBROUTINE s et I Cs (U, gamma, R, g r i d s i z e )
! checked
i mpl i ci t none
! l i s t ICs i n humanr eadabl e form
REAL8 , PARAMETER : : r ho l e f t =1.0
REAL8 , PARAMETER : : r hor i ght =0.5
REAL8 , PARAMETER : : Tl e f t =300.0
REAL8 , PARAMETER : : Tri ght =600
REAL8 , PARAMETER : : u l e f t =1000
REAL8 , PARAMETER : : ur i ght =500
INTEGER g r i d s i z e
REAL8 , DIMENSION( 3 , g r i d s i z e ) : : U
REAL8 gamma, R,CV
integer ha l f
ha l f =( g r i ds i z e 1)/2
CV=(1. 0/(gamma1. 0))R
U( 1 , 1 : ha l f )=r ho l e f t
U( 1 , ha l f +1: g r i d s i z e )=r hor i ght
U( 2 , 1 : ha l f )=r ho l e f t u l e f t
U( 2 , ha l f +1: g r i d s i z e )=r hor i ght ur i ght
U( 3 , 1 : ha l f )=r ho l e f t (CV Tl e f t +1. 0/2. 0 u l e f t 2. 0 d0 )
U( 3 , ha l f +1: g r i d s i z e )=r hor i ght (CV Tri ght +1. 0/2. 0 ur i ght 2. 0 d0 )
C CODE FOR ASSIGNMENT 2 16
ENDSUBROUTINE
SUBROUTINE getF(U, uu , Fplus , Fminus , TT, gamma, R, g r i d s i z e )
i mpl i ci t none
INTEGER g r i ds i z e , i
REAL8 , DIMENSION( g r i d s i z e ) : : uu , TT, p , a , c oe f f , term1 , term2 , term3
REAL8 , DIMENSION( 3 , g r i d s i z e ) : : U, Fplus , Fminus , LP,LM
REAL8 gamma, R, CV, gm1
gm1=gamma1
CV=R/(gamma1.0d0 )
TT=(U( 3 , : ) 0. 5 d0U( 1 , : ) uu2. 0 d0 ) /(U( 1 , : ) CV)
a=s qr t (gammaRTT)
p=(gamma1)(U( 3 , : ) 0. 5 d0/U( 1 , : ) U( 2 , : ) 2 . 0 d0 )
LP( 1 , : ) =0. 5 d0 ( uu+abs ( uu ) )
LP( 2 , : ) =0. 5 d0 ( uu+a+abs ( uu+a ) )
LP( 3 , : ) =0. 5 d0 ( uua+abs ( uua ) )
LM( 1 , : ) =0. 5 d0 ( uuabs ( uu ) )
LM( 2 , : ) =0. 5 d0 ( uu+aabs ( uu+a ) )
LM( 3 , : ) =0. 5 d0 ( uuaabs ( uua ) )
! do i =1, g r i d s i z e
! wr i t e ( , ) LP(1 , i ) ,LM(1 , i )
! wr i t e ( , ) LP(2 , i ) ,LM(2 , i )
! wr i t e ( , ) LP(3 , i ) ,LM(3 , i )
! wr i t e ( , ) .
! enddo
!
Fpl us ( 1 , : ) =0. 5 d0/a 2. 0 d0 (LP( 1 , : ) 2 . 0 d0 (U( 1 , : ) a 2. 0 d0p)+p(LP( 2 , : ) +LP( 3 , : ) ) )
Fpl us ( 2 , : ) =0. 5 d0/a 2. 0 d0 (LP( 1 , : ) 2 . 0 d0uu(U( 1 , : ) a 2. 0 d0p)+LP( 2 , : ) ( puu+pa)+LP( 3 , : ) ( puupa ) )
Fminus ( 1 , : ) =0. 5 d0/a 2. 0 d0 (LM( 1 , : ) 2 . 0 d0 (U( 1 , : ) a 2. 0 d0p)+p(LM( 2 , : ) +LM( 3 , : ) ) )
Fminus ( 2 , : ) =0. 5 d0/a 2. 0 d0 (LM( 1 , : ) 2 . 0 d0uu(U( 1 , : ) a 2. 0 d0p)+LM( 2 , : ) ( puu+pa)+LM( 3 , : ) ( puupa ) )
Fpl us ( 3 , : ) =(U( 3 , : ) +p)uu
! Fpl us (3 , : )=0. 25 d0/a 2. 0 d0 (LP( 1 , : ) 2. 0 d0uu2. 0 d0 (U( 1 , : ) a 2. 0 d0p) &
! +(LP(2 , : )+LP( 3 , : ) ) puu( uu+2a 2. 0 d0/uu) &
! +(LP(2 , : ) LP( 3 , : ) ) 2. 0 d0apuu)
c o e f f =0.25d0/a 2. 0 d0
term1=2.0d0uu2. 0 d0 (U( 1 , : ) a 2. 0 d0p)
term2=p( uu2. 0 d0+2.0d0auu+2.0d0a 2. 0 d0/gm1)
term3=p( uu2. 0 d02.0d0auu+2.0d0a 2. 0 d0/gm1)
Fpl us ( 3 , : ) = c o e f f (LP( 1 , : ) term1+LP( 2 , : ) term2+LP( 3 , : ) term3 )
Fminus ( 3 , : ) = c o e f f (LM( 1 , : ) term1+LM( 2 , : ) term2+LM( 3 , : ) term3 )
C CODE FOR ASSIGNMENT 2 17
! do i =1, g r i d s i z e
! wr i t e ( , ) term1 ( i ) , term2 ( i ) , term3 ( i )
! wr i t e ( , ) . . .
! enddo
! do i =1, g r i d s i z e
! wr i t e ( , 5 e ) uu( i ) , a( i ) , p( i ) ,U(1 , i ) , Fpl us (3 , i )
! enddo
! CV=(1. 0/(gamma1. 0))R
! TT=(U(3 , : ) 1. 0/2. 0U( 2 , : ) uu 2. 0) /(U( 1 , : ) CV)
!
! Fpl us ( 1 , : ) =1. 0/2. 0U( 1 , : ) ( uu+abs ( uu ) )
! Fpl us ( 2 , : ) =1. 0/2. 0U( 2 , : ) ( uu+abs ( uu ) )
! ! Fpl us ( 3 , : ) =1. 0 d0 /4. 0 d0U( 1 , : ) ( 2. 0 d0CVTTuu &
! ! +2.0d0 abs ( uu)CVTT &
! ! +uu3. 0 d0 &
! ! +abs ( uu)uu2. 0 d0 )
! !
! Fpl us ( 3 , : ) =1. 0 d0 /4. 0 d0U( 1 , : ) ( 2. 0 d0CVTTuu &
! +2.0d0 abs ( uu)CVTT &
! +uu3. 0 d0 &
! +abs ( uu)uu2. 0 d0 )
!
!
! Fminus ( 1 , : ) =1. 0/2. 0U( 1 , : ) ( uuabs ( uu ) )
! Fminus ( 2 , : ) =1. 0/2. 0U( 2 , : ) ( uuabs ( uu ) )
! Fminus ( 3 , : ) =1. 0 d0 /4. 0 d0U( 1 , : ) ( 2. 0 d0CVTTuu &
! 2.0d0 abs ( uu)CVTT &
! +uu3. 0 d0 &
! abs ( uu)uu2. 0 d0 )
ENDSUBROUTINE
SUBROUTINE get dt (U, g r i ds i z e , CFL, dx , dt )
i mpl i ci t none
REAL8 dx , dt , CFL
integer g r i d s i z e
REAL8 , DIMENSION( g r i d s i z e ) : : U
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 18
dt=CFLdx/maxval ( abs (U) )
ENDSUBROUTINE
D Code For Assignment 3 and Final Project
MODULE SETTINGS
integer , PARAMETER : : numdt=1
integer , PARAMETER : : t o l =1e18
integer , parameter : : i nt e r v a l =1
! i nt e g e r f l a g t o s e t which probl em t o s ol v e .
! probl ems numbered as i n pr oj e c t st at ement
! Option 4 gener at es a pl ai n r e c t ang ul ar g r i d
! from 0: 1 i n bot h di mensi ons wi t h number of
! d i v i s i o ns det ermi ned by channel x and channel y
! probl em 0 i s homework s e t 3
INTEGER, PARAMETER : : problem=0
! method : 0=SW,1=MSW
INTEGER, PARAMETER : : method=1
! s oni c g l i t c h c or r e c t i on as f r a c t i o n of sound speed
REAL8 , PARAMETER : : g l i t c hc o r r = 0. 0
! ti me advancement scheme , 1=e x p l i c i t
INTEGER, PARAMETER : : ti meadv=1
REAL8 , PARAMETER : : CFL=0.005
! 0. 005 f or c y l
INTEGER, PARAMETER : : channel x=20
INTEGER, PARAMETER : : channel y=20
REAL8 , PARAMETER : : Minf1=2
REAL8 , PARAMETER : : Minf2=2.5
REAL8 , PARAMETER : : Minf3=5
REAL8 , PARAMETER : : pi nf 1 =100000
REAL8 , PARAMETER : : Ti nf 1=300
REAL8 , PARAMETER : : pi nf 2 =100000
REAL8 , PARAMETER : : Ti nf 2=300
REAL8 , PARAMETER : : Ti nf 3=300
REAL8 , PARAMETER : : pi nf 3 =100000
REAL8 , PARAMETER : : Minf01=1.1
REAL8 , PARAMETER : : Minf02=0.9
REAL8 , PARAMETER : : r hoi nf 01 =1.0d0
REAL8 , PARAMETER : : r hoi nf 02 =1.02d0
REAL8 , PARAMETER : : Ti nf 01 =300.0d0
REAL8 , PARAMETER : : Ti nf 02 =310.0d0
REAL8 , PARAMETER : : vi nf 01 =0.0d0
REAL8 , PARAMETER : : vi nf 02 =10.0d0
ENDMODULE SETTINGS
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 19
MODULE CONSTANTS
REAL8 , PARAMETER : : gamma=1.4
REAL8 , PARAMETER : : R=287
REAL8 , PARAMETER : : CV=R/(gamma1)
REAL8 , PARAMETER : : pi =3.14159
ENDMODULE CONSTANTS
MODULE PARAMS
! St orage f or any const ant s , f or exampl e f i l e names t hat are
! s e l e c t e d from by s e t t i ng t he probl em f l a g .
character ( len=20) , PARAMETER : : channel gr i d=channel gr i d . dat
character ( len=20) , PARAMETER : : c yl i nde r g r i d= cyl i nder gr i d . dat
character ( len=20) , PARAMETER : : rampgri d=rampgr i d . dat
character ( len=20) , PARAMETER : : channel out=channel gr i d . out
character ( len=20) , PARAMETER : : c yl i nde r out= cyl i nder gr i d . out
character ( len=20) , PARAMETER : : rampout=rampgr i d . out
character ( len=20) , PARAMETER : : r ampl i s t=ramp . out
character ( len=20) , PARAMETER : : c ha nne l l i s t= channel . out
character ( len=20) , PARAMETER : : c y l i n d e r l i s t= c yl i nde r . out
character ( len=20) , PARAMETER : : voutbase=V. out
character ( len=20) , PARAMETER : : Uoutbase=U. out
INTEGER i l , j l
ENDMODULE PARAMS
MODULE MAINVARS
USE PARAMS
USE SETTINGS
USE CONSTANTS
INTEGER i , j , count
character ( len=20) f or t r angr i d , gri dout , f i l e l i s t , probname , Vout f i l e , Uout f i l e
REAL8 , DIMENSION( : , : ) ,ALLOCATABLE : : x , y , Si , Sj , Sxi , Syi , Sxj , Syj , V, dx , dy , sxiM , sxjM , syiM , syjM
REAL8 , DIMENSION( : , : , : ) ,ALLOCATABLE,TARGET : : U, Ucal ci , Ucal cj
REAL8 , DIMENSION( : , : , : ) , ALLOCATABLE : : LPi , LMi , LPj , LMj
REAL8 , DIMENSION( : , : , : , : ) , ALLOCATABLE : : CSi , SCi , CSj , SCj
REAL8 , DIMENSION( : , : , : ) , ALLOCATABLE : : Fi , Fj
REAL8 , DIMENSION( : , : ) ,ALLOCATABLE : : p
REAL8 DT, maxdi f f
REAL8 r hoi nf
real 8 a i nf
real 8 r houi nf
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 20
real 8 r hovi nf
real 8 Ei nf
real 8 Minf
real 8 pi nf
real 8 Ti nf
ENDMODULE MAINVARS
MODULE TEMPVARS
USE SETTINGS
USE CONSTANTS
USE PARAMS
REAL8 , DIMENSION( 4) : : CSUP,CSUM, LCSUP,LCSUM, FP,FM
REAL8 , DIMENSION( : , : ) ,ALLOCATABLE : : uu , vv , uv2 , a , T, gma, sxr , syr , rhosum , uprime , g l i t c h
ENDMODULE TEMPVARS
PROGRAMMAIN
USE MAINVARS
i mpl i ci t none
character ( len=20) , PARAMETER : : t e s t f i l e 1= t e s t 1 . t xt
character ( len=20) , PARAMETER : : t e s t f i l e 2= t e s t 2 . t xt
character ( len=20) , PARAMETER : : t e s t f i l e 3= t e s t 3 . t xt
character ( len=20) , PARAMETER : : t e s t f i l e 4= t e s t 4 . t xt
integer r epor t
cal l setup
cal l l oadgr i d
! wr i t e ( , ) Si ( 1: i l , 1 : j l )
cal l wri tegri dML
cal l outputvol umes
CALL SETICS
CALL WRITE4VEC(U, t e s t f i l e 1 , 0 )
maxdi f f=1
r epor t=1
! STOP
! wr i t e ( , ) sxjm
! CALL WRITE4VEC( Fi , t e s t f i l e 1 , 0)
DO count =1,numdt
! i f ( maxdi f f > t o l ) t hen
CALL SETBCS
CALL GETUCALC( Ucal ci , Ucal cj , U)
CALL GETMATRICES( CSi , SCi , LPi , LMi , Ucal ci , s xi , s yi )
CALL GETMATRICES( CSj , SCj , LPj , LMj , Ucal cj , sxjm , s yj )
CALL GETFLUX( Fi , Fj , CSi , SCi , CSj , SCj , U, LPi , LMi , LPj , LMj )
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 21
CALL CALCDT(DT, U, dx , dy)
CALL ADVANCETIME(U, DT, Fi , Fj , Si , Sj , V, maxdi f f )
i f ( r epor t == i nt e r v a l ) then
write ( , ) count
write ( , ) maxdi f f
r epor t=0
end i f
r epor t=r epor t+1
! end i f
enddo
! wr i t e ( , ) V
! do j =1,3
! do i =1, i l +1
! wr i t e ( , 2 i , 4 e ) i , j , Fj ( : , i , j )
! enddo
! enddo
! wr i t e ( , ) . . .
! do j =1,3
! do i =1, i l +1
! wr i t e ( , 2 i , 4 e ) i , j , Fi ( : , i , j )
! enddo
! enddo
do i =1, i l +1
do j =1,3
! wr i t e ( , 2 i , 4 e ) i , j , Fj ( : , i , j )
enddo
enddo
CALL WRITE4VEC(U, Uout f i l e , 0 )
cal l WRITE4VEC( Fj , t e s t f i l e 1 , 0 )
do i =1, i l +1
do j =1, j l +1!
! wr i t e ( , 4 e ) db l e ( i ) , db l e ( j ) , s y i ( i , j ) , s y j ( i , j )
! wr i t e ( , 6 e ) db l e ( i ) , db l e ( j ) , Fi ( : , i , j )
enddo
enddo
do j =1, j l +1
! wr i t e ( , ) j
! wr i t e ( , 4 e ) U(3 , i l 1: i l , j )
! wr i t e ( , ) . . .
! wr i t e ( , 4 e ) U( : , i l 1: i l +1, j )
! wr i t e ( , ) , , ,
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 22
! wr i t e ( , 4 e ) Fi ( : , i l 1: i l +1, j )
! wr i t e ( , 4 e ) sxjm
enddo
! CALL WRITE4VEC(U, t e s t f i l e 2 , 0)
! CALL WRITE4VEC(LMj , t e s t f i l e 2 , 1)
! CALL WRITE4VEC( FPj , t e s t f i l e 3 , 1)
! CALL WRITE4VEC(FMj , t e s t f i l e 4 , 1)
ENDPROGRAMMAIN
SUBROUTINE SETUP
USE MAINVARS
i mpl i ci t none
SELECT CASE( problem)
CASE( 0)
f o r t r a ng r i d=channel gr i d
gr i dout=channel out
f i l e l i s t =c ha nne l l i s t
probname= channel
CASE( 1)
f o r t r a ng r i d=channel gr i d
gr i dout=channel out
f i l e l i s t =c ha nne l l i s t
probname= channel
CASE( 2)
f o r t r a ng r i d=rampgri d
gr i dout=rampout
f i l e l i s t =r ampl i s t
probname=ramp
CASE( 3)
f o r t r a ng r i d=c yl i nde r g r i d
gr i dout=c yl i nde r out
f i l e l i s t =c y l i n d e r l i s t
probname= c yl i nde r
CASE( 4)
f o r t r a ng r i d=channel gr i d
gr i dout=channel out
probname= channel
cal l GENCHANNEL
write ( , ) Channel gr i d generated
write ( , ) channel gr i d , channel out
write ( , ) Executi on wi l l now hal t .
STOP
CASE DEFAULT
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 23
write ( , ) You have s e l e c t e d an unrecogni zed case .
write ( , ) Executi on wi l l now hal t .
STOP
END SELECT
Vout f i l e=tri m( probname ) // // tri m( Voutbase )
Uout f i l e=tri m( probname ) // // tri m( Uoutbase )
open( unit=4, f i l e=f i l e l i s t )
write ( 4 , ) f o r t r a ng r i d
write ( 4 , ) gr i dout
write ( 4 , ) Vout f i l e
WRITE( 4 , ) Uout f i l e
cl ose ( 4)
ENDSUBROUTINE SETUP
SUBROUTINE LOADGRID
USE MAINVARS
USE TEMPVARS
i mpl i ci t none
open( unit=1, f i l e=f o r t r a ng r i d )
! read i n t he array s i z e
read( 1 , ) i l , j l
! now a l l o c a t e
ALLOCATE( x( i l +1, j l +1) , y( i l +1, j l +1) , Si ( i l +1, j l +1) , Sj ( i l +1, j l +1) , Sxi ( i l +1, j l +1) , Syi ( i l +1, j l +1) , Sxj ( i l +1, j l +1) , Syj ( i l +1, j l +1) ,V( i l +1, j l +1) , dx( i l +1, j l +1) , dy( i l +1, j l +1),&
sxiM( i l +1, j l +1) , sxjM( i l +1, j l +1) , syiM( i l +1, j l +1) , syjM( i l +1, j l +1))
! a l l o c a t e some temporary v a r i a b l e s as we l l
ALLOCATE( uu( i l +1, j l +1) , vv( i l +1, j l +1) , uv2 ( i l +1, j l +1) , a ( i l +1, j l +1) ,T( i l +1, j l +1) ,gma( i l +1, j l +1) , s xr ( i l +1, j l +1) , s yr ( i l +1, j l +1) , rhosum( i l +1, j l +1) , uprime ( i l +1, j l +1) , g l i t c h ( i l +1, j l +1))
! a l l o c a t e U
ALLOCATE(U( 4 , i l +1, j l +1) , Ucal ci ( 4 , i l +1, j l +1) , Ucal cj ( 4 , i l +1, j l +1))
! a l l o c a t e mat ri ces
ALLOCATE( CSi ( 4 , 4 , i l +1, j l +1) , SCi ( 4 , 4 , i l +1, j l +1) , CSj ( 4 , 4 , i l +1, j l +1) , SCj ( 4 , 4 , i l +1, j l +1) , LPi ( 4 , i l +1, j l +1) , LPj ( 4 , i l +1, j l +1) ,LMi ( 4 , i l +1, j l +1) ,LMj ( 4 , i l +1, j l +1))
! a l l o c a t e TEMP f l u x v e c t or s
ALLOCATE( Fi ( 4 , i l +1, j l +1) , Fj ( 4 , i l +1, j l +1))
! a l l o c a t e vect or used f or pr es s ur e BC
ALLOCATE( p( i l +1, j l +1))
read( 1 , ) ( ( x( i , j ) , i =1, i l +1) , j =1, j l +1)
read( 1 , ) ( ( y( i , j ) , i =1, i l +1) , j =1, j l +1)
cl ose ( 1)
DO i =1, i l +1
DO j =1, j l
Sxi ( i , j )=y( i , j +1)y( i , j )
Syi ( i , j )=x( i , j +1)x( i , j )
! i=i 1/2
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 24
Si ( i , j )=s qr t ( Sxi ( i , j ) 2. 0 d0+Syi ( i , j ) 2. 0 d0 )
ENDDO
s xi ( i , j l +1)=s xi ( i , j l )
s yi ( i , j l +1)=s yi ( i , j l )
s i ( i , j l +1)=s i ( i , j l )
ENDDO
DO j =1, j l +1
DO i =1, i l
Sxj ( i , j )=y( i +1, j )y( i , j )
Syj ( i , j )=x( i +1, j )x( i , j )
Sj ( i , j )=s qr t ( Sxj ( i , j ) 2. 0 d0+Syj ( i , j ) 2. 0 d0 )
enddo
s xj ( i l +1, j )=s xj ( i l , j )
s yj ( i l +1, j )=s yj ( i l , j )
s j ( i l +1, j )=s j ( i l , j )
enddo
DO i =1, i l
DO j =1, j l
V( i , j )=0. 5d0 ( abs ( ( x( i , j )x( i +1, j ) ) y( i +1, j +1)&
+(x( i +1, j )x( i +1, j +1))y( i , j )&
+(x( i +1, j +1)x( i , j ) ) y( i +1, j ))&
+abs ( ( x( i , j )x( i +1, j +1))y( i , j +1)&
+(x( i +1, j +1)x( i , j +1))y( i , j )&
+(x( i , j +1)x( i , j ) ) y( i +1, j +1)))
dx( i , j )=x( i +1, j )x( i , j )
dy( i , j )=y( i , j +1)y( i , j )
enddo
enddo
! normal i ze cos i nes
Sxi=Sxi / Si
Sxj=Sxj / Sj
Syi=Syi / Si
Syj=Syj / Sj
do j =1, j l +1
do i =2, i l +1
sxiM( i , j )=s xi ( i 1, j )
syiM( i , j )=s yi ( i 1, j )
enddo
sxiM( 1 , j )=sxim( 2 , j )
syim( 1 , j )=syim( 2 , j )
enddo
do i =1, i l +1
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 25
do j =2, j l +1
sxjM( i , j )=s xj ( i , j 1)
syjM( i , j )=s yj ( i , j 1)
enddo
sxjm( i , 1)=sxjm( i , 2 )
syjm( i , 1)=syjm( i , 2 )
enddo
ENDSUBROUTINE LOADGRID
SUBROUTINE WRITEGRIDML
USE MAINVARS
i mpl i ci t none
! code t o out put g r i d t o b e t t e r f ormat
open( unit=2, f i l e=gr i dout )
write ( 2 , 1 I ) i l
write ( 2 , 1 I ) j l
write ( 2 , 1E ) ( ( x( i , j ) , i =1, i l +1) , j =1, j l +1)
write ( 2 , 1E ) ( ( y( i , j ) , i =1, i l +1) , j =1, j l +1)
cl ose ( 2)
ENDSUBROUTINE WRITEGRIDML
SUBROUTINE WRITEGRID
USE MAINVARS
IMPLICIT NONE
open( unit=2, f i l e=f o r t r a ng r i d )
write ( 2 , 1 I ) i l
write ( 2 , 1 I ) j l
write ( 2 , ) ( ( x( i , j ) , i =1, i l +1) , j =1, j l +1)
write ( 2 , ) ( ( y( i , j ) , i =1, i l +1) , j =1, j l +1)
cl ose ( 2)
open( unit=3, f i l e=gr i dout )
write ( 3 , 1 I ) i l
write ( 3 , 1 I ) j l
write ( 3 , 1E ) ( ( x( i , j ) , i =1, i l +1) , j =1, j l +1)
write ( 3 , 1E ) ( ( y( i , j ) , i =1, i l +1) , j =1, j l +1)
cl ose ( 3)
ENDSUBROUTINE WRITEGRID
SUBROUTINE GENCHANNEL
USE MAINVARS
IMPLICIT NONE
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 26
REAL8 ddx , ddy
i l =channel x
j l =channel y
ddx=1.0d0/ dbl e ( i l )
ddy=1.0d0/ dbl e ( j l )
ALLOCATE( x( i l +1, j l +1) , y( i l +1, j l +1))
DO i =1, i l +1
DO j =1, j l +1
x( i , j )=ddx dbl e ( i 1)
y( i , j )=ddx dbl e ( j 1)
ENDDO
ENDDO
cal l WRITEGRID
ENDSUBROUTINE GENCHANNEL
SUBROUTINE OUTPUTVOLUMES
USE MAINVARS
IMPLICIT NONE
open( unit=2, f i l e=Vout f i l e )
write ( 2 , 1 I ) i l
write ( 2 , 1 I ) j l
write ( 2 , 1E ) ( (V( i , j ) , i =1, i l ) , j =1, j l )
cl ose ( 2)
ENDSUBROUTINE OUTPUTVOLUMES
SUBROUTINE GETFLUX( Fi , Fj , CSi , SCi , CSj , SCj , U, LPi , LMi , LPj , LMj )
USE CONSTANTS
USE PARAMS
USE TEMPVARS
IMPLICIT NONE
REAL8 , DIMENSION( 4 , i l +1, j l +1) : : Fi , Fj , U, LPi , LMi , LPj , LMj
REAL8 , DIMENSION( 4 , 4 , i l +1, j l +1) : : CSi , SCi , SCj , CSj
INTEGER i , j
i f ( method == 1) then
do i =2, i l 1
do j =1, j l
CALL mult (CSUP, CSi ( : , : , i , j ) ,U( : , i , j ) )
CALL mult (CSUM, CSi ( : , : , i , j ) ,U( : , i +1, j ) )
LCSUP=LPi ( : , i , j )CSUP
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 27
LCSUM=LMi ( : , i , j )CSUP
CALL mult (FP, SCi ( : , : , i , j ) ,LCSUP)
CALL mult (FM, SCi ( : , : , i , j ) ,LCSUM)
Fi ( : , i , j )=FP+FM
! wr i t e ( , 4 e ) FPi , FMi
enddo
enddo
do i =1, i l
do j =2, j l 1
CALL mult (CSUP, CSj ( : , : , i , j ) ,U( : , i , j ) )
CALL mult (CSUM, CSj ( : , : , i , j ) ,U( : , i , j +1))
LCSUP=LPj ( : , i , j )CSUP
LCSUM=LMj ( : , i , j )CSUM
CALL mult (FP, SCj ( : , : , i , j ) ,LCSUP)
CALL mult (FM, SCj ( : , : , i , j ) ,LCSUM)
Fj ( : , i , j )=FP+FM
! wr i t e ( , 4 e ) FPj , FMj
enddo
enddo
el s ei f ( method == 0) then
do i =2, i l 1
do j =1, j l
CALL mult (CSUP, CSi ( : , : , i , j ) ,U( : , i , j ) )
CALL mult (CSUM, CSi ( : , : , i +1, j ) ,U( : , i +1, j ) )
LCSUP=LPi ( : , i , j )CSUP
LCSUM=LMi ( : , i +1, j )CSUP
CALL mult (FP, SCi ( : , : , i , j ) ,LCSUP)
CALL mult (FM, SCi ( : , : , i +1, j ) ,LCSUM)
Fi ( : , i , j )=FP+FM
! wr i t e ( , 4 e ) FPi , FMi
enddo
enddo
do i =1, i l
do j =2, j l 1
CALL mult (CSUP, CSj ( : , : , i , j ) ,U( : , i , j ) )
CALL mult (CSUM, CSj ( : , : , i , j +1) ,U( : , i , j +1))
LCSUP=LPj ( : , i , j )CSUP
LCSUM=LMj ( : , i , j +1)CSUM
CALL mult (FP, SCj ( : , : , i , j ) ,LCSUP)
CALL mult (FM, SCj ( : , : , i , j +1) ,LCSUM)
Fj ( : , i , j )=FP+FM
! wr i t e ( , 4 e ) FPj , FMj
enddo
enddo
endif
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 28
i f ( problem==0) then
write ( , 4 e ) Fi ( : , i l /22: i l /2+2, j l /2)
write ( , ) . . .
write ( , 4 e ) 0. 5 d0 ( Fi ( : , i l /22, j l /2)+Fi ( : , i l /2+2, j l /2) )
endif
ENDSUBROUTINE GETFLUX
SUBROUTINE MULT(AX, A, X)
IMPLICIT NONE
REAL8 , DIMENSION( 4 , 4) : : A
REAL8 , DIMENSION( 4) : : X,AX
AX(: )=A( : , 1 ) X(1)+A( : , 2 ) X(2)+A( : , 3 ) X(3)+A( : , 4 ) X( 4)
ENDSUBROUTINE MULT
SUBROUTINE GETMATRICES(CS, SC, LP,LM, Ubar , sx , sy )
USE PARAMS
USE CONSTANTS
USE TEMPVARS
IMPLICIT NONE
integer i , j
REAL8 , DIMENSION( 4 , i l +1, j l +1) ,TARGET : : Ubar
REAL8 , DIMENSION( 4 , i l +1, j l +1) : : LM, LP
REAL8 , DIMENSION( 4 , 4 , i l +1, j l +1) : : CS, SC
REAL8 , DIMENSION( i l +1, j l +1) : : sx , sy
REAL8 , POINTER, DIMENSION( : , : ) : : rho , rhou , rhov , E
rho=>Ubar ( 1 , : , : )
rhou=>Ubar ( 2 , : , : )
rhov=>Ubar ( 3 , : , : )
E=>Ubar ( 4 , : , : )
uu=rhou/rho
vv=rhov/rho
uv2=uuuu+vvvv
T=(E0.5 rhouv2 ) /( rhocv )
a=s qr t (gammaRT)
GMA=(gamma1)/( aa )
s xr=sx/rho
s yr=sy/rho
rhosum=rhouasx+rhovasy
uprime=uusx+vvsy
! do i =1, i l
! do j =1, j l
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 29
! wr i t e ( , 5 f ) uu( i , j ) , vv ( i , j ) , sx ( i , j ) , sy ( i , j ) , uprime ( i , j )
! enddo
! enddo
CS( 1 , 1 , : , : ) =1 . 0 d00.5d0gmauv2
CS( 1 , 2 , : , : ) =gmauu
CS( 1 , 3 , : , : ) =gmavv
CS( 1 , 4 , : , : ) = gma
CS( 2 , 1 , : , : ) = 0. 5 d0 s xr uu/a0.5d0 s yr vv/a+0.25d0gmauv2/rho
CS( 2 , 2 , : , : ) =0 . 5 d0 s xr /a0.5d0gmauu/rho
CS( 2 , 3 , : , : ) =0 . 5 d0 s yr /a0.5d0gmavv/rho
CS( 2 , 4 , : , : ) =0 . 5 d0gma/rho
CS( 3 , 1 , : , : ) = s yr uus xr vv
CS( 3 , 2 , : , : ) = s yr
CS( 3 , 3 , : , : ) = s xr
CS( 3 , 4 , : , : ) =0
CS( 4 , 1 , : , : ) =0 . 5 d0 s xr uu/a+0.5d0 s yr vv/a+0.25d0gmauv2/rho
CS( 4 , 2 , : , : ) = 0. 5 d0 s xr /a0.5d0gmauu/rho
CS( 4 , 3 , : , : ) = 0. 5 d0 s yr /a0.5d0gmavv/rho
CS( 4 , 4 , : , : ) =0 . 5 d0gma/rho
SC( 1 , 1 , : , : ) =1
SC( 1 , 2 , : , : ) = rho
SC( 1 , 3 , : , : ) =0
SC( 1 , 4 , : , : ) = rho
SC( 2 , 1 , : , : ) =uu
SC( 2 , 2 , : , : ) = rhou+rhoasx
SC( 2 , 3 , : , : ) = rhosy
SC( 2 , 4 , : , : ) = rhourhoasx
SC( 3 , 1 , : , : ) =vv
SC( 3 , 2 , : , : ) = rhov+rhoasy
SC( 3 , 3 , : , : ) = rhosx
SC( 3 , 4 , : , : ) = rhovrhoasy
SC( 4 , 1 , : , : ) =0 . 5 d0uv2
SC( 4 , 2 , : , : ) =0 . 5 d0uv2rho+rhosum+rho/gma
SC( 4 , 3 , : , : ) = rhousy+rhovsx
SC( 4 , 4 , : , : ) =0 . 5 d0uv2rhorhosum+rho/gma
g l i t c h =( g l i t c hc o r r a ) 2. 0 d0
LP( 1 , : , : ) =0 . 5 d0 ( uprime+s qr t ( uprime 2. 0 d0+g l i t c h ) )
LP( 2 , : , : ) =0 . 5 d0 ( uprime+a+s qr t ( ( uprime+a ) 2. 0 d0+g l i t c h ) )
LP( 3 , : , : ) =LP( 1 , : , : )
LP( 4 , : , : ) =0 . 5 d0 ( uprimea+s qr t ( ( uprimea ) 2. 0 d0+g l i t c h ) )
LM( 1 , : , : ) =0 . 5 d0 ( uprimes qr t ( uprime 2. 0 d0+g l i t c h ) )
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 30
LM( 2 , : , : ) =0 . 5 d0 ( uprime+as qr t ( ( uprime+a ) 2. 0 d0+g l i t c h ) )
LM( 3 , : , : ) =LM( 1 , : , : )
LM( 4 , : , : ) =0 . 5 d0 ( uprimeas qr t ( ( uprimea ) 2. 0 d0+g l i t c h ) )
ENDSUBROUTINE GETMATRICES
SUBROUTINE CALCDT(DT, U, dx , dy)
USE SETTINGS
USE PARAMS
USE TEMPVARS
IMPLICIT NONE
REAL8 DT
REAL8 , DIMENSION( 4 , i l +1, j l +1) : : U
REAL8 , DIMENSION( i l +1, j l +1) : : dx , dy
uu=U( 2 , : , : ) /U( 1 , : , : )
vv=U( 3 , : , : ) /U( 1 , : , : )
! wr i t e ( , ) a ( 2: i l , 2 : j l )
DT=CFL/maxval ( abs ( uu ( 2 : i l , 2 : j l )/ maxval ( abs ( dx ( 2 : i l , 2 : j l )))+vv ( 2 : i l , 2 : j l )/ maxval ( abs ( dy ( 2 : i l , 2 : j l ) ) ) &
+a ( 2 : i l , 2 : j l ) s qr t (1/ maxval ( abs ( dx ( 2 : i l , 2 : j l ) ) ) 2 . 0 d0+1/maxval ( abs ( dy ( 2 : i l , 2 : j l ) 2. 0 d0 ) ) ) ) )
write ( , ) DT: ,DT
ENDSUBROUTINE CALCDT
SUBROUTINE SETICS
USE MAINVARS
IMPLICIT NONE
SELECT CASE( problem)
CASE( 0) ! Assignment 3
U( 1 , 1 : i l /2 , : )= r hoi nf 01
U( 2 , 1 : i l /2 , : )= r hoi nf 01 s qr t ( Minf01Minf01gammaRTi nf01vi nf 01 )
U( 3 , 1 : i l /2 , : )= r hoi nf 01 vi nf 01
U( 4 , 1 : i l /2 , : ) =( ( r hoi nf 01 cv Ti nf 01 +0.5d0 r hoi nf 01 Minf01Minf01gammaR Ti nf 01 ) )
U( 1 , i l /2+1: i l , : ) = r hoi nf 02
U( 2 , i l /2+1: i l , : ) = r hoi nf 02 s qr t ( Minf02Minf02gammaRTi nf02vi nf 02 )
U( 3 , i l /2+1: i l , : ) = r hoi nf 02 vi nf 02
U( 4 , i l /2+1: i l , : ) =( ( r hoi nf 02 cv Ti nf 02 +0.5d0 r hoi nf 02 Minf02Minf02gammaR Ti nf 02 ) )
s xi=s qr t ( 3. 0 d0 ) /2. 0 d0
s yi =0.5d0
CASE( 1) ! channel
Ti nf=Ti nf 1
pi nf=pi nf 1
Minf=Minf1
r hoi nf=pi nf /(R Ti nf )
a i nf=s qr t (gammaR Ti nf )
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 31
r houi nf=Minf a i nf r hoi nf
r hovi nf =0
Ei nf=r hoi nf cv Ti nf +0.5d0 r houi nf r houi nf / r hoi nf
Fj ( 1 , : , : ) =0
Fj ( 2 , : , : ) =0
Fj ( 3 , : , : ) = pi nf
Fj ( 4 , : , : ) =0
Fi ( 1 , : , : ) = r houi nf
Fi ( 2 , : , : ) = r houi nf Minf a i nf+pi nf
Fi ( 3 , : , : ) =0
Fi ( 4 , : , : ) =( Ei nf+pi nf ) Minf a i nf
! f l i p f l ow f or t e s t i ng and v a l i d a t i o n
! r hov i nf=r houi nf
! r houi nf =0
U( 1 , : , : ) = r hoi nf
U( 2 , : , : ) = r houi nf
U( 3 , : , : ) = r hovi nf
U( 4 , : , : ) = Ei nf
CASE( 2) ! ramp
Ti nf=Ti nf 2
pi nf=pi nf 2
Minf=Minf2
r hoi nf=pi nf /(R Ti nf )
a i nf=s qr t (gammaR Ti nf )
r houi nf=Minf a i nf r hoi nf
r hovi nf =0
Ei nf=r hoi nf cv Ti nf +0.5d0 r houi nf r houi nf / r hoi nf
U( 1 , : , : ) = r hoi nf
U( 2 , : , : ) = r houi nf
U( 3 , : , : ) = r hovi nf
U( 4 , : , : ) = Ei nf
Fj ( 1 , : , : ) =0
Fj ( 2 , : , : ) =0
Fj ( 3 , : , : ) = pi nf
Fj ( 4 , : , : ) =0
Fi ( 1 , : , : ) = r houi nf
Fi ( 2 , : , : ) = r houi nf Minf a i nf+pi nf
Fi ( 3 , : , : ) =0
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 32
Fi ( 4 , : , : ) =( Ei nf+pi nf ) Minf a i nf
s xj ( i l +1 ,:)=0
s yj ( i l +1 ,:)=1
s xi ( : , j l +1)=1
s yi ( : , j l +1)=0
CASE( 3) ! c y l i nde r
! Mach 5 i nf l ow
Ti nf=Ti nf 3
pi nf=pi nf 3
Minf=Minf3
r hoi nf=pi nf /(R Ti nf )
a i nf=s qr t (gammaR Ti nf )
r houi nf=Minf a i nf r hoi nf
r hovi nf =0
Ei nf=r hoi nf cv Ti nf +0.5d0 r houi nf r houi nf / r hoi nf
! Fi l l e v e r yt hi ng wi t h f l ow t o s t a r t
U( 1 , : , : ) = r hoi nf
U( 2 , : , : ) = r houi nf
U( 3 , : , : ) = r hovi nf
U( 4 , : , : ) = Ei nf
! e s t a b l i s h i n i t i a l f l u x e s al s o
Fj ( 1 , : , : ) =0
Fj ( 2 , : , : ) =0
Fj ( 3 , : , : ) = pi nf
Fj ( 4 , : , : ) =0
Fi ( 1 , : , : ) = r houi nf
Fi ( 2 , : , : ) = r houi nf Minf a i nf+pi nf
Fi ( 3 , : , : ) =0
Fi ( 4 , : , : ) =( Ei nf+pi nf ) Minf a i nf
CASE DEFAULT
write ( , ) WTF Mate ?
write ( , ) Executi on wi l l now hal t .
STOP
END SELECT
ENDSUBROUTINE SETICS
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 33
SUBROUTINE SETBCS
USE MAINVARS
IMPLICIT NONE
REAL8 , PARAMETER : : wal l cur ve =.1
REAL8 , POINTER, DIMENSION( : , : ) : : rho , rhou , rhov , E
REAL8 , DIMENSION( i l +1, j l +1) : : upri mei , upri mej , upr i mei i nf , upr i me j i nf
rho=>U( 1 , : , : )
rhou=>U( 2 , : , : )
rhov=>U( 3 , : , : )
E=>U( 4 , : , : )
upri mei=rhou/rho s xi+rhov/rho s yi
upri mej=rhou/rhosxjm+rhov/rho s yj
upr i me i i nf=r houi nf / r hoi nf s xi+r hovi nf / r hoi nf s yi
upr i me j i nf=r houi nf / r hoi nf sxjm+r hovi nf / r hoi nf s yi
p=(gamma1.0d0 ) (E0.5d0/rho ( rhourhou+rhovrhov ) )
SELECT CASE( problem)
case ( 0) ! assi gnment 3
! do not hi ng , don t care about boundari es
! j u s t a 1 ti me s t ep probl em i n mi ddl e of domain
CASE( 1) ! channel
! f or t he channel we can j u s t keep t he ICs at t he boundary
! get P one g r i d space above wal l
CASE( 2) ! ramped channel
! i nf l ow
Fj ( 1 , 1 , : ) =0
Fj ( 2 , 1 , : ) =0
Fj ( 3 , 1 , : ) = pi nf
Fj ( 4 , 1 , : ) =0
Fi ( 1 , 1 , : ) = r houi nf
Fi ( 2 , 1 , : ) = r houi nf Minf a i nf+pi nf
Fi ( 3 , 1 , : ) =0
Fi ( 4 , 1 , : ) =( Ei nf+pi nf ) Minf a i nf
! out f l ow
Fj ( 1 , i l , : ) = rho ( i l 1 , : ) upri mej ( i l 1 , : )
Fj ( 2 , i l , : ) = rhou ( i l 1 , : ) upri mej ( i l 1,:)+p( i l 1 , : ) sxjm( i l 1 , : )
Fj ( 3 , i l , : ) = rhov ( i l 1 , : ) upri mej ( i l 1,:)+p( i l 1 , : ) s yj ( i l 1 , : )
Fj ( 4 , i l , : ) =(E( i l 1,:)+p( i l 1 , : ) ) upri mej ( i l 1 , : )
Fi ( 1 , i l , : ) = rho ( i l 1 , : ) upri mei ( i l 1 , : )
Fi ( 2 , i l , : ) = rhou ( i l 1 , : ) upri mei ( i l 1,:)+p( i l 1 , : ) s xi ( i l 1 , : )
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 34
Fi ( 3 , i l , : ) = rhov ( i l 1 , : ) upri mei ( i l 1,:)+p( i l 1 , : ) s yi ( i l 1 , : )
Fi ( 4 , i l , : ) =(E( i l 1,:)+p( i l 1 , : ) ) upri mei ( i l 1 , : )
! wi t h no curvat ure t o t he wal l , pr es s ur e at wal l s houl d match t h i s
! e nt r i e s 2 and 3 i n Fwal l are f unc t i ons of pr es s ur e and cos i ne
! e nt r i e s 1 and 4 are 0
Fj ( 1 , : , 1) =0
Fj ( 2 , : , 1) =p ( : , 2 ) ( sxjm ( : , 1 ) )
Fj ( 3 , : , 1) =p ( : , 2 ) ( s yj ( : , 1 ) )
Fj ( 4 , : , 1) =0
! now do i t at t op bound
! remember p i s t aken a hal f i ndex removed from F i ndex ( i=i 1/2, not i +1/2)
Fj ( 1 , : , j l )=0
Fj ( 2 , : , j l )=p ( : , j l ) ( sxjm ( : , j l ) )
Fj ( 3 , : , j l )=p ( : , j l ) ( s yj ( : , j l ) )
Fj ( 4 , : , j l )=0
CASE( 3) ! c y l i nde r
! i nf l ow @ j l
! out f l ow at i =2, i l
Fj ( 1 , i l , : ) = rho ( i l 1 , : ) upri mej ( i l 1 , : )
Fj ( 2 , i l , : ) = rhou ( i l 1 , : ) upri mej ( i l 1,:)+p( i l 1 , : ) sxjm( i l 1 , : )
Fj ( 3 , i l , : ) = rhov ( i l 1 , : ) upri mej ( i l 1,:)+p( i l 1 , : ) s yj ( i l 1 , : )
Fj ( 4 , i l , : ) =(E( i l 1,:)+p( i l 1 , : ) ) upri mej ( i l 1 , : )
Fi ( 1 , i l , : ) = rho ( i l 1 , : ) upri mei ( i l 1 , : )
Fi ( 2 , i l , : ) = rhou ( i l 1 , : ) upri mei ( i l 1,:)+p( i l 1 , : ) s xi ( i l 1 , : )
Fi ( 3 , i l , : ) = rhov ( i l 1 , : ) upri mei ( i l 1,:)+p( i l 1 , : ) s yi ( i l 1 , : )
Fi ( 4 , i l , : ) =(E( i l 1,:)+p( i l 1 , : ) ) upri mei ( i l 1 , : )
Fj ( 1 , 1 , : ) = rho ( 2 , : ) upri mej ( 2 , : )
Fj ( 2 , 1 , : ) =rhou ( 2 , : ) upri mej ( 2 , : ) +p ( 2 , : ) sxjm ( 2 , : )
Fj ( 3 , 1 , : ) = rhov ( 2 , : ) upri mej ( 2 , : ) +p ( 2 , : ) s yj ( 2 , : )
Fj ( 4 , 1 , : ) =(E( 2 , : ) +p ( 2 , : ) ) upri mej ( 2 , : )
Fi ( 1 , 1 , : ) = rho ( 2 , : ) upri mei ( 2 , : )
Fi ( 2 , 1 , : ) =rhou ( 2 , : ) upri mei ( 2 , : ) +p ( 2 , : ) s xi ( 2 , : )
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 35
Fi ( 3 , 1 , : ) = rhov ( 2 , : ) upri mei ( 2 , : ) +p ( 2 , : ) s yi ( 2 , : )
Fi ( 4 , 1 , : ) =(E( 2 , : ) +p ( 2 , : ) ) upri mei ( 2 , : )
! now s e t up surf ace , usi ng curvat ure f or t he curved s ur f ace
! j =1
Fj ( 1 , : , 1) =0
! Fj (2 , : , 1)=( p (: , 2)+ Si ( : , 2) rho ( : , 2) ( rhou ( : , 2) rhou (: , 2)+ rhov ( : , 2) rhov ( : , 2) ) /( rho ( : , 2) rho ( : , 2) ) / wal l cur ve )( sxjm ( : , 1 ) )
! Fj (3 , : , 1)=( p (: , 2)+ Si ( : , 2) rho ( : , 2) ( rhou ( : , 2) rhou (: , 2)+ rhov ( : , 2) rhov ( : , 2) ) /( rho ( : , 2) rho ( : , 2) ) / wal l cur ve )( s y j ( : , 1 ) )
Fj ( 2 , : , 1) =( p ( : , 2 ) ( sxjm ( : , 1 ) ) )
Fj ( 3 , : , 1) =( p ( : , 2 ) ( s yj ( : , 1 ) ) )
Fj ( 4 , : , 1) =0
! i nf l ow
Fj ( 1 , : , j l )=r hoi nf upr i me j i nf ( : , j l )
Fj ( 2 , : , j l )=r houi nf upr i me j i nf ( : , j l )+pi nf sxjm ( : , j l )
Fj ( 3 , : , j l )=r hovi nf upr i me j i nf ( : , j l )+pi nf s yj ( : , j l )
Fj ( 4 , : , j l )=( Ei nf+pi nf ) upr i me j i nf ( : , j l )
Fi ( 1 , : , j l )=r hoi nf upr i me i i nf ( : , j l )
Fi ( 2 , : , j l )=r houi nf upr i me i i nf ( : , j l )+pi nf s xi ( : , j l )
Fi ( 3 , : , j l )=r hovi nf upr i me i i nf ( : , j l )+pi nf s yi ( : , j l )
Fi ( 4 , : , j l )=( Ei nf+pi nf ) upr i me i i nf ( : , j l )
CASE DEFAULT
write ( , ) WTF Mate ?
write ( , ) Executi on wi l l now hal t .
STOP
END SELECT
ENDSUBROUTINE SETBCS
SUBROUTINE WRITE4VEC(U, Uout f i l e , c u l l )
USE PARAMS
IMPLICIT NONE
REAL8 , DIMENSION( 4 , i l +1, j l +1) : : U
character ( len=20) Uout f i l e
integer i , j
integer c u l l
write ( , ) Wri ti ng : , Uout f i l e
open( unit=5, f i l e=Uout f i l e )
write ( 5 , 1 I ) i l c u l l
write ( 5 , 1 I ) j l c u l l
write ( 5 , 4E ) ( (U( : , i , j ) , i =1, i l c u l l +1) , j =1, j l c u l l +1)
cl ose ( 5)
ENDSUBROUTINE WRITE4VEC
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 36
SUBROUTINE GETUCALC( Ucal ci , Ucal cj , U)
USE PARAMS
USE SETTINGS
IMPLICIT NONE
REAL8 , DIMENSION( 4 , i l +1, j l +1) : : Ucal ci , Ucal cj , U
INTEGER i , j
SELECT CASE( method)
CASE( 0)
! Standard St eger Warming , don t a c t ua l l y do any averagi ng , j u s t shoot back same v a r i a b l e
Ucal ci=U
Ucal cj=U
CASE( 1)
! Modi f i ed St eger Warming , average U Val ues
do i =1, i l
Ucal ci ( : , i , : ) =0. 5 d0 (U( : , i , : ) +U( : , i +1 , : ) )
enddo
do j =1, j l
Ucal cj ( : , : , j )=0. 5d0 (U( : , : , j )+U( : , : , j +1))
enddo
END SELECT
ENDSUBROUTINE GETUCALC
SUBROUTINE ADVANCETIME(U, DT, Fi , Fj , Si , Sj , V, maxdi f f )
USE PARAMS
USE SETTINGS
IMPLICIT NONE
integer i , j , k
REAL8 , DIMENSION( 4 , i l +1, j l +1) : : U, Fi , Fj ,DU
REAL8 , DIMENSION( i l +1, j l +1) : : Si , Sj , V
REAL8 DT, maxdi f f
do k=1,4
do i =2, i l
do j =2, j l
DU( k , i , j )=DT/V( i , j ) ( Fi ( k , i , j ) Si ( i , j )Fi ( k , i 1, j ) Si ( i 1, j ) &
+Fj ( k , i , j ) Sj ( i , j )Fj ( k , i , j 1) Sj ( i , j 1))
! wr i t e ( , ) i , j ,DU( k , i , j )
enddo
enddo
enddo
maxdi f f=maxval ( abs (DU( : , 2 : i l , 2 : j l ) ) ) / maxval ( abs (U( : , 2 : i l , 2 : j l ) ) )
do k=1,4
do i =2, i l
do j =2, j l
U( k , i , j )=U( k , i , j )+DU( k , i , j )
D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 37
enddo
enddo
enddo
! wr i t e ( , ) ( ( Sj ( i , j ) , i =1, i l ) , j =1, j l )
! wr i t e ( , ) DU( 1: i l , 1 : j l )
! wr i t e ( , ) maxdi f f
ENDSUBROUTINE ADVANCETIME

Você também pode gostar