Skip to content

Commit c4d85ae

Browse files
authored
Merge pull request #140 from jbisits/updateinferredverticaldiffusivity
Change methods for computing IVD
2 parents 5ded149 + 35dfac6 commit c4d85ae

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TwoLayerDirectNumericalShenanigans"
22
uuid = "40aaee9f-3595-48be-b36c-f1067009652f"
33
authors = ["Josef Bisits <[email protected]>"]
4-
version = "0.4.3"
4+
version = "0.4.5"
55

66
[deps]
77
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

src/kernelfunctions.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ wᶜᶜᶜ(w, grid) = KernelFunctionOperation{Center, Center, Center}(ℑzᵃᵃ
3737
∂b∂z(model) = ∂b∂z(model.buoyancy, model.grid, model.tracers)
3838
∂b∂z(b, grid, tracers) = KernelFunctionOperation{Center, Center, Face}(∂z_b, grid, b, tracers)
3939

40+
@inline vertical_buoyancy_flux(i, j, k, grid, b::SeawaterBuoyancy, C, w) =
41+
-ℑzᵃᵃᶜ(i, j, k, w) * buoyancy_perturbationᶜᶜᶜ(i, j, k, grid, b, C)
42+
@inline function vertical_buoyancy_flux(model)
43+
44+
grid = model.grid
45+
b = model.buoyancy.model
46+
C = model.tracers
47+
w = model.velocities.w
48+
49+
return KernelFunctionOperation{Center, Center, Center}(vertical_buoyancy_flux, grid, b, C, w)
50+
end
4051
@inline function Kᵥ(i, j, k, grid, b::SeawaterBuoyancy, C, w)
4152

4253
if ∂z_b(i, j, k, grid, b, C) != 0

src/output_utils.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,39 @@ function non_dimensional_numbers!(simulation::Simulation, dns::TwoLayerDNS)
331331

332332
return nothing
333333

334+
end
335+
"""
336+
function inferred_vertical_diffusivity(saved_output::AbstractString)
337+
Calculate the inferred vertical diffusivity using the horizontally averaged vertical
338+
buoyancy gradient and horizontally averaged vertical buoyancy flux
339+
```math
340+
κᵥ = -\\frac{\\overline{w'b'}}{\\overline{\\frac{∂b}{∂z}}}.
341+
```
342+
**Note:** the horizontally avergaed vertical buoyancy gradient and vertical buoyancy flux
343+
must be saved in `saved_output`. This is the default behaviour as of version 0.4.5.
344+
Further it is assumed the horizontal resolution is equal.
345+
"""
346+
function inferred_vertical_diffusivity(saved_output::AbstractString)
347+
348+
NCDataset(saved_output, "a") do ds
349+
b_grad = ds[:∫ₐb_grad][2:end, :]
350+
replace!(b_grad, 0 => NaN)
351+
b_flux = ds[:∫ₐb_flux][:, :]
352+
∫ₐκᵥ = similar(b_flux)
353+
∫ₐκᵥ .= b_flux ./ b_grad
354+
defVar(ds, "∫ₐκᵥ", ∫ₐκᵥ, ("zC", "time"),
355+
attrib = Dict("longname" => "Horizontally integrated inferred vertical diffusivity",
356+
"units" => "m²s⁻¹"))
357+
dV = (diff(ds[:xC][1:2]) .* diff(ds[:yC][1:2])) .* diff(ds[:zF][:])
358+
replace!(∫ₐκᵥ, NaN => 0)
359+
∫κᵥ = mapslices(sum, ∫ₐκᵥ .* dV, dims = 1)
360+
defVar(ds, "∫κᵥ", ∫κᵥ, ("time",),
361+
attrib = Dict("longname" => "Volume integrated inferred vertical diffusivity",
362+
"units" => "m²s⁻¹"))
363+
end
364+
365+
return nothing
366+
334367
end
335368
"""
336369
funciton find_file_type(file::AbstractString)

src/twolayerdns.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,29 +181,34 @@ function DNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
181181
σ = PotentialDensity(model, parameters)
182182

183183
# Inferred vertical diffusivity
184-
κᵥ = InferredVerticalDiffusivity(model)
185-
∫κᵥ = Integral(κᵥ)
184+
b_flux = vertical_buoyancy_flux(model)
185+
∫ₐb_flux = Integral(b_flux, dims = (1, 2))
186+
b_grad = ∂b∂z(model)
187+
∫ₐb_grad = Integral(b_grad, dims = (1, 2))
186188

187-
# Minimum in space Kolmogorov length scale
188189
ϵ = KineticEnergyDissipationRate(model)
190+
# Volume integrated TKE dissipation
191+
∫ϵ = Integral(ϵ)
192+
# Minimum in space Kolmogorov length scale
189193
η_space(model) = (model.closure.ν^3 / maximum(ϵ))^(1/4)
190194

191195
# Volume integrated TKE dissipation
192196
∫ϵ = Integral(ϵ)
193197

194198
# Dimensions and attributes for custom saved output
195-
dims = Dict("η_space" => (), "σ" => ("xC", "xC", "zC"), "∫κᵥ" => (), "∫ϵ" => ())
199+
dims = Dict("η_space" => ())
196200
oa = Dict(
197201
"σ" => Dict("longname" => "Seawater potential density calculated using TEOS-10 at $(density_reference_gp_height)dbar",
198202
"units" => "kgm⁻³"),
199203
"η_space" => Dict("longname" => "Minimum (in space) Kolmogorov length"),
200-
"κᵥ" => Dict("longname" => "Volume integrated inferred vertical diffusivity",
201-
"units" => "m²s⁻¹"),
204+
"ₐb_flux" => Dict("longname" => "Horizontally integrated vertical buoyacny flux (w'b')"),
205+
"∫ₐb_grad" => Dict("longname" => "Horizontally integrated vertical buoyancy gradient (∂b/∂z)"),
202206
"∫ϵ" => Dict("longname" => "Volume integrated turbulent kintetic energy dissipation")
203207
)
204208

205209
# outputs to be saved during the simulation
206-
outputs = Dict("S" => S, "T" => T, "η_space" => η_space, "σ" => σ, "∫κᵥ" => ∫κᵥ, "∫ϵ" => ∫ϵ)
210+
outputs = Dict("S" => S, "T" => T, "η_space" => η_space, "σ" => σ, "∫ϵ" => ∫ϵ,
211+
"∫ₐb_flux" => ∫ₐb_flux, "∫ₐb_grad" => ∫ₐb_grad)
207212
if save_velocities
208213
u, v, w = model.velocities
209214
velocities = Dict("u" => u, "v" => v, "w" => w)

0 commit comments

Comments
 (0)