finite volume code for compressible flow

38
Finite Volume Code for Compressible Flows Matt Stegmeir May 16, 2005 AEM8251: Finite Volume Methods 1

Upload: mafrisbe

Post on 03-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Volume Code for Compressible Flow

 

Finite Volume Code for Compressible Flows

Matt Stegmeir

May 16, 2005

AEM8251: Finite Volume Methods

1

Page 2: Finite Volume Code for Compressible Flow

 

2 NUMERICAL METHOD: MODIFIED STEGER-WARMING FLUX VECTOR SPLITTING 1

Abstract

This paper documents the final project for AEM8251:Finite Volume methods in Fluid Mechanics, a code tosimulate compressible flows. A finite volume codewas created to study 3 problems, flow through achannel with slip boundaries, flow through a chan-nel with a ramp constriction in its middle section,and flow around a sphere, all with supersonic bound-aries. The code is able to load a properly formatted 2-dimensional structured curvilinear grid and calculatecompressible flows, provided with the correct bound-ary conditions. The results of applying this code areincluded in the main report. The appendices containreference information including results of previous as-signments.

1 Introduction

2 Numerical Method: Mod-

ified Steger-Warming Flux

Vector Splitting

2.1 Spatial

In order to promote stability and enhance accuracyby using information from physically meaningful lo-cations, it is desirable to employ a scheme that cansense the direction of the flow of information andbias itself in the appropriate direction. One tech-nique which accomplishes this is finite volume Steger-Warming flux vector splitting for conservation laws.To employ this method, the vector of flux of con-served variables must be homogeneous. This allowsthe flux to be written as a product of a Jacobianmatrix and the vector of conserved quantities. Fur-thermore, this Jacobian (A) can be rearranged intoan easily diagonalizable form based on the conservedvariables U, the primitive variables V, and the flux(in terms of an arbitrary coordinate system) F .

F  =

ρu

ρuu + psxρvu + psy(E + p)u

(1)

sx and sy are the direction cosines in the x and ydirections and u is the normal velocity usx + usy.

U  =

ρρuρvE 

(2)

V  =

ρuv p

(3)

A =∂F 

∂U =

∂U 

∂V 

∂V 

∂U 

∂F 

∂V 

∂V 

∂U (4)

Thus, F  = AU . For convenience we define 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 eigenvaluematrix with eigenvalues (u, u + a, u, u − a). Thepositive eigenvalues compose the positive flux andthe negative eigenvalues compose the negative flux.Separating the positive and negative fluxes allowsus to use physically meaningful locations whencomputing total flux across boundaries. Upwindingin this manner forms the base of the Steger-Warmingmethod. Flux across each face of a cell is computedby summing the positive flux from the lower-indexeddirection and the negative flux from the higherindexed direction:

F i+ 1

2,j

= F +i,j + F −i+1,j= A

+i,jU i,j + A−i+1,jU i+1,j

(5)

A+ is the portion of the Jacobian arising frompositive eigenvalues and A− is the portion arisingfrom negative eigenvalues. This method works, but

Page 3: Finite Volume Code for Compressible Flow

 

3 TIME ADVANCEMENT  2

has the distinct disadvantage of being extremely dis-sipative. Because of the high numerical dissipationinherent in applying this method, it is not used forsolving real problems. However, a small modificationto 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 Modified Steger-Warming method is muchless dissipative and is a superior general-purposemethod. However, it does have a weakness in thatit is not a good method for use in regions of strongshocks, large gradients, and similar sharp discontinu-ities. In such situations it may be desirable to locallyrevert to the pure Steger-Warming approach forincreased dissipation and hence stability. Anothersituation where errors may occur is in regions whereeigenvalues approach zero, either in the form of a sonic glitch at speeds near the sound speed orcarbuncle problems around flow stagnation. Thismay be avoided by making a modification to thevalue of u used in calculating them.

λ1,± =1

2(u ±

 

u2 + 2) (8)

is commonly defined as some small fraction of sound speed, for example 0.1a. The other correctedeigenvalues 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 fluxes through thesurfaces surrounding that point. This scheme can bewritten 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 productswas needed, balancing computational efficiency andease of debugging. It was decided that the bestcourse was to follow was to compute and store thetwo matrix products S C  and CS  as well as theeigenvalue matrices. These three pieces of data,along with the velocity, were used to compute theflux. This approach allowed for simple enoughexpressions to be easily proofed and debugged,but still avoided excessively complicated matrixmultiplications or obscene numbers of data elements.The code multiplies from right to left, so all matrixmultiplication operations performed are a 4x1 vectorright-multiplied by a 4x4 matrix to yield another4x1 vector. Appendix B contains the calculatedvalues for S C  and CS . They were computingMATLAB symbolic routines combined with manualsubstitution based on known relationships betweenthe variables used.

3 Time Advancement

For this assignment time advancement was accom-plished through explicit Euler time integration. Atimestep δt was calculated based on a specifiedCourant number and the maximum value of a spa-tial function:

∆t =CF L

MAX 

|u|∆x

+ |v|∆y

+ a 

1

∆x2+ 1

∆y2

(10)

This time step was used to obtain a change δU  in thevalue of the vector of conserved variables:

δU ni,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+1i,j = U ni.j + δU ni,j (12)

Page 4: Finite Volume Code for Compressible Flow

 

5 RAMP CHANNEL FLOW  3

This method of time advancement has advantagesand disadvantages. Its primary advantages are thatit is easy to implement (reliable, easy to troubleshoot,etc) and it provides a time accurate (although onlyfirst order accurate) solution. Its main disadvantageis that it’s not an especially efficient way to advancetime, and it scales poorly. When decreasing grid sizesis needed to resolve smaller flow features the allow-able time step becomes smaller as well. As grid sizesget small enough, this becomes a prohibitive expense.The higher-performing alternative is implicit time ad-vancement, which is not time accurate but is muchmore efficient.

4 Plain Channel Flow

The first flow that the scheme was tested on wasa simple straight channel flow with slip boundaries.This was a simple validation of the ability of themethod to correctly maintain a steady flow in variousdirections. The flow was initialized in positive andnegative x and y directions and time was advancedto ensure that there were no steady state errors. Per-turbations were introduced to see if the flow wouldstill correctly stabilize. All of these tests were suc-cessful. If illustration of flow properties is required,refer to the left third of the ramp flow images. Thecode for this problem is part of the final project codeincluded in Appendix D.

5 Ramp Channel Flow

For this section of the project, the task was tosimulate a Mach 2.5 flow entering a channel, witha 15o ramp located through the middle third of the channel. The top and bottom boundaries areslip boundaries, and the outlet is supersonic. Theresults given were obtained using the ModifiedSteger-Warming method. A sonic glitch factor of 0.1a was employed in the mean flow direction toavoid instabilities stemming from a subsonic flowregion which develops near the upper channel wall.The resulting flow contains a number of distinctivefeatures, most prominent being a shock that is

Figure 1: Grid for Channel With Ramp

generated at the base of the ramp and reflected off of the opposite wall. In addition, an expansion fanis visible at the top of the ramp.

As a simple validity check, the flow field afterthe first shock may be determined by using basicshock relationships and the result can be comparedto the simulation data. First, the shock angleis calculated using the θ-β  equation. For a 15o

deflection a shock angle of approximately 37ø isexpected. However, closer examination of the gridreveals that the 15ø specification is not quite correct,the actual angle of the ramp is closer to 18 o. Thisyields a 40o shock angle. Dividing the channel heightby the tangent of this angle gives the location theshock should hit the opposite wall, a good first checkof simulation validity. Using the grid provided, thiscollision should occur at x=0.12. Figure 2 shows theshock (and where it collides with the opposite wall).The angle of the shock and hence the location of theinteraction match the expected result.

A second point of comparison is the pressure ratio

Page 5: Finite Volume Code for Compressible Flow

 

5 RAMP CHANNEL FLOW  4

Figure 2: Mach Number Contours

across the shock. Using shock relations, an expectedpressure ratio of 2.9 is obtained for an 18 o shock. Fig-ure 3 shows the pressure contours generated by thesimulation. The simulation’s pressure values matchup reasonably well with the expected ones, althoughthe pressure rise is overpredicted to a value of ap-proximately 3.0. As shown in figure 4, temperaturebehind the lead shock increased by a factor of 1.45.This is close to the predicted value of 1.4, with a slightoverprediction once again. Figure 5 shows stream-lines plotted by MATLAB (using interpolated valueson an interpolated grid for technical reasons). Theybehave as expected, although their direction changesare smoothed out by the calculation process. Figure6 shows the raw velocity vectors for a more accuraterepresentation. The code for this problem is part of the final project code included in Appendix D.

