Skip to content

Commit 17ec41b

Browse files
Fixing XPartialslip
1 parent 85bbeff commit 17ec41b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

parcels/application_kernels/interpolation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ def is_land(ti: int, zi: int, yi: int, xi: int):
183183
f_v = np.ones_like(eta)
184184

185185
if lenZ == 1:
186-
f_u = np.where(is_land(0, 0, 0, 0) & is_land(0, 0, 0, 1) & (eta > 0), f_u / eta, f_u)
187-
f_u = np.where(is_land(0, 0, 1, 0) & is_land(0, 0, 1, 1) & (eta < 1), f_u / (1 - eta), f_u)
188-
f_v = np.where(is_land(0, 0, 0, 0) & is_land(0, 0, 1, 0) & (xsi > 0), f_v / xsi, f_v)
189-
f_v = np.where(is_land(0, 0, 0, 1) & is_land(0, 0, 1, 1) & (xsi < 1), f_v / (1 - xsi), f_v)
186+
f_u = np.where(is_land(0, 0, 0, 0) & is_land(0, 0, 0, 1) & (eta > 0), f_u * (a + b * eta) / eta, f_u)
187+
f_u = np.where(is_land(0, 0, 1, 0) & is_land(0, 0, 1, 1) & (eta < 1), f_u * (1 - b * eta) / (1 - eta), f_u)
188+
f_v = np.where(is_land(0, 0, 0, 0) & is_land(0, 0, 1, 0) & (xsi > 0), f_v * (a + b * xsi) / xsi, f_v)
189+
f_v = np.where(is_land(0, 0, 0, 1) & is_land(0, 0, 1, 1) & (xsi < 1), f_v * (1 - b * xsi) / (1 - xsi), f_v)
190190
else:
191191
f_u = np.where(
192192
is_land(0, 0, 0, 0) & is_land(0, 0, 0, 1) & is_land(0, 1, 0, 0) & is_land(0, 1, 0, 1) & (eta > 0),
@@ -195,7 +195,7 @@ def is_land(ti: int, zi: int, yi: int, xi: int):
195195
)
196196
f_u = np.where(
197197
is_land(0, 0, 1, 0) & is_land(0, 0, 1, 1) & is_land(0, 1, 1, 0) & is_land(0, 1, 1, 1) & (eta < 1),
198-
f_u * (a - b * eta) / (1 - eta),
198+
f_u * (1 - b * eta) / (1 - eta),
199199
f_u,
200200
)
201201
f_v = np.where(
@@ -205,7 +205,7 @@ def is_land(ti: int, zi: int, yi: int, xi: int):
205205
)
206206
f_v = np.where(
207207
is_land(0, 0, 0, 1) & is_land(0, 0, 1, 1) & is_land(0, 1, 0, 1) & is_land(0, 1, 1, 1) & (xsi < 1),
208-
f_v * (a - b * xsi) / (1 - xsi),
208+
f_v * (1 - b * xsi) / (1 - xsi),
209209
f_v,
210210
)
211211
f_u = np.where(
@@ -215,7 +215,7 @@ def is_land(ti: int, zi: int, yi: int, xi: int):
215215
)
216216
f_u = np.where(
217217
is_land(0, 1, 0, 0) & is_land(0, 1, 0, 1) & is_land(0, 1, 1, 0 & is_land(0, 1, 1, 1) & (zeta < 1)),
218-
f_u * (a - b * zeta) / (1 - zeta),
218+
f_u * (1 - b * zeta) / (1 - zeta),
219219
f_u,
220220
)
221221
f_v = np.where(
@@ -225,7 +225,7 @@ def is_land(ti: int, zi: int, yi: int, xi: int):
225225
)
226226
f_v = np.where(
227227
is_land(0, 1, 0, 0) & is_land(0, 1, 0, 1) & is_land(0, 1, 1, 0 & is_land(0, 1, 1, 1) & (zeta < 1)),
228-
f_v * (a - b * zeta) / (1 - zeta),
228+
f_v * (1 - b * zeta) / (1 - zeta),
229229
f_v,
230230
)
231231

tests/v4/test_interpolation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
XFreeslip,
1212
XLinear,
1313
XNearest,
14+
XPartialslip,
1415
ZeroInterpolator,
1516
)
1617
from parcels.field import Field, VectorField
@@ -88,7 +89,11 @@ def test_raw_2d_interpolation(field, func, t, z, y, x, expected):
8889
@pytest.mark.parametrize(
8990
"func, t, z, y, x, expected",
9091
[
92+
(XPartialslip, np.timedelta64(1, "s"), 0, 0, 0.0, [[1], [1]]),
9193
(XFreeslip, np.timedelta64(1, "s"), 0, 0.5, 1.5, [[1], [0.5]]),
94+
(XPartialslip, np.timedelta64(1, "s"), 0, 2.5, 1.5, [[0.75], [0.5]]),
95+
(XFreeslip, np.timedelta64(1, "s"), 0, 2.5, 1.5, [[1], [0.5]]),
96+
(XPartialslip, np.timedelta64(1, "s"), 0, 1.5, 0.5, [[0.5], [0.75]]),
9297
(XFreeslip, np.timedelta64(1, "s"), 0, 1.5, 0.5, [[0.5], [1]]),
9398
(
9499
XFreeslip,
@@ -103,7 +108,6 @@ def test_raw_2d_interpolation(field, func, t, z, y, x, expected):
103108
def test_spatial_slip_interpolation(field, func, t, z, y, x, expected):
104109
field.data[:] = 1.0
105110
field.data[:, :, 1:3, 1:3] = 0.0 # Set zero land value to test spatial slip
106-
print(field.data[0, 0, :, :])
107111
U = field
108112
V = field
109113
UV = VectorField("UV", U, V, vector_interp_method=func)

0 commit comments

Comments
 (0)