From aeef04cba80074fd019097eb7ffcbe715578e6b1 Mon Sep 17 00:00:00 2001 From: jbisits Date: Tue, 7 Jan 2025 12:57:47 +1100 Subject: [PATCH 1/3] Change so interface steepness is required --- examples/single_interface.jl | 2 +- src/interface_smoothing.jl | 7 ++++++- src/set_initial_conditions.jl | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/single_interface.jl b/examples/single_interface.jl index 496d980..2e6be12 100644 --- a/examples/single_interface.jl +++ b/examples/single_interface.jl @@ -12,7 +12,7 @@ model_setup = (;architecture, diffusivities, domain_extent, domain_topology, res depth_of_interface = -0.5 salinity = [34.58, 34.70] temperature = [-1.5, 0.5] -interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature) +interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature, interface_smoothing = Tanh(1000.0)) velocity_noise = VelocityNoise() ## setup model diff --git a/src/interface_smoothing.jl b/src/interface_smoothing.jl index 8d6fd77..954f7bf 100644 --- a/src/interface_smoothing.jl +++ b/src/interface_smoothing.jl @@ -2,7 +2,7 @@ struct TanhInterfaceSmoothing Container to set a hyperbolic tangent over a single interface as an initial condition. """ -struct TanhInterfaceSmoothing{T} <: AbstractInterfaceSmoothing +mutable struct TanhInterfaceSmoothing{T} <: AbstractInterfaceSmoothing "Tracer in the deeper of the two layers seperated by an interface" Cₗ :: T "Change in tracer content over an interface" @@ -15,9 +15,14 @@ struct TanhInterfaceSmoothing{T} <: AbstractInterfaceSmoothing z_range :: T end const Tanh = TanhInterfaceSmoothing{T} where {T} +"This is a bit of a hack to allow the steepness to be set without needin to set everything +else which requires knowledge of grid and layer setup. Basically a container for just the +steepness of the tanh change." +Tanh(D) = Tanh(0.0, 0.0, D, 0.0, 0.0) @inline (p::TanhInterfaceSmoothing)(x, y, z) = p.Cₗ - 0.5 * p.ΔC * (1 + tanh(p.D * (z - p.z_interface) / p.z_range)) Base.summary(p::Type{<:TanhInterfaceSmoothing}) = "tanh smoothing" +Base.summary(p::TanhInterfaceSmoothing) = "tanh smoothing" struct NoInterfaceSmoothing <: AbstractInterfaceSmoothing end const NoSmoothing = NoInterfaceSmoothing diff --git a/src/set_initial_conditions.jl b/src/set_initial_conditions.jl index 663d2a0..dbf7c58 100644 --- a/src/set_initial_conditions.jl +++ b/src/set_initial_conditions.jl @@ -64,7 +64,8 @@ function set_initial_conditions!(model, ics, return nothing end set_initial_conditions!(model, ics, interface_smoothing::Type{<:NoSmoothing}, background_state) = nothing -function set_initial_conditions!(model, ics, interface_smoothing::Type{<:Tanh}, background_state) +"By default there is a difference in the steepness of the tanh change to create an instabiltiy." +function set_initial_conditions!(model, ics, interface_smoothing::Tanh, background_state) depth_of_interface = ics.depth_of_interface Lz = model.grid.Lz @@ -72,18 +73,17 @@ function set_initial_conditions!(model, ics, interface_smoothing::Type{<:Tanh}, S = Array(ics.salinity_values) Sᵤ, Sₗ = S ΔS = diff(S)[1] - S₀(x, y, z) = Tanh(Sₗ, ΔS, 100.0, depth_of_interface, abs(Lz))(x, y, z) + S₀(x, y, z) = Tanh(Sₗ, ΔS, interface_smoothing.D, depth_of_interface, abs(Lz))(x, y, z) T = Array(ics.temperature_values) Tᵤ, Tₗ = T ΔT = diff(T)[1] - T₀(x, y, z) = Tanh(Tₗ, ΔT, 100.0, depth_of_interface, abs(Lz))(x, y, z) + T₀(x, y, z) = Tanh(Tₗ, ΔT, interface_smoothing.D / 3, depth_of_interface, abs(Lz))(x, y, z) set!(model, S = S₀, T = T₀) return nothing end - "Fallback --- don't set any noise." set_noise!(model, noise::Nothing) = nothing From 21f0bb029f2affb89a289c6d8863419524097328 Mon Sep 17 00:00:00 2001 From: jbisits Date: Tue, 7 Jan 2025 13:08:29 +1100 Subject: [PATCH 2/3] Small fixes to avoid too much changing at once --- src/interface_smoothing.jl | 2 +- src/set_initial_conditions.jl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/interface_smoothing.jl b/src/interface_smoothing.jl index 954f7bf..be51a00 100644 --- a/src/interface_smoothing.jl +++ b/src/interface_smoothing.jl @@ -2,7 +2,7 @@ struct TanhInterfaceSmoothing Container to set a hyperbolic tangent over a single interface as an initial condition. """ -mutable struct TanhInterfaceSmoothing{T} <: AbstractInterfaceSmoothing +struct TanhInterfaceSmoothing{T} <: AbstractInterfaceSmoothing "Tracer in the deeper of the two layers seperated by an interface" Cₗ :: T "Change in tracer content over an interface" diff --git a/src/set_initial_conditions.jl b/src/set_initial_conditions.jl index dbf7c58..e0c880c 100644 --- a/src/set_initial_conditions.jl +++ b/src/set_initial_conditions.jl @@ -64,6 +64,26 @@ function set_initial_conditions!(model, ics, return nothing end set_initial_conditions!(model, ics, interface_smoothing::Type{<:NoSmoothing}, background_state) = nothing +function set_initial_conditions!(model, ics, interface_smoothing::Tanh, background_state) + + depth_of_interface = ics.depth_of_interface + Lz = model.grid.Lz + + S = Array(ics.salinity_values) + Sᵤ, Sₗ = S + ΔS = diff(S)[1] + tanh_change = 500.0 + S₀(x, y, z) = Tanh(Sₗ, ΔS, tanh_change, depth_of_interface, abs(Lz))(x, y, z) + + T = Array(ics.temperature_values) + Tᵤ, Tₗ = T + ΔT = diff(T)[1] + T₀(x, y, z) = Tanh(Tₗ, ΔT, tanh_change / 3, depth_of_interface, abs(Lz))(x, y, z) + + set!(model, S = S₀, T = T₀) + + return nothing +end "By default there is a difference in the steepness of the tanh change to create an instabiltiy." function set_initial_conditions!(model, ics, interface_smoothing::Tanh, background_state) From 1e98186e512a7d22d9199c0a0cfee92a6cb6c4be Mon Sep 17 00:00:00 2001 From: jbisits Date: Tue, 7 Jan 2025 13:31:11 +1100 Subject: [PATCH 3/3] Better way to do it --- examples/single_interface.jl | 6 +++--- src/StaircaseShenanigans.jl | 2 +- src/interface_smoothing.jl | 18 ++++++++++++++---- src/set_initial_conditions.jl | 22 +++++----------------- test/model_ic_instantiation.jl | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/examples/single_interface.jl b/examples/single_interface.jl index 2e6be12..0d70ca2 100644 --- a/examples/single_interface.jl +++ b/examples/single_interface.jl @@ -10,9 +10,9 @@ model_setup = (;architecture, diffusivities, domain_extent, domain_topology, res ## Initial conditions depth_of_interface = -0.5 -salinity = [34.58, 34.70] +salinity = [34.54, 34.70] temperature = [-1.5, 0.5] -interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature, interface_smoothing = Tanh(1000.0)) +interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature, interface_smoothing = TanhInterfaceSteepness()) velocity_noise = VelocityNoise() ## setup model @@ -21,7 +21,7 @@ sdns = StaircaseDNS(model_setup, interface_ics, velocity_noise) ## Build simulation Δt = 1e-1 stop_time = 4 * 60 * 60 # seconds -save_schedule = 30 # seconds +save_schedule = 60 # seconds output_path = joinpath(@__DIR__, "output_non_periodic") simulation = SDNS_simulation_setup(sdns, stop_time, save_computed_output!, save_vertical_velocities!; Δt, save_schedule, diff --git a/src/StaircaseShenanigans.jl b/src/StaircaseShenanigans.jl index 2d7e78d..752c7b7 100644 --- a/src/StaircaseShenanigans.jl +++ b/src/StaircaseShenanigans.jl @@ -31,7 +31,7 @@ export STStaircaseInitialConditions, StaircaseICs, SmoothSTStaircaseInitialCondi STSingleInterfaceInitialConditions, SingleInterfaceICs, set_initial_conditions! -export TanhInterfaceSmoothing, Tanh, NoSmoothing +export TanhInterfaceSmoothing, Tanh, TanhInterfaceSteepness, NoSmoothing export BackgroundTanh, BackgroundLinear, BackgroundStep, NoBackground, tanh_background, linear_background, step_background diff --git a/src/interface_smoothing.jl b/src/interface_smoothing.jl index be51a00..06d47c4 100644 --- a/src/interface_smoothing.jl +++ b/src/interface_smoothing.jl @@ -15,14 +15,24 @@ struct TanhInterfaceSmoothing{T} <: AbstractInterfaceSmoothing z_range :: T end const Tanh = TanhInterfaceSmoothing{T} where {T} -"This is a bit of a hack to allow the steepness to be set without needin to set everything -else which requires knowledge of grid and layer setup. Basically a container for just the -steepness of the tanh change." -Tanh(D) = Tanh(0.0, 0.0, D, 0.0, 0.0) @inline (p::TanhInterfaceSmoothing)(x, y, z) = p.Cₗ - 0.5 * p.ΔC * (1 + tanh(p.D * (z - p.z_interface) / p.z_range)) +"Container for the steepness of the `tanh` over the interface for both salinity and temperature. +Allows easy setting of both and avoids having to set other parts of the container before the +model has been setup." +struct TanhInterfaceSteepness{T} + "Salinity interface steepness" + DS :: T + "Temperature interface steepness" + DT :: T +end +"Some defaults that are unstable to diffusive convection." +TanhInterfaceSteepness() = TanhInterfaceSteepness(500.0, 250.0) +TanhInterfaceSteepness(S) = TanhInterfaceSteepness(S, S / 3) + Base.summary(p::Type{<:TanhInterfaceSmoothing}) = "tanh smoothing" Base.summary(p::TanhInterfaceSmoothing) = "tanh smoothing" +Base.summary(p::TanhInterfaceSteepness) = "tanh smoothing" struct NoInterfaceSmoothing <: AbstractInterfaceSmoothing end const NoSmoothing = NoInterfaceSmoothing diff --git a/src/set_initial_conditions.jl b/src/set_initial_conditions.jl index e0c880c..3c7fcef 100644 --- a/src/set_initial_conditions.jl +++ b/src/set_initial_conditions.jl @@ -66,26 +66,14 @@ end set_initial_conditions!(model, ics, interface_smoothing::Type{<:NoSmoothing}, background_state) = nothing function set_initial_conditions!(model, ics, interface_smoothing::Tanh, background_state) - depth_of_interface = ics.depth_of_interface - Lz = model.grid.Lz - - S = Array(ics.salinity_values) - Sᵤ, Sₗ = S - ΔS = diff(S)[1] - tanh_change = 500.0 - S₀(x, y, z) = Tanh(Sₗ, ΔS, tanh_change, depth_of_interface, abs(Lz))(x, y, z) - - T = Array(ics.temperature_values) - Tᵤ, Tₗ = T - ΔT = diff(T)[1] - T₀(x, y, z) = Tanh(Tₗ, ΔT, tanh_change / 3, depth_of_interface, abs(Lz))(x, y, z) + S₀(x, y, z) = interface_smoothing(x, y, z) + T₀(x, y, z) = interface_smoothing(x, y, z) set!(model, S = S₀, T = T₀) return nothing end -"By default there is a difference in the steepness of the tanh change to create an instabiltiy." -function set_initial_conditions!(model, ics, interface_smoothing::Tanh, background_state) +function set_initial_conditions!(model, ics, interface_smoothing::TanhInterfaceSteepness, background_state) depth_of_interface = ics.depth_of_interface Lz = model.grid.Lz @@ -93,12 +81,12 @@ function set_initial_conditions!(model, ics, interface_smoothing::Tanh, backgrou S = Array(ics.salinity_values) Sᵤ, Sₗ = S ΔS = diff(S)[1] - S₀(x, y, z) = Tanh(Sₗ, ΔS, interface_smoothing.D, depth_of_interface, abs(Lz))(x, y, z) + S₀(x, y, z) = Tanh(Sₗ, ΔS, interface_smoothing.DS, depth_of_interface, abs(Lz))(x, y, z) T = Array(ics.temperature_values) Tᵤ, Tₗ = T ΔT = diff(T)[1] - T₀(x, y, z) = Tanh(Tₗ, ΔT, interface_smoothing.D / 3, depth_of_interface, abs(Lz))(x, y, z) + T₀(x, y, z) = Tanh(Tₗ, ΔT, interface_smoothing.DT, depth_of_interface, abs(Lz))(x, y, z) set!(model, S = S₀, T = T₀) diff --git a/test/model_ic_instantiation.jl b/test/model_ic_instantiation.jl index cd9d51a..9146595 100644 --- a/test/model_ic_instantiation.jl +++ b/test/model_ic_instantiation.jl @@ -3,5 +3,5 @@ depth_of_interface = -0.6 salinity = [34.57, 34.69] temperature = [-1.5, 0.5] -smoothing = (NoSmoothing, Tanh) +smoothing = (NoSmoothing, TanhInterfaceSteepness(), TanhInterfaceSteepness(100.0), TanhInterfaceSteepness(1000.0, 200.0)) background = (NoBackground, BackgroundTanh(), BackgroundLinear(), BackgroundStep())