Skip to content

Commit ac7341e

Browse files
committed
Change default behaviour of overwrite_existing
1 parent b7c7c6a commit ac7341e

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

examples/twolayer_example.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ set_two_layer_initial_conditions!(tldns)
2929
Δt = 1e-4
3030
stop_time = 60
3131
save_schedule = 0.5 # seconds
32-
output_path = joinpath(@__DIR__, "outputs/")
33-
simulation = TLDNS_simulation_setup(tldns, Δt, stop_time, save_schedule,
34-
overwrite_existing = true; output_path)
32+
output_path = joinpath(@__DIR__, "outputs")
33+
simulation = TLDNS_simulation_setup(tldns, Δt, stop_time, save_schedule; output_path)
3534

3635
## Run the simulation
3736
run!(simulation)

src/twolayerdns.jl

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ function grid_stretching(Lz::Number, Nz::Number, refinement::Number, stretching:
128128

129129
end
130130
"""
131-
function TLDNS_simulation_setup(dns::TwoLayerDNS, Δt::Number, stop_time::Number,
131+
function TLDNS_simulation_setup(tldns::TwoLayerDNS, Δt::Number, stop_time::Number,
132132
save_schedule::Number; cfl = 0.75, diffusive_cfl = 0.75,
133133
max_change = 1.2, max_Δt = 1e-1)
134-
Setup a `Simulation` of `dns` from `initial_conditions` that are of type `TwoLayerInitialConditions`.
134+
Setup a `Simulation` of `tldns` from `initial_conditions` that are of type `TwoLayerInitialConditions`.
135135
Important non-dimensional numbers that are part of this experiment are computed and saved
136136
to the simulation output file.
137137
@@ -144,7 +144,7 @@ the course of a simulation;
144144
- `savefile` name of the file to save the data to,
145145
- `save_schedule` number (representing time in seconds) at which to save model output, e.g.,
146146
`save_schedule = 1` saves output every second;
147-
- `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
148148
`NetCDF` format (`.nc`) ot `JLD2` format ('.jld2).
149149
150150
## Keyword arguments:
@@ -159,23 +159,23 @@ there is no `Checkpointer`.
159159
- `max_Δt` the maximum timestep;
160160
- `density_reference_gp_height` for the seawater density calculation;
161161
- `save_velocities` defaults to `false`, if `true` model velocities will be saved to output;
162-
- `overwrite_existing` whether the output overwrites a file of the same name, default is
163-
`false`.
162+
- `overwrite_saved_output` whether the output overwrites a file of the same name, default is
163+
`true`.
164164
"""
165-
function TLDNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
166-
stop_time::Number, save_schedule::Number,
167-
output_writer::Symbol=:netcdf;
165+
function TLDNS_simulation_setup(tldns::TwoLayerDNS, Δt::Number,
166+
stop_time::Number, save_schedule::Number;
167+
save_file = :netcdf,
168168
output_path = SIMULATION_PATH,
169169
checkpointer_time_interval = nothing,
170170
cfl = 0.75,
171171
diffusive_cfl = 0.75,
172172
max_change = 1.2,
173173
max_Δt = 1e-1,
174174
density_reference_gp_height = 0,
175-
overwrite_existing = false,
175+
overwrite_saved_output = nothing,
176176
save_velocities = false)
177177

178-
model = dns.model
178+
model = tldns.model
179179
simulation = Simulation(model; Δt, stop_time)
180180

181181
# time step adjustments
@@ -204,9 +204,6 @@ function TLDNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
204204
# Minimum in space Kolmogorov length scale
205205
η_space(model) = (model.closure.ν^3 / maximum(ϵ))^(1/4)
206206

207-
# Volume integrated TKE dissipation
208-
∫ϵ = Integral(ϵ)
209-
210207
# Dimensions and attributes for custom saved output
211208
dims = Dict("η_space" => ())
212209
oa = Dict(
@@ -227,22 +224,21 @@ function TLDNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
227224
merge!(outputs, velocities)
228225
end
229226

230-
filename = form_filename(dns, stop_time, output_writer, output_path)
231-
simulation.output_writers[:outputs] = output_writer == :netcdf ?
232-
NetCDFOutputWriter(model, outputs;
233-
filename,
234-
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,
235231
schedule = TimeInterval(save_schedule),
236232
dimensions = dims,
237233
output_attributes = oa
238234
) :
239235
JLD2OutputWriter(model, outputs;
240236
filename,
241237
schedule = TimeInterval(save_schedule),
242-
overwrite_existing)
238+
overwrite_existing = overwrite_saved_output)
243239

244-
non_dimensional_numbers!(simulation, dns)
245-
predicted_maximum_density!(simulation, dns)
240+
non_dimensional_numbers!(simulation, tldns)
241+
predicted_maximum_density!(simulation, tldns)
246242

247243
# progress reporting
248244
simulation.callbacks[:progress] = Callback(simulation_progress, IterationInterval(100))
@@ -253,26 +249,26 @@ function TLDNS_simulation_setup(dns::TwoLayerDNS, Δt::Number,
253249

254250
end
255251
"""
256-
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)
257253
Create a filename for saved output based on the `profile_function`,`initial_conditions`,
258254
`tracer_perturbation` and length of the simulation.
259255
"""
260-
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)
261257

262-
pf_string = lowercase(string(typeof(dns.profile_function))[1:findfirst('{', string(typeof(dns.profile_function))) - 1])
263-
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)
264260
ic_string = ic_type <: StableTwoLayerInitialConditions ? "stable" :
265261
ic_type <: CabbelingTwoLayerInitialConditions ?
266262
"cabbeling" : ic_type <: UnstableTwoLayerInitialConditions ?
267263
"unstable" : ic_type <: IsohalineTwoLayerInitialConditions ?
268264
"isohaline" : "isothermal"
269265

270-
tp_string = lowercase(string(typeof(dns.tracer_perturbation)))
266+
tp_string = lowercase(string(typeof(tldns.tracer_perturbation)))
271267
tp_find = isnothing(findfirst('{', tp_string)) ? length(tp_string) :
272268
findfirst('{', tp_string) - 1
273269
stop_time_min = stop_time / 60 1 ? string(round(Int, stop_time / 60)) :
274270
string(round(stop_time / 60; digits = 2))
275-
filetype = output_writer == :netcdf ? ".nc" : ".jld2"
271+
filetype = save_file == :netcdf ? ".nc" : ".jld2"
276272
savefile = ic_string *"_"* pf_string *"_"* tp_string[1:tp_find] *"_"* stop_time_min * "min" * filetype
277273

278274
# make a simulation directory if one is not present
@@ -285,11 +281,11 @@ function form_filename(dns::TwoLayerDNS, stop_time::Number, output_writer::Symbo
285281

286282
end
287283
"""
288-
function checkpointer_setup!(simulation, model, checkpointer_time_interval)
284+
function checkpointer_setup!(simulation, model, output_path, checkpointer_time_interval)
289285
Setup a `Checkpointer` at `checkpointer_time_interval` for a `simulation`
290286
"""
291-
function checkpointer_setup!(simulation::Simulation, model::Oceananigans.AbstractModel,
292-
output_path::AbstractString, checkpointer_time_interval::Number)
287+
function checkpointer_setup!(simulation, model, output_path,
288+
checkpointer_time_interval::Number)
293289

294290
dir = output_path == SIMULATION_PATH ? CHECKPOINT_PATH :
295291
joinpath(output_path, "model_checkpoints/")

0 commit comments

Comments
 (0)