Skip to content

Commit 8cd6548

Browse files
Do not restrict bathymetry (#335)
* Update Bathymetry.jl * add a fill halo * go ahead * the bathymetry is supposed to be on centers not on nodes * this should work * bugfix
1 parent 8a10921 commit 8cd6548

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

src/Bathymetry.jl

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,10 @@ function regrid_bathymetry(target_grid;
126126
close(dataset)
127127

128128
# Diagnose target grid information
129-
arch = architecture(target_grid)
130-
φ₁, φ₂ = y_domain(target_grid)
131-
λ₁, λ₂ = x_domain(target_grid)
132-
133-
if λ₁ < 0 || λ₂ > 360
134-
throw(ArgumentError("Cannot regrid bathymetry between λ₁ = $(λ₁) and λ₂ = $(λ₂).
135-
Bathymetry data is defined on longitudes spanning λ = (0, 360)."))
136-
end
137-
138-
# Calculate limiting indices on the bathymetry grid
139-
i₁ = searchsortedfirst(λ_data, λ₁)
140-
i₂ = searchsortedfirst(λ_data, λ₂) - 1
141-
ii = i₁:i₂
142-
143-
j₁ = searchsortedfirst(φ_data, φ₁)
144-
j₂ = searchsortedfirst(φ_data, φ₂) - 1
145-
jj = j₁:j₂
146-
147-
# Restrict bathymetry coordinate_data to region of interest
148-
λ_data = λ_data[ii] |> Array{BigFloat}
149-
φ_data = φ_data[jj] |> Array{BigFloat}
150-
z_data = z_data[ii, jj]
151-
129+
arch = architecture(target_grid)
130+
λ_data = λ_data |> Array{BigFloat}
131+
φ_data = φ_data |> Array{BigFloat}
132+
152133
if !isnothing(height_above_water)
153134
# Overwrite the height of cells above water.
154135
# This has an impact on reconstruction. Greater height_above_water reduces total
@@ -170,6 +151,7 @@ function regrid_bathymetry(target_grid;
170151
Nyn = length(φ_data)
171152
Nzn = 1
172153

154+
173155
native_grid = LatitudeLongitudeGrid(arch, Float32;
174156
size = (Nxn, Nyn, Nzn),
175157
latitude = (φ₁_data, φ₂_data),
@@ -179,7 +161,8 @@ function regrid_bathymetry(target_grid;
179161

180162
native_z = Field{Center, Center, Nothing}(native_grid)
181163
set!(native_z, z_data)
182-
164+
fill_halo_regions!(native_z)
165+
183166
target_z = interpolate_bathymetry_in_passes(native_z, target_grid;
184167
passes = interpolation_passes)
185168

@@ -206,9 +189,15 @@ function interpolate_bathymetry_in_passes(native_z, target_grid;
206189
Nλt, Nφt = Nt = size(target_grid)
207190
Nλn, Nφn = Nn = size(native_z)
208191

192+
resxt = minimum_xspacing(target_grid)
193+
resyt = minimum_yspacing(target_grid)
194+
195+
resxn = minimum_xspacing(native_z.grid)
196+
resyn = minimum_yspacing(native_z.grid)
197+
209198
# Check whether we are coarsening the grid in any directions.
210199
# If so, skip interpolation passes.
211-
if Nλt > Nλn || Nφt > Nφn
200+
if resxt > resxn || resyt > resyn
212201
target_z = Field{Center, Center, Nothing}(target_grid)
213202
interpolate!(target_z, native_z)
214203
@info string("Skipping passes for interpolating bathymetry of size $Nn ", '\n',

test/test_distributed_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ end
7878
end
7979

8080
@testset "Distributed Bathymetry interpolation" begin
81-
# We start by building a fake bathyemtry on rank 0 and save it to file
81+
# We start by building a fake bathymetry on rank 0 and save it to file
8282
@root begin
83-
λ = -180:0.1:180
83+
λ = -179.5:0.1:179.5
8484
φ = 0:0.1:50
8585

8686
= length(λ)

test/test_simulations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include("runtests_setup.jl")
22

33
using CUDA
44
using OrthogonalSphericalShellGrids
5-
using ClimaOcean.OceanSeaIceModels: adjust_freezing_ocean_temperature!
5+
using ClimaOcean.OceanSeaIceModels: above_freezing_ocean_temperature!
66
using ClimaSeaIce.SeaIceThermodynamics: melting_temperature
77

88
@testset "GPU time stepping test" begin
@@ -53,7 +53,7 @@ using ClimaSeaIce.SeaIceThermodynamics: melting_temperature
5353
# Set the ocean temperature and salinity
5454
set!(ocean.model, T=temperature_metadata[1], S=salinity_metadata[1])
5555

56-
adjust_freezing_ocean_temperature!(ocean, sea_ice)
56+
above_freezing_ocean_temperature!(ocean, sea_ice)
5757

5858
# Test that ocean temperatures are above freezing
5959
T = on_architecture(CPU(), ocean.model.T)

0 commit comments

Comments
 (0)