finite volume code for compressible flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005....

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

Upload: others

Post on 01-Mar-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

Finite Volume Code for Compressible Flows

Matt Stegmeir

May 16, 2005

AEM8251: Finite Volume Methods

1

Page 2: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 FluxVector 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′ + ps′xρvu′ + ps′y(E + p)u′

(1)

s′x and s′y are the direction cosines in the x and ydirections and u′ is the normal velocity us′x + us′y.

U =

ρρuρvE

(2)

V =

ρuvp

(3)

A′ =∂F ′

∂U=

∂U

∂V

∂V

∂U

∂F ′

∂V

∂V

∂U(4)

Thus, F ′ = A′U . 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 shalldenote 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,jUi,j + A′

−i+1,jUi+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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 ofusing A′

+i,j and A′−i,j+1 an averaged Jacobian is

computed.

A′±i+ 1

2 ,j = A′±(

12(Ui,j + Ui+1,j) (6)

and used as follows:

F ′i+ 1

2 ,j

= F ′+i,j + F ′

−i+1,j

= A′+i+ 1

2 ,jUi,j + A′

−i+ 12 ,j

Ui+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 ofa 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,± =12(u′ ±

√u′2 + ε2) (8)

ε is commonly defined as some small fraction ofsound 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

Vi,j

(F ′

i+ 12 ,j

Si+ 12 ,j − F ′

i− 12 ,j

Si− 12 ,j

+F ′i,j++ 1

2Si,j+ 1

2− F ′

i,j− 12Si,j− 1

2

)(9)

Vi,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 =CFL

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:

δUni,j =

−∆t

Vi,j

(F ′

i+ 12 ,j

Si+ 12 ,j − F ′

i− 12 ,j

Si− 12 ,j

+F ′i,j++ 1

2Si,j+ 1

2− F ′

i,j− 12Si,j− 1

2

)n+1

(11)This δU is then used to compute a new U .

Un+1i,j = Un

i.j + δUni,j (12)

Page 4: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 ofthe 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 of0.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 offof 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 18o. 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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 18o 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 ofthe final project code included in Appendix D.

Figure 3: Pressure Contours

Figure 4: Temperature Contours

Page 6: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

5 RAMP CHANNEL FLOW 5

Figure 5: Streamlines

Figure 6: Velocity Vectors

Page 7: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 ofa 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 ofthis 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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

8 FUTURE WORK 8

Figure 14: Velocity Vectors

Page 10: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

A PREVIOUS WORK 10

Figure 16: 141 Grid Points Used

Page 12: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

A PREVIOUS WORK 11

Figure 17: 281 Grid Points Used

Page 13: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 : Fav =

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

Pure Steger −Warming : FS−W =

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

Modified Steger −Warming : FM−S−W =

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

Modified Steger −Warming with ε = 0.1a : FM−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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

B MATRIX CALCULATIONS 13

BM

atr

ixC

alc

ula

tions

CS

1−

1 2

(γ−

1)(u

2+

v2)

a2

(γ−

1)u

a2

(γ−

1)v

a2

−(γ−

1)

a2

−1 2

s′ xu

aρ−

1 2

s′ yv

+1 4

(γ−

1)(u

2+

v2)

ρa2

1 2s′ x

aρ−

1 2(γ−

1)u

ρa2

1 2

s′ y

aρ−

1 2(γ−

1)v

ρa2

1 2(γ−

1)

ρa2

s′ yu

ρ−

s′ xv

ρ−

s′ y ρ

s′ x ρ

0

1 2s′ xu

+1 2

s′ yv

+1 4

(γ−

1)(u

2+

v2)

ρa2

−1 2

s′ x

aρ−

1 2(γ−

1)u

ρa2

−1 2

s′ y

aρ−

1 2(γ−

1)v

ρa2

1 2(γ−

1)

ρa2

S′∗

C′

1

ρ0

ρ

u+

ρas′ x

−ρs′ y

ρu−

ρas′ x

v+

ρas′ y

ρs′ x

ρv−

ρas′ y

1 2u

2+

1 2v2( 1 2

u2

+1 2

v2) ρ

uas′ x

vas′ y

a2

(γ−

1)

−ρ

us′ y

vs′ x

( 1 2u

2+

1 2v2) ρ−

ρuas′ x−

ρvas′ y

a2

(γ−

1)

Page 15: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

C CODE FOR ASSIGNMENT 2 14

C Code for Assignment 2

PROGRAM ASS2

implicit none! S imulat ion s e t t i n g s

INTEGER, 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 ength =.1∗141

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

! computed v a r i a b l e sREAL∗8 ,PARAMETER : : dx=length / g r i d s i z eINTEGER iREAL∗8 t , dtREAL∗8 , DIMENSION(3 , g r i d s i z e ) : : U, Fplus , Fminus !U=rho , rhou , E, uREAL∗8 , dimension ( g r i d s i z e ) : : uu , TT, x

write (∗ ,∗ ) ’ dx ’ , dxt=0ca l l s e t ICs (U,gamma,R, g r i d s i z e )uu=U( 2 , : ) /U( 1 , : ) ! c a l c u l a t e u from rhou and rho

ca l l getdt (uu , g r i d s i z e ,CFL, dx , dt )! t=tmax−dtwrite (∗ ,∗ ) t , tmax , dtDO WHILE ( t < tmax)write (∗ ,∗ ) t

ca l l getdt (uu , g r i d s i z e ,CFL, dx , dt )! wr i t e (∗ ,∗ ) t , d tt=t+dtca 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 −1

U( : , i )=U( : , i )−dt/dx∗( Fplus ( : , i )+Fminus ( : , i+1)−Fplus ( : , i−1)−Fminus ( : , i ) )END DOuu=U( 2 , : ) /U( 1 , : )

END DO! do i =1, g r i d s i z e! wr i t e (∗ ,∗ ) i! wr i t e (∗ ,∗ ) Fplus ( : , i )

Page 16: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

C CODE FOR ASSIGNMENT 2 15

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

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

x ( i )=x( i−1)+dxEND DOopen(unit=911 , f i l e=”U. out” )write (911 ,∗ ) Uclose (911)open(unit=911 , f i l e=”x . out” )write (911 , ’ 1 F10 . 1 ’ ) xclose (911)

ENDPROGRAM

SUBROUTINE s e t ICs (U,gamma,R, g r i d s i z e )! checked

implicit none

! l i s t ICs in human−r eadab l e formREAL∗8 , PARAMETER : : r h o l e f t =1.0REAL∗8 , PARAMETER : : r ho r i gh t =0.5REAL∗8 , PARAMETER : : T l e f t =300.0REAL∗8 , PARAMETER : : Tright=600REAL∗8 , PARAMETER : : u l e f t =1000REAL∗8 , PARAMETER : : u r i gh 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 ha l fh a l f=( g r i d s i z e −1)/2CV=(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 )= rho r i gh 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 )= rho r i gh t ∗ ur i ghtU( 3 , 1 : h a l f )= r h o l e f t ∗(CV∗Tl e f t +1.0/2.0∗ u l e f t ∗∗2 .0 d0 )U(3 , h a l f +1: g r i d s i z e )= rho r i gh t ∗(CV∗Tright +1.0/2.0∗ ur i ght ∗∗2 .0 d0 )

