Skip to content

Commit a30ec1c

Browse files
mojiastonybrookzingale
authored andcommitted
Add double Mach reflection problem to compressible solver as ramp. (#31)
* Add double Mach reflection problem to compressible solver as ramp. * flake8 check. * flake8 check. * flake8 check.
1 parent 41a67e3 commit a30ec1c

6 files changed

Lines changed: 265 additions & 1 deletion

File tree

compressible/BC.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import compressible.eos as eos
1414
from util import msg
1515

16+
import math
17+
import numpy as np
18+
1619

1720
def user(bc_name, bc_edge, variable, ccdata):
1821
"""
@@ -132,5 +135,117 @@ def user(bc_name, bc_edge, variable, ccdata):
132135
else:
133136
msg.fail("error: hse BC not supported for xlb or xrb")
134137

138+
elif bc_name == "ramp":
139+
# Boundary conditions for double Mach reflection problem
140+
141+
gamma = ccdata.get_aux("gamma")
142+
143+
if bc_edge == "xlb":
144+
# lower x boundary
145+
# inflow condition with post shock setup
146+
147+
v = ccdata.get_var(variable)
148+
i = myg.ilo - 1
149+
if variable in ["density", "x-momentum", "y-momentum", "energy"]:
150+
val = inflow_post_bc(variable, gamma)
151+
while i >= 0:
152+
v[i, :] = val
153+
i = i - 1
154+
else:
155+
v[:, :] = 0.0 # no source term
156+
157+
elif bc_edge == "ylb":
158+
# lower y boundary
159+
# for x > 1./6., reflective boundary
160+
# for x < 1./6., inflow with post shock setup
161+
162+
if variable in ["density", "x-momentum", "y-momentum", "energy"]:
163+
v = ccdata.get_var(variable)
164+
j = myg.jlo - 1
165+
jj = 0
166+
while j >= 0:
167+
xcen_l = myg.x < 1.0/6.0
168+
xcen_r = myg.x >= 1.0/6.0
169+
v[xcen_l, j] = inflow_post_bc(variable, gamma)
170+
171+
if variable == "y-momentum":
172+
v[xcen_r, j] = -1.0*v[xcen_r, myg.jlo+jj]
173+
else:
174+
v[xcen_r, j] = v[xcen_r, myg.jlo+jj]
175+
j = j - 1
176+
jj = jj + 1
177+
else:
178+
v = ccdata.get_var(variable)
179+
v[:, :] = 0.0 # no source term
180+
181+
elif bc_edge == "yrb":
182+
# upper y boundary
183+
# time-dependent boundary, the shockfront moves with a 10 mach velocity forming an angle
184+
# to the x-axis of 30 degrees clockwise.
185+
# x coordinate of the grid is used to judge whether the cell belongs to pure post shock area,
186+
# the pure pre shock area or the mixed area.
187+
188+
if variable in ["density", "x-momentum", "y-momentum", "energy"]:
189+
v = ccdata.get_var(variable)
190+
for j in range(myg.jhi+1, myg.jhi+myg.ng+1):
191+
shockfront_up = 1.0/6.0 + (myg.y[j] + 0.5*myg.dy*math.sqrt(3))/math.tan(math.pi/3.0) \
192+
+ (10.0/math.sin(math.pi/3.0))*ccdata.t
193+
shockfront_down = 1.0/6.0 + (myg.y[j] - 0.5*myg.dy*math.sqrt(3))/math.tan(math.pi/3.0) \
194+
+ (10.0/math.sin(math.pi/3.0))*ccdata.t
195+
shockfront = np.array([shockfront_down, shockfront_up])
196+
for i in range(myg.ihi+myg.ng+1):
197+
v[i, j] = 0.0
198+
cx_down = myg.x[i] - 0.5*myg.dx*math.sqrt(3)
199+
cx_up = myg.x[i] + 0.5*myg.dx*math.sqrt(3)
200+
cx = np.array([cx_down, cx_up])
201+
202+
for sf in shockfront:
203+
for x in cx:
204+
if x < sf:
205+
v[i, j] = v[i, j] + 0.25*inflow_post_bc(variable, gamma)
206+
else:
207+
v[i, j] = v[i, j] + 0.25*inflow_pre_bc(variable, gamma)
208+
else:
209+
v = ccdata.get_var(variable)
210+
v[:, :] = 0.0 # no source term
211+
135212
else:
136213
msg.fail("error: bc type %s not supported" % (bc_name))
214+
215+
216+
def inflow_post_bc(var, g):
217+
# inflow boundary condition with post shock setup
218+
r_l = 8.0
219+
u_l = 7.1447096
220+
v_l = -4.125
221+
p_l = 116.5
222+
if var == "density":
223+
vl = r_l
224+
elif var == "x-momentum":
225+
vl = r_l*u_l
226+
elif var == "y-momentum":
227+
vl = r_l*v_l
228+
elif var == "energy":
229+
vl = p_l/(g - 1.0) + 0.5*r_l*(u_l*u_l + v_l*v_l)
230+
else:
231+
vl = 0.0
232+
return vl
233+
234+
235+
def inflow_pre_bc(var, g):
236+
# pre shock setup
237+
r_r = 1.4
238+
u_r = 0.0
239+
v_r = 0.0
240+
p_r = 1.0
241+
if var == "density":
242+
vl = r_r
243+
elif var == "x-momentum":
244+
vl = r_r*u_r
245+
elif var == "y-momentum":
246+
vl = r_r*v_r
247+
elif var == "energy":
248+
vl = p_r/(g - 1.0) + 0.5*r_r*(u_r*u_r + v_r*v_r)
249+
else:
250+
vl = 0.0
251+
return vl

compressible/problems/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__all__ = ['acoustic_pulse', 'advect', 'bubble', 'hse', 'kh', 'logo', 'quad', 'rt', 'rt2', 'sedov', 'sod', 'test']
1+
__all__ = ['acoustic_pulse', 'advect', 'bubble', 'hse', 'kh', 'logo', 'quad', 'rt', 'rt2', 'sedov', 'sod',
2+
'test', 'ramp']
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# these defaults comes from the third test problem in
2+
# Woodward and Colella. Journal of Computational Physics, 54, 115-174, 1984
3+
#
4+
# Also, the numbers is consitent with the ones in Castro
5+
#
6+
7+
8+
[ramp]
9+
rhol = 8.0 ; post-shock initial density
10+
ul = 7.1447096 ; post-shock initial x-velocity
11+
vl = -4.125 ; post-shock initial y-velocity
12+
pl = 116.5 ; post-shock initial pressure
13+
14+
rhor = 1.4 ; pre-shock initial density
15+
ur = 0.0 ; pre-shock initial x-velocity
16+
vr = 0.0 ; pre-shock initial y-velocity
17+
pr = 1.0 ; pre-shock initial pressure
18+
19+

compressible/problems/inputs.ramp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# simple inputs files for the double Mach reflection problem.
2+
3+
[driver]
4+
max_steps = 12500
5+
tmax = 0.25
6+
7+
8+
[compressible]
9+
limiter = 2
10+
cvisc = 0.1
11+
12+
[io]
13+
basename = double_mach_reflection_
14+
dt_out = 0.1
15+
16+
17+
[mesh]
18+
nx = 1024
19+
ny = 256
20+
xmax = 4.0
21+
ymax = 1.0
22+
23+
xlboundary = ramp
24+
xrboundary = outflow
25+
26+
ylboundary = ramp
27+
yrboundary = ramp
28+
29+
30+
[ramp]
31+
rhol = 8.0
32+
ul = 7.1447096
33+
vl = -4.125
34+
pl = 116.5
35+
36+
rhor = 1.4
37+
ur = 0.0
38+
vr = 0.0
39+
pr = 1.0
40+

compressible/problems/ramp.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from __future__ import print_function
2+
3+
import sys
4+
5+
import numpy as np
6+
import math
7+
8+
import mesh.patch as patch
9+
from util import msg
10+
11+
12+
def init_data(my_data, rp):
13+
""" initialize the double Mach reflection problem """
14+
15+
msg.bold("initializing the double Mach reflection problem...")
16+
17+
# make sure that we are passed a valid patch object
18+
if not isinstance(my_data, patch.CellCenterData2d):
19+
print("ERROR: patch invalid in ramp.py")
20+
print(my_data.__class__)
21+
sys.exit()
22+
23+
# get the density, momenta, and energy as separate variables
24+
dens = my_data.get_var("density")
25+
xmom = my_data.get_var("x-momentum")
26+
ymom = my_data.get_var("y-momentum")
27+
ener = my_data.get_var("energy")
28+
29+
# initialize the components, remember, that ener here is
30+
# rho*eint + 0.5*rho*v**2, where eint is the specific
31+
# internal energy (erg/g)
32+
33+
r_l = rp.get_param("ramp.rhol")
34+
u_l = rp.get_param("ramp.ul")
35+
v_l = rp.get_param("ramp.vl")
36+
p_l = rp.get_param("ramp.pl")
37+
38+
r_r = rp.get_param("ramp.rhor")
39+
u_r = rp.get_param("ramp.ur")
40+
v_r = rp.get_param("ramp.vr")
41+
p_r = rp.get_param("ramp.pr")
42+
43+
gamma = rp.get_param("eos.gamma")
44+
45+
energy_l = p_l/(gamma - 1.0) + 0.5*r_l*(u_l*u_l + v_l*v_l)
46+
energy_r = p_r/(gamma - 1.0) + 0.5*r_r*(u_r*u_r + v_r*v_r)
47+
48+
# there is probably an easier way to do this, but for now, we
49+
# will just do an explicit loop. Also, we really want to set
50+
# the pressue and get the internal energy from that, and then
51+
# compute the total energy (which is what we store). For now
52+
# we will just fake this
53+
54+
myg = my_data.grid
55+
dens[:, :] = 1.4
56+
57+
for j in range(myg.jlo, myg.jhi+1):
58+
cy_up = myg.y[j] + 0.5*myg.dy*math.sqrt(3)
59+
cy_down = myg.y[j] - 0.5*myg.dy*math.sqrt(3)
60+
cy = np.array([cy_down, cy_up])
61+
62+
for i in range(myg.ilo, myg.ihi+1):
63+
dens[i, j] = 0.0
64+
xmom[i, j] = 0.0
65+
ymom[i, j] = 0.0
66+
ener[i, j] = 0.0
67+
68+
sf_up = math.tan(math.pi/3.0)*(myg.x[i] + 0.5*myg.dx*math.sqrt(3)-1.0/6.0)
69+
sf_down = math.tan(math.pi/3.0)*(myg.x[i] - 0.5*myg.dx*math.sqrt(3)-1.0/6.0)
70+
sf = np.array([sf_down, sf_up]) # initial shock front
71+
72+
for y in cy:
73+
for shockfront in sf:
74+
if y >= shockfront:
75+
dens[i, j] = dens[i, j] + 0.25*r_l
76+
xmom[i, j] = xmom[i, j] + 0.25*r_l*u_l
77+
ymom[i, j] = ymom[i, j] + 0.25*r_l*v_l
78+
ener[i, j] = ener[i, j] + 0.25*energy_l
79+
else:
80+
dens[i, j] = dens[i, j] + 0.25*r_r
81+
xmom[i, j] = xmom[i, j] + 0.25*r_r*u_r
82+
ymom[i, j] = ymom[i, j] + 0.25*r_r*v_r
83+
ener[i, j] = ener[i, j] + 0.25*energy_r
84+
85+
86+
def finalize():
87+
""" print out any information to the user at the end of the run """
88+
pass

compressible/simulation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def initialize(self, extra_vars=None, ng=4):
112112

113113
# define solver specific boundary condition routines
114114
bnd.define_bc("hse", BC.user, is_solid=False)
115+
bnd.define_bc("ramp", BC.user, is_solid=False) # for double mach reflection problem
115116

116117
bc, bc_xodd, bc_yodd = bc_setup(self.rp)
117118

0 commit comments

Comments
 (0)