-
Notifications
You must be signed in to change notification settings - Fork 188
/
linear_bottom_example_take1.jl
189 lines (133 loc) · 6.25 KB
/
linear_bottom_example_take1.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using Oceananigans
using Oceananigans.Units
using Oceananigans.ImmersedBoundaries: mask_immersed_field!, PartialCellBottom
using CairoMakie
using Printf
# FJP: to do
# no slip on v at bottom
# db/dz = plus/minus N^2
# nonisotropic diffusion
Nx, Nz = 100, 100
Lx, Lz = 1kilometers, 200meters
V∞ = -0.1
N² = 1e-5
α = 2e-2
bottom(x) = -Lz + α*x
refinement = 1.8 # controls spacing near surface (higher means finer spaced)
stretching = 10 # controls rate of stretching at bottom
h(k) = (Nz + 1 - k) / Nz
ζ(k) = 1 + (h(k) - 1) / refinement
Σ(k) = (1 - exp(-stretching * h(k))) / (1 - exp(-stretching))
z_faces(k) = - Lz * (ζ(k) * Σ(k) - 1) - Lz
underlying_grid = RectilinearGrid(size = (Nx, Nz),
x = (0, Lx),
z = z_faces,
halo = (4, 4),
topology = (Bounded, Flat, Bounded))
grid = ImmersedBoundaryGrid(underlying_grid, PartialCellBottom(bottom, minimum_fractional_cell_height=0.95))
x = xnodes(grid, Center())
bottom_boundary = interior(grid.immersed_boundary.bottom_height, :, 1, 1)
top_boundary = 0*x
fig = Figure(size = (700, 200))
ax = Axis(fig[1, 1],
xlabel="x [km]",
ylabel="z [m]",
limits=((0, grid.Lx/1e3), (-grid.Lz, 0)))
# FJP better to plot actual topography not just a line
band!(ax, x/1e3, bottom_boundary, top_boundary, color = :mediumblue)
fig
bottom_bc = ImmersedBoundaryCondition(bottom=ValueBoundaryCondition(0.0))
velocity_bcs = FieldBoundaryConditions(immersed=bottom_bc)
v_bcs = FieldBoundaryConditions(bottom = ValueBoundaryCondition(0.0));
horizontal_closure = HorizontalScalarDiffusivity(ν=1e-2, κ=1e-2)
vertical_closure = VerticalScalarDiffusivity(ν=1e-2, κ=1e-2)
using Oceananigans.TurbulenceClosures: ExplicitTimeDiscretization, VerticallyImplicitTimeDiscretization
model = HydrostaticFreeSurfaceModel(; grid,
coriolis = FPlane(f = 1e-4),
buoyancy = BuoyancyTracer(),
free_surface = SplitExplicitFreeSurface(grid; cfl = 0.7),
closure = ScalarDiffusivity(VerticallyImplicitTimeDiscretization(), ν=1e-2, κ=1e-2),
#closure = (horizontal_closure, vertical_closure),
tracers = :b,
#boundary_conditions = (v = velocity_bcs,),
momentum_advection = UpwindBiasedFifthOrder(),
tracer_advection = UpwindBiasedFifthOrder())
vᵢ = V∞
bᵢ(x, z) = N² * z
set!(model, v = vᵢ, b=bᵢ)
simulation = Simulation(model, Δt = 0.5 * minimum_zspacing(grid) / V∞, stop_time = 2hours)
wizard = TimeStepWizard(max_change=1.1, cfl=0.1, min_Δt = 0.1)
simulation.callbacks[:wizard] = Callback(wizard, IterationInterval(4))
start_time = time_ns() # so we can print the total elapsed wall time
progress_message(sim) =
@printf("Iteration: %04d, time: %s, Δt: %s, max|w|: %.1e m s⁻¹, wall time: %s\n",
iteration(sim), prettytime(time(sim)),
prettytime(sim.Δt), maximum(abs, sim.model.velocities.w),
prettytime((time_ns() - start_time) * 1e-9))
simulation.callbacks[:progress] = Callback(progress_message, IterationInterval(20))
u, v, w = model.velocities
b = model.tracers.b
filename = "linear_bathymetry_take1"
simulation.output_writers[:fields] = JLD2OutputWriter(model, (; u, v, w, b);
filename,
schedule = TimeInterval(10minutes),
overwrite_existing = true)
run!(simulation)
saved_output_filename = filename * ".jld2"
u_t = FieldTimeSeries(saved_output_filename, "u")
v_t = FieldTimeSeries(saved_output_filename, "v")
w_t = FieldTimeSeries(saved_output_filename, "w")
b_t = FieldTimeSeries(saved_output_filename, "b")
umax = maximum(abs, u_t[end])
vmax = maximum(abs, v_t[end])
wmax = maximum(abs, w_t[end])
bmax = maximum(abs, b_t[end])
times = u_t.times
for φ_t in (u_t, v_t, w_t, b_t), n in 1:length(times)
mask_immersed_field!(φ_t[n], NaN)
end
xu, yu, zu = nodes(u_t[1]) ./ 1e3
xv, yv, zv = nodes(v_t[1]) ./ 1e3
xw, yw, zw = nodes(w_t[1]) ./ 1e3
xb, yb, zb = nodes(b_t[1]) ./ 1e3
n = Observable(1)
title = @lift @sprintf("t = %1.2f hours",
round(times[$n] / hours, digits=2))
uₙ = @lift u_t[1:Nx, 1, 1:Nz, $n]
vₙ = @lift v_t[1:Nx, 1, 1:Nz, $n]
wₙ = @lift w_t[1:Nx, 1, 1:Nz, $n]
bₙ = @lift b_t[1:Nx, 1, 1:Nz, $n]
axis_kwargs = (xlabel = "x [km]",
ylabel = "z [km]",
limits = ((0, grid.Lx/1e3), (-grid.Lz/1e3, -grid.Lz/4e3)),
titlesize = 20)
fig = Figure(size = (700, 900))
fig[1, :] = Label(fig, title, fontsize=24, tellwidth=false)
ax_v = Axis(fig[2, 1]; title = "v", axis_kwargs...)
hm_v = heatmap!(ax_v, xv, zv, vₙ; colorrange = (-0.103, -0.099), colormap = :balance)
Colorbar(fig[2, 2], hm_v, label = "m s⁻¹")
ax_w = Axis(fig[3, 1]; title = "w", axis_kwargs...)
hm_w = heatmap!(ax_w, xw, zw, wₙ; colorrange = (-1e-4, 2e-4), colormap = :balance)
Colorbar(fig[3, 2], hm_w, label = "m s⁻¹")
ax_b = Axis(fig[4, 1]; title = "b", axis_kwargs...)
hm_b = heatmap!(ax_b, xb, zb, bₙ; colorrange = (-0.002, 0), colormap = :balance)
Colorbar(fig[4, 2], hm_b, label = "m s⁻¹")
fig
@info "Making an animation from saved data..."
frames = 1:length(times)
record(fig, filename * ".mp4", frames, framerate=16) do i
@info string("Plotting frame ", i, " of ", frames[end])
n[] = i
end
fig = Figure(size = (700, 700))
ax_v = Axis(fig[1, 1]; title = "v (take 1)", axis_kwargs...)
hm_v = heatmap!(ax_v, xv, zv, vₙ; colormap = :balance)
cn_b = contour!(ax_v, xb, zb, bₙ, levels=30, color="black")
Colorbar(fig[1,2], hm_v, label = "m s⁻¹")
save("v_b_final_take1.png", fig)
fig = Figure(size = (700, 700))
ax_w = Axis(fig[1, 1]; title = "w (take 1)", axis_kwargs...)
hm_w = heatmap!(ax_w, xw, zw, wₙ; colorrange = (-3e-4, 3e-4), colormap = :balance)
cn_w = contour!(ax_w, xb, zb, bₙ, levels=30, color="black")
Colorbar(fig[1,2], hm_w, label = "m s⁻¹")
save("w_b_final_take1.png", fig)