Page 17: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

C CODE FOR ASSIGNMENT 2 16

END SUBROUTINE

SUBROUTINE getF (U, uu , Fplus , Fminus ,TT,gamma,R, g r i d s i z e )implicit noneINTEGER g r i d s i z e , iREAL∗8 , DIMENSION( g r i d s i z e ) : : uu ,TT, p , a , c o e f f , term1 , term2 , term3REAL∗8 , DIMENSION(3 , g r i d s i z e ) : : U, Fplus , Fminus ,LP,LMREAL∗8 gamma,R,CV, gm1

gm1=gamma−1CV=R/(gamma−1.0d0 )TT=(U(3 , : ) −0 .5 d0∗U(1 , : ) ∗ uu∗∗2 .0 d0 )/ (U( 1 , : ) ∗CV)a=sq r t (gamma∗R∗TT)p=(gamma−1)∗(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 ∗(uu−a+abs (uu−a ) )LM(1 , : )=0 . 5 d0 ∗(uu−abs (uu ) )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! 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!

Fplus ( 1 , : )=0 . 5 d0/a ∗∗2 .0 d0 ∗(LP( 1 , : ) ∗ 2 . 0 d0 ∗(U( 1 , : ) ∗ a ∗∗2 .0 d0−p)+p∗(LP(2 , : )+LP( 3 , : ) ) )Fplus ( 2 , : )=0 . 5 d0/a ∗∗2 .0 d0 ∗(LP( 1 , : ) ∗ 2 . 0 d0∗uu∗(U( 1 , : ) ∗ a ∗∗2 .0 d0−p)+LP( 2 , : ) ∗ ( p∗uu+p∗a)+LP( 3 , : ) ∗ ( p∗uu−p∗a ) )Fminus (1 , : )=0 . 5 d0/a ∗∗2 .0 d0 ∗(LM( 1 , : ) ∗ 2 . 0 d0 ∗(U( 1 , : ) ∗ a ∗∗2 .0 d0−p)+p∗(LM(2 , : )+LM( 3 , : ) ) )Fminus (2 , : )=0 . 5 d0/a ∗∗2 .0 d0 ∗(LM( 1 , : ) ∗ 2 . 0 d0∗uu∗(U( 1 , : ) ∗ a ∗∗2 .0 d0−p)+LM( 2 , : ) ∗ ( p∗uu+p∗a)+LM( 3 , : ) ∗ ( p∗uu−p∗a ) )Fplus (3 , : )=(U(3 , : )+p)∗uu

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

c o e f f =0.25d0/a ∗∗2 .0 d0term1=2.0d0∗uu∗∗2 .0 d0 ∗(U( 1 , : ) ∗ a ∗∗2 .0 d0−p)term2=p∗(uu∗∗2 .0 d0+2.0d0∗a∗uu+2.0d0∗a ∗∗2 .0 d0/gm1)term3=p∗(uu∗∗2 .0 d0−2.0d0∗a∗uu+2.0d0∗a ∗∗2 .0 d0/gm1)Fplus (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 )

Page 18: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 ) , Fplus (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)!! Fplus (1 , : )=1.0/2 .0∗U(1 , : )∗ ( uu+abs (uu ))! Fplus (2 , : )=1.0/2 .0∗U(2 , : )∗ ( uu+abs (uu ))! ! Fplus (3 , : )=1.0 d0 /4.0 d0∗U(1 , : ) ∗ ( 2 . 0 d0∗CV∗TT∗uu &! ! +2.0d0∗ abs (uu )∗CV∗TT &! ! +uu ∗∗3.0 d0 &! ! +abs (uu )∗uu ∗∗2.0 d0 )! !! Fplus (3 , : )=1.0 d0 /4.0 d0∗U(1 , : ) ∗ ( 2 . 0 d0∗CV∗TT∗uu &! +2.0d0∗ abs (uu )∗CV∗TT &! +uu ∗∗3.0 d0 &! +abs (uu )∗uu ∗∗2.0 d0 )!!! Fminus (1 , : )=1.0/2 .0∗U(1 , : )∗ ( uu−abs (uu ))! Fminus (2 , : )=1.0/2 .0∗U(2 , : )∗ ( uu−abs (uu ))! Fminus (3 , : )=1.0 d0 /4.0 d0∗U(1 , : ) ∗ ( 2 . 0 d0∗CV∗TT∗uu &! −2.0d0∗ abs (uu )∗CV∗TT &! +uu ∗∗3.0 d0 &! −abs (uu )∗uu ∗∗2.0 d0 )

