Skip to content

Commit

Permalink
Merge pull request #95 from jbisits/jib-backgroundstepstate
Browse files Browse the repository at this point in the history
Background state that is a step function
  • Loading branch information
jbisits authored Dec 5, 2024
2 parents a9d88c2 + 5eae401 commit cfc6cfe
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StaircaseShenanigans"
uuid = "c2bb06a8-94f3-4279-b990-30bf3ab8ba6f"
authors = ["Josef Bisits <jbisits@gmail.com>"]
version = "0.6.0"
version = "0.6.1"

[deps]
GibbsSeaWater = "9a22fb26-0b63-4589-b28e-8f9d0b5c3d05"
Expand Down
12 changes: 6 additions & 6 deletions examples/single_interface.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using StaircaseShenanigans

architecture = CPU() # or GPU()
diffusivities == 1e-5, κ = (S = 1e-7, T = 1e-5))
diffusivities == 1e-5, κ = (S = 1e-8, T = 1e-6))
domain_extent = (Lx = 0.1, Ly = 0.1, Lz = -1.0)
domain_topology = (x = Periodic, y = Periodic, z = Bounded)
resolution = (Nx = 5, Ny = 5, Nz = 50)
Expand All @@ -12,17 +12,17 @@ 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_smoothing = Tanh)
velocity_noise = VelocityNoise(0.0, 0.0, 1e-7)
interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature)
velocity_noise = VelocityNoise()

## setup model
sdns = StaircaseDNS(model_setup, interface_ics, velocity_noise)

## Build simulation
Δt = 1e-1
stop_time = 210 * 60 # seconds
save_schedule = 10 # seconds
output_path = joinpath(@__DIR__, "output_single_interface")
stop_time = 4 * 60 * 60 # seconds
save_schedule = 30 # seconds
output_path = joinpath(@__DIR__, "output_non_periodic")
simulation = SDNS_simulation_setup(sdns, stop_time, save_computed_output!, save_vertical_velocities!;
Δt, save_schedule,
output_path, max_Δt = 5)
Expand Down
8 changes: 4 additions & 4 deletions examples/single_interface_periodic_tanh_background.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using StaircaseShenanigans

architecture = CPU() # or GPU()
diffusivities == 1e-5, κ = (S = 1e-7, T = 1e-5))
diffusivities == 1e-5, κ = (S = 1e-8, T = 1e-6))
domain_extent = (Lx = 0.1, Ly = 0.1, Lz = -1.0)
domain_topology = (x = Periodic, y = Periodic, z = Periodic)
resolution = (Nx = 5, Ny = 5, Nz = 50)
Expand All @@ -12,11 +12,11 @@ model_setup = (;architecture, diffusivities, domain_extent, domain_topology, res
depth_of_interface = -0.5
salinity = [34.56, 34.70]
temperature = [-1.5, 0.5]
interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature)
tracer_noise = TracerNoise(1e-6, 1e-6)
interface_ics = SingleInterfaceICs(eos, depth_of_interface, salinity, temperature, background_state = BackgroundStep())
noise = (tracers = TracerNoise(1e-6, 1e-6), velocities = VelocityNoise())

## setup model
sdns = StaircaseDNS(model_setup, interface_ics, tracer_noise)
sdns = StaircaseDNS(model_setup, interface_ics, noise)

## Build simulation
Δt = 1e-1
Expand Down
3 changes: 2 additions & 1 deletion src/StaircaseShenanigans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export STStaircaseInitialConditions, StaircaseICs, SmoothSTStaircaseInitialCondi

export TanhInterfaceSmoothing, Tanh, NoSmoothing

export BackgroundTanh, BackgroundLinear, tanh_background, linear_background, NoBackground
export BackgroundTanh, BackgroundLinear, BackgroundStep, NoBackground,
tanh_background, linear_background, step_background

export AbstractNoise, VelocityNoise, TracerNoise

