Skip to content

Commit 5b0bd75

Browse files
author
Milan K
authored
Merge pull request #112 from milankl/whatsnext
Whatsnext
2 parents 47efc13 + 2f58a29 commit 5b0bd75

File tree

8 files changed

+115
-26
lines changed

8 files changed

+115
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.jld
33
*.nc
44
nohup.out
5+
progress.txt
6+
parameter.txt

src/Constants.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Constants{T<: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π)
2021
end
2122

2223
"""Generator function for the mutable struct Constants."""
@@ -53,5 +54,8 @@ function Constants{T}(P::Parameter,G::Grid) where {T<:AbstractFloat}
5354
jSST = T(G.dtadvint/(P.jSST*3600*24)) # tracer consumption [1]
5455
SSTmin = T(P.SSTmin)
5556

56-
return Constants{T}(RKaΔt,RKbΔt,one_minus_α,g,cD,rD,γ,cSmag,νB,rSST,jSST,SSTmin)
57+
# SURFACE FORCING
58+
ωyr = -2π*P.ωyr/24/365/3600
59+
60+
return Constants{T}(RKaΔt,RKbΔt,one_minus_α,g,cD,rD,γ,cSmag,νB,rSST,jSST,SSTmin,ωyr)
5761
end

src/Continuity.jl

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
"""Continuity equation's right-hand side with surface relaxation
22
-∂x(uh) - ∂y(vh) + γ*(η_ref - η)."""
3-
function continuity_surf_forc!(dη,dUdx,dVdy,η,η_ref,Fη,t)
4-
m,n = size(dη) .- (2*haloη,2*haloη)
3+
function continuity_surf_relax!::AbstractMatrix,
4+
Diag::DiagnosticVars,
5+
S::ModelSetup,
6+
t::Int) where {T<:AbstractFloat}
7+
8+
@unpack= Diag.Tendencies
9+
@unpack dUdx,dVdy = Diag.VolumeFluxes
10+
@unpack η_ref = S.forcing
11+
@unpack γ = S.constants
12+
13+
m,n = size(dη) .- (2,2)
514
@boundscheck (m,n+2) == size(dUdx) || throw(BoundsError())
615
@boundscheck (m+2,n) == size(dVdy) || throw(BoundsError())
716
@boundscheck (m+2,n+2) == size(η) || throw(BoundsError())
@@ -15,14 +24,24 @@ function continuity_surf_forc!(dη,dUdx,dVdy,η,η_ref,Fη,t)
1524
end
1625

1726
"""Continuity equation's right-hand side with time&space dependent forcing."""
18-
function continuity_forcing!(dη,dUdx,dVdy,η,η_ref,Fη,t)
19-
m,n = size(dη) .- (2*haloη,2*haloη)
27+
function continuity_forcing!( ::Type{T},
28+
η::AbstractMatrix,
29+
Diag::DiagnosticVars,
30+
S::ModelSetup,
31+
t::Int) where {T<:AbstractFloat}
32+
33+
@unpack= Diag.Tendencies
34+
@unpack dUdx,dVdy = Diag.VolumeFluxes
35+
@unpack= S.forcing
36+
37+
m,n = size(dη) .- (2,2) # cut off halo
2038
@boundscheck (m,n+2) == size(dUdx) || throw(BoundsError())
2139
@boundscheck (m+2,n) == size(dVdy) || throw(BoundsError())
2240
@boundscheck (m,n) == size(Fη) || throw(BoundsError())
2341

2442
# avoid recomputation
25-
Fηtt = Fηt(t)
43+
@unpack ωyr = S.constants
44+
Fηtt = Fηt(T,t,ωyr)
2645

2746
@inbounds for j 1:n
2847
for i 1:m
@@ -32,7 +51,11 @@ function continuity_forcing!(dη,dUdx,dVdy,η,η_ref,Fη,t)
3251
end
3352

3453
"""Continuity equation's right-hand side -∂x(uh) - ∂y(vh) without forcing."""
35-
function continuity!(Diag::DiagnosticVars,S::ModelSetup)
54+
function continuity_itself!(::Type{T},
55+
η::AbstractMatrix,
56+
Diag::DiagnosticVars,
57+
S::ModelSetup,
58+
t::Int) where {T<:AbstractFloat}
3659

3760
@unpack= Diag.Tendencies
3861
@unpack dUdx,dVdy = Diag.VolumeFluxes
@@ -48,10 +71,18 @@ function continuity!(Diag::DiagnosticVars,S::ModelSetup)
4871
end
4972
end
5073

