mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
async
This commit is contained in:
parent
e2f06265df
commit
1c17e05a53
4 changed files with 17 additions and 10 deletions
|
@ -10,7 +10,7 @@ using JLD2: JLD2
|
||||||
using JSON3: JSON3
|
using JSON3: JSON3
|
||||||
|
|
||||||
import Dates: now, CompoundPeriod, canonicalize
|
import Dates: now, CompoundPeriod, canonicalize
|
||||||
import Base: push!, iterate
|
import Base: push!, iterate, wait
|
||||||
|
|
||||||
# BEGIN dev deps
|
# BEGIN dev deps
|
||||||
using Revise
|
using Revise
|
||||||
|
|
|
@ -49,10 +49,10 @@ function set_status(dir::String, n_bundles::Int64, T::Float64)
|
||||||
end
|
end
|
||||||
|
|
||||||
function save_bundle(dir::String, bundle::Bundle, n::Int64, T::Float64)
|
function save_bundle(dir::String, bundle::Bundle, n::Int64, T::Float64)
|
||||||
bundle_dir = "$dir/bundles/bundle$n"
|
bundles_dir = "$dir/bundles"
|
||||||
mkpath(bundle_dir)
|
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)
|
set_status(dir, n, T)
|
||||||
|
|
||||||
|
|
|
@ -81,13 +81,13 @@ function run_sim(
|
||||||
|
|
||||||
n_bundles::Int64 = status.n_bundles
|
n_bundles::Int64 = status.n_bundles
|
||||||
next_bundle = n_bundles + 1
|
next_bundle = n_bundles + 1
|
||||||
next_bundle_path = "$dir/bundles/bundle$next_bundle"
|
bundles_path = "$dir/bundles"
|
||||||
mkpath(next_bundle_path)
|
mkpath(bundles_path)
|
||||||
|
|
||||||
if n_bundle_snapshots > 0
|
if n_bundle_snapshots > 0
|
||||||
save_data = true
|
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)
|
JSON3.pretty(f, run_vars)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -63,6 +63,8 @@ function euler!(args)
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
wait(n::Nothing) = n
|
||||||
|
|
||||||
function simulate(
|
function simulate(
|
||||||
args,
|
args,
|
||||||
δt::Float64,
|
δt::Float64,
|
||||||
|
@ -79,18 +81,23 @@ function simulate(
|
||||||
start_time = now()
|
start_time = now()
|
||||||
println("Started simulation at $start_time.")
|
println("Started simulation at $start_time.")
|
||||||
|
|
||||||
|
task::Union{Task,Nothing} = nothing
|
||||||
|
|
||||||
@showprogress 0.6 for (integration_step, t) in enumerate(T0:δt:T)
|
@showprogress 0.6 for (integration_step, t) in enumerate(T0:δt:T)
|
||||||
if (integration_step % n_steps_before_snapshot == 0) && save_data
|
if (integration_step % n_steps_before_snapshot == 0) && save_data
|
||||||
|
wait(task)
|
||||||
bundle_snapshot_counter += 1
|
bundle_snapshot_counter += 1
|
||||||
save_snapshot!(args.bundle, bundle_snapshot_counter, t, args.particles)
|
save_snapshot!(args.bundle, bundle_snapshot_counter, t, args.particles)
|
||||||
|
|
||||||
if bundle_snapshot_counter == args.n_bundle_snapshots
|
if bundle_snapshot_counter == args.n_bundle_snapshots
|
||||||
|
task = @async begin
|
||||||
bundle_snapshot_counter = 0
|
bundle_snapshot_counter = 0
|
||||||
n_bundles += 1
|
n_bundles += 1
|
||||||
|
|
||||||
save_bundle(dir, args.bundle, n_bundles, t)
|
save_bundle(dir, args.bundle, n_bundles, t)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if integration_step % n_steps_before_verlet_list_update == 0
|
if integration_step % n_steps_before_verlet_list_update == 0
|
||||||
update_verlet_list!(args)
|
update_verlet_list!(args)
|
||||||
|
|
Loading…
Reference in a new issue