diff --git a/src/ReCo.jl b/src/ReCo.jl index 75b2e95..48333b3 100644 --- a/src/ReCo.jl +++ b/src/ReCo.jl @@ -10,7 +10,7 @@ using JLD2: JLD2 using JSON3: JSON3 import Dates: now, CompoundPeriod, canonicalize -import Base: push!, iterate +import Base: push!, iterate, wait # BEGIN dev deps using Revise diff --git a/src/data.jl b/src/data.jl index d61b915..320a02a 100644 --- a/src/data.jl +++ b/src/data.jl @@ -49,10 +49,10 @@ function set_status(dir::String, n_bundles::Int64, T::Float64) end function save_bundle(dir::String, bundle::Bundle, n::Int64, T::Float64) - bundle_dir = "$dir/bundles/bundle$n" - mkpath(bundle_dir) + bundles_dir = "$dir/bundles" + mkpath(bundles_dir) - JLD2.save_object("$bundle_dir/bundle.jld2", bundle) + JLD2.save_object("$bundles_dir/bundle_$n.jld2", bundle) set_status(dir, n, T) diff --git a/src/run.jl b/src/run.jl index cd190c9..fcae647 100644 --- a/src/run.jl +++ b/src/run.jl @@ -81,13 +81,13 @@ function run_sim( n_bundles::Int64 = status.n_bundles next_bundle = n_bundles + 1 - next_bundle_path = "$dir/bundles/bundle$next_bundle" - mkpath(next_bundle_path) + bundles_path = "$dir/bundles" + mkpath(bundles_path) if n_bundle_snapshots > 0 save_data = true - open("$next_bundle_path/run_vars.json", "w") do f + open("$bundles_dir/run_vars_$next_bundle.json", "w") do f JSON3.pretty(f, run_vars) end else diff --git a/src/simulation.jl b/src/simulation.jl index 9e06308..f6c9085 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -63,6 +63,8 @@ function euler!(args) return nothing end +wait(n::Nothing) = n + function simulate( args, δt::Float64, @@ -79,16 +81,21 @@ function simulate( start_time = now() println("Started simulation at $start_time.") + task::Union{Task,Nothing} = nothing + @showprogress 0.6 for (integration_step, t) in enumerate(T0:δt:T) if (integration_step % n_steps_before_snapshot == 0) && save_data + wait(task) bundle_snapshot_counter += 1 save_snapshot!(args.bundle, bundle_snapshot_counter, t, args.particles) if bundle_snapshot_counter == args.n_bundle_snapshots - bundle_snapshot_counter = 0 - n_bundles += 1 + task = @async begin + bundle_snapshot_counter = 0 + n_bundles += 1 - save_bundle(dir, args.bundle, n_bundles, t) + save_bundle(dir, args.bundle, n_bundles, t) + end end end