Skip to content

Commit 1cce7df

Browse files
authored
update the Riemann docs (#33)
1 parent ddbeb52 commit 1cce7df

1 file changed

Lines changed: 99 additions & 14 deletions

File tree

ppmpy/riemann_exact.py

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
gas. The left and right states are stored as State objects. We then
33
create a RiemannProblem object with the left and right state:
44
5-
> rp = RiemannProblem(left_state, right_state)
5+
`rp = RiemannProblem(left_state, right_state)`
66
77
Next we solve for the star state:
88
9-
> rp.find_star_state()
9+
`rp.find_star_state()`
1010
1111
Finally, we sample the solution to find the interface state, which
1212
is returned as a State object:
1313
14-
> q_int = rp.sample_solution()
14+
`q_int = rp.sample_solution()`
1515
"""
1616

1717
import numpy as np
@@ -20,9 +20,19 @@
2020

2121

2222
class State:
23-
""" a simple object to hold a primitive variable state """
24-
25-
def __init__(self, p=1.0, u=0.0, rho=1.0):
23+
""" a simple object to hold a primitive variable state
24+
25+
Parameters
26+
----------
27+
p : float
28+
pressure
29+
u : float
30+
velocity
31+
rho : float
32+
density
33+
"""
34+
35+
def __init__(self, *, p=1.0, u=0.0, rho=1.0):
2636
self.p = p
2737
self.u = u
2838
self.rho = rho
@@ -33,9 +43,19 @@ def __str__(self):
3343

3444
class RiemannProblem:
3545
""" a class to define a Riemann problem. It takes a left
36-
and right state. Note: we assume a constant gamma """
37-
38-
def __init__(self, left_state, right_state, gamma=1.4):
46+
and right state. Note: we assume a constant gamma.
47+
48+
Parameters
49+
----------
50+
left_state : State
51+
primitive variable state to the left of the interface.
52+
right_state : State
53+
primitive variable state to the right of the interface.
54+
gamma : float
55+
ratio of specific heats.
56+
"""
57+
58+
def __init__(self, left_state, right_state, *, gamma=1.4):
3959
self.left = left_state
4060
self.right = right_state
4161
self.gamma = gamma
@@ -47,7 +67,20 @@ def __str__(self):
4767
return f"pstar = {self.pstar}, ustar = {self.ustar}"
4868

4969
def u_hugoniot(self, p, side):
50-
"""define the Hugoniot curve, u(p)."""
70+
"""define the Hugoniot curve, u(p).
71+
72+
Parameters
73+
----------
74+
p : float
75+
pressure
76+
side : str
77+
"left" or "right" to indicate which state to use.
78+
79+
Returns
80+
-------
81+
float
82+
the velocity on the Hugoniot curve for the input pressure
83+
"""
5184

5285
if side == "left":
5386
state = self.left
@@ -73,7 +106,15 @@ def u_hugoniot(self, p, side):
73106
return u
74107

75108
def find_star_state(self, p_min=0.001, p_max=1000.0):
76-
""" root find the Hugoniot curve to find ustar, pstar """
109+
""" root find the Hugoniot curve to find ustar, pstar.
110+
111+
Parameters
112+
----------
113+
p_min : float, optional
114+
minimum possible pressure.
115+
p_max : float, optional
116+
maximum possible pressure.
117+
"""
77118

78119
# we need to root-find on
79120
try:
@@ -89,7 +130,21 @@ def find_star_state(self, p_min=0.001, p_max=1000.0):
89130
self.ustar = self.u_hugoniot(self.pstar, "left")
90131

91132
def shock_solution(self, sgn, state):
92-
"""return the interface solution considering a shock"""
133+
"""return the interface solution considering a shock.
134+
135+
Parameters
136+
----------
137+
sgn : float
138+
a sign, -1 or +1, indicating whether it is "+" or "-" in the
139+
shock expression (this depends on left or right jump).
140+
state : State
141+
the Riemann state on the non-star side of the shock.
142+
143+
Returns
144+
-------
145+
State
146+
the star state across the shock.
147+
"""
93148

94149
p_ratio = self.pstar/state.p
95150
c = np.sqrt(self.gamma*state.p/state.rho)
@@ -111,7 +166,21 @@ def shock_solution(self, sgn, state):
111166
return solution
112167

113168
def rarefaction_solution(self, sgn, state):
114-
"""return the interface solution considering a rarefaction wave"""
169+
"""return the interface solution considering a rarefaction wave.
170+
171+
Parameters
172+
----------
173+
sgn : float
174+
a sign, -1 or +1, indicating whether it is "+" or "-" in the
175+
rarefaction expression (this depends on left or right jump).
176+
state : State
177+
the Riemann state on the non-star side of the rarefaction.
178+
179+
Returns
180+
-------
181+
State
182+
the star state across the rarefaction.
183+
"""
115184

116185
# find the speed of the head and tail of the rarefaction fan
117186

@@ -171,7 +240,23 @@ def sample_solution(self):
171240

172241

173242
def plot_hugoniot(riemann_problem, p_min=0.0, p_max=1.5, N=500):
174-
""" plot the Hugoniot curves """
243+
""" plot the Hugoniot curves.
244+
245+
Parameters
246+
----------
247+
riemann_problem : RiemannProblem
248+
the Riemann problem object.
249+
p_min : float
250+
the minimum pressure to plot.
251+
p_max : float
252+
the maximum pressure to plot.
253+
N : int
254+
number of points to use in the plot.
255+
256+
Returns
257+
-------
258+
matplotlib.pyplot.Figure
259+
"""
175260

176261
fig = plt.figure()
177262
ax = fig.add_subplot(111)

0 commit comments

Comments
 (0)