@@ -189,11 +189,7 @@ function regrid_bathymetry(target_grid;
189
189
passes = interpolation_passes)
190
190
191
191
if minimum_depth > 0
192
- zi = interior (target_z, :, :, 1 )
193
-
194
- # Set the height of cells with z > -mininum_depth to z=0.
195
- # (In-place + GPU-friendly)
196
- zi .*= zi .<= - minimum_depth
192
+ launch! (arch, target_grid, :xy , _enforce_minimum_depth!, target_z, minimum_depth)
197
193
end
198
194
199
195
if major_basins < Inf
@@ -205,6 +201,17 @@ function regrid_bathymetry(target_grid;
205
201
return target_z
206
202
end
207
203
204
+ @kernel function _enforce_minimum_depth! (target_z, minimum_depth)
205
+ i, j = @index (Global, NTuple)
206
+ z = @inbounds target_z[i, j, 1 ]
207
+
208
+ # Fix active cells to be at least `-minimum_depth`.
209
+ active = z < 0 # it's a wet cell
210
+ z = ifelse (active, min (z, - minimum_depth), z)
211
+
212
+ @inbounds target_z[i, j, 1 ] = z
213
+ end
214
+
208
215
# Here we can either use `regrid!` (three dimensional version) or `interpolate!`.
209
216
function interpolate_bathymetry_in_passes (native_z, target_grid;
210
217
passes = 10 )
462
469
retrieve_bathymetry (grid, :: Nothing ; kw... ) = regrid_bathymetry (grid; kw... )
463
470
retrieve_bathymetry (grid; kw... ) = regrid_bathymetry (grid; kw... )
464
471
465
- end # module
472
+ end # module
0 commit comments