Expand Down
28 changes: 24 additions & 4 deletions src/staircase_background.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Oceananigans.BackgroundField(bf::AbstractBackgroundFunction) =
BackgroundField(bf.func, parameters = bf.parameters)

"""
mutable struct BackgroundTanh{F, T, P}
Container for a tanh background field.
Expand All @@ -14,26 +15,39 @@ mutable struct BackgroundTanh{F, T} <: AbstractBackgroundFunction
end
BackgroundTanh() = BackgroundTanh(tanh_background, 100, NamedTuple())
BackgroundTanh(scale) = BackgroundTanh(tanh_background, scale, NamedTuple())

"""
mutable struct BackgroundLinear{F, P}
mutable struct BackgroundLinear{F}
Container for a linear background field.
"""
mutable struct BackgroundLinear{F} <: AbstractBackgroundFunction
"Linear function"
func :: F
"Parameters for the tanh background field"
"Parameters for the linear background field"
parameters :: NamedTuple
end
BackgroundLinear() = BackgroundLinear(linear_background, NamedTuple())

"""
mutable struct BackgroundStep{F}
Container for a step change background field.
"""
mutable struct BackgroundStep{F} <: AbstractBackgroundFunction
"Heaviside function"
func :: F
"Parameters for the step change background field"
parameters :: NamedTuple
end
BackgroundStep() = BackgroundStep(step_background, NamedTuple())

function Base.show(io::IO, bf::AbstractBackgroundFunction)
if bf isa BackgroundTanh
println(io, "BackgroundTanh")
println(io, "┣━━━ function: $(bf.func)")
println(io, "┣━━━━━━ scale: $(bf.scale)")
print(io, "┗━ parameters: $(bf.parameters)")
elseif bf isa BackgroundLinear
println(io, "BackgroundLinear")
else
println(io, "$(typeof(bf))")
println(io, "┣━━━ function: $(bf.func)")
print(io, "┗━ parameters: $(bf.parameters)")
end
Expand Down Expand Up @@ -68,6 +82,7 @@ end
tanh_background(z, ΔC, Cₗ, Lz, z_interface, D) = Cₗ - 0.5 * ΔC * (1 + tanh(D * (z - z_interface) / Lz))
@inline linear_background(x, y, z, t, p) = p.Cᵤ - p.ΔC * z / p.Lz
linear_background(z, ΔC, Cᵤ, Lz) = Cᵤ - ΔC * z / Lz
@inline step_background(x, y, z, t, p) = z > p.z_interface ? p.Cᵤ : p.Cₗ

function get_parameters!(ics::STSingleInterfaceInitialConditions, tracer::Symbol, Lz)

Expand All @@ -90,6 +105,11 @@ function update_parameters!(backgound_state::BackgroundLinear, ΔC, Cᵤ, Cₗ,
backgound_state.parameters = (; ΔC, Cᵤ, Lz)
return nothing
end
function update_parameters!(backgound_state::BackgroundStep, ΔC, Cᵤ, Cₗ, Lz, z_interface)

backgound_state.parameters = (; Cᵤ, Cₗ, z_interface)
return nothing
end

"""
function save_background_state!(simulation, sdns)
Expand Down
2 changes: 1 addition & 1 deletion src/staircase_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function SDNS_simulation_setup(sdns::StaircaseDNS, stop_time::Number,
save_file = :netcdf,
output_path = SIMULATION_PATH,
checkpointer_time_interval = nothing,
cfl = 0.75,
cfl = 0.2,
diffusive_cfl = 0.75,
overwrite_saved_output = true)

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 @@ -4,4 +4,4 @@ salinity = [34.57, 34.69]
temperature = [-1.5, 0.5]

smoothing = (NoSmoothing, Tanh)
background = (NoBackground, BackgroundTanh, BackgroundLinear)
background = (NoBackground, BackgroundTanh(), BackgroundLinear(), BackgroundStep())

0 comments on commit cfc6cfe

Please sign in to comment.