Skip to content

Typo in generate_surface_fluxes.jl + add mediterranean example #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bb3e0bc
Update generate_surface_fluxes.jl
simone-silvestri Nov 13, 2024
2237089
add example
simone-silvestri Nov 13, 2024
39cc88f
add fix to the basins removal
simone-silvestri Nov 13, 2024
81b41c8
this works
simone-silvestri Nov 13, 2024
c3b240b
whoops wrong PR
simone-silvestri Nov 13, 2024
5611b6e
add surface mask
simone-silvestri Nov 13, 2024
b919653
bugfix
simone-silvestri Nov 13, 2024
b7e96a4
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Nov 14, 2024
dc92845
add manifest just to see if the parameter space issue is fixed
simone-silvestri Nov 15, 2024
952664e
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Nov 15, 2024
7af1731
Merge branch 'ss/typo-in-generate-fluxes' of github.com:CliMA/ClimaOc…
simone-silvestri Nov 15, 2024
00ca151
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Nov 20, 2024
3d1ab6d
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Nov 22, 2024
05c2e42
remove manifest
simone-silvestri Nov 22, 2024
3145e78
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Nov 23, 2024
e1ed35f
fix med simulation
simone-silvestri Nov 23, 2024
bab14ea
fix simulation
simone-silvestri Nov 28, 2024
eb13746
no segfault
simone-silvestri Dec 2, 2024
e192a8e
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Dec 3, 2024
853e156
Merge branch 'main' into ss/typo-in-generate-fluxes
simone-silvestri Jan 4, 2025
a80b85e
Update mediterranean_simulation_with_ecco_restoring.jl
simone-silvestri Jan 4, 2025
30e87fb
test if this works
simone-silvestri Jan 11, 2025
4c380ae
add the visualization
simone-silvestri Jan 20, 2025
5869c3d
Merge branch 'main' into ss/typo-in-generate-fluxes
navidcy Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
OrthogonalSphericalShellGrids = "c2be9673-fb75-4747-82dc-aa2bb9f4aed0"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ to_be_literated = [
"generate_bathymetry.jl",
"generate_surface_fluxes.jl",
"single_column_os_papa_simulation.jl",
# "mediterranean_simulation_with_ecco_restoring.jl",
"mediterranean_simulation_with_ecco_restoring.jl",
"near_global_ocean_simulation.jl"
]

Expand Down Expand Up @@ -45,7 +45,7 @@ pages = [
"Generate bathymetry" => "literated/generate_bathymetry.md",
"Surface fluxes" => "literated/generate_surface_fluxes.md",
"Single column simulation" => "literated/single_column_os_papa_simulation.md",
# "Mediterranean simulation with ECCO restoring" => "literated/mediterranean_simulation_with_ecco_restoring.md",
"Mediterranean simulation with ECCO restoring" => "literated/mediterranean_simulation_with_ecco_restoring.md",
"Near-global Ocean simulation" => "literated/near_global_ocean_simulation.md",
],

Expand Down
2 changes: 1 addition & 1 deletion examples/generate_surface_fluxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using CairoMakie

# # Computing fluxes on the ECCO2 grid
#
# We start by building the ECCO2 grid, using `ECCO_bottom_height` to identify the bottom height.
# We start by building the ECCO2 grid, using `ECCO_immersed_grid` function.

grid = ECCO_immersed_grid()

Expand Down
83 changes: 29 additions & 54 deletions examples/mediterranean_simulation_with_ecco_restoring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ z_faces = stretched_vertical_faces(depth = 5000,
stretching = PowerLawStretching(1.070),
surface_layer_height = 50)

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