END SUBROUTINE

SUBROUTINE getdt (U, g r i d s i z e ,CFL, dx , dt )implicit noneREAL∗8 dx , dt ,CFLinteger g r i d s i z eREAL∗8 , DIMENSION( g r i d s i z e ) : : U

Page 19: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 g e r f l a g to s e t which problem to s o l v e .! problems numbered as in p r o j e c t s ta tement! Option 4 genera t e s a p l a i n r e c t angu l a r g r i d! from 0:1 in both dimensions wi th number o f! d i v i s i o n s determined by channelx and channely! problem 0 i s homework s e t 3INTEGER, PARAMETER : : problem=0! method : 0=SW,1=MSWINTEGER, PARAMETER : : method=1! son ic g l i t c h co r r e c t i on as f r a c t i o n o f sound speedREAL∗8 , PARAMETER : : g l i t c h c o r r = 0 .0! t ime advancement scheme , 1= e x p l i c i tINTEGER, PARAMETER : : timeadv=1REAL∗8 , PARAMETER : : CFL=0.005! 0 .005 f o r c y lINTEGER, PARAMETER : : channelx=20INTEGER, PARAMETER : : channely=20REAL∗8 , PARAMETER : : Minf1=2REAL∗8 , PARAMETER : : Minf2=2.5REAL∗8 , PARAMETER : : Minf3=5REAL∗8 , PARAMETER : : p in f 1 =100000REAL∗8 , PARAMETER : : Tinf1=300REAL∗8 , PARAMETER : : p in f 2 =100000REAL∗8 , PARAMETER : : Tinf2=300REAL∗8 , PARAMETER : : Tinf3=300REAL∗8 , PARAMETER : : p in f 3 =100000REAL∗8 , PARAMETER : : Minf01=1.1REAL∗8 , PARAMETER : : Minf02=0.9REAL∗8 , PARAMETER : : r ho in f 01 =1.0d0REAL∗8 , PARAMETER : : r ho in f 02 =1.02d0REAL∗8 , PARAMETER : : Tinf01 =300.0d0REAL∗8 , PARAMETER : : Tinf02 =310.0d0REAL∗8 , PARAMETER : : v in f 01 =0.0d0REAL∗8 , PARAMETER : : v in f 02 =10.0d0

ENDMODULE SETTINGS

Page 20: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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.14159

ENDMODULE CONSTANTS

MODULE PARAMS! S torage f o r any constants , f o r example f i l e names t ha t are! s e l e c t e d from by s e t t i n g the problem f l a g .character ( len=20) , PARAMETER : : channe lg r id=”channel−g r id . dat”character ( len=20) , PARAMETER : : c y l i n d e r g r i d=” cy l inde r−g r id . dat”character ( len=20) , PARAMETER : : rampgrid=”ramp−g r id . dat”

character ( len=20) , PARAMETER : : channelout=”channel−g r id . out”character ( len=20) , PARAMETER : : c y l i nde rou t=” cy l inde r−g r id . out”character ( len=20) , PARAMETER : : rampout=”ramp−g r id . out”

character ( len=20) , PARAMETER : : r ampl i s t=”ramp . out”character ( len=20) , PARAMETER : : c h a nn e l l i s t=” channel . out”character ( len=20) , PARAMETER : : c y l i n d e r l i s t=” cy l i nd e r . out”

character ( len=20) , PARAMETER : : voutbase=”V. out”character ( len=20) , PARAMETER : : Uoutbase=”U. out”INTEGER i l , j l

ENDMODULE PARAMS

MODULE MAINVARSUSE PARAMSUSE SETTINGSUSE CONSTANTS

INTEGER i , j , countcharacter ( len=20) f o r t r ang r i d , gr idout , f i l e l i s t , probname , Vout f i l e , Uou t f i l eREAL∗8 , DIMENSION( : , : ) ,ALLOCATABLE : : x , y , Si , Sj , Sxi , Syi , Sxj , Syj ,V, dx , dy , sxiM , sxjM , syiM , syjMREAL∗8 , DIMENSION( : , : , : ) ,ALLOCATABLE,TARGET : : U, Ucalc i , Uca 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, maxdi f f

