implemented first switching mechanisms
parent
509417bc54
commit
a52272f30d
|
|
@ -9,42 +9,44 @@ using GLMakie
|
|||
using .Constants
|
||||
using .Visualization
|
||||
|
||||
"""
|
||||
model_type = Observable(:gray_scott) # or :fhn
|
||||
|
||||
# GSParams
|
||||
N = 128
|
||||
dx = 1.0
|
||||
Du, Dv = Observable(0.16), Observable(0.08)
|
||||
F, k = Observable(0.060), Observable(0.062)
|
||||
|
||||
param_observables = (
|
||||
Du=Du,
|
||||
Dv=Dv,
|
||||
F=F,
|
||||
k=k,
|
||||
gray_params = (
|
||||
Du = Observable(0.16),
|
||||
Dv = Observable(0.08),
|
||||
F = Observable(0.060),
|
||||
k = Observable(0.062)
|
||||
)
|
||||
"""
|
||||
|
||||
# FHNParams
|
||||
N = 128
|
||||
dx = 1.0
|
||||
Du, Dv = Observable(0.016), Observable(0.1)
|
||||
ϵ, a, b = Observable(0.1), Observable(0.5), Observable(0.9)
|
||||
param_observables = (
|
||||
Du=Du,
|
||||
Dv=Dv,
|
||||
ϵ=ϵ,
|
||||
a=a,
|
||||
b=b
|
||||
fhn_params = (
|
||||
Du = Observable(0.16),
|
||||
Dv = Observable(0.08),
|
||||
ϵ = Observable(0.05),
|
||||
a = Observable(0.7),
|
||||
b = Observable(0.8)
|
||||
)
|
||||
|
||||
#params_obs = Observable(Constants.GSParams(N, dx, Du[], Dv[], F[], k[]))
|
||||
params_obs = Observable(Constants.FHNParams(N=N, dx=dx, Du=Du[], Dv=Dv[], ϵ=ϵ[], a=a[], b=b[]))
|
||||
params_obs = Observable(Constants.GSParams(N, dx, gray_params.Du[], gray_params.Dv[], gray_params.F[], gray_params.k[]))
|
||||
#params_obs = Observable(Constants.FHNParams(N=N, dx=dx, Du=Du[], Dv=Dv[], ϵ=ϵ[], a=a[], b=b[]))
|
||||
|
||||
"""
|
||||
lift(Du, Dv, F, k) do u, v, f, ki
|
||||
params_obs[] = Constants.GSParams(N, dx, u, v, f, ki)
|
||||
# Rebuild when model or sliders change
|
||||
function setup_param_binding!(model_type, gray_params, fhn_params, params_obs)
|
||||
if model_type[] == :gray_scott
|
||||
lift(gray_params.Du, gray_params.Dv, gray_params.F, gray_params.k) do Du, Dv, F, k
|
||||
params_obs[] = GSParams(N, dx, Du, Dv, F, k)
|
||||
end
|
||||
else
|
||||
lift(fhn_params.Du, fhn_params.Dv, fhn_params.ϵ, fhn_params.a, fhn_params.b) do Du, Dv, ϵ, a, b
|
||||
params_obs[] = FHNParams(N, dx, Du, Dv, ϵ, a, b)
|
||||
end
|
||||
end
|
||||
end
|
||||
"""
|
||||
|
||||
lift(Du, Dv, ϵ, a, b) do d_u, d_v, eps, aa, bb
|
||||
params_obs[] = Constants.FHNParams(N=N, dx=dx, Du=d_u, Dv=d_v, ϵ=eps, a=aa, b=bb)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ function fhn!(du, u, p::FHNParams, t)
|
|||
du .= vcat(vec(fu), vec(fv))
|
||||
end
|
||||
|
||||
function step!(U, V, params_obs::Observable; dx=1)
|
||||
function step_fhn!(U, V, params_obs::Observable; dx=1)
|
||||
"""
|
||||
p = params_obs[]
|
||||
|
||||
|
|
@ -75,6 +75,6 @@ end
|
|||
|
||||
function multi_step!(state, n_steps, heat_obs::Observable, params_obs::Observable; dx=1)
|
||||
for _ in 1:n_steps
|
||||
heat_obs[] = step!(state[1], state[2], params_obs; dx=1)
|
||||
heat_obs[] = step_fhn!(state[1], state[2], params_obs; dx=1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using Observables
|
|||
using .Constants
|
||||
using .Laplacian
|
||||
|
||||
function step!(U, V, params_obs::Observable; dx=1)
|
||||
function step_gray_scott!(U, V, params_obs::Observable; dx=1)
|
||||
lap_u = laplacian5(U, dx)
|
||||
lap_v = laplacian5(V, dx)
|
||||
diff_u = params_obs[].Du
|
||||
|
|
@ -40,6 +40,6 @@ function step!(U, V, params_obs::Observable; dx=1)
|
|||
end
|
||||
function multi_step!(state, n_steps, heat_obs::Observable, params_obs::Observable; dx=1)
|
||||
for _ in 1:n_steps
|
||||
heat_obs[] = step!(state[1], state[2], params_obs; dx=1)
|
||||
heat_obs[] = step_gray_scott!(state[1], state[2], params_obs; dx=1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -47,7 +47,33 @@ function param_box!(grid, row, labeltxt, observable::Observable)
|
|||
end
|
||||
end
|
||||
|
||||
function rebuild_param_boxes!(grid, model_type, gray_params, fhn_params)
|
||||
empty!(grid)
|
||||
|
||||
if model_type[] == :gray_scott
|
||||
param_box!(grid, 1, "Du", gray_params.Du)
|
||||
param_box!(grid, 2, "Dv", gray_params.Dv)
|
||||
param_box!(grid, 3, "Feed", gray_params.F)
|
||||
param_box!(grid, 4, "Kill", gray_params.k)
|
||||
else
|
||||
param_box!(grid, 1, "Du", fhn_params.Du)
|
||||
param_box!(grid, 2, "Dv", fhn_params.Dv)
|
||||
param_box!(grid, 3, "ϵ", fhn_params.ϵ)
|
||||
param_box!(grid, 4, "a", fhn_params.a)
|
||||
param_box!(grid, 5, "b", fhn_params.b)
|
||||
end
|
||||
end
|
||||
|
||||
function step_model!(U, V, model_type, params_obs, heat_obs)
|
||||
if model_type[] == :gray_scott
|
||||
heat_obs[] = step_gray_scott!(U, V, params_obs)
|
||||
else
|
||||
heat_obs[] = step_fhn!(U, V, params_obs)
|
||||
end
|
||||
end
|
||||
|
||||
function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
||||
|
||||
reset!(U, V, heat_obs)
|
||||
fig = Figure(size=(800, 800))
|
||||
gh = GridLayout(fig[1, 1])
|
||||
|
|
@ -61,6 +87,7 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
|||
spoint = select_point(ax.scene)
|
||||
|
||||
# Controls
|
||||
dropdown = Dropdown(fig[0, 1], options=["Gray-Scott" => :gray_scott, "FHN" => :fhn])
|
||||
fig[2, 1] = buttongrid = GridLayout(ax.scene, tellwidth=false)
|
||||
btn_step = Button(buttongrid[1, 1], width=50, label="Step")
|
||||
btn_start = Button(buttongrid[1, 2], width=50, label=run_label)
|
||||
|
|
@ -142,6 +169,12 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
|||
|
||||
heat_obs[] = copy(U)
|
||||
end
|
||||
|
||||
on(dropdown.selection) do sel
|
||||
model_type[] = sel
|
||||
setup_param_binding!(model_type, gray_params, fhn_params, params_obs)
|
||||
rebuild_param_boxes!(param_grid, model_type, gray_params, fhn_params)
|
||||
end
|
||||
return fig
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue