This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
/
moisture.jl
280 lines (253 loc) · 6.57 KB
/
moisture.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
export DryModel, EquilMoist, NonEquilMoist
#### Moisture component in atmosphere model
abstract type MoistureModel end
vars_state(::MoistureModel, ::AbstractStateType, FT) = @vars()
function atmos_nodal_update_auxiliary_state!(
::MoistureModel,
m::AtmosModel,
state::Vars,
aux::Vars,
t::Real,
) end
function flux_moisture!(
::MoistureModel,
::AtmosModel,
flux::Grad,
state::Vars,
aux::Vars,
t::Real,
) end
function compute_gradient_flux!(
::MoistureModel,
diffusive,
∇transform,
state,
aux,
t,
) end
function flux_second_order!(
::MoistureModel,
flux::Grad,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
) end
function flux_first_order!(::MoistureModel, _...) end
function compute_gradient_argument!(
::MoistureModel,
transform::Vars,
state::Vars,
aux::Vars,
t::Real,
) end
internal_energy(atmos::AtmosModel, state::Vars, aux::Vars) =
internal_energy(atmos.moisture, atmos.orientation, state, aux)
@inline function internal_energy(
moist::MoistureModel,
orientation::Orientation,
state::Vars,
aux::Vars,
)
Thermodynamics.internal_energy(
state.ρ,
state.ρe,
state.ρu,
gravitational_potential(orientation, aux),
)
end
"""
DryModel
Assumes the moisture components is in the dry limit.
"""
struct DryModel <: MoistureModel end
vars_state(::DryModel, ::Auxiliary, FT) = @vars(θ_v::FT, air_T::FT)
@inline function atmos_nodal_update_auxiliary_state!(
moist::DryModel,
atmos::AtmosModel,
state::Vars,
aux::Vars,
t::Real,
)
ts = new_thermo_state(atmos, state, aux)
aux.moisture.θ_v = virtual_pottemp(ts)
aux.moisture.air_T = air_temperature(ts)
nothing
end
"""
EquilMoist
Assumes the moisture components are computed via thermodynamic equilibrium.
"""
struct EquilMoist{FT} <: MoistureModel
maxiter::Int
tolerance::FT
end
EquilMoist{FT}(;
maxiter::IT = 3,
tolerance::FT = FT(1e-1),
) where {FT <: AbstractFloat, IT <: Int} = EquilMoist{FT}(maxiter, tolerance)
vars_state(::EquilMoist, ::Prognostic, FT) = @vars(ρq_tot::FT)
vars_state(::EquilMoist, ::Gradient, FT) = @vars(q_tot::FT)
vars_state(::EquilMoist, ::GradientFlux, FT) = @vars(∇q_tot::SVector{3, FT})
vars_state(::EquilMoist, ::Auxiliary, FT) =
@vars(temperature::FT, θ_v::FT, q_liq::FT, q_ice::FT)
@inline function atmos_nodal_update_auxiliary_state!(
moist::EquilMoist,
atmos::AtmosModel,
state::Vars,
aux::Vars,
t::Real,
)
ts = new_thermo_state(atmos, state, aux)
aux.moisture.temperature = air_temperature(ts)
aux.moisture.θ_v = virtual_pottemp(ts)
aux.moisture.q_liq = PhasePartition(ts).liq
aux.moisture.q_ice = PhasePartition(ts).ice
nothing
end
function compute_gradient_argument!(
moist::EquilMoist,
transform::Vars,
state::Vars,
aux::Vars,
t::Real,
)
ρinv = 1 / state.ρ
transform.moisture.q_tot = state.moisture.ρq_tot * ρinv
end
function compute_gradient_flux!(
moist::EquilMoist,
diffusive::Vars,
∇transform::Grad,
state::Vars,
aux::Vars,
t::Real,
)
# diffusive flux of q_tot
diffusive.moisture.∇q_tot = ∇transform.moisture.q_tot
end
function flux_moisture!(
moist::EquilMoist,
atmos::AtmosModel,
flux::Grad,
state::Vars,
aux::Vars,
t::Real,
)
ρ = state.ρ
u = state.ρu / ρ
flux.moisture.ρq_tot += u * state.moisture.ρq_tot
end
function flux_second_order!(
moist::EquilMoist,
flux::Grad,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
)
d_q_tot = (-D_t) .* diffusive.moisture.∇q_tot
flux_second_order!(moist, flux, state, d_q_tot)
end
#TODO: Consider whether to not pass ρ and ρu (not state), foc BCs reasons
function flux_second_order!(moist::EquilMoist, flux::Grad, state::Vars, d_q_tot)
flux.ρ += d_q_tot * state.ρ
flux.ρu += d_q_tot .* state.ρu'
flux.moisture.ρq_tot += d_q_tot * state.ρ
end
"""
NonEquilMoist
Does not assume that the moisture components are in equilibrium.
"""
struct NonEquilMoist <: MoistureModel end
vars_state(::NonEquilMoist, ::Prognostic, FT) =
@vars(ρq_tot::FT, ρq_liq::FT, ρq_ice::FT)
vars_state(::NonEquilMoist, ::Gradient, FT) =
@vars(q_tot::FT, q_liq::FT, q_ice::FT)
vars_state(::NonEquilMoist, ::GradientFlux, FT) = @vars(
∇q_tot::SVector{3, FT},
∇q_liq::SVector{3, FT},
∇q_ice::SVector{3, FT}
)
vars_state(::NonEquilMoist, ::Auxiliary, FT) = @vars(temperature::FT, θ_v::FT)
@inline function atmos_nodal_update_auxiliary_state!(
moist::NonEquilMoist,
atmos::AtmosModel,
state::Vars,
aux::Vars,
t::Real,
)
ts = new_thermo_state(atmos, state, aux)
aux.moisture.temperature = air_temperature(ts)
aux.moisture.θ_v = virtual_pottemp(ts)
nothing
end
function compute_gradient_argument!(
moist::NonEquilMoist,
transform::Vars,
state::Vars,
aux::Vars,
t::Real,
)
ρinv = 1 / state.ρ
transform.moisture.q_tot = state.moisture.ρq_tot * ρinv
transform.moisture.q_liq = state.moisture.ρq_liq * ρinv
transform.moisture.q_ice = state.moisture.ρq_ice * ρinv
end
function compute_gradient_flux!(
moist::NonEquilMoist,
diffusive::Vars,
∇transform::Grad,
state::Vars,
aux::Vars,
t::Real,
)
# diffusive fluxes of moisture variables
diffusive.moisture.∇q_tot = ∇transform.moisture.q_tot
diffusive.moisture.∇q_liq = ∇transform.moisture.q_liq
diffusive.moisture.∇q_ice = ∇transform.moisture.q_ice
end
function flux_moisture!(
moist::NonEquilMoist,
atmos::AtmosModel,
flux::Grad,
state::Vars,
aux::Vars,
t::Real,
)
ρ = state.ρ
u = state.ρu / ρ
flux.moisture.ρq_tot += u * state.moisture.ρq_tot
flux.moisture.ρq_liq += u * state.moisture.ρq_liq
flux.moisture.ρq_ice += u * state.moisture.ρq_ice
end
function flux_second_order!(
moist::NonEquilMoist,
flux::Grad,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
)
d_q_tot = (-D_t) .* diffusive.moisture.∇q_tot
d_q_liq = (-D_t) .* diffusive.moisture.∇q_liq
d_q_ice = (-D_t) .* diffusive.moisture.∇q_ice
flux_second_order!(moist, flux, state, d_q_tot, d_q_liq, d_q_ice)
end
function flux_second_order!(
moist::NonEquilMoist,
flux::Grad,
state::Vars,
d_q_tot,
d_q_liq,
d_q_ice,
)
flux.ρ += d_q_tot * state.ρ
flux.ρu += d_q_tot .* state.ρu'
flux.moisture.ρq_tot += d_q_tot * state.ρ
flux.moisture.ρq_liq += d_q_liq * state.ρ
flux.moisture.ρq_ice += d_q_ice * state.ρ
end