Skip to content

Commit b7c1704

Browse files
SierdCopilot
andauthored
Update aeolis/avalanching.py
added boundary definition. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e83ea56 commit b7c1704

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

aeolis/avalanching.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,32 @@ def avalanche_loop(zb, zne, ds, dn, nx, ny, E, max_iter_ava, tan_dyn):
151151
center = zb[i, j]
152152
# +X direction
153153
g0 = 0.0
154-
right = zb[i, (j + 1) % nx]
155-
left = zb[i, (j - 1) % nx]
156-
if not ((right > center) and (left > center)):
157-
if right > left:
158-
g0 = left - center
159-
else:
160-
g0 = center - right
161-
grad_h_down[i, j, 0] = g0 / ds[i, j]
154+
# Handle boundaries: set gradient to zero at edges
155+
if j == 0 or j == nx - 1:
156+
grad_h_down[i, j, 0] = 0.0
157+
else:
158+
right = zb[i, j + 1]
159+
left = zb[i, j - 1]
160+
if not ((right > center) and (left > center)):
161+
if right > left:
162+
g0 = left - center
163+
else:
164+
g0 = center - right
165+
grad_h_down[i, j, 0] = g0 / ds[i, j]
162166

163167
# +Y direction
164168
g1 = 0.0
165-
down = zb[(i + 1) % ny, j]
166-
up = zb[(i - 1) % ny, j]
167-
if not ((down > center) and (up > center)):
168-
if down > up:
169-
g1 = up - center
170-
else:
171-
g1 = center - down
172-
grad_h_down[i, j, 1] = g1 / dn[i, j]
169+
if i == 0 or i == ny - 1:
170+
grad_h_down[i, j, 1] = 0.0
171+
else:
172+
down = zb[i + 1, j]
173+
up = zb[i - 1, j]
174+
if not ((down > center) and (up > center)):
175+
if down > up:
176+
g1 = up - center
177+
else:
178+
g1 = center - down
179+
grad_h_down[i, j, 1] = g1 / dn[i, j]
173180

174181
# normalize by grid spacing (assume ds, dn are 2D fields)
175182
# for i in range(ny):

0 commit comments

Comments
 (0)