@@ -8,48 +8,122 @@ function comp_u_v_eta_t(nx::Int,
88 interp:: Interps ,
99 grad:: Derivatives ,
1010 advec:: Advection
11- )
11+ )
12+
13+ # unpack stuff
14+ u = rhs. u1
15+ v = rhs. v1
16+ eta = rhs. eta1
17+
18+ (;ITu, ITv, ITq, IuT, IvT) = interp # interpolation operators
19+ (;Iuv, Ivu, Iqu, Iqv) = interp
20+ (;GTx, GTy, Gux, Guy, Gvx, Gvy) = grad # gradient operators
21+ (;h, h_u, h_v, h_q, U, V, p, q) = rhs # diagnostic variables
22+ (;kinetic) = rhs
23+ (;GTx_p, GTy_p, Gux_U, Gvy_V, Gvx_v1, Guy_u1) = rhs
24+ (;adv_u, adv_v) = rhs
25+ (;IuT_u1, IvT_v1, ITu_ksq,ITv_ksq) = rhs
26+ (;u_t, v_t, eta_t) = rhs # tendencies
27+ (;H, coriolis, g, wind_stress) = params
28+
29+ h .= eta .+ H
30+
31+ @inplacemul h_q = ITq * h
32+ @inplacemul h_u = ITu * h
33+ @inplacemul h_v = ITv * h
34+ U .= u .* h_u # volume fluxes U,V
35+ V .= v .* h_v
36+
37+ # kinetic energy u² + v²
38+ u²_T, u² = IuT_u1, ITu_ksq # reuse and rename arrays for u²
39+ v²_T, v² = IvT_v1, ITv_ksq # and v², _T is on T-grid
40+ u² .= u.^ 2
41+ v² .= v.^ 2
42+ @inplacemul u²_T = IuT * u²
43+ @inplacemul v²_T = IvT * v²
44+ kinetic .= u²_T .+ v²_T
45+
46+ # Kloewer defined new terms q and p corresponding to potential vorticity and
47+ # Bernoulli potential respectively. To avoid errors in my mimic I'm following
48+ # along and doing the same
49+ @inplacemul Guy_u1 = Guy * u
50+ @inplacemul Gvx_v1 = Gvx * v
51+
52+ q .= (coriolis .+ Gvx_v1 .- Guy_u1) ./ h_q
53+ p .= 0.5 .* kinetic .+ g .* h
1254
13- rhs. h .= rhs. eta1 .+ params. H
55+ # deal with the advection term
56+ # comp_advection(nx, rhs, advec) # Arakawa and Lamb advection scheme
1457
15- rhs. h_u .= interp. ITu * rhs. h
16- rhs. h_v .= interp. ITv * rhs. h
17- rhs. h_q .= interp. ITq * rhs. h
58+ # Sadourny, 1975 enstrophy conserving advection scheme
59+ V_u = ITu_ksq # reuse and rename array
60+ @inplacemul V_u = Ivu * V
61+ @inplacemul adv_u = Iqu * q # u-component qhv
62+ adv_u .*= V_u
1863
19- rhs. U .= rhs. u1 .* rhs. h_u
20- rhs. V .= rhs. v1 .* rhs. h_v
64+ U_v = ITv_ksq # reuse and rename array
65+ @inplacemul U_v = Iuv * U
66+ # @inplacemul adv_v = Iqv * q # v-component -qhu
67+ adv_v .*= .- U_v
2168
22- rhs. kinetic .= interp. IuT * (rhs. u1.^ 2 ) .+ interp. IvT * (rhs. v1.^ 2 )
69+ # bernoulli gradient ∇p = ∇(1/2(u²+v² + gh))
70+ @inplacemul GTx_p = GTx * p
71+ @inplacemul GTy_p = GTy * p
2372
24- # Kloewer defined new terms q and p corresponding to potential vorticity and
25- # Bernoulli potential respectively. To avoid errors in my mimic I'm following
26- # along and doing the same
27- rhs. q .= (params. coriolis .+ grad. Gvx * rhs. v1 .- grad. Guy * rhs. u1) ./ rhs. h_q
28- rhs. p .= 0.5 .* rhs. kinetic .+ params. g .* rhs. h
73+ # momentum equations
74+ u_t .= adv_u .- GTx_p .+ wind_stress ./ h_u
75+ v_t .= adv_v .- GTy_p
2976
30- # bottom friction
31- rhs . kinetic_sq . = sqrt .(rhs . kinetic)
32- rhs . bfric_u . = params . bottom_drag .* ((interp . ITu * rhs . kinetic_sq) .* rhs . u1) ./ rhs . h_u
33- rhs . bfric_v . = params . bottom_drag .* ((interp . ITv * rhs . kinetic_sq) .* rhs . v1) ./ rhs . h_v
77+ # continuity equations
78+ @inplacemul Gux_U = Gux * U # volume flux divergence dUdx + dVdy
79+ @inplacemul Gvy_V = Gvy * V
80+ @. eta_t = - (Gux_U + Gvy_V)
3481
35- # deal with the advection term
36- comp_advection (nx, rhs, advec)
82+ return nothing
83+ end
3784
38- # rhs.Mu .= params.A_h .* (grad.LLu * rhs.u1)
39- # rhs.Mv .= params.A_h .* (grad.LLv * rhs.v1)
40-
41- rhs. Mu .= (interp. ITu * params. nu) .* (grad. LLu * rhs. u1)
42- rhs. Mv .= (interp. ITv * params. nu) .* (grad. LLv * rhs. v1)
85+ function dissipative_terms! (nx:: Int ,
86+ rhs:: RHS_terms ,
87+ params:: Params ,
88+ interp:: Interps ,
89+ grad:: Derivatives ,
90+ advec:: Advection
91+ )
4392
44- rhs. u_t .= rhs. adv_u .- grad. GTx * rhs. p .+ params. wind_stress ./ rhs. h_u .- rhs. Mu .- rhs. bfric_u
93+ # unpack stuff
94+ u = rhs. u0 # calculate based on prognostics at
95+ v = rhs. v0 # t + dt of the non-dissipative RHS
4596
46- rhs. v_t .= rhs. adv_v .- grad. GTy * rhs. p .- rhs. Mv .- rhs. bfric_v
97+ (;ITu, ITv) = interp # interpolation operators
98+ (;LLu, LLv) = grad # gradient operators
99+ (;h_u, h_v) = rhs # diagnostic variables
100+ (;kinetic, kinetic_sq, Mu, Mv, nu_u, nu_v) = rhs
101+ (;bfric_u, bfric_v) = rhs
102+ (;ITu_ksq,ITv_ksq) = rhs
103+ (;u_t, v_t) = rhs # tendencies
104+ (;nu, bottom_drag) = params
47105
48- rhs. eta_t .= - (grad. Gux * rhs. U .+ grad. Gvy * rhs. V)
106+ # bottom friction
107+ kinetic_sq .= sqrt .(kinetic)
108+ @inplacemul ITu_ksq = ITu * kinetic_sq
109+ @inplacemul ITv_ksq = ITv * kinetic_sq
110+ bfric_u .= bottom_drag .* ITu_ksq .* u ./ h_u
111+ bfric_v .= bottom_drag .* ITv_ksq .* v ./ h_v
112+
113+ # diffusion term ν∇⁴(u,v)
114+ @inplacemul nu_u = ITu * nu
115+ @inplacemul nu_v = ITv * nu
116+ @inplacemul Mu = LLu * u
117+ @inplacemul Mv = LLv * v
118+ Mu .*= nu_u
119+ Mv .*= nu_v
120+
121+ # tendencies for bottom friction and diffusion
122+ u_t .= .- Mu .- bfric_u
123+ v_t .= .- Mv .- bfric_v
49124
50125 return nothing
51-
52- end
126+ end
53127
54128function comp_u_v_eta_t (nx:: Int ,
55129 rhs:: SWM_pde ,
0 commit comments