51-
# if surface_relax
52-
# continuity! = continuity_surf_forc!
53-
# elseif surface_forcing
54-
# continuity! = continuity_forcing!
55-
# else
56-
# continuity! = continuity_itself!
57-
# end
74+
75+
"""Transit function to call the specified continuity function."""
76+
function continuity!( η::Array{T,2},
77+
Diag::DiagnosticVars,
78+
S::ModelSetup,
79+
t::Int) where {T<:AbstractFloat}
80+
81+
if S.parameters.surface_relax
82+
continuity_surf_relax!(T,η,Diag,S,t)
83+
elseif S.parameters.surface_forcing
84+
continuity_forcing!(T,η,Diag,S,t)
85+
else
86+
continuity_itself!(T,η,Diag,S,t)
87+
end
88+
end

src/DefaultParameters.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
surface_relax::Bool=false # yes?
3131
t_relax::Real=100. # time scale of the relaxation [days]
3232
η_refh::Real=5. # height difference [m] of the interface relaxation profile
33-
η_refw::Real=100e3 # width [m] of the tangent used for the interface relaxation
33+
η_refw::Real=50e3 # width [m] of the tangent used for the interface relaxation
3434

35-
# SURFACE FORCING
35+
# SURFACE FORCING (Currently only Kelvin wave pumping at Eq.)
3636
surface_forcing::Bool=false # yes?
3737
ωyr::Real=1.0 # (annual) frequency [1/year]
3838
A::Real=3e-5 # Amplitude [m/s]

src/Feedback.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ function feedback_init(S::ModelSetup)
9797
write(txt,"Boundary conditions are $bc with lbc=.\n")
9898
write(txt,"Number format is "*string(T)*".\n")
9999
write(txt,"\nAll data will be stored in $runpath\n")
100+
101+
# Parameter.txt
102+
ptxt = open(joinpath(runpath,"parameter.txt"),"w")
103+
print(ptxt,S.parameters)
104+
close(ptxt)
100105
else
101106
println("Starting Juls on "*Dates.format(now(),Dates.RFC1123Format)*" without output.")
102107
txt = nothing

src/Forcing.jl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ struct Forcing{T<:AbstractFloat}
33
Fy::Array{T,2}
44
H::Array{T,2}
55
η_ref::Array{T,2}
6+
::Array{T,2}
67
#sst_ref::Array{T,2}
78
#sst_γ::Array{T,2}
89
end
@@ -19,6 +20,8 @@ function Forcing{T}(P::Parameter,G::Grid) where {T<:AbstractFloat}
1920
Fx,_ = DoubleGyreWind(T,P,G)
2021
elseif wind_forcing_x == "constant"
2122
Fx,_ = ConstantWind(T,P,G)
23+
elseif wind_forcing_x == "none"
24+
Fx,_ = NoWind(T,P,G)
2225
end
2326

2427
if wind_forcing_y == "channel"
@@ -29,6 +32,8 @@ function Forcing{T}(P::Parameter,G::Grid) where {T<:AbstractFloat}
2932
_,Fy = DoubleGyreWind(T,P,G)
3033
elseif wind_forcing_y == "constant"
3134
_,Fy = ConstantWind(T,P,G)
35+
elseif wind_forcing_x == "none"
36+
_,Fy = NoWind(T,P,G)
3237
end
3338

3439
if topography == "ridge"
@@ -42,8 +47,9 @@ function Forcing{T}(P::Parameter,G::Grid) where {T<:AbstractFloat}
4247
end
4348

4449
η_ref = InterfaceRelaxation(T,P,G)
50+
= KelvinPump(T,P,G)
4551

46-
return Forcing{T}(Fx,Fy,H,η_ref)
52+
return Forcing{T}(Fx,Fy,H,η_ref,Fη)
4753
end
4854

4955
"""Returns the constant forcing matrices Fx,Fy that vary only meriodionally/zonally
@@ -104,6 +110,17 @@ function ConstantWind(::Type{T},P::Parameter,G::Grid) where {T<:AbstractFloat}
104110
return Fx,Fy
105111
end
106112

113+
"""Returns constant in in space forcing matrices Fx,Fy."""
114+
function NoWind(::Type{T},P::Parameter,G::Grid) where {T<:AbstractFloat}
115+
116+
@unpack nux,nuy,nvx,nvy = G
117+
118+
# for non-dimensional gradients the wind forcing needs to contain the grid spacing Δ
119+
Fx = zeros(T,nux,nuy)
120+
Fy = zeros(T,nvx,nvy)
121+
122+
return Fx,Fy
123+
end
107124

108125
"""Returns a reference state for Newtonian cooling/surface relaxation shaped as a
109126
hyperbolic tangent to force the continuity equation."""
@@ -176,3 +193,31 @@ function FlatBottom(::Type{T},P::Parameter,G::Grid) where {T<:AbstractFloat}
176193
@unpack H = P
177194
return fill(T(H),(nx+2*haloη,ny+2*haloη))
178195
end
196+
197+
"""Returns Kelvin wave pumping forcing of the continuity equation at the equator."""
198+
function KelvinPump(::Type{T},P::Parameter,G::Grid) where {T<:AbstractFloat}
199+
200+
@unpack x_T,y_T,Lx,Ly = G
201+
@unpack c,β,R,ϕ,Δ = G
202+
@unpack A = P
203+
204+
xx_T,yy_T = meshgrid(x_T,y_T)
205+
206+
# y-coordinate of the Equator
207+
= 2π*R/360. # meters per degree latitude
208+
y_eq = Ly/2 - ϕ*
209+
y_15S = Ly/2 -+15)*
210+
y_15N = Ly/2 --15)*
211+
212+
= A*Δ*exp.(-β*(yy_T.-y_eq).^2/(2c))
213+
214+
Fη[yy_T .< y_15S] .= 0.0
215+
Fη[yy_T .> y_15N] .= 0.0
216+
217+
return T.(Fη)
218+
end
219+
220+
"""Time evolution of surface forcing."""
221+
function Fηt(::Type{T},t::Int,ωyr::AbstractFloat) where {T<:AbstractFloat}
222+
return T(sin(ωyr*t))
223+
end

src/TimeIntegration.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function time_integration( ::Type{T},
4747
ghost_points!(u1,v1,η1,S)
4848
end
4949

50-
rhs!(u1,v1,η1,Diag,S)
50+
rhs!(u1,v1,η1,Diag,S,t)
5151

5252
if rki < RKo
5353
caxb!(u1,u,RKbΔt[rki],du) #u1 .= u .+ RKb[rki]*Δt*du

src/rhs.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ function rhs!( u::AbstractMatrix,
33
v::AbstractMatrix,
44
η::AbstractMatrix,
55
Diag::DiagnosticVars,
6-
S::ModelSetup)
6+
S::ModelSetup,
7+
t::Int)
78

89
@unpack dynamics = S.parameters
910

1011
if dynamics == "linear"
11-
rhs_linear!(u,v,η,Diag,S)
12+
rhs_linear!(u,v,η,Diag,S,t)
1213
else
13-
rhs_nonlinear!(u,v,η,Diag,S)
14+
rhs_nonlinear!(u,v,η,Diag,S,t)
1415
end
1516
end
1617

@@ -25,7 +26,8 @@ function rhs_nonlinear!(u::AbstractMatrix,
2526
v::AbstractMatrix,
2627
η::AbstractMatrix,
2728
Diag::DiagnosticVars,
28-
S::ModelSetup)
29+
S::ModelSetup,
30+
t::Int)
2931

3032
@unpack h,h_u,h_v,U,V,dUdx,dVdy = Diag.VolumeFluxes
3133
@unpack H = S.forcing
@@ -55,14 +57,13 @@ function rhs_nonlinear!(u::AbstractMatrix,
5557
∂x!(dpdx,p)
5658
∂y!(dpdy,p)
5759

58-
#TODO check whether the order of PV,PVadvection etc. is correct
5960
# Potential vorticity and advection thereof
6061
PVadvection!(Diag,S)
6162

6263
# adding the terms
6364
momentum_u!(Diag,S)
6465
momentum_v!(Diag,S)
65-
continuity!(Diag,S)
66+
continuity!(η,Diag,S,t)
6667
end
6768

6869
"""Tendencies du,dv,dη of
@@ -76,7 +77,8 @@ function rhs_linear!( u::AbstractMatrix,
7677
v::AbstractMatrix,
7778
η::AbstractMatrix,
7879
Diag::DiagnosticVars,
79-
S::ModelSetup)
80+
S::ModelSetup,
81+
t::Int)
8082

8183
@unpack h,h_u,h_v,U,V,dUdx,dVdy = Diag.VolumeFluxes
8284
@unpack g = S.constants
@@ -106,7 +108,7 @@ function rhs_linear!( u::AbstractMatrix,
106108
# adding the terms
107109
momentum_u!(Diag,S)
108110
momentum_v!(Diag,S)
109-
continuity!(Diag,S)
111+
continuity!(η,Diag,S,t)
110112
end
111113

112114
""" Update advective and Coriolis tendencies."""

0 commit comments

Comments
 (0)