1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00
This commit is contained in:
MoBit 2021-11-26 14:50:47 +01:00
parent e2f06265df
commit 1c17e05a53
4 changed files with 17 additions and 10 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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