mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2025-09-02 09:02:35 +00:00
Added mean_kappa.jl
This commit is contained in:
parent
e6c70a8967
commit
d6900d9a92
11 changed files with 114 additions and 12 deletions
96
analysis/mean_kappa.jl
Normal file
96
analysis/mean_kappa.jl
Normal file
|
@ -0,0 +1,96 @@
|
|||
using CairoMakie
|
||||
using LaTeXStrings: @L_str
|
||||
using Statistics: Statistics
|
||||
|
||||
using ReCo: ReCo
|
||||
|
||||
includet("../src/Visualization/common_CairoMakie.jl")
|
||||
|
||||
function plot_mean_kappa(; rl_dir::String, n_last_episodes::Int64)
|
||||
dir_content = readdir(rl_dir; join=true, sort=true)
|
||||
n_content = length(dir_content)
|
||||
|
||||
sim_dirs = Vector{String}(undef, n_last_episodes)
|
||||
sim_dir_counter = 1
|
||||
|
||||
# Skip first sim_dir for the case that the simulation is still running
|
||||
skipped_first_sim_dir = false
|
||||
|
||||
for file_or_dir_ind in n_content:-1:1
|
||||
file_or_dir = dir_content[file_or_dir_ind]
|
||||
|
||||
if isdir(file_or_dir)
|
||||
if skipped_first_sim_dir
|
||||
sim_dirs[sim_dir_counter] = file_or_dir
|
||||
sim_dir_counter += 1
|
||||
if sim_dir_counter > n_last_episodes
|
||||
break
|
||||
end
|
||||
else
|
||||
skipped_first_sim_dir = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if sim_dir_counter < n_last_episodes
|
||||
error("The rl_dir does not have n_last_episodes + 1 dirs!")
|
||||
end
|
||||
|
||||
sim_consts = ReCo.load_sim_consts(sim_dirs[1])
|
||||
half_box_len = sim_consts.half_box_len
|
||||
total_n_snapshots = ReCo.BundlesInfo(sim_dirs[1]).total_n_snapshots
|
||||
|
||||
snapshot_κs = zeros(Float64, total_n_snapshots)
|
||||
|
||||
for sim_dir in sim_dirs
|
||||
bundles_info = ReCo.BundlesInfo(sim_dir)
|
||||
total_n_snapshots = bundles_info.total_n_snapshots
|
||||
|
||||
for snapshot_ind in 1:total_n_snapshots
|
||||
bundle, bundle_snapshot = ReCo.get_bundle_to_snapshot(
|
||||
bundles_info, snapshot_ind
|
||||
)
|
||||
|
||||
cs_view = view(bundle.c, :, bundle_snapshot)
|
||||
|
||||
κ = ReCo.gyration_tensor_eigvals_ratio(cs_view, half_box_len)
|
||||
snapshot_κs[snapshot_ind] += κ
|
||||
end
|
||||
end
|
||||
|
||||
snapshot_κs ./= n_last_episodes
|
||||
|
||||
mean_κ = Statistics.mean(snapshot_κs)
|
||||
|
||||
init_cairomakie!()
|
||||
fig = gen_figure(; padding=9)
|
||||
|
||||
ax = Axis(
|
||||
fig[1, 1];
|
||||
xlabel="Frame",
|
||||
ylabel=L"\kappa",
|
||||
limits=(1, total_n_snapshots, 0.0, 1.04),
|
||||
title="Averaged over last $n_last_episodes episodes",
|
||||
)
|
||||
|
||||
lines!(ax, 1:total_n_snapshots, snapshot_κs; label=L"\kappa")
|
||||
|
||||
rounded_mean_κ = round(mean_κ; digits=2)
|
||||
|
||||
lines!(
|
||||
ax,
|
||||
[1, total_n_snapshots],
|
||||
[mean_κ, mean_κ];
|
||||
label=L"Mean $\tilde{\kappa} = %$rounded_mean_κ$",
|
||||
linestyle=:dash,
|
||||
color=:red,
|
||||
)
|
||||
|
||||
axislegend(ax; position=:lb, padding=3, rowgap=-3)
|
||||
|
||||
set_gaps!(fig)
|
||||
|
||||
save_fig("mean_kappa.pdf", fig; parent_dir=rl_dir)
|
||||
|
||||
return nothing
|
||||
end
|
|
@ -90,7 +90,7 @@ function mean_squared_displacement(;
|
|||
(ts,), (:t,), sim_dirs[1, 1]; particle_slice=1, snapshot_slice=:, first_bundle=2
|
||||
) # Skip the first bundle to avoid t = 0
|
||||
|
||||
mean_sq_displacements = zeros((length(ts), n_v₀s))
|
||||
mean_sq_displacements = zeros(Float64, (length(ts), n_v₀s))
|
||||
|
||||
@simd for v₀_ind in 1:n_v₀s
|
||||
for sim_ind in 1:n_simulations
|
||||
|
|
|
@ -102,7 +102,7 @@ function radial_distribution(;
|
|||
error("snapshot_conunter != n_last_snapshots")
|
||||
end
|
||||
|
||||
g = zeros(n_radii)
|
||||
g = zeros(Float64, n_radii)
|
||||
|
||||
for snapshot_ind in 1:n_last_snapshots
|
||||
for p1_ind in 1:n_particles
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue