Skip to content

Commit b4e7d54

Browse files
Drop ClimaOcean.GridUtils in favor of Oceananigans.Grids coordinate_utils since Oceananigans 0.97.2 (#583)
* drop GridUtils in favor of Oceananigans.Grids coord_utils methods * no, don't delete that * Update vertical_grids.md * Update Project.toml --------- Co-authored-by: Simone Silvestri <[email protected]>
1 parent 85e70e1 commit b4e7d54

14 files changed

+21
-655
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "ClimaOcean"
22
uuid = "0376089a-ecfe-4b0e-a64f-9c555d74d754"
33
license = "MIT"
44
authors = ["Climate Modeling Alliance and contributors"]
5-
version = "0.7.3"
5+
version = "0.8.0"
66

77
[deps]
88
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -55,7 +55,7 @@ JLD2 = "0.4, 0.5"
5555
KernelAbstractions = "0.9"
5656
MPI = "0.20"
5757
NCDatasets = "0.12, 0.13, 0.14"
58-
Oceananigans = "0.97.1"
58+
Oceananigans = "0.97.3"
5959
OffsetArrays = "1.14"
6060
PrecompileTools = "1"
6161
PythonCall = "0.9"

docs/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
1010
SeawaterPolynomials = "d496a93d-167e-4197-9f49-d3af4ff8fe40"
1111

1212
[compat]
13-
CUDA = "5"
1413
Documenter = "1"
1514
DocumenterCitations = "1.3"
1615
Literate = "2.2"

docs/src/library/internals.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ Modules = [ClimaOcean.Bathymetry]
6565
Public = false
6666
```
6767

68-
## GridUtils
69-
70-
```@autodocs
71-
Modules = [ClimaOcean.GridUtils]
72-
Public = false
73-
```
74-
7568
## OceanSimulations
7669

7770
```@autodocs

docs/src/library/public.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ Private = false
6666
Modules = [ClimaOcean.Bathymetry]
6767
Private = false
6868
```
69-
## GridUtils
70-
71-
```@autodocs
72-
Modules = [ClimaOcean.GridUtils]
73-
Private = false
74-
```
7569

7670
## OceanSimulations
7771

docs/src/vertical_grids.md

Lines changed: 5 additions & 293 deletions
Original file line numberDiff line numberDiff line change
@@ -1,295 +1,7 @@
11
# Vertical grids
22

3-
A few vertical grids are implemented within the [Grid Utilities](@ref ClimaOcean.GridUtils) module.
4-
5-
### Exponential spacing
6-
7-
The [`ExponentialCoordinate`](@ref) method returns a coordinate with interfaces that lie on an exponential profile.
8-
By that, we mean that a uniformly discretized domain in the range ``[a, b]`` is mapped back onto itself via either
9-
10-
```math
11-
z \mapsto w(z) = b - (b - a) \frac{\exp{[(b - z) / h]} - 1}{\exp{[(b - a) / h]} - 1} \quad \text{(right biased)}
12-
```
13-
14-
or
15-
16-
```math
17-
z \mapsto w(z) = a + (b - a) \frac{\exp{[(z - a) / h]} - 1}{\exp{[(b - a) / h]} - 1} \quad \text{(left biased)}
18-
```
19-
20-
The exponential mappings above have an e-folding controlled by scale ``h``.
21-
It worths noting that the exponential maps imply that the cell widths (distances between interfaces) grow linearly at a rate inversely proportional to ``h / (b - a)``.
22-
23-
The right-biased map biases the interfaces being closer towards ``b``; the left-biased map biases the interfaces towards ``a``.
24-
25-
At the limit ``h / (b - a) \to \infty`` both mappings reduce to identity (``w \to z``) and thus the grid becomes uniformly spaced.
26-
27-
28-
!!! note "Oceanography-related bias"
29-
For oceanographic purposes, the right-biased exponential mapping is usually more relevant as it implies finer vertical resolution closer to the ocean's surface.
30-
31-
```@setup vgrids
32-
using CairoMakie
33-
set_theme!(Theme(Lines = (linewidth = 3,)))
34-
CairoMakie.activate!(type="svg")
35-
```
36-
37-
```@example vgrids
38-
using ClimaOcean
39-
using ClimaOcean.GridUtils: rightbiased_exponential_mapping, leftbiased_exponential_mapping
40-
41-
using CairoMakie
42-
43-
depth = 1000
44-
45-
zb = - depth # left
46-
zt = 0 # right
47-
z = range(zb, stop=zt, length=501)
48-
zp = range(zb, stop=zt, length=6) # coarser for plotting
49-
50-
axis_labels = (xlabel="uniform coordinate z / (b-a)",
51-
ylabel="mapped coordinate w / (b-a)")
52-
53-
fig = Figure(size=(800, 350))
54-
axl = Axis(fig[1, 1]; title="left-biased map", axis_labels...)
55-
axr = Axis(fig[1, 2]; title="right-biased map", axis_labels...)
56-
57-
for scale in [depth/20, depth/5, depth/2, 1e12*depth]
58-
label = "h / (b-a) = $(scale / depth)"
59-
lines!(axl, z / depth, leftbiased_exponential_mapping.(z, zb, zt, scale) / depth; label)
60-
scatter!(axl, zp / depth, leftbiased_exponential_mapping.(zp, zb, zt, scale) / depth)
61-
62-
lines!(axr, z / depth, rightbiased_exponential_mapping.(z, zb, zt, scale) / depth; label)
63-
scatter!(axr, zp / depth, rightbiased_exponential_mapping.(zp, zb, zt, scale) / depth)
64-
end
65-
66-
Legend(fig[2, :], axl, orientation = :horizontal)
67-
68-
fig
69-
```
70-
71-
Note that the smallest the ratio ``h / (b-a)`` is, the more finely-packed are the mapped points towards the left or right side of the domain.
72-
73-
74-
Let's see to use [`ExponentialCoordinate`](@ref) works. Here we construct a vertical grid with 10 cells that goes down to 1000 meters depth.
75-
76-
```@example vgrids
77-
using ClimaOcean
78-
79-
Nz = 10
80-
depth = 1000
81-
left = zb = -depth
82-
right = 0
83-
84-
z = ExponentialCoordinate(Nz, left, right)
85-
```
86-
87-
By default, the oceanographically-relevant right-biased map was used.
88-
Also note above, that the default e-folding scale (`scale = (right - left) / 5`) was used.
89-
If we don't prescribe a value for `right` then its default oceanographically-appropriate value of 0 is used.
90-
91-
We can inspect the interfaces of the coordinate via
92-
93-
```@example vgrids
94-
[z(k) for k in 1:Nz+1]
95-
```
96-
97-
To demonstrate how the scale ``h`` affects the coordinate, we construct below two such exponential
98-
coordinates: the first with ``h / (b - a) = 1/5`` and the second with ``h / (b - a) = 1/2``.
99-
100-
```@example vgrids
101-
using ClimaOcean
102-
using Oceananigans
103-
104-
Nz = 10
105-
depth = 1000
106-
107-
108-
using CairoMakie
109-
110-
fig = Figure()
111-
112-
scale = depth / 5
113-
z = ExponentialCoordinate(Nz, -depth; scale)
114-
grid = RectilinearGrid(; size=Nz, z, topology=(Flat, Flat, Bounded))
115-
zf = znodes(grid, Face())
116-
zc = znodes(grid, Center())
117-
Δz = zspacings(grid, Center())[1, 1, 1:Nz]
118-
119-
120-
axΔz1 = Axis(fig[1, 1]; xlabel = "z-spacing (m)", ylabel = "z (m)", title = "scale = depth / 5")
121-
axz1 = Axis(fig[1, 2])
122-
linkaxes!(axΔz1, axz1)
123-
124-
lΔz = lines!(axΔz1, - zf * (depth/scale) / Nz, zf, color=(:purple, 0.3))
125-
scatter!(axΔz1, Δz, zc)
126-
hidespines!(axΔz1, :t, :r)
127-
128-
lines!(axz1, [0, 0], [-depth, 0], color=:gray)
129-
scatter!(axz1, 0 * zf, zf, marker=:hline, color=:gray, markersize=20)
130-
scatter!(axz1, 0 * zc, zc)
131-
hidedecorations!(axz1)
132-
hidespines!(axz1)
133-
134-
135-
scale = depth / 2
136-
z = ExponentialCoordinate(Nz, -depth; scale)
137-
grid = RectilinearGrid(; size=Nz, z, topology=(Flat, Flat, Bounded))
138-
zf = znodes(grid, Face())
139-
zc = znodes(grid, Center())
140-
Δz = zspacings(grid, Center())[1, 1, 1:Nz]
141-
142-
axΔz2 = Axis(fig[1, 3]; xlabel = "z-spacing (m)", ylabel = "z (m)", title = "scale = depth / 2")
143-
axz2 = Axis(fig[1, 4])
144-
linkaxes!(axΔz2, axz2)
145-
146-
lΔz = lines!(axΔz2, - zf * (depth/scale) / Nz, zf, color=(:purple, 0.3))
147-
scatter!(axΔz2, Δz, zc)
148-
hidespines!(axΔz2, :t, :r)
149-
150-
lines!(axz2, [0, 0], [-depth, 0], color=:gray)
151-
scatter!(axz2, 0 * zf, zf, marker=:hline, color=:gray, markersize=20)
152-
scatter!(axz2, 0 * zc, zc)
153-
hidedecorations!(axz2)
154-
hidespines!(axz2)
155-
156-
157-
colsize!(fig.layout, 2, Relative(0.1))
158-
colsize!(fig.layout, 4, Relative(0.1))
159-
160-
legend = Legend(fig[2, :], [lΔz], ["slope = (depth / scale) / Nz"], orientation = :horizontal)
161-
162-
fig
163-
```
164-
165-
For both grids, the spacings grow linearly with depth and sum up to the total depth.
166-
But with the larger ``h / L`` is, the smaller the rate is that the spacings increase with depth.
167-
168-
A ridiculously large value of ``h / L`` (approximating infinity) gives a uniform grid:
169-
170-
```@example vgrids
171-
z = ExponentialCoordinate(Nz, depth, scale = 1e12*depth)
172-
[z(k) for k in 1:Nz+1]
173-
```
174-
175-
A downside of [`ExponentialCoordinate`](@ref) is that we don't have tight control on the minimum
176-
spacing at the surface.
177-
To prescribe the surface spacing we need to play around with the scale ``h`` and the number of vertical cells ``N_z``.
178-
179-
### Stretched ``z`` faces
180-
181-
The [`StretchedCoordinate`](@ref) method allows a tighter control on the vertical spacing at the surface.
182-
That is, we can prescribe a constant spacing over the top `surface_layer_height` below which the grid spacing
183-
increases following a prescribed stretching law.
184-
The downside here is that neither the final grid depth nor the total number of vertical cells can be prescribed.
185-
The final depth we get is greater or equal from what we prescribe via the keyword argument `depth`.
186-
Also, the total number of cells we end up with depends on the stretching law.
187-
188-
The three grids below have constant 20-meter spacing for the top 120 meters.
189-
We prescribe to all three a `depth = 750` meters and we apply power-law stretching for depths below 120 meters.
190-
The bigger the power-law stretching factor is, the further the last interface goes beyond the prescribed depth and/or with less total number of cells.
191-
192-
```@example vgrids
193-
depth = 750
194-
surface_layer_Δz = 20
195-
surface_layer_height = 120
196-
197-
z = StretchedCoordinate(; depth,
198-
surface_layer_Δz,
199-
surface_layer_height,
200-
stretching = PowerLawStretching(1.08))
201-
grid = RectilinearGrid(; size=length(z), z, topology=(Flat, Flat, Bounded))
202-
zf = znodes(grid, Face())
203-
zc = znodes(grid, Center())
204-
Δz = zspacings(grid, Center())
205-
Δz = view(Δz, 1, 1, :) # for plotting
206-
207-
fig = Figure(size=(800, 550))
208-
209-
axΔz1 = Axis(fig[1, 1];
210-
xlabel = "z-spacing (m)",
211-
ylabel = "z (m)",
212-
title = "PowerLawStretching(1.09)\n $(length(zf)-1) cells\n bottom interface at z = $(zf[1]) m\n ")
213-
214-
axz1 = Axis(fig[1, 2])
215-
216-
ldepth = hlines!(axΔz1, -depth, color = :salmon, linestyle=:dash)
217-
lzbottom = hlines!(axΔz1, zf[1], color = :grey)
218-
scatter!(axΔz1, Δz, zc)
219-
hidespines!(axΔz1, :t, :r)
220-
221-
lines!(axz1, [0, 0], [zf[1], 0], color=:gray)
222-
scatter!(axz1, 0 * zf, zf, marker=:hline, color=:gray, markersize=20)
223-
scatter!(axz1, 0 * zc, zc)
224-
hidedecorations!(axz1)
225-
hidespines!(axz1)
226-
227-
228-
z = StretchedCoordinate(; depth,
229-
surface_layer_Δz,
230-
surface_layer_height,
231-
stretching = PowerLawStretching(1.04))
232-
grid = RectilinearGrid(; size=length(z), z, topology=(Flat, Flat, Bounded))
233-
zf = znodes(grid, Face())
234-
zc = znodes(grid, Center())
235-
Δz = zspacings(grid, Center())
236-
Δz = view(Δz, 1, 1, :) # for plotting
237-
238-
axΔz2 = Axis(fig[1, 3];
239-
xlabel = "z-spacing (m)",
240-
ylabel = "z (m)",
241-
title = "PowerLawStretching(1.04)\n $(length(zf)-1) cells\n bottom interface at z = $(zf[1]) m\n ")
242-
axz2 = Axis(fig[1, 4])
243-
244-
ldepth = hlines!(axΔz2, -depth, color = :salmon, linestyle=:dash)
245-
lzbottom = hlines!(axΔz2, zf[1], color = :grey)
246-
scatter!(axΔz2, Δz, zc)
247-
hidespines!(axΔz2, :t, :r)
248-
249-
lines!(axz2, [0, 0], [zf[1], 0], color=:gray)
250-
scatter!(axz2, 0 * zf, zf, marker=:hline, color=:gray, markersize=20)
251-
scatter!(axz2, 0 * zc, zc)
252-
hidedecorations!(axz2)
253-
hidespines!(axz2)
254-
255-
256-
z = StretchedCoordinate(; depth,
257-
surface_layer_Δz,
258-
surface_layer_height,
259-
stretching = PowerLawStretching(1.04),
260-
constant_bottom_spacing_depth = 500)
261-
grid = RectilinearGrid(; size=length(z), z, topology=(Flat, Flat, Bounded))
262-
zf = znodes(grid, Face())
263-
zc = znodes(grid, Center())
264-
Δz = zspacings(grid, Center())
265-
Δz = view(Δz, 1, 1, :) # for plotting
266-
267-
axΔz3 = Axis(fig[1, 5];
268-
xlabel = "z-spacing (m)",
269-
ylabel = "z (m)",
270-
title = "PowerLawStretching(1.04)\n $(length(zf)-1) cells\n bottom interface at z = $(zf[1]) m\n constant spacing below 500 m")
271-
axz3 = Axis(fig[1, 6])
272-
273-
ldepth = hlines!(axΔz3, -depth, color = :salmon, linestyle=:dash)
274-
lzbottom = hlines!(axΔz3, zf[1], color = :grey)
275-
scatter!(axΔz3, Δz, zc)
276-
277-
hidespines!(axΔz3, :t, :r)
278-
279-
lines!(axz3, [0, 0], [zf[1], 0], color=:gray)
280-
scatter!(axz3, 0 * zf, zf, marker=:hline, color=:gray, markersize=20)
281-
scatter!(axz3, 0 * zc, zc)
282-
hidedecorations!(axz3)
283-
hidespines!(axz3)
284-
285-
286-
linkaxes!(axΔz1, axz1, axΔz2, axz2, axΔz3, axz3)
287-
288-
Legend(fig[2, :], [ldepth, lzbottom], ["prescribed depth", "bottom-most z interface"], orientation = :horizontal)
289-
290-
colsize!(fig.layout, 2, Relative(0.1))
291-
colsize!(fig.layout, 4, Relative(0.1))
292-
colsize!(fig.layout, 6, Relative(0.1))
293-
294-
fig
295-
```
3+
We construct vertical coordinates using `Oceananigans.ExponentialCoordinate` and
4+
`Oceananigans.ConstantToStretchedCoordinate`. The
5+
[Grids section](https://clima.github.io/OceananigansDocumentation/dev/grids/#Coordinate-helper-utilities)
6+
in the Oceananigans Documentation includes a mini-tutorial on how the above-mentioned methods
7+
can be used to generate a coordinate of your liking.

examples/download_glorys_data.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Ny = 20 * 12
88
Nz = 50
99

1010
depth = 6000
11-
z = ExponentialCoordinate(Nz, -depth; scale=depth/4.5)
11+
z = ExponentialCoordinate(Nz, -depth, 0; scale=depth/4.5)
1212

1313
grid = LatitudeLongitudeGrid(arch;
1414
size = (Nx, Ny, Nz),

examples/mediterranean_simulation_with_ecco_restoring.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ using CUDA
2727
# ## Grid Configuration for the Mediterranean Sea
2828
#
2929
# The script defines a high-resolution grid to represent the Mediterranean Sea, specifying the domain
30-
# in terms of longitude (λ₁, λ₂), latitude (φ₁, φ₂), and a stretched vertical grid (via `StretchedCoordinate`)
31-
# to capture the depth variation.
32-
# The grid resolution is set to approximately 1/15th of a degree, which corresponds to about 7 km.
30+
# in terms of longitude (λ₁, λ₂), latitude (φ₁, φ₂), and a stretched vertical grid (constructed via
31+
# `Oceananigans.ConstantToStretchedCoordinate`) to capture the depth variation.
32+
# The grid resolution is set to approximately 1/15th of a degree, which corresponds to about 7 kilometers.
3333
#
3434
# This section demonstrates using the `LatitudeLongitudeGrid` to create a grid that matches the
3535
# Mediterranean's geographical and bathymetric features.
3636

3737
λ₁, λ₂ = ( 0, 42) # domain in longitude
3838
φ₁, φ₂ = (30, 45) # domain in latitude
3939

40-
z = StretchedCoordinate(; depth = 5000,
41-
surface_layer_Δz = 2.5,
42-
stretching = PowerLawStretching(1.07),
43-
surface_layer_height = 50)
40+
z = ConstantToStretchedCoordinate(; extent = 5000,
41+
constant_spacing = 2.5,
42+
constant_spacing_extent = 50,
43+
stretching = PowerLawStretching(1.07))
4444

4545
Nx = 15 * Int(λ₂ - λ₁) # 1/15 th of a degree resolution
4646
Ny = 15 * Int(φ₂ - φ₁) # 1/15 th of a degree resolution

examples/near_global_ocean_simulation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Ny = 600
3737
Nz = 40
3838

3939
depth = 6000meters
40-
z = ExponentialCoordinate(Nz, -depth)
40+
z = ExponentialCoordinate(Nz, -depth, 0)
4141

4242
grid = LatitudeLongitudeGrid(arch;
4343
size = (Nx, Ny, Nz),

0 commit comments

Comments
 (0)