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

Change so interface steepness is required in TanhInterfaceSmoothing #104

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions examples/single_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature, interface_smoothing = TanhInterfaceSteepness())
velocity_noise = VelocityNoise()

## setup model
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/StaircaseShenanigans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/interface_smoothing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ end
const Tanh = TanhInterfaceSmoothing{T} where {T}
@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
Expand Down
16 changes: 12 additions & 4 deletions src/set_initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,34 @@ 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)
function set_initial_conditions!(model, ics, interface_smoothing::Tanh, background_state)

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
function set_initial_conditions!(model, ics, interface_smoothing::TanhInterfaceSteepness, 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]
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.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, 100.0, 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₀)

return nothing
end

"Fallback --- don't set any noise."
set_noise!(model, noise::Nothing) = nothing

Expand Down
2 changes: 1 addition & 1 deletion test/model_ic_instantiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Loading