1
- # solve the Riemann problem for a gamma-law gas
1
+ """An exact Riemann solver for the Euler equations with a gamma-law
2
+ gas. The left and right states are stored as State objects. We then
3
+ create a RiemannProblem object with the left and right state:
4
+
5
+ > rp = RiemannProblem(left_state, right_state)
6
+
7
+ Next we solve for the star state:
8
+
9
+ > rp.find_star_state()
10
+
11
+ Finally, we sample the solution to find the interface state, which
12
+ is returned as a State object:
13
+
14
+ > q_int = rp.sample_solution()
15
+ """
2
16
3
17
import numpy as np
4
18
import scipy .optimize as optimize
@@ -95,6 +109,8 @@ def rarefaction_solution(self, sgn, state):
95
109
lambda_head = state .u + sgn * c
96
110
lambda_tail = self .ustar + sgn * cstar
97
111
112
+ gam_fac = (self .gamma - 1.0 )/ (self .gamma + 1.0 )
113
+
98
114
if (sgn > 0 and lambda_head < 0 ) or (sgn < 0 and lambda_head > 0 ):
99
115
# R/L region
100
116
solution = state
@@ -118,8 +134,6 @@ def rarefaction_solution(self, sgn, state):
118
134
def sample_solution (self ):
119
135
"""given the star state (ustar, pstar), find the state on the interface"""
120
136
121
- gam_fac = (self .gamma - 1.0 )/ (self .gamma + 1.0 )
122
-
123
137
if self .ustar < 0 :
124
138
# we are in the R* or R region
125
139
state = self .right
@@ -150,6 +164,7 @@ def cons_flux(state, v):
150
164
state .p / (v .gamma - 1.0 ) + state .p ) * state .u
151
165
return flux
152
166
167
+
153
168
if __name__ == "__main__" :
154
169
155
170
q_l = State (rho = 1.0 , u = 0.0 , p = 1.0 )
0 commit comments