grid = LatitudeLongitudeGrid(GPU();
Expand All @@ -60,26 +60,24 @@ grid = LatitudeLongitudeGrid(GPU();
# are adjusted to refine the bathymetry representation.

bottom_height = regrid_bathymetry(grid,
height_above_water = 1,
minimum_depth = 10,
interpolation_passes = 25,
connected_regions_allowed = 1)
interpolation_passes = 10,
major_basins = 1)

grid = ImmersedBoundaryGrid(grid, GridFittedBottom(bottom_height))

# ## Downloading ECCO data
#
# The model is initialized with temperature and salinity fields from the ECCO dataset,
# using the function `ECCO_restoring_forcing` to apply restoring forcings for these tracers.
# using the function `ECCORestoring` to apply restoring forcings for these tracers.
# This allows us to nudge the model towards realistic temperature and salinity profiles.

dates = DateTimeProlepticGregorian(1993, 1, 1) : Month(1) : DateTimeProlepticGregorian(1993, 12, 1)
@inline surface_mask(x, y, z, t) = z > - 50

temperature = ECCOMetadata(:temperature, dates, ECCO4Monthly())
salinity = ECCOMetadata(:salinity, dates, ECCO4Monthly())
dates = DateTimeProlepticGregorian(1993, 1, 1) : Month(1) : DateTimeProlepticGregorian(1993, 12, 1)

FT = ECCO_restoring_forcing(temperature; architecture = GPU(), timescale = 2days)
FS = ECCO_restoring_forcing(salinity; architecture = GPU(), timescale = 2days)
FT = ECCORestoring(GPU(), :temperature; dates, mask=surface_mask, version=ECCO4Monthly(), rate=1/5days)
FS = ECCORestoring(GPU(), :salinity; dates, mask=surface_mask, version=ECCO4Monthly(), rate=1/5days)

# Constructing the Simulation
#
Expand All @@ -94,13 +92,17 @@ ocean = ocean_simulation(grid; forcing = (T = FT, S = FS))
# In this case, our ECCO dataset has access to a temperature and a salinity
# field, so we initialize temperature T and salinity S from ECCO.

set!(ocean.model, T = temperature[1], S = salinity[1])
set!(ocean.model, T=ECCOMetadata(:temperature; dates=dates[1]),
S=ECCOMetadata(:salinity; dates=dates[1]))

fig = Figure()
ax = Axis(fig[1, 1])
heatmap!(ax, interior(model.tracers.T, :, :, Nz), colorrange = (10, 20), colormap = :thermal)
heatmap!(ax, view(model.tracers.T, :, :, Nz), colorrange = (10, 20), colormap = :thermal)
ax = Axis(fig[1, 2])
heatmap!(ax, interior(model.tracers.S, :, :, Nz), colorrange = (35, 40), colormap = :haline)
heatmap!(ax, view(model.tracers.S, :, :, Nz), colorrange = (35, 40), colormap = :haline)

save("initial_conditions.png", fig)
# ![](initial_conditions.png)

function progress(sim)
u, v, w = sim.model.velocities
Expand Down Expand Up @@ -129,17 +131,12 @@ ocean.stop_iteration = 1000
run!(ocean)

# ## Run the real simulation
#
# Now that the solution has adjusted to the bathymetry we can ramp up the time
# step size. We use a `TimeStepWizard` to automatically adapt to a CFL of 0.2.

wizard = TimeStepWizard(; cfl = 0.2, max_Δt = 10minutes, max_change = 1.1)

ocean.callbacks[:wizard] = Callback(wizard, IterationInterval(10))
# Let's reset the maximum number of iterations and we can not increase the time step size

# Let's reset the maximum number of iterations
ocean.Δt = 3minutes
ocean.stop_iteration = Inf
ocean.stop_time = 200days
ocean.stop_time = 100days

ocean.output_writers[:surface_fields] = JLD2OutputWriter(model, merge(model.velocities, model.tracers);
indices = (:, :, Nz),
Expand All @@ -164,45 +161,23 @@ S_series = FieldTimeSeries("med_surface_field.jld2", "S")
c_series = FieldTimeSeries("med_surface_field.jld2", "c")
iter = Observable(1)

u = @lift begin
f = interior(u_series[$iter], :, :, 1)
f[f .== 0] .= NaN
f
end
v = @lift begin
f = interior(v_series[$iter], :, :, 1)
f[f .== 0] .= NaN
f
end
T = @lift begin
f = interior(T_series[$iter], :, :, 1)
f[f .== 0] .= NaN
f
end
S = @lift begin
f = interior(S_series[$iter], :, :, 1)
f[f .== 0] .= NaN
f
end
c = @lift begin
f = interior(c_series[$iter], :, :, 1)
f[f .== 0] .= NaN
f
end
u = @lift(u_series[$iter])
v = @lift(v_series[$iter])
T = @lift(T_series[$iter])
S = @lift(S_series[$iter])

fig = Figure()
ax = Axis(fig[1, 1], title = "surface zonal velocity ms⁻¹")
heatmap!(u)
heatmap!(ax, u)
ax = Axis(fig[1, 2], title = "surface meridional velocity ms⁻¹")
heatmap!(v)
heatmap!(ax, v)
ax = Axis(fig[2, 1], title = "surface temperature ᵒC")
heatmap!(T)
heatmap!(ax, T)
ax = Axis(fig[2, 2], title = "surface salinity psu")
heatmap!(S)
ax = Axis(fig[2, 3], title = "passive tracer -")
heatmap!(c)
heatmap!(ax, S)

CairoMakie.record(fig, "mediterranean_video.mp4", 1:length(u_series.times); framerate = 5) do i
@info "recording iteration $i"
iter[] = i
end
end
# ![](mediterranean_video.mp4)
31 changes: 18 additions & 13 deletions src/Bathymetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ using Oceananigans.BoundaryConditions
using KernelAbstractions: @kernel, @index
using JLD2

using ClimaOcean

using NCDatasets
using Downloads
using Printf
Expand Down Expand Up @@ -92,19 +90,26 @@ function regrid_bathymetry(target_grid;
major_basins = Inf) # Allow an `Inf` number of ``lakes''

filepath = joinpath(dir, filename)
fileurl = joinpath(url, filename)

@root begin # perform all this only on rank 0, aka the "root" rank
if !isfile(filepath)
try
Downloads.download(fileurl, filepath; progress=download_progress, verbose=true)
catch
cmd = `wget --no-check-certificate -O $filepath $fileurl`
@root run(cmd)
end

if isfile(filepath)
@info "Regridding bathymetry from existing file $filepath."
else
@info "Downloading bathymetry..."
if !ispath(dir)
@info "Making bathymetry directory $dir..."
mkdir(dir)
end

fileurl = joinpath(url, filename)

try
Downloads.download(fileurl, filepath; progress=download_progress, verbose=true)
catch
cmd = `wget --no-check-certificate -O $filepath $fileurl`
run(cmd)
end
end

dataset = Dataset(filepath)

FT = eltype(target_grid)
Expand Down
Loading