add documentation and simplify running loop

feat/diff_Jaguar
Nikola Sebastian Munder 2025-06-09 13:05:25 +02:00
parent 951f9281a5
commit 50d5766fef
1 changed files with 22 additions and 21 deletions

View File

@ -6,7 +6,9 @@ using .Constants
# Parameters and initial conditions # Parameters and initial conditions
N = 128 N = 128
dx = 1.0 dx = 1.0
# diffusion rates of substance 'u' and 'v'
Du, Dv = Observable(0.16), Observable(0.08) Du, Dv = Observable(0.16), Observable(0.08)
# feed rate of 'u' and kill rate of 'v'
F, k = Observable(0.060), Observable(0.062) F, k = Observable(0.060), Observable(0.062)
dt = 1.0 dt = 1.0
params_obs = Observable(GSParams(N, dx, Du[], Dv[], F[], k[])) params_obs = Observable(GSParams(N, dx, Du[], Dv[], F[], k[]))
@ -16,6 +18,7 @@ function update_params!(params_obs, u, v, feed, kill)
params_obs[] = GSParams(old.N, old.dx, u, v, feed, kill) params_obs[] = GSParams(old.N, old.dx, u, v, feed, kill)
end end
# Whenever a value gets changed via the textbox, update params object to reflect changes in simulation
lift(Du, Dv, F, k) do u, v, F, k lift(Du, Dv, F, k) do u, v, F, k
update_params!(params_obs, u, v, F, k) update_params!(params_obs, u, v, F, k)
end end
@ -23,6 +26,7 @@ U = ones(N, N)
V = zeros(N, N) V = zeros(N, N)
center = N ÷ 2 center = N ÷ 2
radius = 10 radius = 10
# set a cube in the center with starting concentrations for 'u' and 'v'
U[center-radius:center+radius, center-radius:center+radius] .= 0.50 U[center-radius:center+radius, center-radius:center+radius] .= 0.50
V[center-radius:center+radius, center-radius:center+radius] .= 0.25 V[center-radius:center+radius, center-radius:center+radius] .= 0.25
@ -85,8 +89,11 @@ gh = GridLayout(fig[1, 1])
ax = Axis(gh[1, 1]) ax = Axis(gh[1, 1])
hm = Makie.heatmap!(ax, heat_obs, colormap=:viridis) hm = Makie.heatmap!(ax, heat_obs, colormap=:viridis)
Makie.deactivate_interaction!(ax, :rectanglezoom)
ax.aspect = DataAspect() ax.aspect = DataAspect()
spoint = select_point(ax.scene)
# # Controls # # Controls
run_label = Observable("Run") run_label = Observable("Run")
fig[2, 1] = buttongrid = GridLayout(tellwidth=false) fig[2, 1] = buttongrid = GridLayout(tellwidth=false)
@ -126,32 +133,26 @@ function reset!(U, V, heat_obs)
heat_obs[] = copy(U) heat_obs[] = copy(U)
end end
function animation_loop() on(running) do r
while running[] run_label[] = r ? "Pause" : "Run"
# step!(U, V) end
# Button Listeners
on(btn_step.clicks) do _
multi_step!((U, V), 30)
end
on(btn_start.clicks) do _
running[] = !running[]
end
on(btn_start.clicks) do _
@async while running[]
multi_step!((U, V), 30) multi_step!((U, V), 30)
sleep(0.05) # ~20 FPS sleep(0.05) # ~20 FPS
end end
end end
on(running) do r
run_label[] = r ? "Pause" : "Run"
end
on(btn_step.clicks) do _
multi_step!((U, V), 30)
end
on(btn_start.clicks) do _
running[] = !running[]
end
on(btn_start.clicks) do _
@async while running[]
animation_loop()
end
end
on(btn_reset.clicks) do _ on(btn_reset.clicks) do _
running[] = false running[] = false
reset!(U, V, heat_obs) reset!(U, V, heat_obs)