REAL∗8 rho i n freal ∗8 a i n freal ∗8 rhou in f

Page 21: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 20

real ∗8 rhov in freal ∗8 Einfreal ∗8 Minfreal ∗8 p in freal ∗8 Tinf

ENDMODULE 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 , g l i t c h

ENDMODULE TEMPVARS

PROGRAM MAINUSE MAINVARSimplicit none

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

integer r epo r t

ca l l setupca l l l o adg r id

! wr i t e (∗ ,∗ ) Si ( 1 : i l , 1 : j l )ca l l writegridMLca l l outputvolumesCALL SETICSCALL WRITE4VEC(U, t e s t f i l e 1 , 0 )

maxdi f f=1repor 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 ) then

CALL SETBCSCALL GETUCALC( Ucalc i , Ucalc j ,U)CALL GETMATRICES(CSi , SCi , LPi , LMi , Ucalc i , sx i , s y i )CALL GETMATRICES(CSj , SCj , LPj , LMj , Ucalc 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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 epo r t == i n t e r v a l ) then

write (∗ ,∗ ) countwrite (∗ ,∗ ) maxdi f fr epo r t=0

end i fr epo r t=repor t+1

! end i fenddo

! 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 +1do j =1,3

! wr i t e (∗ , ’2 i , 4 e ’ ) i , j , Fj ( : , i , j )enddoenddo

CALL WRITE4VEC(U, Uout f i l e , 0 )ca 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 !

! wr i t e (∗ , ’4 e ’ ) d b l e ( i ) , d b l e ( j ) , s y i ( i , j ) , s y j ( i , j )! wr i t e (∗ , ’6 e ’ ) d b l e ( i ) , d b l e ( j ) , Fi ( : , i , j )

enddoenddo

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 (∗ ,∗ ) ’ , , , ’

Page 23: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 )

ENDPROGRAM MAIN

SUBROUTINE SETUPUSE MAINVARSimplicit none

SELECT CASE( problem )CASE(0 )

f o r t r a n g r i d=channe lg r idgr idout=channeloutf i l e l i s t=c h a nn e l l i s tprobname=” channel ”

CASE(1 )f o r t r a n g r i d=channe lg r idgr idout=channeloutf i l e l i s t=c h a nn e l l i s tprobname=” channel ”

CASE(2 )f o r t r a n g r i d=rampgridgr idout=rampoutf i l e l i s t=rampl i s tprobname=”ramp”

CASE(3 )f o r t r a n g r i d=cy l i n d e r g r i dgr idout=cy l i nde rou tf i l e l i s t=c y l i n d e r l i s tprobname=” cy l i nd e r ”

CASE(4 )f o r t r a n g r i d=channe lg r idgr idout=channeloutprobname=” channel ”ca l l GENCHANNELwrite (∗ ,∗ ) ’ Channel g r id generated ’write (∗ ,∗ ) channe lgr id , channeloutwrite (∗ ,∗ ) ’ Execution w i l l now ha l t . ’STOP

CASE DEFAULT

Page 24: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 23

write (∗ ,∗ ) ’You have s e l e c t e d an unrecognized case . ’write (∗ ,∗ ) ’ Execution w i l l now ha l t . ’STOP

END SELECTVout f i l e=trim (probname )// ’ ’ // trim ( Voutbase )Uou t f i l e=trim (probname )// ’ ’ // trim ( Uoutbase )open(unit=4, f i l e=f i l e l i s t )

write ( 4 ,∗ ) f o r t r a n g r i dwrite ( 4 ,∗ ) g r idoutwrite ( 4 ,∗ ) Vou t f i l eWRITE( 4 ,∗ ) Uou t f i l e

close (4 )

END SUBROUTINE SETUP

SUBROUTINE LOADGRIDUSE MAINVARSUSE TEMPVARSimplicit none

