Skip to content

Commit 17b50f4

Browse files
committed
numba and fortran don't quite agree for incompressible and LM solvers (as you'd expect), so have made separate solver-test notebooks for them. This is not ideal, but can't find a way to pass in a relative error value to nbval
1 parent d1bb66d commit 17b50f4

8 files changed

Lines changed: 1576 additions & 91 deletions

File tree

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ python:
55

66
matrix:
77
include:
8-
- env: MK_ARGS=""
9-
- env: MK_ARGS=fortran
8+
- env:
9+
- MK_ARGS=""
10+
- NB_IGNORE="solver-test-fortran.ipynb"
11+
- env:
12+
- MK_ARGS=fortran
13+
- NB_IGNORE="solver-test.ipynb"
1014

1115
before_install:
1216
- export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")
@@ -28,7 +32,7 @@ before_script:
2832

2933
script:
3034
- flake8 --ignore=W504,F403,E226,E126,E127,E128,E129,E241,E741 .
31-
- pytest -v --cov=. --cov-config .coveragerc --nbval --ignore=docs --ignore=./multigrid/variable_coeff_elliptic.ipynb --ignore=examples/mesh --ignore=examples/multigrid
35+
- pytest -v --cov=. --cov-config .coveragerc --nbval --ignore=docs --ignore=./multigrid/variable_coeff_elliptic.ipynb --ignore=examples/mesh --ignore=examples/multigrid --ignore=$NB_IGNORE
3236
# - travis-sphinx build
3337

3438
# after_success:

advection_fv4/interface.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def states(a, qx, qy, ng, idir):
3232
# we need interface values on all faces of the domain
3333
if (idir == 1):
3434

35-
for j in range(jlo - 1, jhi + 2):
36-
for i in range(ilo - 2, ihi + 4):
35+
for j in range(jlo - 1, jhi + 1):
36+
for i in range(ilo - 2, ihi + 3):
3737

3838
# interpolate to the edges
3939
a_int[i, j] = (7.0 / 12.0) * (a[i - 1, j] + a[i, j]) - \
@@ -42,8 +42,8 @@ def states(a, qx, qy, ng, idir):
4242
al[i, j] = a_int[i, j]
4343
ar[i, j] = a_int[i, j]
4444

45-
for j in range(jlo - 1, jhi + 2):
46-
for i in range(ilo - 2, ihi + 4):
45+
for j in range(jlo - 1, jhi + 1):
46+
for i in range(ilo - 2, ihi + 3):
4747
# these live on cell-centers
4848
dafm[i, j] = a[i, j] - a_int[i, j]
4949
dafp[i, j] = a_int[i + 1, j] - a[i, j]
@@ -52,19 +52,19 @@ def states(a, qx, qy, ng, idir):
5252
d2af[i, j] = 6.0 * (a_int[i, j] - 2.0 *
5353
a[i, j] + a_int[i + 1, j])
5454

55-
for j in range(jlo - 1, jhi + 2):
56-
for i in range(ilo - 3, ihi + 4):
55+
for j in range(jlo - 1, jhi + 1):
56+
for i in range(ilo - 3, ihi + 3):
5757
d2ac[i, j] = a[i - 1, j] - 2.0 * a[i, j] + a[i + 1, j]
5858

59-
for j in range(jlo - 1, jhi + 2):
60-
for i in range(ilo - 2, ihi + 4):
59+
for j in range(jlo - 1, jhi + 1):
60+
for i in range(ilo - 2, ihi + 3):
6161
# this lives on the interface
6262
d3a[i, j] = d2ac[i, j] - d2ac[i - 1, j]
6363

6464
# this is a look over cell centers, affecting
6565
# i-1/2,R and i+1/2,L
66-
for j in range(jlo - 1, jhi + 2):
67-
for i in range(ilo - 1, ihi + 2):
66+
for j in range(jlo - 1, jhi + 1):
67+
for i in range(ilo - 1, ihi + 1):
6868

