-
Notifications
You must be signed in to change notification settings - Fork 191
/
nonhydrostatic_tendency_kernel_functions.jl
242 lines (194 loc) · 10.7 KB
/
nonhydrostatic_tendency_kernel_functions.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
using Oceananigans.Advection
using Oceananigans.BuoyancyModels
using Oceananigans.Coriolis
using Oceananigans.Operators
using Oceananigans.StokesDrift
using Oceananigans.Biogeochemistry: biogeochemistry_rhs
using Oceananigans.TurbulenceClosures: ∂ⱼ_τ₁ⱼ, ∂ⱼ_τ₂ⱼ, ∂ⱼ_τ₃ⱼ, ∇_dot_qᶜ
using Oceananigans.TurbulenceClosures: immersed_∂ⱼ_τ₁ⱼ, immersed_∂ⱼ_τ₂ⱼ, immersed_∂ⱼ_τ₃ⱼ, immersed_∇_dot_qᶜ
"return the ``x``-gradient of hydrostatic pressure"
hydrostatic_pressure_gradient_x(i, j, k, grid, hydrostatic_pressure) = ∂xᶠᶜᶜ(i, j, k, grid, hydrostatic_pressure)
hydrostatic_pressure_gradient_x(i, j, k, grid, ::Nothing) = zero(grid)
"return the ``y``-gradient of hydrostatic pressure"
hydrostatic_pressure_gradient_y(i, j, k, grid, hydrostatic_pressure) = ∂yᶜᶠᶜ(i, j, k, grid, hydrostatic_pressure)
hydrostatic_pressure_gradient_y(i, j, k, grid, ::Nothing) = zero(grid)
"""
$(SIGNATURES)
Return the tendency for the horizontal velocity in the ``x``-direction, or the east-west
direction, ``u``, at grid point `i, j, k`.
The tendency for ``u`` is called ``G_u`` and defined via
```math
∂_t u = G_u - ∂_x p_n ,
```
where ``∂_x p_n`` is the non-hydrostatic kinematic pressure gradient in the ``x``-direction.
`coriolis`, `stokes_drift`, and `closure` are types encoding information about Coriolis
forces, surface waves, and the prescribed turbulence closure.
`background_fields` is a `NamedTuple` containing background velocity and tracer
`FunctionFields`.
The arguments `velocities`, `tracers`, and `diffusivities` are `NamedTuple`s with the three
velocity components, tracer fields, and precalculated diffusivities where applicable.
`forcings` is a named tuple of forcing functions. `hydrostatic_pressure` is the hydrostatic
pressure anomaly.
`clock` keeps track of `clock.time` and `clock.iteration`.
"""
@inline function u_velocity_tendency(i, j, k, grid,
advection,
coriolis,
stokes_drift,
closure,
u_immersed_bc,
buoyancy,
background_fields,
velocities,
tracers,
auxiliary_fields,
diffusivities,
forcings,
hydrostatic_pressure,
clock)
model_fields = merge(velocities, tracers, auxiliary_fields)
return ( - div_𝐯u(i, j, k, grid, advection, velocities, velocities.u)
- div_𝐯u(i, j, k, grid, advection, background_fields.velocities, velocities.u)
- div_𝐯u(i, j, k, grid, advection, velocities, background_fields.velocities.u)
- x_f_cross_U(i, j, k, grid, coriolis, velocities)
- hydrostatic_pressure_gradient_x(i, j, k, grid, hydrostatic_pressure)
- ∂ⱼ_τ₁ⱼ(i, j, k, grid, closure, diffusivities, clock, model_fields, buoyancy)
- immersed_∂ⱼ_τ₁ⱼ(i, j, k, grid, velocities, u_immersed_bc, closure, diffusivities, clock, model_fields)
+ x_curl_Uˢ_cross_U(i, j, k, grid, stokes_drift, velocities, clock.time)
+ ∂t_uˢ(i, j, k, grid, stokes_drift, clock.time)
+ x_dot_g_b(i, j, k, grid, buoyancy, tracers)
+ forcings.u(i, j, k, grid, clock, model_fields))
end
"""
$(SIGNATURES)
Return the tendency for the horizontal velocity in the ``y``-direction, or the north-south
direction, ``v``, at grid point `i, j, k`.
The tendency for ``v`` is called ``G_v`` and defined via
```math
∂_t v = G_v - ∂_y p_n ,
```
where ``∂_y p_n`` is the non-hydrostatic kinematic pressure gradient in the ``y``-direction.
`coriolis`, `stokes_drift`, and `closure` are types encoding information about Coriolis
forces, surface waves, and the prescribed turbulence closure.
`background_fields` is a `NamedTuple` containing background velocity and tracer
`FunctionFields`.
The arguments `velocities`, `tracers`, and `diffusivities` are `NamedTuple`s with the three
velocity components, tracer fields, and precalculated diffusivities where applicable.
`forcings` is a named tuple of forcing functions. `hydrostatic_pressure` is the hydrostatic
pressure anomaly.
`clock` keeps track of `clock.time` and `clock.iteration`.
"""
@inline function v_velocity_tendency(i, j, k, grid,
advection,
coriolis,
stokes_drift,
closure,
v_immersed_bc,
buoyancy,
background_fields,
velocities,
tracers,
auxiliary_fields,
diffusivities,
forcings,
hydrostatic_pressure,
clock)
model_fields = merge(velocities, tracers, auxiliary_fields)
return ( - div_𝐯v(i, j, k, grid, advection, velocities, velocities.v)
- div_𝐯v(i, j, k, grid, advection, background_fields.velocities, velocities.v)
- div_𝐯v(i, j, k, grid, advection, velocities, background_fields.velocities.v)
- y_f_cross_U(i, j, k, grid, coriolis, velocities)
- hydrostatic_pressure_gradient_y(i, j, k, grid, hydrostatic_pressure)
- ∂ⱼ_τ₂ⱼ(i, j, k, grid, closure, diffusivities, clock, model_fields, buoyancy)
- immersed_∂ⱼ_τ₂ⱼ(i, j, k, grid, velocities, v_immersed_bc, closure, diffusivities, clock, model_fields)
+ y_curl_Uˢ_cross_U(i, j, k, grid, stokes_drift, velocities, clock.time)
+ ∂t_vˢ(i, j, k, grid, stokes_drift, clock.time)
+ y_dot_g_b(i, j, k, grid, buoyancy, tracers)
+ forcings.v(i, j, k, grid, clock, model_fields))
end
"""
$(SIGNATURES)
Return the tendency for the vertical velocity ``w`` at grid point `i, j, k`.
The tendency for ``w`` is called ``G_w`` and defined via
```math
∂_t w = G_w - ∂_z p_n ,
```
where ``∂_z p_n`` is the non-hydrostatic kinematic pressure gradient in the ``z``-direction.
`coriolis`, `stokes_drift`, and `closure` are types encoding information about Coriolis
forces, surface waves, and the prescribed turbulence closure.
`background_fields` is a `NamedTuple` containing background velocity and tracer
`FunctionFields`.
The arguments `velocities`, `tracers`, and `diffusivities` are `NamedTuple`s with the three
velocity components, tracer fields, and precalculated diffusivities where applicable.
`forcings` is a named tuple of forcing functions.
`clock` keeps track of `clock.time` and `clock.iteration`.
"""
@inline function w_velocity_tendency(i, j, k, grid,
advection,
coriolis,
stokes_drift,
closure,
w_immersed_bc,
buoyancy,
background_fields,
velocities,
tracers,
auxiliary_fields,
diffusivities,
forcings,
clock)
model_fields = merge(velocities, tracers, auxiliary_fields)
return ( - div_𝐯w(i, j, k, grid, advection, velocities, velocities.w)
- div_𝐯w(i, j, k, grid, advection, background_fields.velocities, velocities.w)
- div_𝐯w(i, j, k, grid, advection, velocities, background_fields.velocities.w)
- z_f_cross_U(i, j, k, grid, coriolis, velocities)
- ∂ⱼ_τ₃ⱼ(i, j, k, grid, closure, diffusivities, clock, model_fields, buoyancy)
- immersed_∂ⱼ_τ₃ⱼ(i, j, k, grid, velocities, w_immersed_bc, closure, diffusivities, clock, model_fields)
+ z_curl_Uˢ_cross_U(i, j, k, grid, stokes_drift, velocities, clock.time)
+ ∂t_wˢ(i, j, k, grid, stokes_drift, clock.time)
+ forcings.w(i, j, k, grid, clock, model_fields))
end
"""
$(SIGNATURES)
Return the tendency for a tracer field with index `tracer_index`
at grid point `i, j, k`.
The tendency is called ``G_c`` and defined via
```math
∂_t c = G_c ,
```
where `c = C[tracer_index]`.
`closure` and `buoyancy` are types encoding information about the prescribed
turbulence closure and buoyancy model.
`background_fields` is a `NamedTuple` containing background velocity and tracer
`FunctionFields`.
The arguments `velocities`, `tracers`, and `diffusivities` are `NamedTuple`s with the three
velocity components, tracer fields, and precalculated diffusivities where applicable.
`forcings` is a named tuple of forcing functions.
`clock` keeps track of `clock.time` and `clock.iteration`.
"""
@inline function tracer_tendency(i, j, k, grid,
val_tracer_index::Val{tracer_index},
val_tracer_name,
advection,
closure,
c_immersed_bc,
buoyancy,
biogeochemistry,
background_fields,
velocities,
tracers,
auxiliary_fields,
diffusivities,
forcing,
clock) where tracer_index
@inbounds c = tracers[tracer_index]
@inbounds background_fields_c = background_fields.tracers[tracer_index]
model_fields = merge(velocities, tracers, auxiliary_fields)
return ( - div_Uc(i, j, k, grid, advection, velocities, c)
- div_Uc(i, j, k, grid, advection, background_fields.velocities, c)
- div_Uc(i, j, k, grid, advection, velocities, background_fields_c)
- ∇_dot_qᶜ(i, j, k, grid, closure, diffusivities, val_tracer_index, c, clock, model_fields, buoyancy)
- immersed_∇_dot_qᶜ(i, j, k, grid, c, c_immersed_bc, closure, diffusivities, val_tracer_index, clock, model_fields)
+ biogeochemistry_rhs(i, j, k, grid, biogeochemistry, val_tracer_name, clock, model_fields)
+ forcing(i, j, k, grid, clock, model_fields))
end