Skip to content

Commit

Permalink
Merge pull request #30 from jbisits/joey-addnoise
Browse files Browse the repository at this point in the history
Add simple velocity noise
  • Loading branch information
jbisits authored Aug 16, 2024
2 parents 97f857d + 536909e commit ba27d5e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 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.2.2"
version = "0.3"

[deps]
GibbsSeaWater = "9a22fb26-0b63-4589-b28e-8f9d0b5c3d05"
Expand Down
3 changes: 3 additions & 0 deletions src/StaircaseShenanigans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export StaircaseDNS, DNSModel, SDNS_simulation_setup

export StepInitialConditions, SmoothStepInitialConditions, set_staircase_initial_conditions!

export AbstractNoise, VelocityNoise

export OuterStairMask, OuterStairTargets

export CustomLinearRoquetSeawaterPolynomial, CustomLinearEquationOfState
Expand All @@ -31,6 +33,7 @@ export save_computed_output!
export animate_tracers, animate_density, visualise_initial_conditions, visualise_initial_density

include("staircase_initial_conditions.jl")
include("staircase_noise.jl")
include("staircase_model.jl")
include("set_staircase_initial_conditions.jl")
include("staircase_restoring.jl")
Expand Down
17 changes: 17 additions & 0 deletions src/set_staircase_initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,26 @@ function set_staircase_initial_conditions!(model, ics::SmoothStepInitialConditio

return nothing
end
set_noise!(model, noise::Nothing) = nothing
function set_noise!(model, noise::VelocityNoise)

u, v, w = model.velocities
u_m, v_m, w_m = noise.u_magnitude, noise.v_magnitude, noise.w_magnitude
u_noise = u_m * randn(size(u))
v_noise = v_m * randn(size(v))
w_noise = w_m * randn(size(w))

set!(model, u = u_noise, v = v_noise, w = w_noise)

end
"""
function set_staircase_initial_conditions!(sdns::StaircaseDNS)
Set initial staircase and noise for a `StaircaseDNS`.
"""
function set_staircase_initial_conditions!(sdns::StaircaseDNS)

set_staircase_initial_conditions!(sdns.model, sdns.initial_conditions)
set_noise!(sdns.model, sdns.initial_noise)

return nothing
end
2 changes: 1 addition & 1 deletion src/staircase_initial_conditions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
abstract type AbstractStaircaseInitialConditions <: AbstractInitialConditions end

Base.iterate(sics::AbstractStaircaseInitialConditions, state = 1) =
state > length(fieldnames(sics)) ? nothing : (getfield(sdns, state), state + 1)
state > length(fieldnames(sics)) ? nothing : (getfield(sics, state), state + 1)

"Container for initial conditions that have well mixed layers seperated by sharp step interfaces."
struct StepInitialConditions{T} <: AbstractStaircaseInitialConditions
Expand Down
25 changes: 25 additions & 0 deletions src/staircase_noise.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
struct VelocityNoise{T}
Container for magnitudes for normally distributed noise added to velocity fields.
"""
struct VelocityNoise{T} <: AbstractNoise
"Magnitude for u velocity field"
u_magnitude :: T
"Magnitude for v velocity field"
v_magnitude :: T
"Magnitude for w velocity field"
w_magnitude :: T
end
Base.iterate(noise::AbstractNoise, state = 1) =
state > length(fieldnames(noise)) ? nothing : (getfield(noise, state), state + 1)

function Base.show(io::IO, noise::AbstractNoise)
if noise isa VelocityNoise
println(io, "VelocityNoise")
println(io, "┣━━ u_noise_magnitude: $(noise.u_magnitude)")
println(io, "┣━━ v_noise_magnitude: $(noise.v_magnitude)")
print(io, "┗━━ w_noise_magnitude: $(noise.w_magnitude)")
end
end
"Convenience for all noise at same magnitude `c`, default behaviour is 1e-4"
VelocityNoise(c::Float64=1e-4) = VelocityNoise(c, c, c)

0 comments on commit ba27d5e

Please sign in to comment.