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