Skip to content
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

Add biogeochemical interface to ocean_simulation #123

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Changes from 8 commits
Commits
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
15 changes: 13 additions & 2 deletions src/OceanSimulations/OceanSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ default_tracer_advection() = TracerAdvection(WENO(; order = 7),
@inline u_immersed_bottom_drag(i, j, k, grid, clock, fields, μ) = @inbounds - μ * fields.u[i, j, k] * is_immersed_drag_u(i, j, k, grid) * spᶠᶜᶜ(i, j, k, grid, fields) / Δzᶠᶜᶜ(i, j, k, grid)
@inline v_immersed_bottom_drag(i, j, k, grid, clock, fields, μ) = @inbounds - μ * fields.v[i, j, k] * is_immersed_drag_v(i, j, k, grid) * spᶜᶠᶜ(i, j, k, grid, fields) / Δzᶜᶠᶜ(i, j, k, grid)


# TODO: Specify the grid to a grid on the sphere; otherwise we can provide a different
# function that requires latitude and longitude etc for computing coriolis=FPlane...
function ocean_simulation(grid; Δt = 5minutes,
Expand All @@ -63,6 +64,9 @@ function ocean_simulation(grid; Δt = 5minutes,
coriolis = HydrostaticSphericalCoriolis(; rotation_rate),
momentum_advection = default_momentum_advection(),
tracer_advection = default_tracer_advection(),
biogeochemistry = nothing,
tracers = (:T, :S),
boundary_conditions = NamedTuple(),
verbose = false)

# Set up boundary conditions using Field
Expand All @@ -78,6 +82,10 @@ function ocean_simulation(grid; Δt = 5minutes,
v = FieldBoundaryConditions(top = FluxBoundaryCondition(Jᵛ), bottom = v_bot_bc),
T = FieldBoundaryConditions(top = FluxBoundaryCondition(Jᵀ)),
S = FieldBoundaryConditions(top = FluxBoundaryCondition(Jˢ)))

if !isempty(boundary_conditions)
ocean_boundary_conditions = merge(ocean_boundary_conditions, boundary_conditions)
end

if grid isa ImmersedBoundaryGrid
Fu = Forcing(u_immersed_bottom_drag, discrete_form=true, parameters=bottom_drag_coefficient)
Expand All @@ -96,10 +104,12 @@ function ocean_simulation(grid; Δt = 5minutes,
momentum_advection = nothing
end

vtamsitt marked this conversation as resolved.
Show resolved Hide resolved
tracers = (:T, :S)

if closure isa CATKEVerticalDiffusivity
tracers = tuple(tracers..., :e)
tracer_advection = (; T = tracer_advection, S = tracer_advection, e = nothing)
advection_value = tuple(fill(tracer_advection, length(tracers))...)
tracer_advection = (; zip(tracers,advection_value)...)
tracer_advection = merge(tracer_advection, (e = nothing,))
Copy link
Member

Choose a reason for hiding this comment

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

Something along these lines might work too:

tracer_advection = NamedTuple(name => tracer_advection for name in tracers)
tracer_advection = merge(tracer_advection, (; e=nothing))

Copy link
Member

@glwagner glwagner Aug 10, 2024

Choose a reason for hiding this comment

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

Also should we have something that checks if the user has already provided a named tuple? something like

if !(tracer_advection isa NamedTuple)
    # expand tracer_advection into a named tuple with `e=nothing`
end

That way people can experiment with also advecting TKE which may be useful.

cc @simone-silvestri

Copy link
Member

@glwagner glwagner Aug 10, 2024

Choose a reason for hiding this comment

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

Dictionaries also can be used which may be a little easier to understand:

tracer_advection = Dict{Symbol, Any}(name => tracer_advection for name in tracers)
tracer_advection[:e] = nothing
tracer_advection = NamedTuple(name => tracer_advection[name] for name in tracers)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @glwagner for the suggestions

end

ocean_model = HydrostaticFreeSurfaceModel(; grid,
Expand All @@ -111,6 +121,7 @@ function ocean_simulation(grid; Δt = 5minutes,
free_surface,
coriolis,
forcing,
biogeochemistry,
Copy link
Member

Choose a reason for hiding this comment

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

🚀

boundary_conditions = ocean_boundary_conditions)

ocean = Simulation(ocean_model; Δt, verbose)
Expand Down
Loading