6969
# limit? MC Eq. 24 and 25
7070
if (dafm[i, j] * dafp[i, j] <= 0.0 or
@@ -121,8 +121,8 @@ def states(a, qx, qy, ng, idir):
121121

122122
elif (idir == 2):
123123

124-
for j in range(jlo - 2, jhi + 4):
125-
for i in range(ilo - 1, ihi + 2):
124+
for j in range(jlo - 2, jhi + 3):
125+
for i in range(ilo - 1, ihi + 1):
126126

127127
# interpolate to the edges
128128
a_int[i, j] = (7.0 / 12.0) * (a[i, j - 1] + a[i, j]) - \
@@ -131,8 +131,8 @@ def states(a, qx, qy, ng, idir):
131131
al[i, j] = a_int[i, j]
132132
ar[i, j] = a_int[i, j]
133133

134-
for j in range(jlo - 2, jhi + 4):
135-
for i in range(ilo - 1, ihi + 2):
134+
for j in range(jlo - 2, jhi + 3):
135+
for i in range(ilo - 1, ihi + 1):
136136
# these live on cell-centers
137137
dafm[i, j] = a[i, j] - a_int[i, j]
138138
dafp[i, j] = a_int[i, j + 1] - a[i, j]
@@ -141,19 +141,19 @@ def states(a, qx, qy, ng, idir):
141141
d2af[i, j] = 6.0 * (a_int[i, j] - 2.0 *
142142
a[i, j] + a_int[i, j + 1])
143143

144-
for j in range(jlo - 3, jhi + 4):
145-
for i in range(ilo - 1, ihi + 2):
144+
for j in range(jlo - 3, jhi + 3):
145+
for i in range(ilo - 1, ihi + 1):
146146
d2ac[i, j] = a[i, j - 1] - 2.0 * a[i, j] + a[i, j + 1]
147147

148-
for j in range(jlo - 2, jhi + 3):
149-
for i in range(ilo - 1, ihi + 2):
148+
for j in range(jlo - 2, jhi + 2):
149+
for i in range(ilo - 1, ihi + 1):
150150
# this lives on the interface
151151
d3a[i, j] = d2ac[i, j] - d2ac[i, j - 1]
152152

153153
# this is a look over cell centers, affecting
154154
# j-1/2,R and j+1/2,L
155-
for j in range(jlo - 1, jhi + 2):
156-
for i in range(ilo - 1, ihi + 2):
155+
for j in range(jlo - 1, jhi + 1):
156+
for i in range(ilo - 1, ihi + 1):
157157

158158
# limit? MC Eq. 24 and 25
159159
if (dafm[i, j] * dafp[i, j] <= 0.0 or
@@ -232,8 +232,8 @@ def states_nolimit(a, qx, qy, ng, idir):
232232
# we need interface values on all faces of the domain
233233
if (idir == 1):
234234

235-
for j in range(jlo - 1, jhi + 2):
236-
for i in range(ilo - 2, ihi + 4):
235+
for j in range(jlo - 1, jhi + 1):
236+
for i in range(ilo - 2, ihi + 3):
237237

238238
# interpolate to the edges
239239
a_int[i, j] = (7.0 / 12.0) * (a[i - 1, j] + a[i, j]) - \
@@ -244,8 +244,8 @@ def states_nolimit(a, qx, qy, ng, idir):
244244

245245
elif (idir == 2):
246246

247-
for j in range(jlo - 2, jhi + 4):
248-
for i in range(ilo - 1, ihi + 2):
247+
for j in range(jlo - 2, jhi + 3):
248+
for i in range(ilo - 1, ihi + 1):
249249

250250
# interpolate to the edges
251251
a_int[i, j] = (7.0 / 12.0) * (a[i, j - 1] + a[i, j]) - \

compressible/interface.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def states(idir, qx, qy, ng, dx, dt,
8787
betar = np.zeros(nvar)
8888

8989
# this is the loop over zones. For zone i, we see q_l[i+1] and q_r[i]
90-
for j in range(jlo - 2, jhi + 3):
91-
for i in range(ilo - 2, ihi + 3):
90+
for j in range(jlo - 2, jhi + 2):
91+
for i in range(ilo - 2, ihi + 2):
9292

9393
dq[:] = dqv[i, j, :]
9494
q[:] = qv[i, j, :]
@@ -166,7 +166,7 @@ def states(idir, qx, qy, ng, dx, dt,
166166

167167
# compute the Vhat functions
168168
for m in range(nvar):
169-
sum = np.dot(lvec[m, :], dq[:])
169+
sum = np.dot(lvec[m, :], dq)
170170

171171
betal[m] = dtdx4 * (e_val[3] - e_val[m]) * \
172172
(np.copysign(1.0, e_val[m]) + 1.0) * sum
@@ -175,8 +175,8 @@ def states(idir, qx, qy, ng, dx, dt,
175175

176176
# construct the states
177177
for m in range(nvar):
178-
sum_l = np.dot(betal[:], rvec[:, m])
179-
sum_r = np.dot(betar[:], rvec[:, m])
178+
sum_l = np.dot(betal, rvec[:, m])
179+
sum_r = np.dot(betar, rvec[:, m])
180180

181181
if (idir == 1):
182182
q_l[i + 1, j, m] = q_l[i + 1, j, m] + sum_l
@@ -237,8 +237,8 @@ def riemann_cgf(idir, qx, qy, ng,
237237
jlo = ng
238238
jhi = ng + ny
239239

240-
for j in range(jlo - 1, jhi + 2):
241-
for i in range(ilo - 1, ihi + 2):
240+
for j in range(jlo - 1, jhi + 1):
241+
for i in range(ilo - 1, ihi + 1):
242242

243243
# primitive variable states
244244
rho_l = U_l[i, j, idens]
@@ -522,8 +522,8 @@ def riemann_prim(idir, qx, qy, ng,
522522
jlo = ng
523523
jhi = ng + ny
524524

525-
for j in range(jlo - 1, jhi + 2):
526-
for i in range(ilo - 1, ihi + 2):
525+
for j in range(jlo - 1, jhi + 1):
526+
for i in range(ilo - 1, ihi + 1):
527527

528528
# primitive variable states
529529
rho_l = q_l[i, j, irho]
@@ -755,8 +755,8 @@ def riemann_hllc(idir, qx, qy, ng,
755755
jlo = ng
756756
jhi = ng + ny
757757

758-
for j in range(jlo - 1, jhi + 2):
759-
for i in range(ilo - 1, ihi + 2):
758+
for j in range(jlo - 1, jhi + 1):
759+
for i in range(ilo - 1, ihi + 1):
760760

761761
# primitive variable states
762762
rho_l = U_l[i, j, idens]
@@ -976,8 +976,7 @@ def consFlux(idir, gamma, idens, ixmom, iymom, iener, irhoX, nvar, nspec, U_stat
976976
u = U_state[ixmom] / U_state[idens]
977977
v = U_state[iymom] / U_state[idens]
978978

979-
p = (U_state[iener] - 0.5 * U_state[idens] *
980-
(u * u + v * v)) * (gamma - 1.0)
979+
p = (U_state[iener] - 0.5 * U_state[idens] * (u * u + v * v)) * (gamma - 1.0)
981980

982981
if (idir == 1):
983982
F[idens] = U_state[idens] * u
@@ -1041,8 +1040,8 @@ def artificial_viscosity(qx, qy, ng, dx, dy,
10411040
jlo = ng
10421041
jhi = ng + ny
10431042

1044-
for j in range(jlo - 1, jhi + 2):
1045-
for i in range(ilo - 1, ihi + 2):
1043+
for j in range(jlo - 1, jhi + 1):
1044+
for i in range(ilo - 1, ihi + 1):
10461045

10471046
# start by computing the divergence on the x-interface. The
10481047
# x-difference is simply the difference of the cell-centered

incompressible/incomp_interface.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
109109
dtdx = dt / dx
110110
dtdy = dt / dy
111111

112-
for j in range(jlo - 2, jhi + 3):
113-
for i in range(ilo - 2, ihi + 3):
112+
for j in range(jlo - 2, jhi + 2):
113+
for i in range(ilo - 2, ihi + 2):
114114

115115
# u on x-edges
116116
u_xl[i + 1, j] = u[i, j] + 0.5 * \
@@ -156,8 +156,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
156156
# considered the normal to the interface portion of the predictor.
157157

158158
# add the transverse flux differences to the preliminary interface states
159-
for j in range(jlo - 2, jhi + 3):
160-
for i in range(ilo - 2, ihi + 3):
159+
for j in range(jlo - 2, jhi + 2):
160+
for i in range(ilo - 2, ihi + 2):
161161

162162
ubar = 0.5 * (uhat_adv[i, j] + uhat_adv[i + 1, j])
163163
vbar = 0.5 * (vhat_adv[i, j] + vhat_adv[i, j + 1])
@@ -212,8 +212,8 @@ def upwind(qx, qy, ng, q_l, q_r, s, q_int):
212212
jlo = ng
213213
jhi = ng + ny
214214

215-
for j in range(jlo - 1, jhi + 2):
216-
for i in range(ilo - 1, ihi + 2):
215+
for j in range(jlo - 1, jhi + 1):
216+
for i in range(ilo - 1, ihi + 1):
217217

218218
if (s[i, j] > 0.0):
219219
q_int[i, j] = q_l[i, j]
@@ -240,8 +240,8 @@ def riemann(qx, qy, ng, q_l, q_r, s):
240240
jlo = ng
241241
jhi = ng + ny
242242

243-
for j in range(jlo - 1, jhi + 2):
244-
for i in range(ilo - 1, ihi + 2):
243+
for j in range(jlo - 1, jhi + 1):
244+
for i in range(ilo - 1, ihi + 1):
245245

246246
if (q_l[i, j] > 0.0 and q_l[i, j] + q_r[i, j] > 0.0):
247247
s[i, j] = q_l[i, j]

lm_atm/LM_atm_interface.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ def rho_states(qx, qy, ng, dx, dy, dt,
235235
dtdx = dt / dx
236236
dtdy = dt / dy
237237

238-
for j in range(jlo - 2, jhi + 3):
239-
for i in range(ilo - 2, ihi + 3):
238+
for j in range(jlo - 2, jhi + 2):
239+
for i in range(ilo - 2, ihi + 2):
240240

241241
# u on x-edges
242242
rho_xl[i + 1, j] = rho[i, j] + 0.5 * \
@@ -256,8 +256,8 @@ def rho_states(qx, qy, ng, dx, dy, dt,
256256

257257
# now add the transverse term and the non-advective part of the normal
258258
# divergence
259-
for j in range(jlo - 2, jhi + 3):
260-
for i in range(ilo - 2, ihi + 3):
259+
for j in range(jlo - 2, jhi + 2):
260+
for i in range(ilo - 2, ihi + 2):
261261

262262
u_x = (u_MAC[i + 1, j] - u_MAC[i, j]) / dx
263263
v_y = (v_MAC[i, j + 1] - v_MAC[i, j]) / dy
@@ -333,8 +333,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
333333
dtdx = dt / dx
334334
dtdy = dt / dy
335335

336-
for j in range(jlo - 2, jhi + 3):
337-
for i in range(ilo - 2, ihi + 3):
336+
for j in range(jlo - 2, jhi + 2):
337+
for i in range(ilo - 2, ihi + 2):
338338

339339
# u on x-edges
340340
u_xl[i + 1, j] = u[i, j] + 0.5 * \
@@ -385,8 +385,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
385385
# considered the normal to the interface portion of the predictor.
386386

387387
# add the transverse flux differences to the preliminary interface states
388-
for j in range(jlo - 1, jhi + 2):
389-
for i in range(ilo - 1, ihi + 2):
388+
for j in range(jlo - 1, jhi + 1):
389+
for i in range(ilo - 1, ihi + 1):
390390

391391
ubar = 0.5 * (uhat_adv[i, j] + uhat_adv[i + 1, j])
392392
vbar = 0.5 * (vhat_adv[i, j] + vhat_adv[i, j + 1])
@@ -440,8 +440,8 @@ def upwind(qx, qy, ng, q_l, q_r, s, q_int):
440440
jlo = ng
441441
jhi = ng + ny
442442

443-
for j in range(jlo - 1, jhi + 3):
444-
for i in range(ilo - 1, ihi + 3):
443+
for j in range(jlo - 1, jhi + 2):
444+
for i in range(ilo - 1, ihi + 2):
445445

446446
if (s[i, j] > 0.0):
447447
q_int[i, j] = q_l[i, j]
@@ -467,8 +467,8 @@ def riemann(qx, qy, ng, q_l, q_r, s):
467467
jlo = ng
468468
jhi = ng + ny
469469

470-
for j in range(jlo - 1, jhi + 3):
471-
for i in range(ilo - 1, ihi + 3):
470+
for j in range(jlo - 1, jhi + 2):
471+
for i in range(ilo - 1, ihi + 2):
472472

473473
if (q_l[i, j] > 0.0 and q_l[i, j] + q_r[i, j] > 0.0):
474474
s[i, j] = q_l[i, j]

setup_fortran.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
from numpy.distutils.core import setup, Extension
88

9-
f_modules = ["compressible.interface", "advection_fv4.interface", "lm_atm.LM_atm_interface", "incompressible.incomp_interface", "swe.interface"]
9+
f_modules = ["compressible.interface", "advection_fv4.interface",
10+
"lm_atm.LM_atm_interface", "incompressible.incomp_interface", "swe.interface"]
1011

11-
ext_modules = [Extension(module, [module.replace('.', '/')+'_f.f90']) for module in f_modules]
12+
ext_modules = [Extension(module, [module.replace('.', '/') + '_f.f90'])
13+
for module in f_modules]
1214

1315
setup(ext_modules=ext_modules)

0 commit comments

Comments
 (0)