-
Notifications
You must be signed in to change notification settings - Fork 18
Add biogeochemical interface to ocean_simulation #123
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
Draft
vtamsitt
wants to merge
17
commits into
CliMA:main
Choose a base branch
from
vtamsitt:add-bgc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a1fd5b9
added biogeochemistry kwarg and merge user boundary_conditions
fb2537b
add tracer kwarg and merge tracer_advection
95646da
pass through biogeochemistry
b51e727
try a different way to merge tracer_advection
7f97325
fix NamedTuple tracer_advection
f2a705b
if statement for boundary conditions merge
31b8f15
changed biogeochemistry default to nothing
b67ae79
Merge branch 'CliMA:main' into add-bgc
vtamsitt abbb510
Update src/OceanSimulations/OceanSimulations.jl
vtamsitt 163e01a
update tracer_advection
b059186
boundary_conditions merge retaining defaults
a96b28c
Merge branch 'CliMA:main' into add-bgc
vtamsitt 5012fb7
Merge branch 'main' into add-bgc
vtamsitt 9cd5f7e
Merge branch 'main' into add-bgc
glwagner 1fc667d
Merge branch 'main' into add-bgc
vtamsitt f1f0589
added biogeochemistry kwarg and merge user boundary_conditions
ba6ae1d
Merge branch 'main' into add-bgc
vtamsitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 | ||
|
@@ -74,10 +78,40 @@ function ocean_simulation(grid; Δt = 5minutes, | |
u_bot_bc = FluxBoundaryCondition(u_quadratic_bottom_drag, discrete_form=true, parameters=bottom_drag_coefficient) | ||
v_bot_bc = FluxBoundaryCondition(v_quadratic_bottom_drag, discrete_form=true, parameters=bottom_drag_coefficient) | ||
|
||
ocean_boundary_conditions = (u = FieldBoundaryConditions(top = FluxBoundaryCondition(τx), bottom = u_bot_bc), | ||
v = FieldBoundaryConditions(top = FluxBoundaryCondition(τy), bottom = v_bot_bc), | ||
T = FieldBoundaryConditions(top = FluxBoundaryCondition(Jᵀ)), | ||
S = FieldBoundaryConditions(top = FluxBoundaryCondition(Jˢ))) | ||
ocean_boundary_conditions = Dict( | ||
:u => FieldBoundaryConditions(top = FluxBoundaryCondition(Jᵘ), bottom = u_bot_bc), | ||
:v => FieldBoundaryConditions(top = FluxBoundaryCondition(Jᵛ), bottom = v_bot_bc), | ||
:T => FieldBoundaryConditions(top = FluxBoundaryCondition(Jᵀ)), | ||
:S => FieldBoundaryConditions(top = FluxBoundaryCondition(Jˢ)) | ||
) | ||
|
||
#convert user boundary conditions to dict | ||
bcdict = Dict(name => getproperty(boundary_conditions, name) for name in propertynames(boundary_conditions)) | ||
|
||
if !isempty(bcdict) | ||
# Merge user-supplied boundary conditions with the defaults | ||
for (key, bc) in bcdict | ||
if haskey(ocean_boundary_conditions, key) | ||
# Extract all fields from the default and user FieldBoundaryConditions into dictionaries | ||
default_bc_dict = Dict(name => getproperty(ocean_boundary_conditions[key], name) for name in propertynames(ocean_boundary_conditions[key])) | ||
user_bc_dict = Dict(name => getproperty(bc, name) for name in propertynames(bc)) | ||
|
||
# Merge the dictionaries | ||
merged_bc_dict = merge(default_bc_dict, user_bc_dict) | ||
|
||
# Reconstruct the FieldBoundaryConditions using the merged dictionary | ||
ocean_boundary_conditions[key] = FieldBoundaryConditions(; merged_bc_dict...) | ||
else | ||
# If the user specifies a new tracer not in the defaults, simply add it | ||
ocean_boundary_conditions[key] = bc | ||
end | ||
end | ||
|
||
#ocean_boundary_conditions = merge(ocean_boundary_conditions, boundary_conditions) | ||
end | ||
# Convert the dictionary back to a NamedTuple if needed | ||
ocean_boundary_conditions = (; ocean_boundary_conditions...) | ||
|
||
|
||
if grid isa ImmersedBoundaryGrid | ||
Fu = Forcing(u_immersed_bottom_drag, discrete_form=true, parameters=bottom_drag_coefficient) | ||
|
@@ -96,10 +130,12 @@ function ocean_simulation(grid; Δt = 5minutes, | |
momentum_advection = nothing | ||
end | ||
|
||
tracers = (:T, :S) | ||
tracers = unique(tuple(tracers..., :T, :S)) | ||
if closure isa CATKEVerticalDiffusivity | ||
tracers = tuple(tracers..., :e) | ||
tracer_advection = (; T = tracer_advection, S = tracer_advection, e = nothing) | ||
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) | ||
end | ||
|
||
ocean_model = HydrostaticFreeSurfaceModel(; grid, | ||
|
@@ -111,6 +147,7 @@ function ocean_simulation(grid; Δt = 5minutes, | |
free_surface, | ||
coriolis, | ||
forcing, | ||
biogeochemistry, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
boundary_conditions = ocean_boundary_conditions) | ||
|
||
ocean = Simulation(ocean_model; Δt, verbose) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.