Skip to content

Commit

Permalink
Fix bottom drag bug (#218)
Browse files Browse the repository at this point in the history
* fix bottom drag

* Fix default_or_override

* Even better docstring

---------

Co-authored-by: Gregory Wagner <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
  • Loading branch information
3 people authored Nov 9, 2024
1 parent 9c858b0 commit 7ea9e55
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/OceanSimulations/OceanSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ struct Default{V}
value :: V
end

Default() = Default(nothing)
default_or_override(default::Default, value=default.value) = value
"""
default_or_override(default::Default, alternative_default=default.value) = alternative_default
default_or_override(override, alternative_default) = override
Either return `default.value`, an `alternative_default`, or an `override`.
The purpose of this function is to help define constructors with "configuration-dependent" defaults.
For example, the default bottom drag should be 0 for a single column model, but 0.003 for a global model.
We therefore need a way to specify both the "normal" default 0.003 as well as the "alternative default" 0,
all while respecting user input and changing this to a new value if specified.
"""
default_or_override(default::Default, possibly_alternative_default=default.value) = possibly_alternative_default
default_or_override(override, alternative_default=nothing) = override

# Some defaults
default_free_surface(grid) = SplitExplicitFreeSurface(grid; cfl=0.7)
Expand Down Expand Up @@ -94,6 +105,8 @@ function ocean_simulation(grid; Δt = 5minutes,
bottom_drag_coefficient = default_or_override(bottom_drag_coefficient)
end

bottom_drag_coefficient = convert(FT, bottom_drag_coefficient)

# Set up boundary conditions using Field
top_zonal_momentum_flux = τx = Field{Face, Center, Nothing}(grid)
top_meridional_momentum_flux = τy = Field{Center, Face, Nothing}(grid)
Expand Down

0 comments on commit 7ea9e55

Please sign in to comment.