Skip to content

Commit f837287

Browse files
Added a multi-region tracer advection test case
It is not working, most probably due to an error associated with PrescribedVelocityFields on the conformal cubed sphere grid.
1 parent b69f126 commit f837287

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Oceananigans
2+
using Oceananigans.MultiRegion: getregion
3+
using Oceananigans.Utils: Iterate,
4+
get_lat_lon_nodes_and_vertices,
5+
get_cartesian_nodes_and_vertices
6+
using Oceananigans.BoundaryConditions: fill_halo_regions!
7+
8+
9+
function multi_region_tracer_advection!(Nx, Ny, Nt, tracer_field)
10+
11+
grid = ConformalCubedSphereGrid(panel_size=(Nx, Ny, Nz = 1), z = (-1, 0), radius=1, horizontal_direction_halo = 1,
12+
partition = CubedSpherePartition(; R = 1))
13+
14+
u0 = Oceananigans.Fields.ZeroField()
15+
v0 = Oceananigans.Fields.ZeroField()
16+
17+
velocities = PrescribedVelocityFields(; u = u0, v = v0)
18+
19+
model = HydrostaticFreeSurfaceModel(; grid, velocities, tracers = , buoyancy = nothing)
20+
21+
θᵢ(x, y, z) = exp(-x^2/100 - y^2/100)
22+
set!(model, θ = θᵢ)
23+
24+
fill_halo_regions!(model.tracers.θ)
25+
26+
Δt = 1.0
27+
T = Nt * Δt
28+
29+
simulation = Simulation(model, Δt=Δt, stop_time=T)
30+
31+
# Figure out OutputWriters for a CubedSphere (`reconstruct_global_grid` is not defined for a CubedSphere neither
32+
# does it make sense to define it for a CubedSphere). Then we can use the following lines of code:
33+
#
34+
# simulation.output_writers[:fields] = JLD2OutputWriter(model, model.tracers, schedule = TimeInterval(0.02),
35+
# filename = "tracer_advection_over_bump")
36+
#
37+
# simulation.output_writers[:fields] = Checkpointer(model, schedule = TimeInterval(1.0),
38+
# prefix = "multi_region_tracer_advection")
39+
40+
function save_tracer(sim)
41+
push!(tracer_field, sim.model.tracers.θ)
42+
end
43+
44+
simulation.callbacks[:save_tracer] = Callback(save_tracer, TimeInterval(1.0))
45+
46+
run!(simulation)
47+
48+
return nothing
49+
end
50+
51+
52+
Nx = 10
53+
Ny = 10
54+
Nt = 10
55+
56+
tracer_fields = Field[]
57+
multi_region_tracer_advection!(Nx, Ny, Nt, tracer_fields)
58+
tracer = tracer_fields[1]
59+
60+
@info "Making an animation from the saved data..."
61+
62+
n = Observable(1)
63+
64+
θGrid = @lift begin
65+
interior(tracer_fields[$n], :, :, 1)
66+
end
67+
68+
fig = Figure(resolution = (850, 750))
69+
title_θ = @lift "Tracer Concentration after " *string(round(times[$n], digits = 1))*" seconds"
70+
71+
@apply_regionally heatsphere!(ax, θGrid)
72+
73+
ax_θ = Axis3(fig[1,1]; xlabel = "Longitude (m)", ylabel = "Meridional Distance (m)", xlabelsize = 22.5, ylabelsize = 22.5,
74+
xticklabelsize = 17.5, yticklabelsize = 17.5, xlabelpadding = 10, ylabelpadding = 10, aspect = 1.0,
75+
title = title_θ, titlesize = 27.5, titlegap = 15, titlefont = :bold)
76+
77+
@apply_regionally heatsphere!(ax_θ, model.tracers.θ)
78+
79+
Colorbar(fig[1,2], hm_θ; label = "Tracer Concentration", labelsize = 22.5, labelpadding = 10.0, ticksize = 17.5)
80+
81+
frames = 1:length(times)
82+
83+
CairoMakie.record(fig, filename * "_" * immersed_boundary_type * "_" * plot_type * ".mp4", frames, framerate = 8) do i
84+
msg = string("Plotting frame ", i, " of ", frames[end])
85+
print(msg * " \r")
86+
n[] = i
87+
end

0 commit comments

Comments
 (0)