Skip to content
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
63 changes: 63 additions & 0 deletions examples/lock_exchange.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Oceananigans
using Oceananigans.Units
using Oceananigans.Grids: MutableVerticalDiscretization
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using Oceananigans.Grids: MutableVerticalDiscretization
using Oceananigans.Grids

This worked fine for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this at all? What name is missing?



# Set resolution of the simulation grid
Nx, Nz = 256, 64

# Set grid size
L = 8kilometers # horizontal length
H = 50meters # depth

# Allow for mutable surface height
z_disc = MutableVerticalDiscretization((-50, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
z_disc = MutableVerticalDiscretization((-50, 0))
z = MutableVerticalDiscretization((-50, 0))


# Initialize the grid
underlying_grid = RectilinearGrid(
size = (Nx, Nz),
x = (0, L),
z = z_disc,
topology = (Bounded, Flat, Bounded),
halo = (5, 5)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Allow for mutable surface height
z_disc = MutableVerticalDiscretization((-50, 0))
# Initialize the grid
underlying_grid = RectilinearGrid(
size = (Nx, Nz),
x = (0, L),
z = z_disc,
topology = (Bounded, Flat, Bounded),
halo = (5, 5)
)
# Allow for mutable surface height
z = MutableVerticalDiscretization((-50, 0))
x = (0, L)
# Initialize the grid
underlying_grid = RectilinearGrid(size = (Nx, Nz); halo = (5, 5), x, z, topology = (Bounded, Flat, Bounded))


# Add a slope at the bottom of the grid
h_left = -H
h_right = -25meters
slope = (h_right - h_left) / L
bottom(x) = h_left + slope * x

# Use an immersed boundary with grid fitted bottom to describe the sloped bottom of the domain
grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))
grid = ImmersedBoundaryGrid(underlying_grid, PartialCellBottom(bottom))


# Initialize the model
# Want to use a hydrostatic model
# Tracers act as markers within the fluid to track movement and dispersion
# Weighted Essentially Non-Oscillatory (WENO) methods are useful for capturing sharp changes in density
# Closures simplify complex systems by approximating the effects of unresolved scales
# ZStarCoordinate allows for the top of the grid to move with the free surface
# Runge Kutta good for integrating multiple processes

model = HydrostaticFreeSurfaceModel(; grid,
tracers = (:b,),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tracers = (:b,),
tracers = :b,

buoyancy = BuoyancyTracer(),
momentum_advection = WENO(order=5),
tracer_advection = WENO(order=7),
closure = (VerticalScalarDiffusivity=1e-4), HorizontalScalarDiffusivity=1.0)),
Copy link
Member

@glwagner glwagner Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
closure = (VerticalScalarDiffusivity(ν=1e-4), HorizontalScalarDiffusivity(ν=1.0)),

I suggest running this as an ILES unless that doesn't work for some reason!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I have removed the closure.

vertical_coordinate = ZStarCoordinate(grid),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this automatically inferred from the grid's z coordinate type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought so too. we need to hear from @simone-silvestri on this!

free_surface = SplitExplicitFreeSurface(grid; substeps=10),
timestepper = :SplitRungeKutta3
)

# Set initial conditions for lock exchange with different densities
bᵢ(x, z) = x > 4kilometers ? 0.06 : 0.01
set!(model, b=bᵢ)

# Set the timesteps
Δt = 5minutes
stop_time = 3days
simulation = Simulation(model; Δt, stop_time)

# Run simulation
run!(simulation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example should conclude with a visualization of the results, including some analysis / physical interpretation of what the results show