Skip to content

Commit 68afcc9

Browse files
committed
Switched nested loops to C order
1 parent deabdef commit 68afcc9

5 files changed

Lines changed: 66 additions & 66 deletions

File tree

advection_fv4/interface.py

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

57-
for j in range(jlo - 1, jhi + 1):
58-
for i in range(ilo - 2, ihi + 3):
57+
for i in range(ilo - 2, ihi + 3):
58+
for j in range(jlo - 1, jhi + 1):
5959

6060
# interpolate to the edges
6161
a_int[i, j] = (7.0 / 12.0) * (a[i - 1, j] + a[i, j]) - \
@@ -64,8 +64,8 @@ def states(a, qx, qy, ng, idir):
6464
al[i, j] = a_int[i, j]
6565
ar[i, j] = a_int[i, j]
6666

67-
for j in range(jlo - 1, jhi + 1):
68-
for i in range(ilo - 2, ihi + 3):
67+
for i in range(ilo - 2, ihi + 3):
68+
for j in range(jlo - 1, jhi + 1):
6969
# these live on cell-centers
7070
dafm[i, j] = a[i, j] - a_int[i, j]
7171
dafp[i, j] = a_int[i + 1, j] - a[i, j]
@@ -74,19 +74,19 @@ def states(a, qx, qy, ng, idir):
7474
d2af[i, j] = 6.0 * (a_int[i, j] - 2.0 *
7575
a[i, j] + a_int[i + 1, j])
7676

77-
for j in range(jlo - 1, jhi + 1):
78-
for i in range(ilo - 3, ihi + 3):
77+
for i in range(ilo - 3, ihi + 3):
78+
for j in range(jlo - 1, jhi + 1):
7979
d2ac[i, j] = a[i - 1, j] - 2.0 * a[i, j] + a[i + 1, j]
8080

81-
for j in range(jlo - 1, jhi + 1):
82-
for i in range(ilo - 2, ihi + 3):
81+
for i in range(ilo - 2, ihi + 3):
82+
for j in range(jlo - 1, jhi + 1):
8383
# this lives on the interface
8484
d3a[i, j] = d2ac[i, j] - d2ac[i - 1, j]
8585

8686
# this is a look over cell centers, affecting
8787
# i-1/2,R and i+1/2,L
88-
for j in range(jlo - 1, jhi + 1):
89-
for i in range(ilo - 1, ihi + 1):
88+
for i in range(ilo - 1, ihi + 1):
89+
for j in range(jlo - 1, jhi + 1):
9090

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

144144
elif (idir == 2):
145145

146-
for j in range(jlo - 2, jhi + 3):
147-
for i in range(ilo - 1, ihi + 1):
146+
for i in range(ilo - 1, ihi + 1):
147+
for j in range(jlo - 2, jhi + 3):
148148

149149
# interpolate to the edges
150150
a_int[i, j] = (7.0 / 12.0) * (a[i, j - 1] + a[i, j]) - \
@@ -153,8 +153,8 @@ def states(a, qx, qy, ng, idir):
153153
al[i, j] = a_int[i, j]
154154
ar[i, j] = a_int[i, j]
155155

156-
for j in range(jlo - 2, jhi + 3):
157-
for i in range(ilo - 1, ihi + 1):
156+
for i in range(ilo - 1, ihi + 1):
157+
for j in range(jlo - 2, jhi + 3):
158158
# these live on cell-centers
159159
dafm[i, j] = a[i, j] - a_int[i, j]
160160
dafp[i, j] = a_int[i, j + 1] - a[i, j]
@@ -163,19 +163,19 @@ def states(a, qx, qy, ng, idir):
163163
d2af[i, j] = 6.0 * (a_int[i, j] - 2.0 *
164164
a[i, j] + a_int[i, j + 1])
165165

166-
for j in range(jlo - 3, jhi + 3):
167-
for i in range(ilo - 1, ihi + 1):
166+
for i in range(ilo - 1, ihi + 1):
167+
for j in range(jlo - 3, jhi + 3):
168168
d2ac[i, j] = a[i, j - 1] - 2.0 * a[i, j] + a[i, j + 1]
169169

