Skip to content

Commit

Permalink
Few fixes in few examples (#3414)
Browse files Browse the repository at this point in the history
* fix latex rendering

* better latex rendering

* remove deprecated remark about model architecture

* add oxford comma

* remove deprecated remark about model architecture

* better show for Buoyancy

* few more tweaks

* remove extra line

* revert to previous show

* don't split cell

* revert summary(::Buoyancy)
  • Loading branch information
navidcy committed Jan 2, 2024
1 parent 72b2112 commit 3e26503
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
8 changes: 6 additions & 2 deletions examples/horizontal_convection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,12 @@ nothing #hide
# ```math
# b_{\rm diff}(x, z) = b_s(x) \frac{\cosh \left [2 \pi (H + z) / L_x \right ]}{\cosh(2 \pi H / L_x)} \, ,
# ```
# where $b_s(x)$ is the surface boundary condition. The diffusive solution implies
# ``\langle \chi_{\rm diff} \rangle = \kappa b_*^2 \pi \tanh(2 \pi Η /Lx) / (L_x H)``.
#
# where ``b_s(x)`` is the surface boundary condition. The diffusive solution implies
#
# ```math
# \langle \chi_{\rm diff} \rangle = \frac{\kappa b_*^2 \pi}{L_x H} \tanh(2 \pi Η / L_x) .
# ```
#
# We use the loaded `FieldTimeSeries` to compute the Nusselt number from buoyancy and the volume
# average kinetic energy of the fluid.
Expand Down
4 changes: 1 addition & 3 deletions examples/shallow_water_Bickley_jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ grid = RectilinearGrid(size = (48, 128),
# ## Building a `ShallowWaterModel`
#
# We build a `ShallowWaterModel` with the `WENO` advection scheme,
# 3rd-order Runge-Kutta time-stepping, non-dimensional Coriolis and
# 3rd-order Runge-Kutta time-stepping, non-dimensional Coriolis, and
# gravitational acceleration

gravitational_acceleration = 1
Expand All @@ -50,8 +50,6 @@ model = ShallowWaterModel(; grid, coriolis, gravitational_acceleration,
timestepper = :RungeKutta3,
momentum_advection = WENO())

# Use `architecture = GPU()` to run this problem on a GPU.

# ## Background state and perturbation
#
# The background velocity ``ū`` and free-surface ``η̄`` correspond to a
Expand Down
34 changes: 17 additions & 17 deletions examples/tilted_bottom_boundary_layer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ z_faces(k) = - Lz * (ζ(k) * Σ(k) - 1)
grid = RectilinearGrid(topology = (Periodic, Flat, Bounded),
size = (Nx, Nz),
x = (0, Lx),
z = z_faces,
halo = (3, 3))
z = z_faces)

# Let's make sure the grid spacing is both finer and near-uniform at the bottom,

Expand Down Expand Up @@ -84,7 +83,7 @@ ĝ = [sind(θ), 0, cosd(θ)]
buoyancy = Buoyancy(model = BuoyancyTracer(), gravity_unit_vector = -ĝ)
coriolis = ConstantCartesianCoriolis(f = 1e-4, rotation_axis = ĝ)

# where we have used a constant Coriolis parameter ``$f = 10^{-4} \, \rm{s}^{-1}``.
# where above we used a constant Coriolis parameter ``f = 10^{-4} \, \rm{s}^{-1}``.
# The tilting also affects the kind of density stratified flows we can model.
# In particular, a constant density stratification in the tilted
# coordinate system
Expand All @@ -98,18 +97,19 @@ coriolis = ConstantCartesianCoriolis(f = 1e-4, rotation_axis = ĝ)

B_field = BackgroundField(constant_stratification, parameters=(; ĝ, N² = 1e-5))

# where ``N² = 10⁻⁵ \rm{s}⁻¹`` is the background buoyancy gradient.
# where ``N^2 = 10^{-5} \rm{s}^{-2}`` is the background buoyancy gradient.

# ## Bottom drag
#
# We impose bottom drag that follows Monin-Obukhov theory.
# We impose bottom drag that follows Monin--Obukhov theory.
# We include the background flow in the drag calculation,
# which is the only effect the background flow enters the problem,

V∞ = 0.1 # m s⁻¹
z₀ = 0.1 # m (roughness length)
κ = 0.4 # von Karman constant
z₁ = znodes(grid, Center())[1] # Closest grid center to the bottom
κ = 0.4 # von Karman constant

z₁ = first(znodes(grid, Center())) # Closest grid center to the bottom
cᴰ =/ log(z₁ / z₀))^2 # Drag coefficient

