@@ -33,9 +33,10 @@ Base.iterate(tldns::TwoLayerDNS, state = 1) =
3333 state > length (fieldnames (TwoLayerDNS)) ? nothing :
3434 (getfield (tldns, state), state + 1 )
3535"""
36- function DNS(architecture, domain_extent::NamedTuple, resolution::NamedTuple,
37- diffusivities::NamedTuple)
38- Setup a Direct Numerical Simulation on `architecture` (`CPU()` or `GPU()`) over the
36+ function DNSModel(architecture, domain_extent::NamedTuple, resolution::NamedTuple,
37+ diffusivities::NamedTuple)
38+ Setup a Direct Numerical Simulation [`Model`](https://clima.github.io/OceananigansDocumentation/dev/appendix/library/#Oceananigans.Models.NonhydrostaticModels.NonhydrostaticModel-Tuple{})
39+ on `architecture` (`CPU()` or `GPU()`) over the
3940`domain_extent` with `resolution` and scalar diffusivities for momentum
4041(kinematic viscosity `ν`) and the temperature and salinity tracers (`κₜ` and `κₛ`).
4142To evolve the temperature and salinity tracers, the [polynomial approximation to the
@@ -66,15 +67,15 @@ the rate `stretching`, if `false` uniform grid spacing is used;
6667- `refinement = 1.2` spacing near the surface in the `z` dimension;
6768- `stretching = 100` rate of stretching at the bottom of grid in the `z` dimension.
6869"""
69- function DNS (architecture, domain_extent:: NamedTuple , resolution:: NamedTuple ,
70- diffusivities:: NamedTuple ;
71- linear_eos = false ,
72- α = 1.67e-4 ,
73- β = 7.80e-4 ,
74- reference_density = nothing ,
75- zgrid_stretching = false ,
76- refinement = 1.05 ,
77- stretching = 40 )
70+ function DNSModel (architecture, domain_extent:: NamedTuple , resolution:: NamedTuple ,
71+ diffusivities:: NamedTuple ;
72+ linear_eos = false ,
73+ α = 1.67e-4 ,
74+ β = 7.80e-4 ,
75+ reference_density = nothing ,
76+ zgrid_stretching = false ,
77+ refinement = 1.05 ,
78+ stretching = 40 )
7879
7980 Lx, Ly, Lz = domain_extent. Lx, domain_extent. Ly, domain_extent. Lz
8081 Nx, Ny, Nz = resolution. Nx, resolution. Ny, resolution. Nz
@@ -127,11 +128,11 @@ function grid_stretching(Lz::Number, Nz::Number, refinement::Number, stretching:
127128
128129end
129130"""
130- function DNS_simulation_setup(dns ::TwoLayerDNS, Δt::Number, stop_time::Number,
131- save_schedule::Number; cfl = 0.75, diffusive_cfl = 0.75,
132- max_change = 1.2, max_Δt = 1e-1)
133- Setup a DNS from `initial_conditions` that are of type `TwoLayerInitialConditions`.
134- Important non-dimensional numnbers that are part of this experiment are computed and saved
131+ function TLDNS_simulation_setup(tldns ::TwoLayerDNS, Δt::Number, stop_time::Number,
132+ save_schedule::Number; cfl = 0.75, diffusive_cfl = 0.75,
133+ max_change = 1.2, max_Δt = 1e-1)
134+ Setup a `Simulation` of `tldns` from `initial_conditions` that are of type `TwoLayerInitialConditions`.
135+ Important non-dimensional numbers that are part of this experiment are computed and saved
135136to the simulation output file.
136137
137138## Function arguments:
@@ -143,7 +144,7 @@ the course of a simulation;
143144- `savefile` name of the file to save the data to,
144145- `save_schedule` number (representing time in seconds) at which to save model output, e.g.,
145146`save_schedule = 1` saves output every second;
146- - `output_writer ` a `Symbol` (either `:netcdf` or `:jld2`) choosing whether to save data in
147+ - `save_file ` a `Symbol` (either `:netcdf` or `:jld2`) choosing whether to save data in
147148`NetCDF` format (`.nc`) ot `JLD2` format ('.jld2).
148149
149150## Keyword arguments:
@@ -158,23 +159,23 @@ there is no `Checkpointer`.
158159- `max_Δt` the maximum timestep;
159160- `density_reference_gp_height` for the seawater density calculation;
160161- `save_velocities` defaults to `false`, if `true` model velocities will be saved to output;
161- - `overwrite_existing ` whether the output overwrites a file of the same name, default is
162- `false `.
162+ - `overwrite_saved_output ` whether the output overwrites a file of the same name, default is
163+ `true `.
163164"""
164- function DNS_simulation_setup (dns :: TwoLayerDNS , Δt:: Number ,
165- stop_time:: Number , save_schedule:: Number ,
166- output_writer :: Symbol = :netcdf ;
167- output_path = SIMULATION_PATH,
168- checkpointer_time_interval = nothing ,
169- cfl = 0.75 ,
170- diffusive_cfl = 0.75 ,
171- max_change = 1.2 ,
172- max_Δt = 1e-1 ,
173- density_reference_gp_height = 0 ,
174- overwrite_existing = false ,
175- save_velocities = false )
176-
177- model = dns . model
165+ function TLDNS_simulation_setup (tldns :: TwoLayerDNS , Δt:: Number ,
166+ stop_time:: Number , save_schedule:: Number ;
167+ save_file = :netcdf ,
168+ output_path = SIMULATION_PATH,
169+ checkpointer_time_interval = nothing ,
170+ cfl = 0.75 ,
171+ diffusive_cfl = 0.75 ,
172+ max_change = 1.2 ,
173+ max_Δt = 1e-1 ,
174+ density_reference_gp_height = 0 ,
175+ overwrite_saved_output = nothing ,
176+ save_velocities = false )
177+
178+ model = tldns . model
178179 simulation = Simulation (model; Δt, stop_time)
179180
180181 # time step adjustments
@@ -186,62 +187,58 @@ function DNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
186187
187188 # Custom saved output
188189 # Potential density
189- σ = seawater_density (model, geopotential_height = 0 )
190+ σ = seawater_density (model, geopotential_height = density_reference_gp_height )
190191
191192 # Inferred vertical temperature diffusivity
192- T_mean = Average (T)
193- T′ = T - Field (T_mean)
194- w′ = wᶜᶜᶜ (model)
195- w′T′ = Field (w′ * T′)
196- ∫ₐw′T′ = Integral (w′T′, dims = (1 , 2 ))
197- T_gradient = ∂z (T)
198- ∫ₐT_gradient = Integral (T_gradient, dims = (1 , 2 ))
193+ # T_mean = Average(T)
194+ # T′ = T - Field(T_mean)
195+ # w′ = wᶜᶜᶜ(model)
196+ # w′T′ = Field(w′ * T′)
197+ # ∫ₐw′T′ = Integral(w′T′, dims = (1, 2))
198+ # T_gradient = ∂z(T)
199+ # ∫ₐT_gradient = Integral(T_gradient, dims = (1, 2))
199200
200201 ϵ = KineticEnergyDissipationRate (model)
201202 # Volume integrated TKE dissipation
202203 ∫ϵ = Integral (ϵ)
203204 # Minimum in space Kolmogorov length scale
204205 η_space (model) = (model. closure. ν^ 3 / maximum (ϵ))^ (1 / 4 )
205206
206- # Volume integrated TKE dissipation
207- ∫ϵ = Integral (ϵ)
208-
209207 # Dimensions and attributes for custom saved output
210208 dims = Dict (" η_space" => ())
211209 oa = Dict (
212210 " σ" => Dict (" longname" => " Seawater potential density calculated using TEOS-10 at $(density_reference_gp_height) dbar" ,
213211 " units" => " kgm⁻³" ),
214212 " η_space" => Dict (" longname" => " Minimum (in space) Kolmogorov length" ),
215- " ∫ₐw′T′" => Dict (" longname" => " Horizontally integrated vertical temperature flux (w′T′)" ),
216- " ∫ₐT_gradient" => Dict (" longname" => " Horizontally integrated vertical temperature gradient (∂T/∂z)" ),
213+ # "∫ₐw′T′" => Dict("longname" => "Horizontally integrated vertical temperature flux (w′T′)"),
214+ # "∫ₐT_gradient" => Dict("longname" => "Horizontally integrated vertical temperature gradient (∂T/∂z)"),
217215 " ∫ϵ" => Dict (" longname" => " Volume integrated turbulent kintetic energy dissipation" )
218216 )
219217
220218 # outputs to be saved during the simulation
221- outputs = Dict (" S" => S, " T" => T, " η_space" => η_space, " σ" => σ, " ∫ϵ" => ∫ϵ,
222- " ∫ₐw′T′" => ∫ₐw′T′, " ∫ₐT_gradient" => ∫ₐT_gradient)
219+ outputs = Dict (" S" => S, " T" => T, " η_space" => η_space, " σ" => σ, " ∫ϵ" => ∫ϵ) #= ,
220+ "∫ₐw′T′" => ∫ₐw′T′, "∫ₐT_gradient" => ∫ₐT_gradient)=#
223221 if save_velocities
224222 u, v, w = model. velocities
225223 velocities = Dict (" u" => u, " v" => v, " w" => w)
226224 merge! (outputs, velocities)
227225 end
228226
229- filename = form_filename (dns, stop_time, output_writer, output_path)
230- simulation. output_writers[:outputs ] = output_writer == :netcdf ?
231- NetCDFOutputWriter (model, outputs;
232- filename,
233- overwrite_existing,
227+ filename = form_filename (tldns, stop_time, save_file, output_path)
228+ simulation. output_writers[:outputs ] = save_file == :netcdf ?
229+ NetCDFOutputWriter (model, outputs; filename,
230+ overwrite_existing = overwrite_saved_output,
234231 schedule = TimeInterval (save_schedule),
235232 dimensions = dims,
236233 output_attributes = oa
237234 ) :
238235 JLD2OutputWriter (model, outputs;
239236 filename,
240237 schedule = TimeInterval (save_schedule),
241- overwrite_existing)
238+ overwrite_existing = overwrite_saved_output )
242239
243- non_dimensional_numbers! (simulation, dns )
244- predicted_maximum_density! (simulation, dns )
240+ non_dimensional_numbers! (simulation, tldns )
241+ predicted_maximum_density! (simulation, tldns )
245242
246243 # progress reporting
247244 simulation. callbacks[:progress ] = Callback (simulation_progress, IterationInterval (100 ))
@@ -252,26 +249,26 @@ function DNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
252249
253250end
254251"""
255- function form_filename(dns ::TwoLayerDNS, stop_time::Number, output_writer::Symbol , output_path::AbstractString )
252+ function form_filename(tldns ::TwoLayerDNS, stop_time::Number, save_file , output_path)
256253Create a filename for saved output based on the `profile_function`,`initial_conditions`,
257254`tracer_perturbation` and length of the simulation.
258255"""
259- function form_filename (dns :: TwoLayerDNS , stop_time:: Number , output_writer :: Symbol , output_path:: AbstractString )
256+ function form_filename (tldns :: TwoLayerDNS , stop_time:: Number , save_file , output_path)
260257
261- pf_string = lowercase (string (typeof (dns . profile_function))[1 : findfirst (' {' , string (typeof (dns . profile_function))) - 1 ])
262- ic_type = typeof (dns . initial_conditions)
258+ pf_string = lowercase (string (typeof (tldns . profile_function))[1 : findfirst (' {' , string (typeof (tldns . profile_function))) - 1 ])
259+ ic_type = typeof (tldns . initial_conditions)
263260 ic_string = ic_type <: StableTwoLayerInitialConditions ? " stable" :
264261 ic_type <: CabbelingTwoLayerInitialConditions ?
265262 " cabbeling" : ic_type <: UnstableTwoLayerInitialConditions ?
266263 " unstable" : ic_type <: IsohalineTwoLayerInitialConditions ?
267264 " isohaline" : " isothermal"
268265
269- tp_string = lowercase (string (typeof (dns . tracer_perturbation)))
266+ tp_string = lowercase (string (typeof (tldns . tracer_perturbation)))
270267 tp_find = isnothing (findfirst (' {' , tp_string)) ? length (tp_string) :
271268 findfirst (' {' , tp_string) - 1
272269 stop_time_min = stop_time / 60 ≥ 1 ? string (round (Int, stop_time / 60 )) :
273270 string (round (stop_time / 60 ; digits = 2 ))
274- filetype = output_writer == :netcdf ? " .nc" : " .jld2"
271+ filetype = save_file == :netcdf ? " .nc" : " .jld2"
275272 savefile = ic_string * " _" * pf_string * " _" * tp_string[1 : tp_find] * " _" * stop_time_min * " min" * filetype
276273
277274 # make a simulation directory if one is not present
@@ -284,11 +281,11 @@ function form_filename(dns::TwoLayerDNS, stop_time::Number, output_writer::Symbo
284281
285282end
286283"""
287- function checkpointer_setup!(simulation, model, checkpointer_time_interval)
284+ function checkpointer_setup!(simulation, model, output_path, checkpointer_time_interval)
288285Setup a `Checkpointer` at `checkpointer_time_interval` for a `simulation`
289286"""
290- function checkpointer_setup! (simulation:: Simulation , model:: Oceananigans.AbstractModel ,
291- output_path :: AbstractString , checkpointer_time_interval:: Number )
287+ function checkpointer_setup! (simulation, model, output_path ,
288+ checkpointer_time_interval:: Number )
292289
293290 dir = output_path == SIMULATION_PATH ? CHECKPOINT_PATH :
294291 joinpath (output_path, " model_checkpoints/" )
0 commit comments