Skip to content

Commit

Permalink
Merge pull request #379 from SpeedyWeather/mk/forcing
Browse files Browse the repository at this point in the history
RandomWaves initial conditions
  • Loading branch information
milankl authored Sep 7, 2023
2 parents 36e3412 + 4c96496 commit 2bb8896
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/dynamics/initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,41 @@ function initialize_humidity!( progn::PrognosticVariables,
progn.layers[k].timesteps[1].humid[lm] = humid_surf[lm]*σ_levels_full[k]^scale_height_ratio
end
end
end

"""Parameters for random initial conditions for the interface displacement η
in the shallow water equations.
$(TYPEDFIELDS)"""
Base.@kwdef struct RandomWaves <: InitialConditions
# random interface displacement field
A::Float64 = 2000 # amplitude [m]
lmin::Int64 = 10 # minimum wavenumber
lmax::Int64 = 20 # maximum wavenumber
end

"""
$(TYPEDSIGNATURES)
Random initial conditions for the interface displacement η
in the shallow water equations. The flow (u,v) is zero initially.
This kicks off gravity waves that will interact with orography."""
function initial_conditions!( progn::PrognosticVariables{NF},
initial_conditions::RandomWaves,
model::ShallowWater) where NF

(;A, lmin, lmax) = initial_conditions
(;trunc) = progn

η = progn.surface.timesteps[1].pres
η .= randn(LowerTriangularMatrix{Complex{NF}},trunc+2,trunc+1)

# zero out other wavenumbers
η[1:min(lmin,trunc+2),:] .= 0
η[min(lmax,trunc+2):trunc+2,:] .= 0

# scale to amplitude
η_grid = gridded(η,model.spectral_transform)
η_min,η_max = extrema(η_grid)
η .*= (A/max(abs(η_min),abs(η_max)))

return nothing
end

0 comments on commit 2bb8896

Please sign in to comment.