Skip to content

Commit

Permalink
output at the first timestep
Browse files Browse the repository at this point in the history
The output at time t = 0 is truly the solution at that time, but noticed that current formulation has outputs at t = t* - dt, where t* is the intended time of output (see #46) -- this is because the clock and thickness are updated *before* the outputting is performed
  • Loading branch information
alextbradley committed Oct 20, 2021
1 parent 57a00ba commit db83880
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 215 deletions.
6 changes: 4 additions & 2 deletions src/OutputParams/OutputParams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct OutputParams{T <: Real, R <: Real, O}
output_path::String #folder in which to save
dump_vel::Bool #toggle on dumping the velocity after the final timestep
zip_format::String #specify whether or not to zip the output, and the format
output_start::Bool #flag to specify whether to output the initial state or not
end

#output constructor
Expand All @@ -19,7 +20,8 @@ function OutputParams(;
prefix = "outfile",
output_path = "./",
dump_vel = false,
zip_format = "none")
zip_format = "none",
output_start = false)

#default the n_iter_out to -1 (this is updated in simulation once we know timestep from timestepping_params)
n_iter_out = -1
Expand Down Expand Up @@ -47,7 +49,7 @@ function OutputParams(;
zip_format = "none"
end

return OutputParams(outputs, output_freq, n_iter_out, output_format, prefix, output_path, dump_vel, zip_format)
return OutputParams(outputs, output_freq, n_iter_out, output_format, prefix, output_path, dump_vel, zip_format, output_start)
end

include("output_writing.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/OutputParams/output_writing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function write_output(simulation)
fname = string(fname, ".mat")
matwrite(fname, output_dict)
end

println("outputting at timestep number $(simulation.clock.n_iter)")
end

"""
Expand Down
11 changes: 6 additions & 5 deletions src/Simulations/run_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
Perform one timestep of the simulation
"""
function timestep!(simulation)
@unpack model,timestepping_params = simulation
@unpack model,timestepping_params, output_params = simulation
update_state!(model)
#write solution if at the first timestep (hack for https://github.com/RJArthern/WAVI.jl/issues/46 until synchronicity is fixed)
if (output_params.output_start) && (simulation.clock.n_iter == 0)
write_output(simulation)
end
if timestepping_params.step_thickness
update_thickness!(simulation)
end
Expand Down Expand Up @@ -58,7 +62,7 @@ function run_simulation!(simulation)
chkpt_tag = "A"
for i = (simulation.clock.n_iter+1):timestepping_params.n_iter_total
timestep!(simulation)

#check if we have hit a temporary checkpoint
if mod(i,timestepping_params.n_iter_chkpt) == 0
#output a temporary checkpoint
Expand All @@ -80,9 +84,6 @@ function run_simulation!(simulation)
#check if we have hit an output timestep
if mod(i,simulation.output_params.n_iter_out) == 0
write_output(simulation)
println(simulation.clock.n_iter)
println("outputting at timestep number $(simulation.clock.n_iter)")

end

#check the dump velocity flag at the final timestep
Expand Down
Loading

0 comments on commit db83880

Please sign in to comment.