Figure 3: Pressure Contours

Figure 4: Temperature Contours

Page 6: Finite Volume Code for Compressible Flow

 

5 RAMP CHANNEL FLOW  5

Figure 5: Streamlines

Figure 6: Velocity Vectors

Page 7: Finite Volume Code for Compressible Flow

 

7 CONCLUSION  6

6 Mach 5 Flow Around a Half-

Cylinder

This was the most computationally demanding sec-tion of the project. In this flow a high Mach num-ber flow is brought to a halt at the leading edge of a blunt body, namely a half-cylinder. The Modi-fied Steger-Warming method used for the previousexamples could not handle the sharp gradients thatthis type of flow generates, and would crash withina few time steps of flow initialization. It was unableto develop a reasonable solution. Switching to themore dissipative pure Steger-Warming method witha small time step helped and kept the solution stableenough to establish flow parallel to the surface of thehalf-cylinder. Even in this case, the carbuncle prob-lem was eventually encountered. Due to these issuesit was not possible to obtain steady-state results forthe cylinder problem. The following results show thestate of the solution shortly before the code crashed.I make no representation of their accuracy, they areincluded only to provide information on the state of this portion of the code. The code for this problemis part of the final project code included in AppendixD.

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-ified Steger-Warming flux vector splitting methodswith and without sonic glitch correction in two di-mentions on curvilinear grids has been successfullywritten and used on channel and ramped channelmoderate Mach number flows. In addition, the codewas applied with limited success to a semi-cylindricalbody in flow. The code is amenable to future im-provements discussed below. For the channel flowsagreement with predicted results was acceptable.

Page 8: Finite Volume Code for Compressible Flow

 

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 maybe done in the area of this project. Implicit time ad-vancement will be implemented in order to more effi-ciently advance time, both approximately (Yoon andJameson LU-SGS) and exactly (Gauss-Seidel LineRelaxation). Second-Order accurate flux calculationswill be introduced, as will an intelligent way of de-tecting and switching to a safe method near stronggradients. Viscous terms may also be considered.

Figure 12: Temperature Contours

Figure 13: Streamlines

Page 9: Finite Volume Code for Compressible Flow

 

8 FUTURE WORK   8

Figure 14: Velocity Vectors

Page 10: Finite Volume Code for Compressible Flow

 

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 flow with a velocity discontinuity after 0.05shad passed. The left side of the flow had an initial velocity of 1000 m/s, and the right side a velocity of 500m/s. Density was 1.0 kg/m3 on the left and 0.5kg/m3 on the right. Temperature on the left was 300K andon the right was 600K. Figures 15, 16, and 17 demonstrate the effect 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 thesolution remains stable at higher grid spacings, accuracy suffers.

Page 11: Finite Volume Code for Compressible Flow

 

A PREVIOUS WORK  10

Figure 16: 141 Grid Points Used

Page 12: Finite Volume Code for Compressible Flow

 

A PREVIOUS WORK  11

Figure 17: 281 Grid Points Used

Page 13: Finite Volume Code for Compressible Flow

 

A PREVIOUS WORK  12

The code for this problem is part of the final project code included in Appendix C.

A.2 Assignment 3 - Single 2-D Flux

Homework Assignment 2 was computing a single 2-dimensional flux across a given face from known conditionsusing 4 different methods. This was implemented and the results were as follows:

Simple Averaging : F av =

0.3082046580117479E + 030.1850932310996726E + 060.4563609822582072E + 050.1135750151493932E + 09

P ure Steger− Warming : F S−W  =

0.3100862388776151E + 030.2010361951702728E + 060.4644602567565192E + 050.1183359269341165E + 09

Modified Steger − Warming : F M −S−W  =

0.3307416709140678E + 030.2002338151898726E + 060.4328714021715256E + 050.1236992782944958E + 09

Modified Steger − Warming with = 0.1a : F M −S−W − =

0.3307416709140678E + 030.2002338151898726E + 060.4328714021715256E + 050.1236992782944958E + 09

It is

apparent that the results are correct. The code used to generate these results has been merged with thecode for the final project and can be found in appendix D.

Page 14: Finite Volume Code for Compressible Flow

 

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        ∗     C    

           

     1

    ρ

     0

    ρ

    u

    ρ    u     +

    ρ    a       s     x

   −    ρ       s     y

    ρ    u   −

    ρ    a       s     x

    v

    ρ    v     +

    ρ    a       s     y

    ρ       s     x

    ρ    v   −

    ρ    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

      )

           

Page 15: Finite Volume Code for Compressible Flow

 

C CODE FOR ASSIGNMENT 2  14

C Code for Assignment 2

PROGRAM ASS2

impl icit none

! S i mu l at i on s e t t i n g sINTEGER, PARAMETER : : g r i d s i z e =71REAL∗8 , PARAMETER : : tmax=0.005;REAL∗8 , parameter : : CFL=0. 3;REAL∗8 , PARAMETER : : l e n g th = . 1∗14 1

! p h y s i c a l c o ns t an t q u a n t i t i e sREAL∗8 , PARAMETER : : gamma=1.4REAL∗8 , PARAMETER : : R=287;

! c om pu te d v a r i a b l e sREAL∗8 ,PARAMETER : : dx=l e n g t h / g r i d s i z eINTEGER iREAL∗8 t , d tREAL∗8 , DIMENSION( 3 , g r i d s i z e ) : : U , F p lu s , F min us !U=rho , rhou , E, u  REAL∗8 , dimension ( g r i d s i z e ) : : uu , TT, x

write (∗ ,∗ ) ’ d x ’ , dxt=0c a l l set ICs (U,gamma,R, g r id s iz e )uu=U(2 , :) /U( 1 ,: ) ! c a l c u l a t e u fr om r ho u and r ho

c a l l getd t (uu, g ri ds iz e ,CFL,dx , dt)! t=tmax −d t write (∗ ,∗ ) t , tmax , dt

DO WHILE ( t < tmax)write (∗ ,∗ ) t

c a l l getd t (uu, gr id si ze ,CFL,dx , dt )! w r i t e (  ∗ ,∗) t , d t  t=t+dtc a l l getF (U,uu , Fplus , Fminus ,TT,gamma,R, g r i d s i z e )