170-
for j in range(jlo - 2, jhi + 2):
171-
for i in range(ilo - 1, ihi + 1):
170+
for i in range(ilo - 1, ihi + 1):
171+
for j in range(jlo - 2, jhi + 2):
172172
# this lives on the interface
173173
d3a[i, j] = d2ac[i, j] - d2ac[i, j - 1]
174174

175175
# this is a look over cell centers, affecting
176176
# j-1/2,R and j+1/2,L
177-
for j in range(jlo - 1, jhi + 1):
178-
for i in range(ilo - 1, ihi + 1):
177+
for i in range(ilo - 1, ihi + 1):
178+
for j in range(jlo - 1, jhi + 1):
179179

180180
# limit? MC Eq. 24 and 25
181181
if (dafm[i, j] * dafp[i, j] <= 0.0 or
@@ -277,8 +277,8 @@ def states_nolimit(a, qx, qy, ng, idir):
277277
# we need interface values on all faces of the domain
278278
if (idir == 1):
279279

280-
for j in range(jlo - 1, jhi + 1):
281-
for i in range(ilo - 2, ihi + 3):
280+
for i in range(ilo - 2, ihi + 3):
281+
for j in range(jlo - 1, jhi + 1):
282282

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

290290
elif (idir == 2):
291291

292-
for j in range(jlo - 2, jhi + 3):
293-
for i in range(ilo - 1, ihi + 1):
292+
for i in range(ilo - 1, ihi + 1):
293+
for j in range(jlo - 2, jhi + 3):
294294

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

compressible/interface.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def states(idir, qx, qy, ng, dx, dt,
115115
betar = np.zeros(nvar)
116116

117117
# this is the loop over zones. For zone i, we see q_l[i+1] and q_r[i]
118-
for j in range(jlo - 2, jhi + 2):
119-
for i in range(ilo - 2, ihi + 2):
118+
for i in range(ilo - 2, ihi + 2):
119+
for j in range(jlo - 2, jhi + 2):
120120

121121
dq = dqv[i, j, :]
122122
q = qv[i, j, :]
@@ -290,8 +290,8 @@ def riemann_cgf(idir, qx, qy, ng,
290290
jlo = ng
291291
jhi = ng + ny
292292

293-
for j in range(jlo - 1, jhi + 1):
294-
for i in range(ilo - 1, ihi + 1):
293+
for i in range(ilo - 1, ihi + 1):
294+
for j in range(jlo - 1, jhi + 1):
295295

296296
# primitive variable states
297297
rho_l = U_l[i, j, idens]
@@ -599,8 +599,8 @@ def riemann_prim(idir, qx, qy, ng,
599599
jlo = ng
600600
jhi = ng + ny
601601

602-
for j in range(jlo - 1, jhi + 1):
603-
for i in range(ilo - 1, ihi + 1):
602+
for i in range(ilo - 1, ihi + 1):
603+
for j in range(jlo - 1, jhi + 1):
604604

605605
# primitive variable states
606606
rho_l = q_l[i, j, irho]
@@ -859,8 +859,8 @@ def riemann_hllc(idir, qx, qy, ng,
859859
jlo = ng
860860
jhi = ng + ny
861861

862-
for j in range(jlo - 1, jhi + 1):
863-
for i in range(ilo - 1, ihi + 1):
862+
for i in range(ilo - 1, ihi + 1):
863+
for j in range(jlo - 1, jhi + 1):
864864

865865
# primitive variable states
866866
rho_l = U_l[i, j, idens]
@@ -1186,8 +1186,8 @@ def artificial_viscosity(qx, qy, ng, dx, dy,
11861186
jlo = ng
11871187
jhi = ng + ny
11881188

1189-
for j in range(jlo - 1, jhi + 1):
1190-
for i in range(ilo - 1, ihi + 1):
1189+
for i in range(ilo - 1, ihi + 1):
1190+
for j in range(jlo - 1, jhi + 1):
11911191

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

incompressible/incomp_interface.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
171171
dtdx = dt / dx
172172
dtdy = dt / dy
173173

174-
for j in range(jlo - 2, jhi + 2):
175-
for i in range(ilo - 2, ihi + 2):
174+
for i in range(ilo - 2, ihi + 2):
175+
for j in range(jlo - 2, jhi + 2):
176176

177177
# u on x-edges
178178
u_xl[i + 1, j] = u[i, j] + 0.5 * \
@@ -218,8 +218,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
218218
# considered the normal to the interface portion of the predictor.
219219

220220
# add the transverse flux differences to the preliminary interface states
221-
for j in range(jlo - 2, jhi + 2):
222-
for i in range(ilo - 2, ihi + 2):
221+
for i in range(ilo - 2, ihi + 2):
222+
for j in range(jlo - 2, jhi + 2):
223223

224224
ubar = 0.5 * (uhat_adv[i, j] + uhat_adv[i + 1, j])
225225
vbar = 0.5 * (vhat_adv[i, j] + vhat_adv[i, j + 1])
@@ -338,8 +338,8 @@ def riemann(qx, qy, ng, q_l, q_r):
338338

339339
s = np.zeros((qx, qy))
340340

341-
for j in range(jlo - 1, jhi + 1):
342-
for i in range(ilo - 1, ihi + 1):
341+
for i in range(ilo - 1, ihi + 1):
342+
for j in range(jlo - 1, jhi + 1):
343343

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

lm_atm/LM_atm_interface.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def is_symmetric_pair(qx, qy, ng, nodal, sl, sr):
3535

3636
if (not nodal):
3737
done = False
38-
for j in range(jlo, jhi):
39-
for i in range(nx / 2):
38+
for i in range(nx / 2):
39+
for j in range(jlo, jhi):
4040
il = ilo + i
4141
ir = ihi - i
4242

@@ -50,8 +50,8 @@ def is_symmetric_pair(qx, qy, ng, nodal, sl, sr):
5050
else:
5151
done = False
5252

53-
for j in range(jlo, jhi):
54-
for i in range(nx / 2):
53+
for i in range(nx / 2):
54+
for j in range(jlo, jhi):
5555
il = ilo + i
5656
ir = ihi - i + 1
5757

@@ -124,8 +124,8 @@ def is_asymmetric_pair(qx, qy, ng, nodal, sl, sr):
124124

125125
if (not nodal):
126126
done = False
127-
for j in range(jlo, jhi):
128-
for i in range(nx / 2):
127+
for i in range(nx / 2):
128+
for j in range(jlo, jhi):
129129
il = ilo + i
130130
ir = ihi - i
131131

@@ -139,8 +139,8 @@ def is_asymmetric_pair(qx, qy, ng, nodal, sl, sr):
139139
else:
140140
done = False
141141

142-
for j in range(jlo, jhi):
143-
for i in range(nx / 2):
142+
for i in range(nx / 2):
143+
for j in range(jlo, jhi):
144144
il = ilo + i
145145
ir = ihi - i + 1
146146

@@ -379,8 +379,8 @@ def rho_states(qx, qy, ng, dx, dy, dt,
379379
dtdx = dt / dx
380380
dtdy = dt / dy
381381

382-
for j in range(jlo - 2, jhi + 2):
383-
for i in range(ilo - 2, ihi + 2):
382+
for i in range(ilo - 2, ihi + 2):
383+
for j in range(jlo - 2, jhi + 2):
384384

385385
# u on x-edges
386386
rho_xl[i + 1, j] = rho[i, j] + 0.5 * \
@@ -400,8 +400,8 @@ def rho_states(qx, qy, ng, dx, dy, dt,
400400

401401
# now add the transverse term and the non-advective part of the normal
402402
# divergence
403-
for j in range(jlo - 2, jhi + 2):
404-
for i in range(ilo - 2, ihi + 2):
403+
for i in range(ilo - 2, ihi + 2):
404+
for j in range(jlo - 2, jhi + 2):
405405

406406
u_x = (u_MAC[i + 1, j] - u_MAC[i, j]) / dx
407407
v_y = (v_MAC[i, j + 1] - v_MAC[i, j]) / dy
@@ -497,8 +497,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
497497
dtdx = dt / dx
498498
dtdy = dt / dy
499499

500-
for j in range(jlo - 2, jhi + 2):
501-
for i in range(ilo - 2, ihi + 2):
500+
for i in range(ilo - 2, ihi + 2):
501+
for j in range(jlo - 2, jhi + 2):
502502

503503
# u on x-edges
504504
u_xl[i + 1, j] = u[i, j] + 0.5 * \
@@ -549,8 +549,8 @@ def get_interface_states(qx, qy, ng, dx, dy, dt,
549549
# considered the normal to the interface portion of the predictor.
550550

551551
# add the transverse flux differences to the preliminary interface states
552-
for j in range(jlo - 1, jhi + 1):
553-
for i in range(ilo - 1, ihi + 1):
552+
for i in range(ilo - 1, ihi + 1):
553+
for j in range(jlo - 1, jhi + 1):
554554

555555
ubar = 0.5 * (uhat_adv[i, j] + uhat_adv[i + 1, j])
556556
vbar = 0.5 * (vhat_adv[i, j] + vhat_adv[i, j + 1])
@@ -623,8 +623,8 @@ def upwind(qx, qy, ng, q_l, q_r, s):
623623
jlo = ng
624624
jhi = ng + ny
625625

626-
for j in range(jlo - 1, jhi + 2):
627-
for i in range(ilo - 1, ihi + 2):
626+
for i in range(ilo - 1, ihi + 2):
627+
for j in range(jlo - 1, jhi + 2):
628628

629629
if (s[i, j] > 0.0):
630630
q_int[i, j] = q_l[i, j]
@@ -669,8 +669,8 @@ def riemann(qx, qy, ng, q_l, q_r):
669669

670670
s = np.zeros((qx, qy))
671671

672-
for j in range(jlo - 1, jhi + 2):
673-
for i in range(ilo - 1, ihi + 2):
672+
for i in range(ilo - 1, ihi + 2):
673+
for j in range(jlo - 1, jhi + 2):
674674

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

swe/interface.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def states(idir, qx, qy, ng, dx, dt,
110110
dtdx3 = 0.33333 * dtdx
111111

112112
# this is the loop over zones. For zone i, we see q_l[i+1] and q_r[i]
113-
for j in range(jlo - 2, jhi + 2):
114-
for i in range(ilo - 2, ihi + 2):
113+
for i in range(ilo - 2, ihi + 2):
114+
for j in range(jlo - 2, jhi + 2):
115115

116116
dq = dqv[i, j, :]
117117
q = qv[i, j, :]
@@ -263,8 +263,8 @@ def riemann_roe(idir, qx, qy, ng,
263263
jhi = ng + ny
264264
ns = nvar - nspec
265265

266-
for j in range(jlo - 1, jhi + 1):
267-
for i in range(ilo - 1, ihi + 1):
266+
for i in range(ilo - 1, ihi + 1):
267+
for j in range(jlo - 1, jhi + 1):
268268

269269
# primitive variable states
270270
h_l = U_l[i, j, ih]
@@ -406,8 +406,8 @@ def riemann_hllc(idir, qx, qy, ng,
406406
jlo = ng
407407
jhi = ng + ny
408408

409-
for j in range(jlo - 1, jhi + 1):
410-
for i in range(ilo - 1, ihi + 1):
409+
for i in range(ilo - 1, ihi + 1):
410+
for j in range(jlo - 1, jhi + 1):
411411

412412
# primitive variable states
413413
h_l = U_l[i, j, ih]

0 commit comments

Comments
 (0)