Skip to content

Commit 8947f59

Browse files
committed
Fixed flake issues
1 parent 6fb9ebc commit 8947f59

9 files changed

Lines changed: 69 additions & 69 deletions

File tree

advection/tests/smooth_0040.h5

-20.5 KB
Binary file not shown.

advection_nonuniform/advective_fluxes.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import mesh.reconstruction as reconstruction
22
import numpy as np
33

4+
45
def unsplit_fluxes(my_data, rp, dt, scalar_name):
56
"""
67
Construct the fluxes through the interfaces for the linear advection
@@ -58,10 +59,10 @@ def unsplit_fluxes(my_data, rp, dt, scalar_name):
5859

5960
u = my_data.get_var("x-velocity")
6061
v = my_data.get_var("y-velocity")
61-
62+
6263
cx = myg.scratch_array()
6364
cy = myg.scratch_array()
64-
65+
6566
cx.v(buf=1)[:, :] = u.v(buf=1)*dt/myg.dx
6667
cy.v(buf=1)[:, :] = v.v(buf=1)*dt/myg.dy
6768

@@ -73,37 +74,37 @@ def unsplit_fluxes(my_data, rp, dt, scalar_name):
7374

7475
ldelta_ax = reconstruction.limit(a, myg, 1, limiter)
7576
ldelta_ay = reconstruction.limit(a, myg, 2, limiter)
76-
77+
7778
# x-direction
7879
a_x = myg.scratch_array()
7980
shift_x = my_data.get_var("x-shift").astype(int)
80-
81-
for index,vel in np.ndenumerate(u.v(buf=1)):
81+
82+
for index, vel in np.ndenumerate(u.v(buf=1)):
8283
# upwind
8384
if vel < 0:
8485
a_x.v(buf=1)[index] = a.ip(shift_x.v(buf=1)[index], buf=1)[index] - \
85-
0.5*(1.0 + cx.v(buf=1)[index])* \
86+
0.5*(1.0 + cx.v(buf=1)[index]) * \
8687
ldelta_ax.ip(shift_x.v(buf=1)[index], buf=1)[index]
8788
else:
8889
a_x.v(buf=1)[index] = a.ip(shift_x.v(buf=1)[index], buf=1)[index] + \
89-
0.5*(1.0 - cx.v(buf=1)[index])* \
90+
0.5*(1.0 - cx.v(buf=1)[index]) * \
9091
ldelta_ax.ip(shift_x.v(buf=1)[index], buf=1)[index]
9192

9293
# y-direction
9394
a_y = myg.scratch_array()
9495
shift_y = my_data.get_var("y-shift").astype(int)
95-
96-
for index,vel in np.ndenumerate(v.v(buf=1)):
96+
97+
for index, vel in np.ndenumerate(v.v(buf=1)):
9798
# upwind
9899
if vel < 0:
99100
a_y.v(buf=1)[index] = a.jp(shift_y.v(buf=1)[index], buf=1)[index] - \
100-
0.5*(1.0 + cy.v(buf=1)[index])* \
101+
0.5*(1.0 + cy.v(buf=1)[index]) * \
101102
ldelta_ay.jp(shift_y.v(buf=1)[index], buf=1)[index]
102103
else:
103104
a_y.v(buf=1)[index] = a.jp(shift_y.v(buf=1)[index], buf=1)[index] + \
104-
0.5*(1.0 - cy.v(buf=1)[index])* \
105+
0.5*(1.0 - cy.v(buf=1)[index]) * \
105106
ldelta_ay.jp(shift_y.v(buf=1)[index], buf=1)[index]
106-
107+
107108
# compute the transverse flux differences. The flux is just (u a)
108109
# HOTF
109110
F_xt = u*a_x
@@ -116,15 +117,15 @@ def unsplit_fluxes(my_data, rp, dt, scalar_name):
116117
# depends on the sign of the advective velocity
117118
dtdx2 = 0.5*dt/myg.dx
118119
dtdy2 = 0.5*dt/myg.dy
119-
120+
120121
for index, vel in np.ndenumerate(u.v(buf=1)):
121122
F_x.v(buf=1)[index] = vel*(a_x.v(buf=1)[index] -
122123
dtdy2*(F_yt.ip_jp(shift_x.v(buf=1)[index], 1, buf=1)[index] -
123124
F_yt.ip(shift_x.v(buf=1)[index], buf=1)[index]))
124-
125+
125126
for index, vel in np.ndenumerate(v.v(buf=1)):
126127
F_y.v(buf=1)[index] = vel*(a_y.v(buf=1)[index] -
127128
dtdx2*(F_xt.ip_jp(1, shift_y.v(buf=1)[index], buf=1)[index] -
128129
F_xt.jp(shift_y.v(buf=1)[index], buf=1)[index]))
130+
129131
return F_x, F_y
130-
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
11
from __future__ import print_function
2-
32
import numpy as np
4-
import matplotlib.pyplot as plt
53

64
import mesh.patch as patch
75
from util import msg
86

97

108
def init_data(my_data, rp):
11-
""" initialize the smooth advection problem """
12-
9+
""" initialize the slotted advection problem """
1310
msg.bold("initializing the slotted advection problem...")
1411

1512
# make sure that we are passed a valid patch object
1613
if not isinstance(my_data, patch.CellCenterData2d):
1714
print(my_data.__class__)
1815
msg.fail("ERROR: patch invalid in slotted.py")
19-
16+
2017
offset = rp.get_param("slotted.offset")
2118
omega = rp.get_param("slotted.omega")
22-
19+
2320
myg = my_data.grid
24-
21+
2522
xctr_dens = 0.5*(myg.xmin + myg.xmax)
2623
yctr_dens = 0.5*(myg.ymin + myg.ymax) + offset
27-
24+
2825
# setting initial condition for density
2926
dens = my_data.get_var("density")
3027
dens[:, :] = 0.0
3128

3229
R = 0.15
3330
slot_width = 0.05
34-
31+
3532
inside = (myg.x2d - xctr_dens)**2 + (myg.y2d - yctr_dens)**2 < R**2
36-
33+
3734
slot_x = np.logical_and(myg.x2d > (xctr_dens - slot_width*0.5),
3835
myg.x2d < (xctr_dens + slot_width*0.5))
3936
slot_y = np.logical_and(myg.y2d > (yctr_dens - R),
4037
myg.y2d < (yctr_dens))
4138
slot = np.logical_and(slot_x, slot_y)
42-
39+
4340
dens[inside] = 1.0
4441
dens[slot] = 0.0
45-
42+
4643
# setting initial condition for velocity
4744
u = my_data.get_var("x-velocity")
4845
v = my_data.get_var("y-velocity")
49-
46+
5047
u[:, :] = omega*(myg.y2d - xctr_dens)
5148
v[:, :] = -omega*(myg.x2d - (yctr_dens-offset))
52-
49+
5350
print("extrema: ", np.amax(u), np.amin(u))
54-
51+
52+
5553
def finalize():
5654
""" print out any information to the user at the end of the run """
5755
pass

advection_nonuniform/problems/smooth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import print_function
22

3-
import sys
43
import mesh.patch as patch
5-
import numpy
4+
import numpy as np
65
from util import msg
76

87

@@ -27,15 +26,16 @@ def init_data(my_data, rp):
2726
xctr = 0.5*(xmin + xmax)
2827
yctr = 0.5*(ymin + ymax)
2928

30-
dens[:, :] = 1.0 + numpy.exp(-60.0*((my_data.grid.x2d-xctr)**2 +
29+
dens[:, :] = 1.0 + np.exp(-60.0*((my_data.grid.x2d-xctr)**2 +
3130
(my_data.grid.y2d-yctr)**2))
32-
31+
3332
u = my_data.get_var("x-velocity")
3433
v = my_data.get_var("y-velocity")
35-
34+
3635
u[:, :] = rp.get_param("advection.u")
3736
v[:, :] = rp.get_param("advection.v")
3837

38+
3939
def finalize():
4040
""" print out any information to the user at the end of the run """
4141
pass

advection_nonuniform/problems/test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import print_function
22

3-
import sys
43
import mesh.patch as patch
54

65

@@ -9,9 +8,8 @@ def init_data(my_data, rp):
98

109
# make sure that we are passed a valid patch object
1110
if not isinstance(my_data, patch.CellCenterData2d):
12-
print("ERROR: patch invalid in sedov.py")
1311
print(my_data.__class__)
14-
sys.exit()
12+
msg.fail("ERROR: patch invalid in slotted.py")
1513

1614
# get the density, momenta, and energy as separate variables
1715
dens = my_data.get_var("density")
@@ -20,12 +18,13 @@ def init_data(my_data, rp):
2018
# + 0.5*rho*v**2, where eint is the specific internal energy
2119
# (erg/g)
2220
dens[:, :] = 1.0
23-
21+
2422
u = my_data.get_var("x-velocity")
2523
v = my_data.get_var("y-velocity")
26-
27-
u[:, :] = rp.get_param("advection.u")
28-
v[:, :] = rp.get_param("advection.v")
24+
25+
u[:, :] = 1.0
26+
v[:, :] = 1.0
27+
2928

3029
def finalize():
3130
""" print out any information to the user at the end of the run """
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
from __future__ import print_function
22

3-
import sys
43
import mesh.patch as patch
54
from util import msg
65

76

8-
def init_data(myd, rp):
7+
def init_data(my_data, rp):
98
""" initialize the tophat advection problem """
109

1110
msg.bold("initializing the tophat advection problem...")
1211

1312
# make sure that we are passed a valid patch object
14-
if not isinstance(myd, patch.CellCenterData2d):
15-
print("ERROR: patch invalid in tophat.py")
16-
print(myd.__class__)
17-
sys.exit()
13+
if not isinstance(my_data, patch.CellCenterData2d):
14+
print(my_data.__class__)
15+
msg.fail("ERROR: patch invalid in slotted.py")
1816

19-
dens = myd.get_var("density")
17+
dens = my_data.get_var("density")
2018

21-
xmin = myd.grid.xmin
22-
xmax = myd.grid.xmax
19+
xmin = my_data.grid.xmin
20+
xmax = my_data.grid.xmax
2321

24-
ymin = myd.grid.ymin
25-
ymax = myd.grid.ymax
22+
ymin = my_data.grid.ymin
23+
ymax = my_data.grid.ymax
2624

2725
xctr = 0.5*(xmin + xmax)
2826
yctr = 0.5*(ymin + ymax)
@@ -31,16 +29,17 @@ def init_data(myd, rp):
3129

3230
R = 0.1
3331

34-
inside = (myd.grid.x2d - xctr)**2 + (myd.grid.y2d - yctr)**2 < R**2
32+
inside = (my_data.grid.x2d - xctr)**2 + (my_data.grid.y2d - yctr)**2 < R**2
3533

3634
dens[inside] = 1.0
37-
35+
3836
u = my_data.get_var("x-velocity")
3937
v = my_data.get_var("y-velocity")
40-
38+
4139
u[:, :] = rp.get_param("advection.u")
4240
v[:, :] = rp.get_param("advection.v")
4341

42+
4443
def finalize():
4544
""" print out any information to the user at the end of the run """
4645
pass

advection_nonuniform/simulation.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ def initialize(self):
1919
def shift(velocity):
2020
"""
2121
Computes the direction of shift for each node for upwind
22-
discretization based on sign of veclocity
22+
discretization based on sign of veclocity
2323
"""
2424
shift_vel = np.sign(velocity)
2525
shift_vel[np.where(shift_vel <= 0)] = 0
26-
shift_vel[np.where(shift_vel > 0)] = -1
26+
shift_vel[np.where(shift_vel > 0)] = -1
2727
return shift_vel
28-
28+
2929
my_grid = grid_setup(self.rp, ng=4)
30-
30+
3131
# create the variables
3232
bc, bc_xodd, bc_yodd = bc_setup(self.rp)
33-
33+
3434
my_data = patch.CellCenterData2d(my_grid)
3535

3636
# velocities
@@ -40,10 +40,10 @@ def shift(velocity):
4040
# shift
4141
my_data.register_var("x-shift", bc_xodd)
4242
my_data.register_var("y-shift", bc_yodd)
43-
43+
4444
# density
4545
my_data.register_var("density", bc)
46-
46+
4747
my_data.create()
4848

4949
self.cc_data = my_data
@@ -56,13 +56,13 @@ def shift(velocity):
5656
# now set the initial conditions for the problem
5757
problem = importlib.import_module("advection_nonuniform.problems.{}".format(self.problem_name))
5858
problem.init_data(self.cc_data, self.rp)
59-
59+
6060
# compute the required shift for each node using corresponding velocity at the node
6161
shx = self.cc_data.get_var("x-shift")
6262
shx[:, :] = shift(self.cc_data.get_var("x-velocity"))
6363
shy = self.cc_data.get_var("y-shift")
6464
shy[:, :] = shift(self.cc_data.get_var("y-velocity"))
65-
65+
6666
def method_compute_timestep(self):
6767
"""
6868
The timestep() function computes the advective timestep
@@ -76,7 +76,7 @@ def method_compute_timestep(self):
7676