@inline drag_u(x, t, u, v, p) = - p.cᴰ * (u^2 + (v + p.V∞)^2) * u
Expand Down Expand Up @@ -137,7 +137,7 @@ model = NonhydrostaticModel(; grid, buoyancy, coriolis, closure,
boundary_conditions = (u=u_bcs, v=v_bcs),
background_fields = (; b=B_field))

# Let's introduce a bit of random noise in the bottom of the domain to speed up the onset of
# Let's introduce a bit of random noise at the bottom of the domain to speed up the onset of
# turbulence:

noise(x, z) = 1e-3 * randn() * exp(-(10z)^2 / grid.Lz^2)
Expand All @@ -146,19 +146,19 @@ set!(model, u=noise, w=noise)
# ## Create and run a simulation
#
# We are now ready to create the simulation. We begin by setting the initial time step
# conservatively, based on the smallest grid size of our domain and set-up a

using Oceananigans.Units

simulation = Simulation(model, Δt = 0.5 * minimum_zspacing(grid) / V∞, stop_time = 1days)
# conservatively, based on the smallest grid size of our domain.

# We use `TimeStepWizard` to adapt our time-step and print a progress message,
simulation = Simulation(model, Δt = 0.5 * minimum_zspacing(grid) / V∞, stop_time = 1day)

using Printf
# We use a `TimeStepWizard` to adapt our time-step,

wizard = TimeStepWizard(max_change=1.1, cfl=0.7)
simulation.callbacks[:wizard] = Callback(wizard, IterationInterval(4))

# and also we add another callback to print a progress message,

using Printf

start_time = time_ns() # so we can print the total elapsed wall time

progress_message(sim) =
Expand Down Expand Up @@ -209,8 +209,8 @@ ds = NCDataset(simulation.output_writers[:fields].filepath, "r")

fig = Figure(resolution = (800, 600))

axis_kwargs = (xlabel = "Across-slope distance (x)",
ylabel = "Slope-normal\ndistance (z)",
axis_kwargs = (xlabel = "Across-slope distance (m)",
ylabel = "Slope-normal\ndistance (m)",
limits = ((0, Lx), (0, Lz)),
)

Expand Down
5 changes: 2 additions & 3 deletions src/BuoyancyModels/buoyancy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ Example
=======
```jldoctest
using Oceananigans
grid = RectilinearGrid(size=(1, 8, 8), extent=(1, 1, 1))
θ = 45 # degrees
g̃ = (0, sind(θ), cosd(θ));
g̃ = (0, -sind(θ), -cosd(θ))
buoyancy = Buoyancy(model=BuoyancyTracer(), gravity_unit_vector=g̃)
model = NonhydrostaticModel(grid=grid, buoyancy=buoyancy, tracers=:b)
model = NonhydrostaticModel(; grid, buoyancy, tracers=:b)
# output
Expand Down
1 change: 0 additions & 1 deletion src/Utils/prettytime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ function prettytimeunits(t, longform=true)
end

prettytime(dt::AbstractTime) = "$dt"

8 changes: 3 additions & 5 deletions validation/mesoscale_turbulence/eady_turbulence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ set!(model, u=uᵢ, v=vᵢ, b=bᵢ)

# We subtract off any residual mean velocity to avoid exciting domain-scale
# inertial oscillations. We use a `sum` over the entire `parent` arrays or data
# to ensure this operation is efficient on the GPU (set `architecture = GPU()`
# in `NonhydrostaticModel` constructor to run this problem on the GPU if one
# is available).
# to ensure this operation is efficient on the GPU.

= sum(model.velocities.u.data.parent) / (grid.Nx * grid.Ny * grid.Nz)
= sum(model.velocities.v.data.parent) / (grid.Nx * grid.Ny * grid.Nz)
Expand Down Expand Up @@ -292,8 +290,8 @@ u, v, w = model.velocities # unpack velocity `Field`s

simulation.output_writers[:fields] = JLD2OutputWriter(model, (; ζ, δ),
schedule = TimeInterval(4hours),
filename = "eady_turbulence.jld2",
overwrite_existing = true)
filename = "eady_turbulence.jld2",
overwrite_existing = true)
nothing #hide

# All that's left is to press the big red button:
Expand Down

0 comments on commit 3e26503

Please sign in to comment.