|
1 | | -""" |
2 | | - function compute_density(S_timeseries::FieldTimeSeries, T_timeseries::FieldTimeSeries; |
3 | | - reference_pressure = 0) |
4 | | -Return a density `FieldTimeSeries` calculated from the salinity and temperature |
5 | | -`FieldTimeSeries` DNS simulation output. The keyword argument `reference_pressure` can be |
6 | | -passed to specify a reference pressure at which to compute the density variable. |
7 | | -""" |
8 | | -function compute_density(S_timeseries::FieldTimeSeries, T_timeseries::FieldTimeSeries; |
9 | | - reference_pressure = 0) |
10 | | - |
11 | | - ρ_ts = FieldTimeSeries{Center, Center, Center}(S_timeseries.grid, S_timeseries.times, |
12 | | - indices = S_timeseries.indices, |
13 | | - boundary_conditions = |
14 | | - S_timeseries.boundary_conditions) |
15 | | - |
16 | | - t = S_timeseries.times |
17 | | - for i ∈ eachindex(t) |
18 | | - Sᵢ, Θᵢ = S_timeseries[i], T_timeseries[i] |
19 | | - ρ_ts[i] .= @at (Center, Center, Center) gsw_rho.(Sᵢ, Θᵢ, reference_pressure) |
20 | | - end |
21 | | - |
22 | | - return ρ_ts |
23 | | - |
24 | | -end |
25 | | -""" |
26 | | - function compute_density!(filepath::String; reference_pressure = 0) |
27 | | -Compute a density variable at `reference_pressure` and append it to saved output. **Note** |
28 | | -this only needs to be done once! After that the group will exist and will not be able to be |
29 | | -overwritten but a different group can be made by passing a different `density_string`. |
30 | | -This allows calling `FieldTimeSeries` on the `density_variable` |
31 | | -""" |
32 | | -function compute_density!(filepath::AbstractString; density_string = "σ", reference_pressure = 0) |
33 | | - |
34 | | - file_type = find_file_type(filepath) |
35 | | - if isequal(file_type, ".nc") |
36 | | - |
37 | | - @info "Lazily loading S and T into separate Rasters" |
38 | | - S_rs = Raster(filepath, lazy = true, name = :S) |
39 | | - T_rs = Raster(filepath, lazy = true, name = :T) |
40 | | - time = lookup(S_rs, :Ti) |
41 | | - |
42 | | - NCDataset(filepath, "a") do ds |
43 | | - @info "Appending density variable to saved .nc file" |
44 | | - defVar(ds, density_string, zeros(size(S_rs)), ("xC", "yC", "zC", "time"), |
45 | | - attrib = Dict("units" => "kgm⁻³", |
46 | | - "longname" => "Potential density", |
47 | | - "comments" => "computed at reference pressues p = $reference_pressure")) |
48 | | - @info "Computing density and saving to .nc file" |
49 | | - for t ∈ eachindex(time) |
50 | | - ds[density_string][:, :, :, t] = get_σₚ(S_rs[:, :, :, t], T_rs[:, :, :, t], |
51 | | - reference_pressure) |
52 | | - end |
53 | | - end |
54 | | - |
55 | | - elseif isequal(file_type, ".jld2") |
56 | | - |
57 | | - file = jldopen(filepath, "a+") |
58 | | - file_keys = keys(file["timeseries"]["S"]) |
59 | | - JLD2.Group(file, "timeseries/"*density_string) |
60 | | - for (i, key) ∈ enumerate(file_keys) |
61 | | - if i == 1 |
62 | | - for k ∈ keys(file["timeseries/S/"*key]) |
63 | | - file["timeseries/"*density_string*"/"*key*"/"*k] = |
64 | | - file["timeseries/S/"*key*"/"*k] |
65 | | - end |
66 | | - file["timeseries/"*density_string*"/"*key*"/reference_pressure"] = |
67 | | - reference_pressure |
68 | | - else |
69 | | - Sᵢ, Θᵢ = file["timeseries/S/"*key], file["timeseries/T/"*key] |
70 | | - file["timeseries/"*density_string*"/"*key]= gsw_rho.(Sᵢ, Θᵢ, reference_pressure) |
71 | | - end |
72 | | - end |
73 | | - |
74 | | - close(file) |
75 | | - |
76 | | - end |
77 | | - |
78 | | - return nothing |
79 | | - |
80 | | -end |
81 | | -""" |
82 | | - function append_density!(; saved_simulations = readdir(SIMULATION_PATH, join = true)) |
83 | | -Append a density timeseries to the saved output from a `TwoLayerDNS` simulation. By default |
84 | | -the function looks for saved data at the default filepath for saving `SIMULATION_PATH`. |
85 | | -Pass another path as the keyword argument `saved_simulations` to look somewhere else. |
86 | | -""" |
87 | | -function append_density!(; saved_simulations = readdir(SIMULATION_PATH, join = true)) |
88 | | - |
89 | | - for simulation ∈ saved_simulations |
90 | | - |
91 | | - file_type = find_file_type(simulation) |
92 | | - |
93 | | - if isequal(file_type, ".jld2") |
94 | | - open_sim = jldopen(simulation) |
95 | | - if "σ" ∉ keys(open_sim["timeseries"]) |
96 | | - close(open_sim) |
97 | | - compute_density!(simulation, density_string = "σ₀") |
98 | | - else |
99 | | - @info "A density timeseries already exists in $simulation." |
100 | | - close(open_sim) |
101 | | - end |
102 | | - elseif isequal(file_type, ".nc") |
103 | | - NCDataset(simulation, "a") do ds |
104 | | - if "σ" ∉ keys(ds) |
105 | | - compute_density!(simulation) |
106 | | - else |
107 | | - @info "A density timeseries already exists in $simulation." |
108 | | - end |
109 | | - end |
110 | | - end |
111 | | - end |
112 | | - |
113 | | - return nothing |
114 | | - |
115 | | -end |
116 | | - |
117 | | -"Return the mean from a `FieldTimeSeries` that is `OnDisk()`." |
118 | | -function field_ts_timemean(field_ts::FieldTimeSeries) |
119 | | - |
120 | | - t = field_ts.times |
121 | | - field_data = field_ts[1].data |
122 | | - for i ∈ 2:length(t) |
123 | | - field_data .+= field_ts[i].data |
124 | | - end |
125 | | - |
126 | | - return field_data ./ length(t) |
127 | | - |
128 | | -end |
129 | 1 | """ |
130 | 2 | function predicted_maximum_density |
131 | 3 | Compute the predicted maximum density of water that can form along the mixing line between |
@@ -185,33 +57,6 @@ function predicted_maximum_density!(file::AbstractString; reference_pressure = 0 |
185 | 57 | end |
186 | 58 | "Calculate the Kolmogorov length scale `η` from viscousity and average TKE dissapation." |
187 | 59 | η(ν, ϵ) = (ν^3 / ϵ)^(1/4) |
188 | | -""" |
189 | | - function minimum_η(ϵ::FieldTimeSeries; ν = 1e-6) |
190 | | -Find the minimum `η`, i.e. the Kolmogorov length scale, from the `KineticEnergyDissaption`, |
191 | | - `ϵ`, time series. |
192 | | -""" |
193 | | -function minimum_η(ϵ::FieldTimeSeries; ν = 1e-6) |
194 | | - |
195 | | - t = ϵ.times |
196 | | - minimum_η_t = similar(t) |
197 | | - for i ∈ eachindex(t) |
198 | | - minimum_η_t[i] = minimum(η.(ν, ϵ[i].data)) |
199 | | - end |
200 | | - |
201 | | - return minimum(minimum_η_t) |
202 | | - |
203 | | -end |
204 | | -function minimum_η(ϵ::Raster; ν = 1e-6) |
205 | | - |
206 | | - t = lookup(ϵ, :Ti) |
207 | | - minimum_η_t = similar(t) |
208 | | - for i ∈ eachindex(t) |
209 | | - minimum_η_t[i] = minimum(η.(ν, ϵ.data[:, :, :, i])) |
210 | | - end |
211 | | - |
212 | | - return minimum(minimum_η_t) |
213 | | - |
214 | | -end |
215 | 60 | """ |
216 | 61 | function kolmogorov_and_batchelor_scale!(file::AbstractString) |
217 | 62 | Append the minimum Kolmogorov and Batchelor scales (in space and time) from a `TwoLayerDNS` |
@@ -255,37 +100,6 @@ function kolmogorov_and_batchelor_scale!(file::AbstractString) |
255 | 100 |
|
256 | 101 | return nothing |
257 | 102 |
|
258 | | -end |
259 | | -""" |
260 | | - function batchelor_scale! |
261 | | -Compute and append the minimum space-time Batchelor scale and append it to save output. |
262 | | -""" |
263 | | -function batchelor_scale!(file::AbstractString) |
264 | | - |
265 | | - file_type = find_file_type(file) |
266 | | - if isequal(file_type, ".nc") |
267 | | - |
268 | | - NCDataset(file, "a") do ds |
269 | | - Sc = ds.attrib["Sc"] |
270 | | - find_num = findfirst(' ', ds.attrib["ν"]) - 1 |
271 | | - ν = parse(Float64, ds.attrib["ν"][1:find_num]) |
272 | | - η_min = (ν^3 / maximum(ds["ϵ_maximum"][:])) |
273 | | - ds.attrib["λ_B"] = η_min / sqrt(Sc) # minimum space and time Batchelor scale |
274 | | - end |
275 | | - |
276 | | - elseif isequal(file_type, ".jld2") |
277 | | - |
278 | | - Sc = load(file, "Non_dimensional_numbers")["Sc"] |
279 | | - η = FieldTimeSeries(file, "ϵ_maximum") |
280 | | - min_η = minimum(η) |
281 | | - jldopen(file, "a+") do f |
282 | | - f["minimum_batchelor_scale"] = min_η / sqrt(Sc) |
283 | | - end |
284 | | - |
285 | | - end |
286 | | - |
287 | | - return nothing |
288 | | - |
289 | 103 | end |
290 | 104 | """ |
291 | 105 | function non_dimensional_numbers(simulation::Simulation, dns::TwoLayerDNS) |
|
0 commit comments