forked from glwagner/OceanTurb.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tke_equation_example.jl
157 lines (121 loc) · 3.85 KB
/
tke_equation_example.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using OceanTurb, Printf
function diffusivity!(K, KU, model)
for i in eachindex(K)
@inbounds K[i] = KU(model, i)
end
return nothing
end
@use_pyplot_utils
usecmbright()
c = Constants(f=1e-4, β=0.0)
modelsetup = (N=128, L=128, stepper=:BackwardEuler, constants=c)
Fb = 0.0 #-1e-7
Fu = -1e-4
Fe = 0.0 #-1e-9
N² = 5e-6
Δt = 1
times = (0, 2, 8, 32) .* hour
K₀ = 1e-5
kpp = ModularKPP.Model(; modelsetup...,
diffusivity = ModularKPP.LMDDiffusivity(KU₀=K₀, KT₀=K₀, KS₀=K₀)
)
tke = KPP_TKE.Model(; modelsetup...,
diffusivity = ModularKPP.LMDDiffusivity(KU₀=K₀, KT₀=K₀, KS₀=K₀),
tke = KPP_TKE.TKEParameters(Cτ=Inf, CDe=0.5, KU₀=K₀, KT₀=K₀, KS₀=K₀, Ke₀=1e-5)
)
tkeK = FaceField(tke.grid)
kppK = FaceField(kpp.grid)
# Initial condition and fluxes
Fθ = Fb / (c.α * c.g)
dTdz = N² / (c.α * c.g)
T₀(z) = 20 + dTdz*z
S₀(z) = 20 + dTdz*z
models = (kpp, tke)
for model in models
model.solution.T = T₀
model.solution.S = S₀
model.bcs.T.top = FluxBoundaryCondition(Fθ)
model.bcs.T.bottom = GradientBoundaryCondition(dTdz)
model.bcs.U.top = FluxBoundaryCondition(Fu)
end
tke.bcs.e.top = FluxBoundaryCondition(Fe)
fig, axs = subplots(ncols=4, figsize=(8, 6))
sca(axs[1])
removespines("top", "right")
xlabel(L"T")
ylabel(L"z \, \mathrm{(m)}")
sca(axs[2])
removespines("top", "left", "right")
axs[2].tick_params(left=false, labelleft=false)
xlabel(L"U")
#=
sca(axs[3])
removespines("top", "left", "right")
axs[3].tick_params(left=false, labelleft=false)
xlabel(L"V")
=#
sca(axs[3])
removespines("top", "left", "right")
axs[3].tick_params(left=false, labelleft=false)
xlabel(L"e")
sca(axs[4])
removespines("top", "left")
axs[4].tick_params(left=false, labelleft=false, right=true, labelright=true)
xlabel(L"K")
ylabel(L"z \, \mathrm{(m)}")
for i = 1:length(times)
for model in models
run_until!(model, Δt, times[i])
end
diffusivity!(kppK, ModularKPP.KU, kpp)
diffusivity!(tkeK, KPP_TKE.K_mixing_time, tke)
@printf("""
t : %.1f hours
surface temperature
=============
kpp T(z=0) : %.6f
tke T(z=0) : %.6f
\n""", time(kpp)/hour,
kpp.solution.T[end-1],
tke.solution.T[end-1],
)
if i == 1
vlabel = (kpp="CVMix KPP", tke="TKE")
else
vlabel = (kpp="", tke="")
end
#=
if i == 1
tlabel = text(kpp.solution.T[end], 0.5,
@sprintf("\$ t = %.0f \$ hours", time(kpp)/hour),
verticalalignment="bottom", horizontalalignment="center", color=defaultcolors[i])
else
tlabel = text(maximum(kpp.solution.T.data)-0.003, -kpp.state.h,
@sprintf("\$ t = %.0f \$ hours", time(kpp)/hour),
verticalalignment="bottom", horizontalalignment="left", color=defaultcolors[i])
end
=#
sca(axs[1])
plot(kpp.solution.T, "-", color=defaultcolors[i], label=vlabel.kpp, alpha=0.8, markersize=1.5)
plot(tke.solution.T, "--", color=defaultcolors[i], label=vlabel.tke, alpha=0.8, markersize=1.5)
sca(axs[2])
plot(kpp.solution.U, "-", color=defaultcolors[i], label=vlabel.kpp, alpha=0.8, markersize=1.5)
plot(tke.solution.U, "--", color=defaultcolors[i], label=vlabel.tke, alpha=0.8, markersize=1.5)
#=
sca(axs[3])
plot(kpp.solution.V, "-", color=defaultcolors[i], label=vlabel.kpp, alpha=0.8, markersize=1.5)
plot(tke.solution.V, "--", color=defaultcolors[i], label=vlabel.tke, alpha=0.8, markersize=1.5)
=#
sca(axs[3])
plot(tke.solution.e, "-", color=defaultcolors[i], label=vlabel.tke, alpha=0.8, markersize=1.5)
sca(axs[4])
plot(kppK, "-", color=defaultcolors[i], label=vlabel.kpp, alpha=0.8, markersize=1.5)
plot(tkeK, "--", color=defaultcolors[i], label=vlabel.tke, alpha=0.8, markersize=1.5)
end
#=
for ax in axs
sca(ax)
legend(fontsize=10)
end
=#
gcf()