DO i = 2 , g r i d s i z e −1U( : , i)=U( : , i)−dt/dx∗( Fplu s (: , i )+Fminus ( : , i +1)−Fplus (: , i −1)

END DO

uu=U(2 , :) /U( 1 ,: )END DO

! do i =1, g r i d s i z e! w r i t e (  ∗ ,∗) i ! w r i t e (  ∗ ,∗) F p l u s ( : , i )

Page 16: Finite Volume Code for Compressible Flow

 

C CODE FOR ASSIGNMENT 2  15

! w r i t e (  ∗ ,∗) Fminus( : , i )! w r i t e (  ∗ ,∗) ’ ’ ! end do

x=0do i = 2, g r i d s i z e

x( i )=x( i −1)+dxEND DO

open ( unit =911, f i l e =”U. out”)write (91 1 ,∗ ) Uc l o s e ( 9 1 1 )open ( unit =911, f i l e =”x . out” )write ( 9 1 1 , ’ 1 F 10 . 1 ’ ) xc l o s e ( 9 1 1 )

END PROGRAM

SUBROUTINE set ICs (U,gamma,R, g ri ds iz e )! checked  

impl icit none

! l i s t ICs in human  −r e a d a b l e f or m  REAL∗8 , PARAMETER : : r h o l e f t = 1. 0REAL∗8 , PARAMETER : : r h o r i g h t = 0. 5REAL∗8 , PARAMETER : : T l e f t = 30 0 .0REAL∗8 , PARAMETER : : Tright =600REAL∗8 , PARAMETER : : u l e f t =1000REAL∗8 , PARAMETER : : u r i g h t = 500

INTEGER g r i d s i z eREAL∗8 , DIMENSION( 3 , g r i d s i z e ) : : UREAL∗8 gamma, R,CV

integer h a l f  h a l f = ( g r i d s i z e −1)/2

CV=(1.0/(gamma−1 . 0 ) )∗R

U ( 1 , 1 : h a l f )= r h o l e f tU ( 1 , h a l f + 1: g r i d s i z e )= r h o r i g h tU ( 2 , 1 : h a l f )= r h o l e f t ∗ u l e f tU ( 2 , h a l f + 1: g r i d s i z e )= r h o r i g h t ∗ u r i g h tU ( 3 , 1 : h a l f )= r h o l e f t ∗(CV∗T l e f t + 1 . 0 / 2 .0∗ u l e f t ∗∗2 . 0 d 0 )U ( 3 , h a l f + 1: g r i d s i z e )= r h o r i g h t ∗(CV∗Tright +1.0/2.0∗ u r i g h t ∗∗2 . 0 d 0 )

Page 17: Finite Volume Code for Compressible Flow

 

C CODE FOR ASSIGNMENT 2  16

END SUBROUTINE

SUBROUTINE getF (U,uu , Fplus , Fminus ,TT,gamma,R, g r i d s iz e )impl icit none

INTEGER g r i d s i z e , iREAL∗8 , DIMENSION( gr id s iz e ) : : uu,TT,p , a , co ef f , term1 , term2 , term3REAL∗8 , DIMENSION(3 , gr id s iz e ) : : U, Fplus ,Fminus ,LP,LMREAL∗8 gamma, R, CV, gm1

gm1=gamma−1CV=R/(gamma−1.0d0)TT=(U( 3 , : ) −0 . 5 d 0∗U ( 1 , : ) ∗ uu ∗∗2 . 0 d 0 ) / ( U( 1 , : ) ∗CV)a=sqrt (gamma∗R∗TT)p=(gamma−1)∗(U(3 ,: ) −0.5d0/U(1 , :) ∗U ( 2 , : ) ∗∗ 2 . 0 d 0 )LP ( 1 , : ) = 0 . 5 d 0∗(uu+abs(uu))LP ( 2 , : ) = 0 . 5 d 0∗( uu+a+abs (uu+a ) )LP ( 3 , : ) = 0 . 5 d 0∗( uu−a+abs(uu−a ) )LM(1 ,: )= 0. 5 d0∗( uu−a b s ( u u ) )LM(2 ,: )= 0. 5 d0∗( uu+a−abs(uu+a))LM(3 ,: )= 0. 5 d0∗( uu−a−abs(uu−a ) )

! do i =1, g r i d s i z e! w r i t e (  ∗ ,∗) LP(1 , i ) ,LM(1 , i )! w r i t e (  ∗ ,∗) LP(2 , i ) ,LM(2 , i )! w r i t e (  ∗ ,∗) LP(3 , i ) ,LM(3 , i )! w r i t e (  ∗ ,∗) ” .”! enddo! 

Fplus (1 , :)= 0.5 d0/a ∗∗2 . 0 d 0 ∗(LP( 1 , :) ∗2 . 0 d 0∗(U ( 1 , : ) ∗ a ∗∗2 . 0 d 0−p)+p∗(LP(2 , :) +LPFplus (2 , :)= 0.5 d0/a ∗∗2 . 0 d 0 ∗(LP( 1 , :) ∗2 . 0 d 0∗uu ∗(U ( 1 , : ) ∗ a ∗∗2 . 0 d 0−p)+LP( 2 ,: ) ∗ ( pFminus(1 , :)= 0.5 d0/a ∗∗2 . 0 d 0 ∗(LM(1 , : ) ∗2 . 0 d 0∗(U ( 1 , : ) ∗ a ∗∗2 . 0 d 0−p)+p∗(LM(2 , : )+LFminus(2 , :)= 0.5 d0/a ∗∗2 . 0 d 0 ∗(LM(1 , : ) ∗2 . 0 d 0∗uu ∗(U ( 1 , : ) ∗ a ∗∗2 . 0 d 0−p)+LM( 2 , : ) ∗ (Fplus (3 , :) =(U(3 , :)+ p) ∗uu

! Fplus (3 , :)=0. 25 d0/a  ∗∗2 . 0 d 0  ∗(LP(1 ,:) ∗2. 0 d0  ∗uu ∗∗2 . 0 d 0  ∗(U(1 ,: ) ∗ a ∗∗2.0d0  −p ) & ! +(LP( 2 ,: )+LP (3 , : )) ∗ p∗uu ∗(uu+2 ∗a ∗∗2 .0 d0 /uu ) &  ! +(LP(2 ,:) −LP ( 3 , : ) ) ∗2. 0 d0  ∗a ∗p∗uu )

co ef f =0.25d0/a∗∗2 . 0 d 0term1=2.0d0∗uu ∗∗2 . 0 d 0 ∗(U ( 1 , : ) ∗ a ∗∗2 . 0 d 0−p )term2=p ∗( uu ∗∗2.0d0+2.0d0∗a∗uu+2.0d0∗a ∗∗2.0d0/gm1)term3=p ∗( uu ∗∗2 . 0 d 0−2.0d0∗a∗uu+2.0d0∗a ∗∗2.0d0/gm1)Fplus (3 , :)= co ef f  ∗(LP( 1 , : ) ∗ term1+LP(2 ,:) ∗ term2+LP(3 ,:) ∗ term3)Fminus(3 , :)= co ef f  ∗(LM(1 ,:) ∗ ter m1+LM( 2 , : ) ∗ ter m2+LM( 3 , : ) ∗ term3)

Page 18: Finite Volume Code for Compressible Flow

 

C CODE FOR ASSIGNMENT 2  17

! do i =1, g r i d s i z e! w r i t e (  ∗ ,∗) term1( i ) , term2( i ) , term3( i )! w r i t e (  ∗ ,∗) ” . .. ”! enddo

! do i =1, g r i d s i z e! w r i t e (  ∗ , ’5 e ’) uu( i ) , a( i ) , p( i ) ,U(1 , i ) , Fpl us (3 , i )! enddo

! CV=(1.0/(gamma  −1.0))∗R! TT=(U( 3 , : ) −1 . 0 / 2 . 0  ∗U ( 2 , : ) ∗ uu ∗∗2 . 0 ) / ( U ( 1 , : ) ∗CV)! ! Fp lus ( 1 , : ) = 1 . 0 / 2 . 0  ∗U ( 1 , : ) ∗ (uu+abs(uu))! Fp lus ( 2 , : ) = 1 . 0 / 2 . 0  ∗U ( 2 , : ) ∗ (uu+abs(uu))! ! Fp lus ( 3 , : ) = 1 . 0 d0 / 4. 0 d0  ∗U ( 1 , : ) ∗ (2 .0 d0  ∗CV ∗TT ∗uu & ! ! +2.0 d0  ∗a b s ( u u )∗CV ∗TT & ! ! +uu  ∗∗3 . 0 d 0 &  ! ! +ab s ( uu )∗uu ∗∗2 . 0 d 0 )! ! ! Fp lus ( 3 , : ) = 1 . 0 d0 / 4. 0 d0  ∗U ( 1 , : ) ∗ (2 .0 d0  ∗CV ∗TT ∗uu & ! +2.0 d0  ∗a b s ( u u )∗CV ∗TT & ! +uu  ∗∗3 . 0 d 0 &  ! +ab s ( uu )∗uu ∗∗2 . 0 d 0 )! ! ! Fminus ( 1 , : ) = 1 . 0 / 2 . 0  ∗U ( 1 , : ) ∗ ( uu −a b s ( u u ) )! Fminus ( 2 , : ) = 1 . 0 / 2 . 0  ∗U ( 2 , : ) ∗ ( uu −a b s ( u u ) )! Fminus ( 3 , : ) = 1 . 0 d0 / 4. 0 d0  ∗U ( 1 , : ) ∗ (2 .0 d0  ∗CV ∗TT ∗uu & !  −2.0d0  ∗a b s ( u u )∗CV ∗TT & ! +uu  ∗∗3 . 0 d 0 &  !  −a b s ( u u )∗uu ∗∗2 . 0 d 0 )

END SUBROUTINE

SUBROUTINE getd t (U, gr id si ze ,CFL,dx , dt )impl icit none

REAL∗8 dx , dt ,CFLinteger g r i d s i z e

REAL∗8 , DIMENSION( g r i d s i z e ) : : U

Page 19: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  18

dt=CFL∗dx/maxval(abs(U))END SUBROUTINE

D Code For Assignment 3 and Final Project

MODULE SETTINGSinteger , PARAMETER : : numdt=1integer , PARAMETER : : t o l =1e−18integer , parameter : : i n t e r v a l =1! i n t e ge r f l a g t o s e t w hic h pr ob le m t o s o l v e .! p r ob l em s n umb er ed a s i n p r o j e c t s t a t em e n t  ! O pt io n 4 g e n er a t e s a p l a i n r e c t a n gu l a r g r i d  ! fr om 0 : 1 i n b o t h d im e ns i on s w i t h number o f  ! d i v i s i o n s d e te r mi n ed b y c h an n e lx and c h an n el y  ! p r ob l em 0 i s hom ew ork s e t 3  

INTEGER, PARAMETER : : problem=0! metho d : 0=SW,1 =MSW 

INTEGER, PARAMETER : : method=1! s on ic g l i t c h c o rr e c ti o n as f r a c t i on o f sound s pe ed  

REAL∗8 , PARAMETER : : g l i t c h c o r r = 0 .0! t i m e a dv a nc e me n t s ch em e , 1= e x p l i c i t  

INTEGER, PARAMETER : : timeadv=1REAL∗8 , PARAMETER : : CFL=0.005! 0 .0 05 f o r c y l  

INTEGER, PARAMETER : : channelx=20INTEGER, PARAMETER : : channely=20REAL∗8 , PARAMETER : : Minf1=2REAL∗8 , PARAMETER : : Minf2=2.5REAL∗8 , PARAMETER : : Minf3=5REAL∗8 , PARAMETER : : p i n f 1 = 10 00 00REAL∗8 , PARAMETER : : Tinf1=300REAL∗8 , PARAMETER : : p i n f 2 = 10 00 00REAL∗8 , PARAMETER : : Tinf2=300REAL∗8 , PARAMETER : : Tinf3=300REAL∗8 , PARAMETER : : p i n f 3 = 10 00 00REAL∗8 , PARAMETER : : Minf01=1.1REAL∗8 , PARAMETER : : Minf02=0.9REAL∗8 , PARAMETER : : r h o i n f 0 1 = 1. 0 d0REAL∗8 , PARAMETER : : r h o i n f 0 2 = 1. 02 d0REAL∗8 , PARAMETER : : T i n f 0 1 = 3 00 . 0 d0REAL∗8 , PARAMETER : : T i n f 0 2 = 3 10 . 0 d0REAL∗8 , PARAMETER : : v i n f 0 1 = 0. 0 d0REAL∗8 , PARAMETER : : v i n f 0 2 = 10 .0 d0

END MODULE SETTINGS

Page 20: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  19

MODULE CONSTANTSREAL∗8 , PARAMETER : : gamma=1.4REAL∗8 , PARAMETER : : R=287REAL∗8 , PARAMETER : : CV=R/ (gamma−1)REAL∗8 , PARAMETER : : p i = 3 .1 4 15 9

END MODULE CONSTANTS

MODULE PARAMS! S t o r ag e f o r any c o n s ta n t s , f o r e xa mp le f i l e names t h a t a re! s e l e c t e d from b y s e t t i n g t he p rob lem f l a g .character ( le n =20), PARAMETER : : c h a n n e l g r i d =” c h a n n e l−gri d . dat”character ( le n =20), PARAMETER : : c y l i n d e r g r i d =” c y l i n d e r −gr id . dat”character ( le n =20), PARAMETER : : rampgr id=”ramp−gri d . dat”

character ( le n =20), PARAMETER : : channe lout=”channel−gri d . out”character ( le n =20), PARAMETER : : c y l i n d e r o u t =” c y l i n d e r −gri d . out”character ( le n =20), PARAMETER : : rampout=”ramp−gri d . out”

character ( le n =20), PARAMETER : : ram pli st=”ramp . out”character ( le n =20), PARAMETER : : c h a n n e l l i s t =” c h a n n e l . o ut ”character ( le n =20), PARAMETER : : c y l i n d e r l i s t =” c y l i n d e r . o ut ”

character ( le n =20), PARAMETER : : voutb ase=”V. out”character ( le n =20), PARAMETER : : Uoutbase=”U. out ”

INTEGER i l , j l

END MODULE PARAMS

MODULE MAINVARSUSE PARAMSUSE SETTINGSUSE CONSTANTS

INTEGER i , j , countcharacter ( le n =20) fo rt ra ng ri d , grido ut , f i l e l i s t , probname , Voutf i le , Uou tf i l e

REAL∗8 , DIMENSION( : , : ) ,ALLOCATABLE : : x , y , Si , Sj , Sxi , Syi , Sxj , Syj ,V, dx , dy , sxiM , sxjM ,REAL∗8 , DIMENSION( : , : , : ) ,ALLOCATABLE,TARGET : : U , U c a l c i , U c a l c jREAL∗8 , DIMENSION( : , : , : ) , ALLOCATABLE : : LPi ,LMi , LPj ,LMjREAL∗8 , DIMENSION( : , : , : , : ) , ALLOCATABLE : : CSi , SCi , CSj , SCjREAL∗8 , DIMENSION( : , : , : ) , ALLOCATABLE : : Fi , FjREAL∗8 , DIMENSION( : , : ) ,ALLOCATABLE : : pREAL∗8 DT, maxd iff  

REAL∗8 r h o in f  r e a l∗8 a in f  r e a l∗8 r h o ui n f  

Page 21: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  20

r e a l∗8 r h o v in f  r e a l∗8 E in f  r e a l∗8 M in f  r e a l∗8 p i n f  r e a l∗8 T in f  

END MODULE MAINVARS

MODULE TEMPVARSUSE SETTINGSUSE CONSTANTSUSE PARAMS

REAL∗8 , DIMENSION( 4 ) : : CSUP,CSUM,LCSUP,LCSUM,FP,FMREAL∗8 , DIMENSION( : , : ) ,ALLOCATABLE : : uu, vv , uv2 , a ,T, gma, sxr , syr , rhosum , uprime , gl it c

END MODULE TEMPVARS

PROGRAM MAINUSE MAINVARSimpl icit none

character ( le n =20), PARAMETER : : t e s t f i l e 1 =” t e s t 1 . t x t ”character ( le n =20), PARAMETER : : t e s t f i l e 2 =” t e s t 2 . t x t ”character ( le n =20), PARAMETER : : t e s t f i l e 3 =” t e s t 3 . t x t ”character ( le n =20), PARAMETER : : t e s t f i l e 4 =” t e s t 4 . t x t ”

integer r e p o r t

c a l l s e t u pc a l l l o a d g r i d

! w r i t e (  ∗ ,∗) S i ( 1 : i l , 1 : j l )c a l l writegridMLc a l l outputvolumes

CALL SETICSCALL WRITE4VEC(U, te s t f i l e 1 , 0 )

maxdiff=1report=1

! STOP  ! w r i t e (  ∗ ,∗) s xj m  ! CALL WRITE4VEC( F i , t e s t f i l e 1 , 0 )

DO count=1,numdt! i f ( max diff   > t o l ) t he n  

CALL SETBCSCALL GETUCALC( Ucalci , Ucalcj ,U)CALL GETMATRICES( CSi , SCi , LPi , LMi , Uc al ci , s x i , s y i )CALL GETMATRICES( CSj , SCj , LPj , LMj , Uc a lc j , sxjm , s y j )CALL GETFLUX( Fi , Fj , CSi , SCi , CSj , SCj ,U, LPi ,LMi, LPj ,LMj)

Page 22: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  21

CALL CALCDT(DT, U, dx , dy )CALL ADVANCETIME(U, DT, Fi , Fj , Si , Sj ,V, m a x d if f )i f ( r e p o r t == i n t e r v a l ) then

write (∗ ,∗ ) c ou ntwrite (∗ ,∗ ) m a xd i ff  report=0

end i f  

report=report+1! e nd i f  

enddo

! w r i t e (  ∗ ,∗) V ! do j =1,3  ! do i =1, i l +1! w r i t e (  ∗ , ’2 i ,4 e ’ ) i , j , Fj ( : , i , j )! enddo! enddo! w r i t e (  ∗ ,∗) ’ . . . ’  ! do j =1,3  ! do i =1, i l +1! w r i t e (  ∗ , ’2 i ,4 e ’ ) i , j , Fi ( : , i , j )! enddo! enddo

do i =1, i l +1do j = 1 , 3

! w r i t e (  ∗ , ’2 i ,4 e ’ ) i , j , Fj ( : , i , j )enddo

enddo

CALL WRITE4VEC(U, U o u t f i l e , 0 )c a l l WRITE4VEC(Fj , t e s t f i l e 1 , 0 )do i =1, i l +1do j =1, j l +1 ! 

! w r i t e (  ∗ , ’4 e ’ ) db le ( i ) , db le ( j ) , syi ( i , j ) , syj ( i , j )! w r i t e (  ∗ , ’6 e ’ ) db le ( i ) , db le ( j ) , Fi (: , i , j )

enddo

enddo

do j =1, j l +1! w r i t e (  ∗ ,∗) j ! w r i t e (  ∗ , ’4 e ’) U(3 , i l  −1: i l , j )

! writ e (  ∗ ,∗) ’ . . . ’  ! writ e (  ∗ , ’ 4 e ’ ) U ( : , i l  −1: i l +1, j )! writ e (  ∗ ,∗) ’ , , , ’  

Page 23: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  22

! writ e (  ∗ , ’ 4 e ’ ) F i ( : , i l  −1: i l +1, j )! w r i t e (  ∗ , ’ 4 e ’ ) s x jm  

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 )

END PROGRAM MAIN

SUBROUTINE SETUPUSE MAINVARSimpl icit none

SELECT CASE(problem)CASE( 0 )

f o r t r a n g r i d = c h a n n e l g r i dg r i d o u t = c h a n n e l o u tf i l e l i s t=cha nn el l i stprobname=”channel”

CASE( 1 )f o r t r a n g r i d = c h a n n e l g r i dg r i d o u t = c h a n n e l o u tf i l e l i s t=cha nn el l i stprobname=”channel”

CASE( 2 )f o r t r a n g r i d = r a m p g r i dgridout=rampoutf i l e l i s t=ra mp li stprobname=”ramp”

CASE( 3 )f o r t r a n g r i d = c y l i n d e r g r i dg r i d o u t = c y l i n d e r o u tf i l e l i s t = c y l i n d e r l i s tprobname=”cylinder”

CASE( 4 )f o r t r a n g r i d = c h a n n e l g r i dg r i d o u t = c h a n n e l o u tprobname=”channel”c a l l GENCHANNELwrite (∗ ,∗ ) ’ C ha nn el g r i d g e ne r at e d ’write (∗ ,∗ ) c h a n n e l g r i d , c h a n n e l o u twrite (∗ ,∗ ) ’ E x e cu t io n w i l l now h a l t . ’

STOP

CASE DEFAULT

Page 24: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  23

write (∗ ,∗ ) ’ You h av e s e l e c t e d an u n r ec o g ni z ed case . ’write (∗ ,∗ ) ’ E x e cu t io n w i l l now h a l t . ’

STOP

END SELECT

V o u t f i l e =t r i m ( p ro bn am e ) / / ’ ’ / / t r i m ( V o ut b as e )U o u t f i l e =t r i m ( p ro bn am e ) / / ’ ’ / / t r i m ( U o ut b as e )open( unit =4 , f i l e= f i l e l i s t )

write ( 4 , ∗ ) f o r t ra n g r i dwrite ( 4 , ∗ ) g r id o u twrite ( 4 , ∗ ) V o u tf i le

WRITE( 4 , ∗ ) U o u tf i lec l o s e ( 4 )

END SUBROUTINE SETUP

SUBROUTINE LOADGRIDUSE MAINVARSUSE TEMPVARSimpl icit none

open( unit =1 , f i l e=f o r t r a n g r i d )! r ea d i n t he a rr ay s i z eread ( 1 , ∗ ) i l , j l! now a l l o c a t e

ALLOCATE(x ( i l +1, jl +1), y( i l +1, j l +1), Si ( i l +1, jl +1), Sj ( i l +1, jl +1), Sxi ( i l +1, jl +1), SyisxiM( i l +1, jl +1) ,sxjM( i l +1, j l +1), syiM( i l +1, jl +1) ,syjM( i l +1, j l +1))

! a l l o c a t e some t em po ra ry v a r i a b l e s a s w e 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(! a l l o c a t e U  

ALLOCATE(U(4 , i l +1, j l +1), Uc al ci (4 , i l +1, jl +1) , Uc al cj (4 , i l +1, jl +1))! a l l o c a t e m a tr i ce s

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 +! a l l o c a t e TEMP f l u x v e c t o r 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 v e c t or u se d f o r p r e ss u r e BC  

ALLOCATE(p ( i l +1, j l +1))read ( 1 , ∗ ) (( x( i , j ) , i =1, i l +1), j=1, jl +1)read ( 1 , ∗ ) (( y( i , j ) , i =1, i l +1), j=1, jl +1)c l o s e ( 1 )

DO i =1, i l +1DO j =1 , j l

Sx i ( i , j )=y( i , j +1)−y ( i , j )Sy i ( i , j )=x( i , j +1)−x ( i , j )

! i=i −1/2 

Page 25: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  24

Si ( i , j )=s qr t ( Sx i ( i , j ) ∗∗2. 0 d0+Syi ( i , j ) ∗∗2 . 0 d 0 )END DO

sx i ( i , j l +1)=s xi ( i , j l )sy i ( i , j l +1)=s yi ( i , j l )s i ( i , j l +1)= s i ( i , j l )

END DO

DO j =1, j l +1DO 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 )=sq rt ( Sxj ( i , j ) ∗∗2. 0 d0+Syj ( i , j ) ∗∗2 . 0 d 0 )

enddo

sx j ( i l +1, j)=s xj ( il , j )sy j ( i l +1, j)=s yj ( il , j )s j ( i l +1, j )= s j ( il , j )

enddo

DO i =1, i lDO j =1 , j l

V( i , j )=0.5 d0 ∗( 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

! n o r m a l iz e c o s i n e sSxi=Sxi/SiSxj=Sxj/SjSyi=Syi/SiSyj=Syj/Sj

do j =1, j l +1do i =2, i l +1

sxiM ( i , j )=−sx i ( i −1, j )syiM ( i , j )=−sy i ( i −1, j )

enddo

sxiM( 1 , j )=sxim( 2 , j )syim( 1 , j)=syim( 2 , j )

enddo

do i =1, i l +1

Page 26: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  25

do j =2, j l+1sxjM( 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

END SUBROUTINE LOADGRID

SUBROUTINE WRITEGRIDMLUSE MAINVARSimpl icit none

! co de t o o ut pu t g r id t o b e t t e r f or ma t  open( unit =2 , f i l e=grido ut )write ( 2 , ’ 1 I ’ ) i lwrite ( 2 , ’ 1 I ’ ) j lwrite (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)c l o s e ( 2 )

END SUBROUTINE WRITEGRIDML

SUBROUTINE WRITEGRIDUSE MAINVARSIMPLICIT NONE

open( unit =2 , f i l e=f o r t r a n g r i d )write ( 2 , ’ 1 I ’ ) i lwrite ( 2 , ’ 1 I ’ ) j lwrite ( 2 , ∗ ) (( x( i , j ) , i =1, i l +1), j=1, jl +1)write ( 2 , ∗ ) (( y( i , j ) , i =1, i l +1), j=1, jl +1)c l o s e ( 2 )

open( unit =3 , f i l e=grido ut )write ( 3 , ’ 1 I ’ ) i lwrite ( 3 , ’ 1 I ’ ) j lwrite (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)c l o s e ( 3 )

END SUBROUTINE WRITEGRID

SUBROUTINE GENCHANNELUSE MAINVARSIMPLICIT NONE

Page 27: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  26

REAL∗8 ddx , ddyi l=channe lx j l =c han ne ly

ddx=1.0d0/ db le ( i l )ddy=1.0d0/db le ( j l )

ALLOCATE(x ( i l +1, j l +1),y ( i l +1, j l +1))

DO i =1, i l +1DO j =1, j l +1

x ( i , j )=ddx∗db le ( i −1)y ( i , j )=ddx∗d b l e ( j −1)

END DO

END DO

c a l l WRITEGRIDEND SUBROUTINE GENCHANNEL

SUBROUTINE OUTPUTVOLUMESUSE MAINVARSIMPLICIT NONE

open( unit =2 , f i l e= V o u t f i l e )write ( 2 , ’ 1 I ’ ) i lwrite ( 2 , ’ 1 I ’ ) j lwrite (2 , ’1E ’ ) ((V( i , j ) , i =1, i l ) , j=1, j l )c l o s e ( 2 )

END SUBROUTINE OUTPUTVOLUMES

SUBROUTINE GETFLUX( Fi , Fj , CSi , SCi , CSj , SCj ,U, LPi ,LMi, LPj ,LMj)USE CONSTANTSUSE PARAMSUSE TEMPVARSIMPLICIT NONE

REAL∗8 , DIMENSION(4 , i l +1, j l +1) : : Fi , Fj ,U, LPi , LMi , LPj ,LMjREAL∗8 , DIMENSION(4 ,4 , i l +1, j l +1) : : CSi , SCi , SCj , CSj

INTEGER i , ji f ( method == 1) then

do i = 2 , i l −1do 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

Page 28: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  27

LCSUM=LMi ( : , i , j ) ∗CSUPCALL mult (FP, SCi (: , : , i , j ) ,LCSUP)CALL mul t (FM, SCi ( : , : , i , j ) ,LCSUM)Fi ( : , i , j )=FP+FM

! w r i t e (  ∗ , ’4 e ’) FPi ,FMi  enddo

enddo

do i =1, i ldo 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 ) ∗CSUPLCSUM=LMj ( : , i , j ) ∗CSUMCALL mult (FP, SCj ( : , : , i , j ) ,LCSUP)CALL mul t (FM, SCj ( : , : , i , j ) ,LCSUM)Fj ( : , i , j )=FP+FM

! w r i t e (  ∗ , ’4 e ’) FPj ,FMj  enddo

enddo

e l s e i f  (method == 0) then

do i = 2 , i l −1do 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 ) ∗CSUPLCSUM=LMi ( : , i +1 , j )∗CSUPCALL mult (FP, SCi (: , : , i , j ) ,LCSUP)CALL mult (FM, SCi ( : , : , i +1, j ) ,LCSUM)Fi ( : , i , j )=FP+FM

! w r i t e (  ∗ , ’4 e ’) FPi ,FMi  enddo

enddo

do i =1, i ldo 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 ) ∗CSUPLCSUM=LMj ( : , i , j +1)∗CSUMCALL mult (FP, SCj ( : , : , i , j ) ,LCSUP)CALL mul t (FM, SCj ( : , : , i , j +1) ,LCSUM)Fj ( : , i , j )=FP+FM

! w r i t e (  ∗ , ’4 e ’) FPj ,FMj  enddo

enddo

endif  

Page 29: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  28

i f ( prob lem==0) then

write (∗ , ’4 e ’) Fi ( : , i l /2−2: i l /2+2, j l /2)write (∗ ,∗ ) ’ . . . ’write (∗ , ’ 4 e ’ ) 0 . 5 d 0∗( Fi (: , i l /2−2, j l /2)+Fi ( : , i l /2+2, jl /2) )

endif  

END SUBROUTINE GETFLUX

SUBROUTINE MULT(AX,A,X)IMPLICIT NONE

REAL∗8 , DIMENSION( 4 , 4 ) : : AREAL∗8 , DIMENSION( 4 ) : : X ,AXAX(:)=A(: , 1 ) ∗X(1)+A(: ,2 ) ∗X(2)+A(: ,3 ) ∗X(3)+A(: ,4 ) ∗X ( 4 )

END SUBROUTINE MULT

SUBROUTINE GETMATRICES(CS , SC, LP, LM, Ubar , s x , sy )USE PARAMSUSE CONSTANTSUSE TEMPVARSIMPLICIT NONE

integer i , j

REAL∗8 , DIMENSION(4 , i l +1, jl +1) ,TARGET : : UbarREAL∗8 , DIMENSION(4 , i l +1, j l +1) : : LM,LPREAL∗8 , DIMENSION(4 ,4 , i l +1, j l +1) : : CS, SCREAL∗8 , DIMENSION( i l +1, j l +1) : : sx , syREAL∗8 , POINTER, DIMENSION( : , : ) : : r ho , r ho u , r ho v , E

rho=>Ubar ( 1 , : , :)rhou=>Ubar ( 2 , : , :)rhov=>Ubar ( 3 , : , :)E=>Ubar ( 4 , : , :)uu=rhou/rhovv=rhov/rhouv2=uu∗uu+vv∗vvT=(E−0. 5∗ rho∗uv2 )/( rho∗cv )a=sqrt (gamma∗R∗T)

GMA=(gamma−1)/(a∗a )sxr=sx/rhosyr=sy/rhorhosum=rhou∗a∗ sx+rhov∗a∗ syuprime=uu∗ sx+vv∗ sy

! do i =1, i l  ! do j =1, j l  

Page 30: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  29

! w r 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 d0−0.5d0∗gma∗uv2CS( 1 ,2 ,: , : )= gma∗uuCS( 1 ,3 ,: , : )= gma∗vvCS(1 ,4 ,: ,:) = −gmaCS(2 ,1 ,: , : )= −0 . 5 d 0∗ s x r ∗uu/a−0.5d0∗ s y r ∗vv/a+0.25d0∗gma∗uv2/rhoCS ( 2 , 2 , : , : ) = 0 . 5 d 0∗ s x r / a−0.5d0∗gma∗uu/rhoCS ( 2 , 3 , : , : ) = 0 . 5 d 0∗ s y r / a−0.5d0∗gma∗vv/rhoCS ( 2 , 4 , : , : ) = 0 . 5 d 0∗gma/rhoCS(3 ,1 , : , :) = syr ∗uu−s x r ∗vvCS(3 ,2 ,: ,:) = − s y rCS(3 ,3 , : , :) = sxrCS(3 ,4 , : , :) =0CS ( 4 , 1 , : , : ) = 0 . 5 d 0∗ s x r ∗uu/a+0.5d0 ∗ s y r ∗vv/a+0.25d0∗gma∗uv2/rhoCS(4 ,2 ,: , : )= −0 . 5 d 0∗ s x r / a−0.5d0∗gma∗uu/rhoCS(4 ,3 ,: , : )= −0 . 5 d 0∗ s y r / a−0.5d0∗gma∗vv/rhoCS ( 4 , 4 , : , : ) = 0 . 5 d 0∗gma/rho

SC(1 ,1 , : , :) =1SC( 1 ,2 ,: , :) = rhoSC(1 ,3 , : , :) =0SC( 1 ,4 ,: , :) = rhoSC(2 ,1 , : , : )= uuSC( 2 ,2 ,: , :) = rhou+rho ∗a∗ sxSC(2 ,3 ,: ,:) = − rho∗ sySC( 2 ,4 ,: , :) = rhou−rho∗a∗ sxSC(3 ,1 , : , :) = vvSC( 3 ,2 , : , : )= rhov+rho ∗a∗ sySC( 3 ,3 ,: , :) = rho ∗ sxSC( 3 ,4 ,: , :) = rhov−rho∗a∗ sySC ( 4 , 1 , : , : ) = 0 . 5 d 0∗uv 2SC ( 4 , 2 , : , : ) = 0 . 5 d 0∗uv 2∗ rho+rhosum+rho/gmaSC(4 ,3 ,: ,:) = − rhou∗ sy+rhov∗ sxSC ( 4 , 4 , : , : ) = 0 . 5 d 0∗uv 2∗ rh o−rhosum+rho/gma

g l i t c h = ( g l i t c h c o r r ∗a )∗∗2 . 0 d 0LP ( 1 , : , : ) = 0 . 5 d 0∗( uprime+sqr t ( uprime ∗∗2 . 0 d 0+ g l i t c h ) )LP ( 2 , : , : ) = 0 . 5 d 0∗( uprime+a+sq rt (( uprime+a ) ∗∗2 . 0 d 0 + g l i t c h ) )LP ( 3 , : , : ) = LP ( 1 , : , : )LP ( 4 , : , : ) = 0 . 5 d 0∗(uprime−a+sqr t (( uprime−a )∗∗2 . 0 d 0 + g l i t c h ) )

LM(1 , : , :) =0 .5 d0 ∗(uprime−sq rt (uprime ∗∗2 . 0 d 0+ g l i t c h ) )

Page 31: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  30

LM(2 , : , :) =0 .5 d0 ∗(uprime+a−sq rt ( ( uprime+a ) ∗∗2 . 0 d 0 + g l i t c h ) )LM(3 ,: ,:) =LM(1 , : , : )LM(4 , : , :) =0 .5 d0 ∗(uprime−a−sq rt (( uprime−a )∗∗2 . 0 d 0 + g l i t c h ) )

END SUBROUTINE GETMATRICES

SUBROUTINE CALCDT(DT,U, dx , dy )USE SETTINGSUSE PARAMSUSE TEMPVARSIMPLICIT NONE

REAL∗8 DTREAL∗8 , DIMENSION(4 , i l +1, j l +1) : : UREAL∗8 , DIMENSION( i l +1, j l +1) : : dx , dyuu=U( 2 , : , : ) /U( 1 , : , : )v v=U ( 3 , : , : ) / U ( 1 , : , : )

! w r 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( ab+a ( 2 : i l , 2 : j l ) ∗ s q r t ( 1 / ma xv al ( a bs ( dx ( 2 : i l , 2 : j l ) ) ) ∗∗2.0d0+1/maxval(abs(dy(2: i l

write (∗ ,∗ ) ”DT: ” ,DT

END SUBROUTINE CALCDT

SUBROUTINE SETICSUSE MAINVARSIMPLICIT NONE

SELECT CASE(problem)CASE( 0 ) ! Assignment 3  

U(1 ,1 : i l /2 , :)= rhoin f01U(2 ,1 : i l /2 , :)= rhoin f01 ∗ sq rt (Minf01 ∗Minf01 ∗gamma∗R∗Tinf01−v i n f 0 1 )U(3 ,1 : i l /2 , :)= rhoin f01 ∗ v i n f 0 1U ( 4 , 1 : i l / 2 , : ) = ( ( r h o i n f 0 1 ∗cv ∗Tinf01+0.5d0∗ r h o i n f 0 1 ∗Minf01 ∗Minf01 ∗gaU(1 , i l /2+1: i l , :) = rhoi nf0 2U(2 , i l /2+1: i l , :) = rhoi nf0 2 ∗ sq rt (Minf02 ∗Minf02 ∗gamma∗R∗Tinf02−v i n f 0 2U(3 , i l /2+1: i l , :) = rhoi nf0 2 ∗ v i n f 0 2U(4 , i l /2+1: i l , : )= (( rho inf 02 ∗cv ∗Tinf02+0.5d0∗ r h o i n f 0 2 ∗Minf02 ∗Minf02s x i =s q r t ( 3 . 0 d 0 ) / 2 . 0 d0sy i =0.5d0

CASE( 1 ) ! channe l  Tinf=Tinf1p i n f = p i n f 1Minf=Minf1r h o i n f = p i n f / (R∗Tinf )a i n f=sq rt (gamma∗R∗Tinf )

Page 32: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  31

rhouinf=Minf  ∗ a i n f  ∗ r h o i n f  r h o v i n f = 0E i n f = r h o i n f  ∗cv∗Tinf+0.5d0∗ r h o u i n f  ∗ r h o u i n f / r h o i n f  Fj (1 , : , :) =0Fj (2 , : , :) =0F j ( 3 , : , : ) = p i n f  Fj (4 , : , :) =0F i ( 1 , : , : ) = r h o u i n f  F i ( 2 , : , : ) = r h o u i n f  ∗Minf  ∗ a i n f + p i n f  Fi (3 , : , :) =0Fi (4 , : , :) =( Einf+pi nf ) ∗Minf  ∗ a i n f  

! f l i p f l ow f o r t e s t i n g and v a l i d a t io n  ! r h o v i n f = r h o u i n f  ! rhoui nf=0  

U ( 1 , : , : ) = r h o i n f  U ( 2 , : , : ) = r h o u i n f  U ( 3 , : , : ) = r h o v i n f  U ( 4 , : , : ) = E i n f  

CASE( 2 ) !rampTinf=Tinf2p i n f = p i n f 2Minf=Minf2

r h o i n f = p i n f / (R∗Tinf )a i n f=sq rt (gamma∗R∗Tinf )rhouinf=Minf  ∗ a i n f  ∗ r h o i n f  r h o v i n f = 0E i n f = r h o i n f  ∗cv∗Tinf+0.5d0∗ r h o u i n f  ∗ r h o u i n f / r h o i n f  U ( 1 , : , : ) = r h o i n f  U ( 2 , : , : ) = r h o u i n f  U ( 3 , : , : ) = r h o v i n f  U ( 4 , : , : ) = E i n f  

Fj (1 , : , :) =0Fj (2 , : , :) =0F j ( 3 , : , : ) = p i n f  Fj (4 , : , :) =0F i ( 1 , : , : ) = r h o u i n f  F i ( 2 , : , : ) = r h o u i n f  ∗Minf  ∗ a i n f + p i n f  Fi (3 , : , :) =0

Page 33: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  32

Fi (4 , : , :) =( Einf+pi nf ) ∗Minf  ∗ a i n f  sx j ( i l +1,:)=0sy j ( i l +1,:)=1s x i ( : , j l +1)=1s y i ( : , j l +1)=0

CASE( 3 ) ! c y l i n d e r  

! Mach 5 i n f l o w  Tinf=Tinf3p i n f = p i n f 3Minf=Minf3

r h o i n f = p i n f / (R∗Tinf )a i n f=sq rt (gamma∗R∗Tinf )rhouinf=Minf  ∗ a i n f  ∗ r h o i n f  r h o v i n f = 0E i n f = r h o i n f  ∗cv∗Tinf+0.5d0∗ r h o u i n f  ∗ r h o u i n f / r h o i n f  

! F i l l e ve ry t hi ng w it h f lo w t o s t a r t  U ( 1 , : , : ) = r h o i n f  U ( 2 , : , : ) = r h o u i n f  U ( 3 , : , : ) = r h o v i n f  U ( 4 , : , : ) = E i n f  

! e s t a b l i s h i n i t i a l f l ux e s a ls oFj (1 , : , :) =0Fj (2 , : , :) =0F j ( 3 , : , : ) = p i n f  Fj (4 , : , :) =0F i ( 1 , : , : ) = r h o u i n f  F i ( 2 , : , : ) = r h o u i n f  ∗Minf  ∗ a i n f + p i n f  Fi (3 , : , :) =0Fi (4 , : , :) =( Einf+pi nf ) ∗Minf  ∗ a i n f  

CASE DEFAULT

write (∗ ,∗ ) ’WTF Mate? ’write (∗ ,∗ ) ’ E x e cu t io n w i l l now h a l t . ’

STOP

END SELECT

END SUBROUTINE SETICS

Page 34: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  33

SUBROUTINE SETBCSUSE MAINVARSIMPLICIT NONE

REAL∗8 , PARAMETER : : wallc urv e =.1REAL∗8 , POINTER, DIMENSION( : , : ) : : r ho , r ho u , r ho v , EREAL∗8 , DIMENSION( i l +1, j l +1) : : uprimei , uprimej , upr imei inf , upr ime jin f  

rho=>U ( 1 , : , : )rhou=>U ( 2 , : , : )rhov=>U ( 3 , : , : )E=>U ( 4 , : , : )uprimei=rhou/rho ∗ sxi+rhov/rho∗ s y iuprimej=rhou/rho ∗sxjm+rhov/rho ∗ s y ju p r i m e i i n f = r h o u i n f / r h o i n f  ∗ s x i + r h o v i n f / r h o i n f  ∗ s y iu p r i m e j i n f = r h o u i n f / r h o i n f  ∗ s x j m + r h o v i n f / r h o i n f  ∗ s y i

p=(gamma−1.0d0)∗ (E−0.5d0/rho ∗( r h o u∗ rhou+rhov∗ rhov ))SELECT CASE(problem)

case ( 0 ) ! a s s i g n m e n t 3  ! d o n o t h in g , don ’ t c a r e a b o ut b o u n d a r i e s! j u s t a 1 t im e s t e p p ro bl em i n m id dl e o f domain  

CASE( 1 ) ! channe l  ! f o r t h e c ha nn el we c an j u s t k ee p t h e ICs a t t h e b ou nd ar y  

! g e t P on e g r i d s pa ce a bo ve w a l l  

CASE( 2 ) ! r am pe d c h a n n e l  ! i n f l o w  F j ( 1 , 1 , : ) = 0F j ( 2 , 1 , : ) = 0F j ( 3 , 1 , : ) = p i n f  F j ( 4 , 1 , : ) = 0Fi (1 ,1 , :)= rhoui nf  Fi (2 ,1 , :)= rhoui nf  ∗Minf  ∗ a i n f + p i n f  Fi (3 ,1 ,:) =0Fi (4 ,1 , : )=( Einf+pinf ) ∗Minf  ∗ a i n f  

! o u t f l o w  F j ( 1 , i l , : ) = r h o ( i l −1 ,:)∗ u p r i m e j ( i l −1 ,:)Fj (2 , i l , :) = rhou( i l −1 ,:)∗ u p r i m e j ( i l −1,:)+p( i l −1 ,:)∗ sxjm( i l −1 ,:)Fj (3 , i l , :) = rhov( i l −1 ,:)∗ u p r i m e j ( i l −1,:)+p( i l −1 ,:)∗ sy j ( i l −1 ,:)F j ( 4 , i l , : ) = ( E ( i l −1,:)+p( i l −1 , :))∗ u p r i m e j ( i l −1 ,:)

Fi (1 , i l , :) = rho ( i l −1 ,:)∗ upr imei ( il −1 ,:)Fi (2 , i l , : )= rhou ( il −1 ,:)∗ upr imei ( il −1,:)+p( i l −1 ,:)∗ sx i ( i l −1 ,:)

Page 35: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  34

Fi (3 , i l , :) = rhov( i l −1 ,:)∗ upr imei ( il −1,:)+p( i l −1 ,:)∗ sy i ( i l −1 ,:)Fi (4 , i l , : )= (E( i l −1,:)+p( i l −1 , :))∗ upri mei ( il −1 ,:)

! w it h no c u rv a tu r e t o t h e w a ll , p r e ss u r e a t w a l l s h ou l d match t h i s! e n t r i e s 2 and 3 i n F wa ll a re f u n ct i on s o f p r es s ur e and c os i ne! e n t r i e s 1 and 4 a re 0  F j ( 1 , : , 1 ) = 0F j ( 2 , : , 1 ) = p ( : , 2 ) ∗ ( sxjm (: ,1 ) )F j ( 3 , : , 1 ) = p ( : , 2 ) ∗ ( s y j ( : , 1 ) )F j ( 4 , : , 1 ) = 0

! now d o i t a t t o p b oun d  ! r emember p i s t a k en a h a l f  −i n d e x r em ov ed f ro m F i n d e x ( i =i  −1 /2 , n  

Fj (1 ,: , j l )=0Fj (2 , : , j l )=p( : , j l ) ∗ ( sxjm (: , j l ))Fj (3 , : , j l )=p( : , j l ) ∗ ( s y j ( : , j l ) )Fj (4 ,: , j l )=0

CASE( 3 ) ! c y l i n d e r  ! i n f l o w @ j l  

! o u t f l o w a t i = 2, i l  F j ( 1 , i l , : ) = r h o ( i l −1 ,:)∗ u p r i m e j ( i l −1 ,:)Fj (2 , i l , :) = rhou( i l −1 ,:)∗ u p r i m e j ( i l −1,:)+p( i l −1 ,:)∗ sxjm( i l −1 ,:)Fj (3 , i l , :) = rhov( i l −1 ,:)∗ u p r i m e j ( i l −1,:)+p( i l −1 ,:)∗ sy j ( i l −1 ,:)F j ( 4 , i l , : ) = ( E ( i l −1,:)+p( i l −1 , :))∗ u p r i m e j ( i l −1 ,:)

Fi (1 , i l , :) = rho ( i l −1 ,:)∗ upr imei ( il −1 ,:)Fi (2 , i l , : )= rhou ( il −1 ,:)∗ upr imei ( il −1,:)+p( i l −1 ,:)∗ sx i ( i l −1 ,:)Fi (3 , i l , :) = rhov( i l −1 ,:)∗ upr imei ( il −1,:)+p( i l −1 ,:)∗ sy i ( i l −1 ,:)Fi (4 , i l , : )= (E( i l −1,:)+p( i l −1 , :))∗ upri mei ( il −1 ,:)

Fj (1 ,1 , :)= rho (2 , :) ∗ u p r i m e j ( 2 , : )F j ( 2 , 1 , : ) = r h ou ( 2 , : ) ∗ u p r i m e j ( 2 , : ) + p ( 2 , : ) ∗ sxjm (2 , :)Fj (3 ,1 , :)= rhov (2 , :) ∗ u p r i m e j ( 2 , : ) + p ( 2 , : ) ∗ s y j ( 2 , : )F j ( 4 , 1 , : ) = ( E ( 2 , : ) + p ( 2 , : ) ) ∗ u p r i m e j ( 2 , : )

Fi (1 ,1 ,:)= rho (2 , :) ∗ u p r i m e i ( 2 , : )Fi (2 ,1 , :)= rhou (2 , :) ∗ u p r i m e i ( 2 , : ) + p ( 2 , : ) ∗ s x i ( 2 , : )

Page 36: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  35

Fi (3 ,1 ,:)= rhov (2 , :) ∗ u p r i m e i ( 2 , : ) + p ( 2 , : ) ∗ s y i ( 2 , : )F i ( 4 , 1 , : ) = ( E ( 2 , : ) + p ( 2 , : ) ) ∗ u p r i m e i ( 2 , : )

! now s e t up s u rf a ce , u s in g c u rv a tu r e f o r t h e c ur ve d s u r f ac e! j=1F j ( 1 , : , 1 ) = 0

! Fj ( 2 , : , 1 ) = ( p ( : , 2 ) + S i ( : , 2 ) ∗ rho (: ,2 ) ∗ ( rhou (: , 2) ∗ rhou(: ,2)+ rhov (: , 2) ∗! Fj ( 3 , : , 1 ) = ( p ( : , 2 ) + S i ( : , 2 ) ∗ rho (: ,2 ) ∗ ( rhou (: , 2) ∗ rhou(: ,2)+ rhov (: , 2) ∗

F j ( 2 , : , 1 ) = ( p ( : , 2 ) ∗ ( s xj m ( : , 1 ) ) )F j ( 3 , : , 1 ) = ( p ( : , 2 ) ∗ ( s y j ( : , 1 ) ) )F j ( 4 , : , 1 ) = 0

! i n f l o w  Fj (1 , : , j l )=r ho in f  ∗ u p r i m e j i n f ( : , j l )Fj (2 , : , j l )=rh oui nf  ∗ u p r i m e j i n f ( : , j l )+ p i n f  ∗sxjm ( : , j l )Fj (3 , : , j l )=r hov inf  ∗ u p r i m e j i n f ( : , j l )+ p i n f  ∗ s y j ( : , j l )Fj (4 , : , j l )=(Ein f+pin f ) ∗ u p r i m e j i n f ( : , j l )Fi (1 , : , j l )=r ho in f  ∗ u p r i m e i i n f ( : , j l )Fi (2 , : , j l )=rh oui nf  ∗ u p r i m e i i n f ( : , j l )+ p i n f  ∗ s x i ( : , j l )Fi (3 , : , j l )=r hov inf  ∗ u p r i m e i i n f ( : , j l )+ p i n f  ∗ s y i ( : , j l )Fi (4 , : , j l )=(Ein f+pin f ) ∗ u p r i m e i i n f ( : , j l )

CASE DEFAULT

write (∗ ,∗ ) ’WTF Mate? ’write (∗ ,∗ ) ’ E x e cu t io n w i l l now h a l t . ’

STOP

END SELECT

END SUBROUTINE SETBCS

SUBROUTINE WRITE4VEC(U, Uoutfile , cull )USE PARAMSIMPLICIT NONE

REAL∗8 , DIMENSION(4 , i l +1, j l +1) : : Ucharacter ( le n =20) U o u t f i l einteger i , jinteger c u l lwrite (∗ ,∗ ) ” W r it i ng : ” , U o u t f i l eopen( unit =5 , f i l e= U o u t f i l e )write ( 5 , ’ 1 I ’ ) i l −c u l lwrite ( 5 , ’ 1 I ’ ) j l −c u l lwrite ( 5 , ’ 4 E ’ ) ( ( U ( : , i , j ) , i = 1, i l −c u l l +1 ) , j = 1, j l −c u l l + 1 )c l o s e ( 5 )

END SUBROUTINE WRITE4VEC

Page 37: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  36

SUBROUTINE GETUCALC( Ucalci , Ucalcj ,U)USE PARAMSUSE SETTINGSIMPLICIT NONE

REAL∗8 , DIMENSION(4 , i l +1, j l +1) : : Ucalci , Ucalcj ,UINTEGER i , jSELECT CASE(method)

CASE( 0 )! S t an da rd S t e g e r Warming , don ’ t a c t u a l l y do any a v er a gi n g , j u s t s h o ot b ac k  

Uc al ci=UUc al cj=U

CASE( 1 )! M o d i f i e d S t e g e r  −Warming , averag e U Valuesdo i =1, i l

U c a l c i ( : , i , : ) = 0 . 5 d0 ∗(U(: , i , :)+U( : , i +1 , :))enddo

do j =1 , j lUca lcj ( : , : , j )=0.5d0 ∗(U(: , : , j)+U( : , : , j +1))

enddo

END SELECT

END SUBROUTINE GETUCALC

SUBROUTINE ADVANCETIME(U, DT, Fi , Fj , Si , Sj ,V, m a x d if f )USE PARAMSUSE SETTINGSIMPLICIT NONE

integer i , j , kREAL∗8 , DIMENSION(4 , i l +1, j l +1) : : U, Fi , Fj ,DUREAL∗8 , DIMENSION( i l +1, j l +1) : : Si , Sj ,VREAL∗8 DT, maxd iff  

do k=1,4do i =2, i l

do j = 2, j lDU(k , i , j )=−DT/V( i , j ) ∗ ( Fi (k , i , j ) ∗ Si ( i , j )−F i ( k , i −1, j )∗ S i ( i −1 , j ) &

+Fj (k , i , j ) ∗ Sj ( i , j )−Fj( k , i , j −1)∗S j ( i , j −1) )! writ e (  ∗ ,∗) i , j ,DU(k , i , j )

enddo

enddo

enddo

m a x d i f f=m ax va l ( a b s (DU ( : , 2 : i l , 2 : j l ) ) ) / m ax va l ( a b s ( U ( : , 2 : i l , 2 : j l ) ) )do k=1,4

do i =2, i ldo j = 2, j l

U(k , i , j )=U(k , i , j )+DU(k , i , j )

Page 38: Finite Volume Code for Compressible Flow

 

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT  37

enddo

enddo

enddo

! w r i t e (  ∗ ,∗) (( Sj ( i , j ) , i=1, i l ) , j =1, j l )! w r i t e (  ∗ ,∗) DU(1: i l ,1 : j l )! w r i t e (  ∗ ,∗) m a xd if f  

END SUBROUTINE ADVANCETIME