Skip to content

Commit 978f0da

Browse files
author
Milan K
authored
Merge pull request #133 from milankl/wind
time dependent wind forcing
2 parents 8ec1c3c + 3ecc368 commit 978f0da

File tree

6 files changed

+61
-42
lines changed

6 files changed

+61
-42
lines changed

.cirrus.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Constants.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ struct Constants{T<:AbstractFloat,Tprog<:AbstractFloat}
1717
rSST::T # tracer restoring timescale
1818
jSST::T # tracer consumption timescale
1919
SSTmin::T # tracer minimum
20-
ωyr::Float64 # frequency [1/s] of Kelvin pumping (including 2π)
20+
ωFη::Float64 # frequency [1/s] of seasonal surface forcing incl 2π
21+
ωFx::Float64 # frequency [1/s] of seasonal wind x incl 2π
22+
ωFy::Float64 # frequency [1/2] of seasonal wind y incl 2π
2123
end
2224

2325
"""Generator function for the mutable struct Constants."""
@@ -54,8 +56,12 @@ function Constants{T,Tprog}(P::Parameter,G::Grid) where {T<:AbstractFloat,Tprog<
5456
jSST = T(G.dtadvint/(P.jSST*3600*24)) # tracer consumption [1]
5557
SSTmin = T(P.SSTmin)
5658

57-
# SURFACE FORCING
58-
ωyr = -2π*P.ωyr/24/365.25/3600
59+
# TIME DEPENDENT FORCING
60+
ωFη = -2π*P.ωFη/24/365.25/3600
61+
ωFx = 2π*P.ωFx/24/365.25/3600
62+
ωFy = 2π*P.ωFy/24/365.25/3600
5963

60-
return Constants{T,Tprog}(RKaΔt,RKbΔt,one_minus_α,g,cD,rD,γ,cSmag,νB,rSST,jSST,SSTmin,ωyr)
64+
return Constants{T,Tprog}( RKaΔt,RKbΔt,one_minus_α,
65+
g,cD,rD,γ,cSmag,νB,rSST,
66+
jSST,SSTmin,ωFη,ωFx,ωFy)
6167
end

src/Continuity.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ function continuity_forcing!( Diag::DiagnosticVars{T,Tprog},
3838
@boundscheck (m,n) == size(Fη) || throw(BoundsError())
3939

4040
# avoid recomputation
41-
@unpack ωyr = S.constants
42-
Fηtt = Fηt(T,t,ωyr)
41+
@unpack ωFη = S.constants
42+
Fηt = Ftime(T,t,ωFη)
4343

4444
@inbounds for j 1:n
4545
for i 1:m
46-
dη[i+1,j+1] = -(Tprog(dUdx[i,j+1]) + Tprog(dVdy[i+1,j])) + Tprog(Fηtt*Fη[i,j])
46+
dη[i+1,j+1] = -(Tprog(dUdx[i,j+1]) + Tprog(dVdy[i+1,j])) + Tprog(Fηt*Fη[i,j])
4747
end
4848
end
4949
end

src/DefaultParameters.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
wind_forcing_y::String="constant" # "channel", "double_gyre", "shear","constant" or "none"
2424
Fx0::Real=0.12 # wind stress strength [Pa] in x-direction
2525
Fy0::Real=0.0 # wind stress strength [Pa] in y-direction
26+
seasonal_wind_x::Bool=false # Change the wind stress with a sine of frequency ωFx,ωFy
27+
seasonal_wind_y::Bool=false # same for y-component
28+
ωFx::Real=1.0 # frequency [1/year] for x component
29+
ωFy::Real=1.0 # frequency [1/year] for y component
2630

2731
# BOTTOM TOPOGRAPHY OPTIONS
2832
topography::String="ridge" # "ridge", "seamount", "flat", "ridges", "bathtub"
@@ -37,7 +41,7 @@
3741

3842
# SURFACE FORCING
3943
surface_forcing::Bool=false # yes?
40-
ωyr::Real=1.0 # (annual) frequency [1/year]
44+
ωFη::Real=1.0 # frequency [1/year] for surfance forcing
4145
A::Real=3e-5 # Amplitude [m/s]
4246
ϕk::Real=ϕ # Central latitude of Kelvin wave pumping
4347
wk::Real=10e3 # width [m] in y of Gaussian used for surface forcing
@@ -114,7 +118,6 @@
114118
@assert topo_width > 0.0 "topo_width has to be >0, $topo_width given."
115119
@assert t_relax > 0.0 "t_relax has to be >0, $t_relax given."
116120
@assert η_refw > 0.0 "η_refw has to be >0, $η_refw given."
117-
@assert ωyr > 0.0 "ωyr has to be >0, $ωyr given."
118121
@assert RKo in [3,4] "RKo has to be 3 or 4, $RKo given."
119122
@assert Ndays > 0.0 "Ndays has to be >0, $Ndays given."
120123
@assert nstep_diff > 0 "nstep_diff has to be >0, $nstep_diff given."
@@ -144,7 +147,7 @@ Creates a Parameter struct with following options and default values
144147
T::DataType=Float32 # number format
145148
146149
Tprog::DataType=T # number format for prognostic variables
147-
Tcomm::DataType=T # number format for ghost-point copies
150+
Tcomm::DataType=Tprog # number format for ghost-point copies
148151
149152
# DOMAIN RESOLUTION AND RATIO
150153
nx::Int=100 # number of grid cells in x-direction
@@ -155,7 +158,7 @@ Creates a Parameter struct with following options and default values
155158
g::Real=10. # gravitational acceleration [m/s]
156159
H::Real=500. # layer thickness at rest [m]
157160
ρ::Real=1e3 # water density [kg/m^3]
158-
ϕ::Real=45. # central latitue of the domain (for coriolis) [°]
161+
ϕ::Real=45. # central latitude of the domain (for coriolis) [°]
159162
ω::Real=2π/(24*3600) # Earth's angular frequency [s^-1]
160163
R::Real=6.371e6 # Earth's radius [m]
161164
@@ -164,6 +167,10 @@ Creates a Parameter struct with following options and default values
164167
wind_forcing_y::String="constant" # "channel", "double_gyre", "shear","constant" or "none"
165168
Fx0::Real=0.12 # wind stress strength [Pa] in x-direction
166169
Fy0::Real=0.0 # wind stress strength [Pa] in y-direction
170+
seasonal_wind_x::Bool=false # Change the wind stress with a sine of frequency ωFx,ωFy
171+
seasonal_wind_y::Bool=false # same for y-component
172+
ωFx::Real=1.0 # frequency [1/year] for x component
173+
ωFy::Real=1.0 # frequency [1/year] for y component
167174
168175
# BOTTOM TOPOGRAPHY OPTIONS
169176
topography::String="ridge" # "ridge", "seamount", "flat", "ridges", "bathtub"
@@ -176,10 +183,12 @@ Creates a Parameter struct with following options and default values
176183
η_refh::Real=5. # height difference [m] of the interface relaxation profile
177184
η_refw::Real=50e3 # width [m] of the tangent used for the interface relaxation
178185
179-
# SURFACE FORCING (Currently only Kelvin wave pumping at Eq.)
186+
# SURFACE FORCING
180187
surface_forcing::Bool=false # yes?
181-
ωyr::Real=1.0 # (annual) frequency [1/year]
188+
ωFη::Real=1.0 # (annual) frequency [1/year]
182189
A::Real=3e-5 # Amplitude [m/s]
190+
ϕk::Real=ϕ # Central latitude of Kelvin wave pumping
191+
wk::Real=10e3 # width [m] in y of Gaussian used for surface forcing
183192
184193
# TIME STEPPING OPTIONS
185194
RKo::Int=4 # Order of the RK time stepping scheme (3 or 4)
@@ -230,7 +239,7 @@ Creates a Parameter struct with following options and default values
230239
231240
# OUTPUT OPTIONS
232241
output::Bool=false # netcdf output?
233-
output_vars::Array{String,1}=["u","v","η","sst","q","ζ"] # which variables to output?
242+
output_vars::Array{String,1}=["u","v","η","sst","q","ζ"] # which variables to output? "du","dv","dη" also allowed
234243
output_dt::Real=6 # output time step [hours]
235244
outpath::String=pwd() # path to output folder
236245
@@ -240,5 +249,8 @@ Creates a Parameter struct with following options and default values
240249
init_run_id::Int=0 # run id for restart from run number
241250
init_starti::Int=-1 # timestep to start from (-1 meaning last)
242251
get_id_mode::String="continue" # How to determine the run id: "continue" or "fill"
252+
run_id::Int=-1 # Output with a specific run id
253+
init_interpolation::Bool=true # Interpolate the initial conditions in case grids don't match?
254+
243255
"""
244256
Parameter

src/Forcing.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function KelvinPump(::Type{T},P::Parameter,G::Grid) where {T<:AbstractFloat}
211211
return T.(Fη)
212212
end
213213

214-
"""Time evolution of surface forcing."""
215-
function Fηt(::Type{T},t::Int,ωyr::AbstractFloat) where {T<:AbstractFloat}
216-
return T(sin(ωyr*t))
214+
"""Time evolution of forcing."""
215+
function Ftime(::Type{T},t::Int,ω::Real) where {T<:AbstractFloat}
216+
return T(sin(ω*t))
217217
end

src/rhs.jl

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ function rhs_nonlinear!(u::AbstractMatrix,
6161
PVadvection!(Diag,S)
6262

6363
# adding the terms
64-
momentum_u!(Diag,S)
65-
momentum_v!(Diag,S)
64+
momentum_u!(Diag,S,t)
65+
momentum_v!(Diag,S,t)
6666
continuity!(η,Diag,S,t)
6767
end
6868

@@ -106,8 +106,8 @@ function rhs_linear!( u::AbstractMatrix,
106106
fu!(qhu,f_v,u_v)
107107

108108
# adding the terms
109-
momentum_u!(Diag,S)
110-
momentum_v!(Diag,S)
109+
momentum_u!(Diag,S,t)
110+
momentum_v!(Diag,S,t)
111111
continuity!(η,Diag,S,t)
112112
end
113113

@@ -281,7 +281,9 @@ function fu!( qhu::AbstractMatrix,
281281
end
282282

283283
"""Sum up the tendencies of the non-diffusive right-hand side for the u-component."""
284-
function momentum_u!(Diag::DiagnosticVars{T,Tprog},S::ModelSetup) where {T,Tprog}
284+
function momentum_u!( Diag::DiagnosticVars{T,Tprog},
285+
S::ModelSetup,
286+
t::Int) where {T,Tprog}
285287

286288
@unpack du = Diag.Tendencies
287289
@unpack qhv = Diag.Vorticity
@@ -294,15 +296,24 @@ function momentum_u!(Diag::DiagnosticVars{T,Tprog},S::ModelSetup) where {T,Tprog
294296
@boundscheck (m+2-ep,n+2) == size(dpdx) || throw(BoundsError())
295297
@boundscheck (m,n) == size(Fx) || throw(BoundsError())
296298

299+
if S.parameters.seasonal_wind_x
300+
@unpack ωFx = S.constants
301+
Fxt = Ftime(T,t,ωFx)
302+
else
303+
Fxt = one(T)
304+
end
305+
297306
@inbounds for j 1:n
298307
for i 1:m
299-
du[i+2,j+2] = Tprog(qhv[i,j]) - Tprog(dpdx[i+1-ep,j+1]) + Tprog(Fx[i,j])
308+
du[i+2,j+2] = Tprog(qhv[i,j]) - Tprog(dpdx[i+1-ep,j+1]) + Tprog(Fxt*Fx[i,j])
300309
end
301310
end
302311
end
303312

304313
"""Sum up the tendencies of the non-diffusive right-hand side for the v-component."""
305-
function momentum_v!(Diag::DiagnosticVars{T,Tprog},S::ModelSetup) where {T,Tprog}
314+
function momentum_v!( Diag::DiagnosticVars{T,Tprog},
315+
S::ModelSetup,
316+
t::Int) where {T,Tprog}
306317

307318
@unpack dv = Diag.Tendencies
308319
@unpack qhu = Diag.Vorticity
@@ -314,9 +325,16 @@ function momentum_v!(Diag::DiagnosticVars{T,Tprog},S::ModelSetup) where {T,Tprog
314325
@boundscheck (m,n) == size(qhu) || throw(BoundsError())
315326
@boundscheck (m+2,n+2) == size(dpdy) || throw(BoundsError())
316327

328+
if S.parameters.seasonal_wind_y
329+
@unpack ωFy = S.constants
330+
Fyt = Ftime(T,t,ωFy)
331+
else
332+
Fyt = one(T)
333+
end
334+
317335
@inbounds for j 1:n
318336
for i 1:m
319-
dv[i+2,j+2] = -Tprog(qhu[i,j]) - Tprog(dpdy[i+1,j+1]) + Tprog(Fy[i,j])
337+
dv[i+2,j+2] = -Tprog(qhu[i,j]) - Tprog(dpdy[i+1,j+1]) + Tprog(Fyt*Fy[i,j])
320338
end
321339
end
322340
end

0 commit comments

Comments
 (0)