From 7ea9e555499a717da6a4985bc28880f73db82e04 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Sun, 10 Nov 2024 00:51:19 +0100 Subject: [PATCH] Fix bottom drag bug (#218) * fix bottom drag * Fix default_or_override * Even better docstring --------- Co-authored-by: Gregory Wagner Co-authored-by: Navid C. Constantinou --- src/OceanSimulations/OceanSimulations.jl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/OceanSimulations/OceanSimulations.jl b/src/OceanSimulations/OceanSimulations.jl index 599f6037..fa80ae19 100644 --- a/src/OceanSimulations/OceanSimulations.jl +++ b/src/OceanSimulations/OceanSimulations.jl @@ -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) @@ -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)