open(unit=1, f i l e=fo r t r a n g r i d )! read in the array s i z eread ( 1 ,∗ ) i l , j l! now a l l o c a t eALLOCATE( x ( i l +1, j l +1) ,y ( i l +1, j l +1) , S i ( 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 w e l lALLOCATE(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) , sxr ( i l +1, j l +1) , syr ( 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 UALLOCATE(U(4 , i l +1, j l +1) , Uca l c i (4 , i l +1, j l +1) , Uca lc j (4 , i l +1, j l +1))! a l l o c a t e matr icesALLOCATE( 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 o r sALLOCATE( 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 ec t o r used f o r pre s sure BCALLOCATE(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)close (1 )

DO i =1, i l +1DO 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

Page 25: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 24

S i ( i , j )= sq r t ( Sxi ( i , j )∗∗2 .0 d0+Syi ( i , j )∗∗2 .0 d0 )END DO

s x i ( i , j l +1)=sx i ( i , j l )s y i ( i , j l +1)=sy i ( i , j l )s i ( i , j l +1)= s i ( i , j l )

END DODO j =1, j l +1

DO i =1, i lSxj ( i , j )=y ( i +1, j )−y ( i , j )Syj ( i , j )=x ( i +1, j )−x ( i , j )Sj ( i , j )= sq r t ( Sxj ( i , j )∗∗2 .0 d0+Syj ( i , j )∗∗2 .0 d0 )

enddo

s x j ( i l +1, j )= sx j ( i l , j )s y j ( i l +1, j )= sy j ( i l , j )s j ( i l +1, j )= s j ( i l , j )

enddoDO i =1, i l

DO j =1, j lV( 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 )

enddoenddo

! normal ize co s ine sSxi=Sxi / S iSxj=Sxj / SjSyi=Syi / S iSyj=Syj / Sj

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

sxiM ( i , j )=− s x i ( i −1, j )syiM ( i , j )=− s y i ( i −1, j )

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

enddodo i =1, i l +1

Page 26: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 25

do j =2, j l +1sxjM( i , j )=−s x j ( i , j−1)syjM( i , j )=−s y j ( i , j−1)

enddosxjm ( i ,1)= sxjm ( i , 2 )syjm ( i ,1)= syjm ( i , 2 )

enddo

END SUBROUTINE LOADGRID

SUBROUTINE WRITEGRIDMLUSE MAINVARSimplicit none! code to output g r i d to b e t t e r format

open(unit=2, f i l e=gr idout )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)close (2 )

END SUBROUTINE WRITEGRIDML

SUBROUTINE WRITEGRIDUSE MAINVARSIMPLICIT NONE

open(unit=2, f i l e=fo 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, j l +1)write ( 2 ,∗ ) ( ( y ( i , j ) , i =1, i l +1) , j =1, j l +1)close (2 )

open(unit=3, f i l e=gr idout )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)close (3 )

END SUBROUTINE WRITEGRID

SUBROUTINE GENCHANNELUSE MAINVARSIMPLICIT NONE

Page 27: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 26

REAL∗8 ddx , ddyi l=channelxj l=channely

ddx=1.0d0/ dble ( i l )ddy=1.0d0/ dble ( 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∗dble ( i −1)y ( i , j )=ddx∗dble ( j−1)

END DOEND DOcal l WRITEGRID

END SUBROUTINE GENCHANNEL

SUBROUTINE OUTPUTVOLUMESUSE MAINVARSIMPLICIT NONE

open(unit=2, f i l e=Vout 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 )close (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) thendo i =2, i l −1

do j =1, j lCALL 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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 27

LCSUM=LMi ( : , i , j )∗CSUPCALL 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 ,FMienddo

enddodo i =1, i l

do j =2, j l −1CALL 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 mult (FM, SCj ( : , : , i , j ) ,LCSUM)Fj ( : , i , j )=FP+FM

! wr i t e (∗ , ’4 e ’ ) FPj ,FMjenddo

enddoe 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

! wr i t e (∗ , ’4 e ’ ) FPi ,FMienddo

enddodo i =1, i l

do j =2, j l −1CALL 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 mult (FM, SCj ( : , : , i , j +1) ,LCSUM)Fj ( : , i , j )=FP+FM

! wr i t e (∗ , ’4 e ’ ) FPj ,FMjenddo

enddoendif

Page 29: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 28

i f ( problem==0) thenwrite (∗ , ’ 4 e ’ ) Fi ( : , i l /2−2: i l /2+2 , j l /2)write (∗ ,∗ ) ’ . . . ’write (∗ , ’ 4 e ’ ) 0 . 5 d0 ∗( Fi ( : , i l /2−2, j l /2)+Fi ( : , i l /2+2 , j l /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 , sx , sy )USE PARAMSUSE CONSTANTSUSE TEMPVARSIMPLICIT NONE

integer i , j

REAL∗8 , DIMENSION(4 , i l +1, j l +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( : , : ) : : rho , rhou , rhov ,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=sq r t (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 Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

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 d0−0.5d0∗gma∗uv2CS(1 , 2 , : , : )=gma∗uuCS(1 , 3 , : , : )=gma∗vvCS(1 ,4 , : , : )= −gmaCS(2 ,1 , : , : )= −0 .5 d0∗ sxr ∗uu/a−0.5d0∗ syr ∗vv/a+0.25d0∗gma∗uv2/ rhoCS( 2 , 2 , : , : )=0 . 5 d0∗ sxr /a−0.5d0∗gma∗uu/ rhoCS( 2 , 3 , : , : )=0 . 5 d0∗ syr /a−0.5d0∗gma∗vv/ rhoCS( 2 , 4 , : , : )=0 . 5 d0∗gma/rhoCS(3 , 1 , : , : )= syr ∗uu−sxr ∗vvCS(3 ,2 , : , : )= − syrCS(3 , 3 , : , : )= sxrCS(3 , 4 , : , : )=0CS( 4 , 1 , : , : )=0 . 5 d0∗ sxr ∗uu/a+0.5d0∗ syr ∗vv/a+0.25d0∗gma∗uv2/ rhoCS(4 ,2 , : , : )= −0 .5 d0∗ sxr /a−0.5d0∗gma∗uu/ rhoCS(4 ,3 , : , : )= −0 .5 d0∗ syr /a−0.5d0∗gma∗vv/ rhoCS( 4 , 4 , : , : )=0 . 5 d0∗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 d0∗uv2SC(4 , 2 , : , : )=0 . 5 d0∗uv2∗ rho+rhosum+rho/gmaSC(4 ,3 , : , : )= − rhou∗ sy+rhov∗ sxSC( 4 , 4 , : , : )=0 . 5 d0∗uv2∗ rho−rhosum+rho/gma

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

LM(1 , : , : )=0 . 5 d0 ∗( uprime−s q r t ( uprime ∗∗2 .0 d0+g l i t c h ) )

Page 31: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 30

LM(2 , : , : )=0 . 5 d0 ∗( uprime+a−s q r t ( ( uprime+a )∗∗2 .0 d0+g l i t c h ) )LM(3 , : , : )=LM( 1 , : , : )LM(4 , : , : )=0 . 5 d0 ∗( uprime−a−s q r t ( ( uprime−a )∗∗2 .0 d0+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 , : , : )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 q r 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

END SUBROUTINE CALCDT

SUBROUTINE SETICSUSE MAINVARSIMPLICIT NONE

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

U(1 , 1 : i l /2 , : )= rho in f 01U(2 , 1 : i l /2 , : )= rho in f 01 ∗ s q r t ( Minf01∗Minf01∗gamma∗R∗Tinf01−v in f01 )U( 3 , 1 : i l /2 , : )= rho in f 01 ∗ v in f01U(4 , 1 : i l /2 , : )=(( rho in f 01 ∗cv∗Tinf01 +0.5d0∗ rho in f 01 ∗Minf01∗Minf01∗gamma∗R∗Tinf01 ) )U(1 , i l /2+1: i l , : )= rho in f 02U(2 , i l /2+1: i l , : )= rho in f 02 ∗ s q r t ( Minf02∗Minf02∗gamma∗R∗Tinf02−v in f02 )U(3 , i l /2+1: i l , : )= rho in f 02 ∗ v in f02U(4 , i l /2+1: i l , : )= ( ( rho in f 02 ∗cv∗Tinf02 +0.5d0∗ rho in f 02 ∗Minf02∗Minf02∗gamma∗R∗Tinf02 ) )s x i=sq r t ( 3 . 0 d0 )/2 . 0 d0s y i =0.5d0

CASE(1 ) ! channelTinf=Tinf1p in f=p in f1Minf=Minf1rho i n f=p in f /(R∗Tinf )a i n f=sq r t (gamma∗R∗Tinf )

Page 32: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 31

rhou in f=Minf∗ a i n f ∗ r ho i n frhov in f=0Einf=rho i n f ∗cv∗Tinf +0.5d0∗ rhou in f ∗ rhou in f / rho i n fFj ( 1 , : , : )=0Fj ( 2 , : , : )=0Fj ( 3 , : , : )= p in fFj ( 4 , : , : )=0Fi ( 1 , : , : )= rhou in fFi ( 2 , : , : )= rhou in f ∗Minf∗ a i n f+p in fFi ( 3 , : , : )=0Fi ( 4 , : , : )= ( Einf+p in f )∗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 i o n! r hov in f=rhou in f! rhou in f=0

U(1 , : , : )= rho i n fU( 2 , : , : )= rhou in fU( 3 , : , : )= rhov in fU( 4 , : , : )= Einf

CASE(2 ) ! rampTinf=Tinf2p in f=p in f2Minf=Minf2

rho i n f=p in f /(R∗Tinf )a i n f=sq r t (gamma∗R∗Tinf )rhou in f=Minf∗ a i n f ∗ r ho i n frhov in f=0Einf=rho i n f ∗cv∗Tinf +0.5d0∗ rhou in f ∗ rhou in f / rho i n fU( 1 , : , : )= rho i n fU( 2 , : , : )= rhou in fU( 3 , : , : )= rhov in fU( 4 , : , : )= Einf

Fj ( 1 , : , : )=0Fj ( 2 , : , : )=0Fj ( 3 , : , : )= p in fFj ( 4 , : , : )=0Fi ( 1 , : , : )= rhou in fFi ( 2 , : , : )= rhou in f ∗Minf∗ a i n f+p in fFi ( 3 , : , : )=0

Page 33: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 32

Fi ( 4 , : , : )= ( Einf+p in f )∗Minf∗ a i n fs x j ( i l +1 ,:)=0sy j ( i l +1 ,:)=1s x i ( : , j l +1)=1sy i ( : , j l +1)=0

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

!Mach 5 in f l owTinf=Tinf3p in f=p in f3Minf=Minf3

rho i n f=p in f /(R∗Tinf )a i n f=sq r t (gamma∗R∗Tinf )rhou in f=Minf∗ a i n f ∗ r ho i n frhov in f=0Einf=rho i n f ∗cv∗Tinf +0.5d0∗ rhou in f ∗ rhou in f / rho i n f

! F i l l e v e r y t h in g wi th f l ow to s t a r tU(1 , : , : )= rho i n fU( 2 , : , : )= rhou in fU( 3 , : , : )= rhov in fU( 4 , : , : )= Einf

! e s t a b l i s h i n i t i a l f l u x e s a l s oFj ( 1 , : , : )=0Fj ( 2 , : , : )=0Fj ( 3 , : , : )= p in fFj ( 4 , : , : )=0Fi ( 1 , : , : )= rhou in fFi ( 2 , : , : )= rhou in f ∗Minf∗ a i n f+p in fFi ( 3 , : , : )=0Fi ( 4 , : , : )= ( Einf+p in f )∗Minf∗ a i n f

CASE DEFAULTwrite (∗ ,∗ ) ’WTF Mate? ’write (∗ ,∗ ) ’ Execution w i l l now ha l t . ’STOP

END SELECT

END SUBROUTINE SETICS

Page 34: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 33

SUBROUTINE SETBCSUSE MAINVARSIMPLICIT NONE

REAL∗8 , PARAMETER : : wa l l curve =.1REAL∗8 , POINTER, DIMENSION( : , : ) : : rho , rhou , rhov ,EREAL∗8 , DIMENSION( i l +1, j l +1) : : uprimei , uprimej , upr ime i in f , up r ime j i n f

rho=>U( 1 , : , : )rhou=>U( 2 , : , : )rhov=>U( 3 , : , : )E=>U( 4 , : , : )uprimei=rhou/ rho∗ s x i+rhov/ rho∗ s y iuprimej=rhou/ rho∗sxjm+rhov/ rho∗ s y jup r ime i i n f=rhou in f / rho i n f ∗ s x i+rhov in f / rho i n f ∗ s y iupr ime j in f=rhou in f / rho i n f ∗sxjm+rhov in f / rho i n f ∗ s y i

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

case (0 ) ! assignment 3! do nothing , don ’ t care about boundar ies! j u s t a 1 time s t ep problem in middle o f domain

CASE(1 ) ! channel! f o r the channel we can j u s t keep the ICs at the boundary

! g e t P one g r i d space above wa l l

CASE(2 ) ! ramped channel! i n f l owFj (1 ,1 , : )=0Fj (2 ,1 , : )=0Fj (3 ,1 , : )= p in fFj (4 ,1 , : )=0Fi (1 ,1 , : )= rhou in fFi (2 ,1 , : )= rhou in f ∗Minf∗ a i n f+p in fFi (3 ,1 , : )=0Fi (4 , 1 , : )=( Einf+p in f )∗Minf∗ a i n f

! ou t f l owFj (1 , i l , : )= rho ( i l −1 , : )∗ uprimej ( i l −1 , : )Fj (2 , i l , : )= rhou ( i l −1 , : )∗ uprimej ( i l −1 ,:)+p( i l −1 , : )∗ sxjm ( i l −1 , : )Fj (3 , i l , : )= rhov ( i l −1 , : )∗ uprimej ( i l −1 ,:)+p( i l −1 , : )∗ s y j ( i l −1 , : )Fj (4 , i l , : )= (E( i l −1 ,:)+p( i l −1 , : ) )∗ uprimej ( i l −1 , : )

Fi (1 , i l , : )= rho ( i l −1 , : )∗ uprimei ( i l −1 , : )Fi (2 , i l , : )= rhou ( i l −1 , : )∗ uprimei ( i l −1 ,:)+p( i l −1 , : )∗ s x i ( i l −1 , : )

Page 35: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 34

Fi (3 , i l , : )= rhov ( i l −1 , : )∗ uprimei ( i l −1 ,:)+p( i l −1 , : )∗ s y i ( i l −1 , : )Fi (4 , i l , : )= (E( i l −1 ,:)+p( i l −1 , : ) )∗ uprimei ( i l −1 , : )

! wi th no curva ture to the wa l l , p re s sure at wa l l shou ld match t h i s! e n t r i e s 2 and 3 in Fwal l are f unc t i on s o f pre s sure and cos ine! e n t r i e s 1 and 4 are 0Fj (1 , : , 1 )=0Fj (2 , : , 1 )=p ( : , 2 ) ∗ ( sxjm ( : , 1 ) )Fj (3 , : , 1 )=p ( : , 2 ) ∗ ( s y j ( : , 1 ) )Fj (4 , : , 1 )=0

! now do i t a t top bound! remember p i s taken a ha l f−index removed from F index ( i=i −1/2, not i +1/2)

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 ow @ j l

! ou t f l ow at i =2, i lFj (1 , i l , : )= rho ( i l −1 , : )∗ uprimej ( i l −1 , : )Fj (2 , i l , : )= rhou ( i l −1 , : )∗ uprimej ( i l −1 ,:)+p( i l −1 , : )∗ sxjm ( i l −1 , : )Fj (3 , i l , : )= rhov ( i l −1 , : )∗ uprimej ( i l −1 ,:)+p( i l −1 , : )∗ s y j ( i l −1 , : )Fj (4 , i l , : )= (E( i l −1 ,:)+p( i l −1 , : ) )∗ uprimej ( i l −1 , : )

Fi (1 , i l , : )= rho ( i l −1 , : )∗ uprimei ( i l −1 , : )Fi (2 , i l , : )= rhou ( i l −1 , : )∗ uprimei ( i l −1 ,:)+p( i l −1 , : )∗ s x i ( i l −1 , : )Fi (3 , i l , : )= rhov ( i l −1 , : )∗ uprimei ( i l −1 ,:)+p( i l −1 , : )∗ s y i ( i l −1 , : )Fi (4 , i l , : )= (E( i l −1 ,:)+p( i l −1 , : ) )∗ uprimei ( i l −1 , : )

Fj (1 ,1 , : )= rho ( 2 , : ) ∗ uprimej ( 2 , : )Fj (2 ,1 , : )= rhou ( 2 , : ) ∗ uprimej (2 , : )+p ( 2 , : ) ∗ sxjm ( 2 , : )Fj (3 ,1 , : )= rhov ( 2 , : ) ∗ uprimej (2 , : )+p ( 2 , : ) ∗ s y j ( 2 , : )Fj ( 4 , 1 , : )=(E(2 , : )+p ( 2 , : ) ) ∗ uprimej ( 2 , : )

Fi (1 ,1 , : )= rho ( 2 , : ) ∗ uprimei ( 2 , : )Fi (2 ,1 , : )= rhou ( 2 , : ) ∗ uprimei (2 , : )+p ( 2 , : ) ∗ s x i ( 2 , : )

Page 36: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 35

Fi (3 ,1 , : )= rhov ( 2 , : ) ∗ uprimei (2 , : )+p ( 2 , : ) ∗ s y i ( 2 , : )Fi ( 4 , 1 , : )=(E(2 , : )+p ( 2 , : ) ) ∗ uprimei ( 2 , : )

! now s e t up sur face , us ing curva ture f o r the curved sur f a c e! j=1Fj (1 , : , 1 )=0

! Fj (2 , : ,1)=( p (: ,2)+ Si ( : , 2 )∗ rho ( : , 2 ) ∗ ( rhou ( : , 2 )∗ rhou (: ,2)+ rhov ( : , 2 )∗ rhov ( : , 2 ) ) / ( rho ( : , 2 )∗ rho ( : , 2 ) ) / wa l l cu r v e )∗( sxjm ( : , 1 ) )! Fj (3 , : ,1)=( p (: ,2)+ Si ( : , 2 )∗ rho ( : , 2 ) ∗ ( rhou ( : , 2 )∗ rhou (: ,2)+ rhov ( : , 2 )∗ rhov ( : , 2 ) ) / ( rho ( : , 2 )∗ rho ( : , 2 ) ) / wa l l cu r v e )∗( s y j ( : , 1 ) )

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

! i n f l owFj ( 1 , : , j l )= rho i n f ∗ upr ime j in f ( : , j l )Fj ( 2 , : , j l )= rhou in f ∗ upr ime j in f ( : , j l )+p in f ∗sxjm ( : , j l )Fj ( 3 , : , j l )= rhov in f ∗ upr ime j in f ( : , j l )+p in f ∗ s y j ( : , j l )Fj ( 4 , : , j l )=( Einf+p in f )∗ upr ime j in f ( : , j l )Fi ( 1 , : , j l )= rho i n f ∗ upr ime i i n f ( : , j l )Fi ( 2 , : , j l )= rhou in f ∗ upr ime i i n f ( : , j l )+p in f ∗ s x i ( : , j l )Fi ( 3 , : , j l )= rhov in f ∗ upr ime i i n f ( : , j l )+p in f ∗ s y i ( : , j l )Fi ( 4 , : , j l )=( Einf+p in f )∗ upr ime i i n f ( : , j l )

CASE DEFAULTwrite (∗ ,∗ ) ’WTF Mate? ’write (∗ ,∗ ) ’ Execution w i l l now ha l t . ’STOP

END SELECT

END SUBROUTINE SETBCS

SUBROUTINE WRITE4VEC(U, Uout f i l e , c u l l )USE PARAMSIMPLICIT NONE

REAL∗8 , DIMENSION(4 , i l +1, j l +1) : : Ucharacter ( len=20) Uou t f i l einteger i , jinteger c u l lwrite (∗ ,∗ ) ”Writing : ” , Uou t f i l eopen(unit=5, f i l e=Uout f i l e )write (5 , ’ 1 I ’ ) i l−c u l lwrite (5 , ’ 1 I ’ ) j l−c u l lwrite (5 , ’ 4E ’ ) ( (U( : , i , j ) , i =1, i l−c u l l +1) , j =1, j l−c u l l +1)close (5 )

END SUBROUTINE WRITE4VEC

Page 37: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 36

SUBROUTINE GETUCALC( Ucalc i , Ucalc j ,U)USE PARAMSUSE SETTINGSIMPLICIT NONE

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

CASE(0 )! Standard S teger Warming , don ’ t a c t u a l l y do any averaging , j u s t shoot back same v a r i a b l e

Uca l c i=UUca lc j=U

CASE(1 )! Modi f ied Steger−Warming , average U Valuesdo i =1, i l

Uca l c i ( : , i , : )=0 . 5 d0 ∗(U( : , i , : )+U( : , i +1 , : ) )enddodo j =1, j l

Uca l c j ( : , : , j )=0.5d0 ∗(U( : , : , j )+U( : , : , j +1))enddo

END SELECTEND SUBROUTINE GETUCALC

SUBROUTINE ADVANCETIME(U,DT, Fi , Fj , Si , Sj ,V, maxdi f 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, maxdi f f

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 )−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 )

enddoenddo

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 ldo j =2, j l

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

Page 38: Finite Volume Code for Compressible Flowspuresimplicity.net/~mattsteg/candler/report.pdf · 2005. 5. 16. · Steger-Warming method. A sonic glitch factor of 0.1a was employed in the

D CODE FOR ASSIGNMENT 3 AND FINAL PROJECT 37

enddoenddo

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

END SUBROUTINE ADVANCETIME