7777
u = self.cc_data.get_var("x-velocity")
7878
v = self.cc_data.get_var("y-velocity")
79-
79+
8080
# the timestep is min(dx/|u|, dy|v|)
8181
xtmp = self.cc_data.grid.dx/np.amax(np.fabs(u))
8282
ytmp = self.cc_data.grid.dy/np.amax(np.fabs(v))
@@ -90,7 +90,7 @@ def evolve(self):
9090
is part of the Simulation.
9191
"""
9292
myd = self.cc_data
93-
93+
9494
dtdx = self.dt/myd.grid.dx
9595
dtdy = self.dt/myd.grid.dy
9696

@@ -110,7 +110,6 @@ def evolve(self):
110110
dtdy*(flux_y.v() - flux_y.jp(1))
111111

112112
if self.particles is not None:
113-
114113
u = myd.get_var("x-velocity")
115114
v = myd.get_var("y-velocity")
116115

@@ -165,4 +164,3 @@ def dovis(self):
165164

166165
plt.pause(0.001)
167166
plt.draw()
168-

advection_nonuniform/tests/advection_convergence.txt renamed to advection_nonuniform/tests/advection_nonuniform_convergence.txt

File renamed without changes.

advection_nonuniform/tests/test_advection.py renamed to advection_nonuniform/tests/test_advection_nonuniform.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ def teardown_method(self):
3131

3232
def test_initializationst(self):
3333
dens = self.sim.cc_data.get_var("density")
34+
u = self.sim.cc_data.get_var("x-velocity")
35+
v = self.sim.cc_data.get_var("y-velocity")
36+
3437
assert dens.min() == 1.0 and dens.max() == 1.0
38+
assert u.min() == 1.0 and u.max() == 1.0
39+
assert v.min() == 1.0 and v.max() == 1.0

0 commit comments

Comments
 (0)