added docs
parent
2dfdd7c08e
commit
e4cd16564c
|
|
@ -22,6 +22,8 @@ params = (
|
||||||
)
|
)
|
||||||
|
|
||||||
params_obs = Observable{CombinedPDEParams}(CombinedPDEParams(N, dx, params.Du[], params.Dv[], params.F[], params.k[], params.ϵ[], params.a[], params.b[]))
|
params_obs = Observable{CombinedPDEParams}(CombinedPDEParams(N, dx, params.Du[], params.Dv[], params.F[], params.k[], params.ϵ[], params.a[], params.b[]))
|
||||||
|
|
||||||
|
# need so params in param_boxes are updated
|
||||||
lift(params.N, params.dx, params.Du, params.Dv, params.F, params.k, params.ϵ, params.a, params.b) do N, dx, Du, Dv, F, k, ϵ, a, b
|
lift(params.N, params.dx, params.Du, params.Dv, params.F, params.k, params.ϵ, params.a, params.b) do N, dx, Du, Dv, F, k, ϵ, a, b
|
||||||
params_obs[] = CombinedPDEParams(N, dx, Du, Dv, F, k, ϵ, a, b)
|
params_obs[] = CombinedPDEParams(N, dx, Du, Dv, F, k, ϵ, a, b)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,18 @@ using Observables
|
||||||
|
|
||||||
using .Laplacian
|
using .Laplacian
|
||||||
|
|
||||||
|
"""
|
||||||
|
step_fhn!(U, V, params_obs::Observable; dx=1, dt=0.01)
|
||||||
|
|
||||||
|
calculation of new "matrix" for each iteration (step) with FitzHugh-Nagumo
|
||||||
|
|
||||||
|
# Arguments:
|
||||||
|
`U`: activator matrix
|
||||||
|
`V`: inhibitor matrix
|
||||||
|
`param_obs`: used parameters from FHNParams
|
||||||
|
`dx`: dx
|
||||||
|
`dt`: dt
|
||||||
|
"""
|
||||||
function step_fhn!(U, V, params_obs::Observable; dx=1, dt=0.01)
|
function step_fhn!(U, V, params_obs::Observable; dx=1, dt=0.01)
|
||||||
p = params_obs[]
|
p = params_obs[]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,17 @@ using Observables
|
||||||
|
|
||||||
using .Laplacian
|
using .Laplacian
|
||||||
|
|
||||||
|
"""
|
||||||
|
step_fhn!(U, V, params_obs::Observable; dx=1, dt=0.01)
|
||||||
|
|
||||||
|
calculation of new "matrix" for each iteration (step) with GrayScott
|
||||||
|
|
||||||
|
# Arguments:
|
||||||
|
`U`: activator matrix
|
||||||
|
`V`: inhibitor matrix
|
||||||
|
`param_obs`: used parameters from FHNParams
|
||||||
|
`dx`: dx
|
||||||
|
"""
|
||||||
function step_gray_scott!(U, V, params_obs::Observable; dx=1)
|
function step_gray_scott!(U, V, params_obs::Observable; dx=1)
|
||||||
# Extract parameters
|
# Extract parameters
|
||||||
p = params_obs[]
|
p = params_obs[]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,14 @@
|
||||||
module Laplacian
|
module Laplacian
|
||||||
|
|
||||||
|
"""
|
||||||
|
laplacian(U::AbstractMatrix{<:Real}, dx::Real)
|
||||||
|
|
||||||
|
laplacian operator implemented in code
|
||||||
|
|
||||||
|
# Arguments:
|
||||||
|
- `U`: activator or inhibitor matrix
|
||||||
|
- `dx`: dx
|
||||||
|
"""
|
||||||
function laplacian(U::AbstractMatrix{<:Real}, dx::Real)
|
function laplacian(U::AbstractMatrix{<:Real}, dx::Real)
|
||||||
h2 = dx^2
|
h2 = dx^2
|
||||||
center = U[2:end-1, 2:end-1]
|
center = U[2:end-1, 2:end-1]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
module Templates
|
module Templates
|
||||||
|
|
||||||
|
# square in the center
|
||||||
function blocks_ic(N)
|
function blocks_ic(N)
|
||||||
u = fill(1.0, N, N)
|
u = fill(1.0, N, N)
|
||||||
v = fill(0.0, N, N)
|
v = fill(0.0, N, N)
|
||||||
|
|
@ -21,6 +22,7 @@ function blocks_ic(N)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# column that fills center of matrix. column as wide a 1 / col_width of the matrix
|
||||||
function column_ic(N)
|
function column_ic(N)
|
||||||
u = fill(0.01, N, N)
|
u = fill(0.01, N, N)
|
||||||
v = fill(0.99, N, N)
|
v = fill(0.99, N, N)
|
||||||
|
|
@ -36,17 +38,8 @@ function column_ic(N)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
function stripe_ic(N)
|
|
||||||
u = zeros(N, N)
|
|
||||||
v = zeros(N, N)
|
|
||||||
for i in 1:N
|
|
||||||
for j in 1:N
|
|
||||||
u[i, j] = 0.1 + 0.05 * sin(2π * j / 10) + 0.01 * randn()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return u, v
|
|
||||||
end
|
|
||||||
|
|
||||||
|
# two rows that are equally distant from both edges
|
||||||
function two_rows_edge_distance_ic(N)
|
function two_rows_edge_distance_ic(N)
|
||||||
row_width = 8
|
row_width = 8
|
||||||
distance_from_edge = 50
|
distance_from_edge = 50
|
||||||
|
|
@ -83,20 +76,7 @@ function two_rows_edge_distance_ic(N)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
function center_band_ic(N)
|
# circle in the center of matrix
|
||||||
u = fill(0.0, N, N)
|
|
||||||
v = fill(0.0, N, N)
|
|
||||||
|
|
||||||
band_width = div(N, 8)
|
|
||||||
row_start = div(N, 2) - div(band_width, 2)
|
|
||||||
row_end = div(N, 2) + div(band_width, 2)
|
|
||||||
|
|
||||||
u[row_start:row_end, :] .= 0.1 .+ 0.01 .* randn(band_width + 1, N)
|
|
||||||
v[row_start:row_end, :] .= 0.1 .+ 0.01 .* randn(band_width + 1, N)
|
|
||||||
|
|
||||||
return u, v
|
|
||||||
end
|
|
||||||
|
|
||||||
function circle_ic(N)
|
function circle_ic(N)
|
||||||
u = fill(0.01, N, N)
|
u = fill(0.01, N, N)
|
||||||
v = fill(0.99, N, N)
|
v = fill(0.99, N, N)
|
||||||
|
|
@ -112,6 +92,7 @@ function circle_ic(N)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# place three circles at random places of matrix
|
||||||
function three_circles_random_ic(N)
|
function three_circles_random_ic(N)
|
||||||
u = fill(0.01, N, N)
|
u = fill(0.01, N, N)
|
||||||
v = fill(0.99, N, N)
|
v = fill(0.99, N, N)
|
||||||
|
|
@ -125,7 +106,7 @@ function three_circles_random_ic(N)
|
||||||
error("Matrix size N is too small to place circles of this radius without overlap or going out of bounds.")
|
error("Matrix size N is too small to place circles of this radius without overlap or going out of bounds.")
|
||||||
end
|
end
|
||||||
|
|
||||||
for _ in 1:5 # Place 3 circles
|
for _ in 1:3 # Place # of circles
|
||||||
# Generate random center coordinates
|
# Generate random center coordinates
|
||||||
cx = rand(min_coord:max_coord)
|
cx = rand(min_coord:max_coord)
|
||||||
cy = rand(min_coord:max_coord)
|
cy = rand(min_coord:max_coord)
|
||||||
|
|
@ -141,6 +122,7 @@ function three_circles_random_ic(N)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# like column_ic() but with a squiggle in the middle
|
||||||
function squiggle_ic(N, Lx=400.0, Ly=400.0)
|
function squiggle_ic(N, Lx=400.0, Ly=400.0)
|
||||||
uplus = 0.01
|
uplus = 0.01
|
||||||
vplus = 0.99
|
vplus = 0.99
|
||||||
|
|
@ -168,6 +150,7 @@ function squiggle_ic(N, Lx=400.0, Ly=400.0)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# places patches for coral pattern
|
||||||
function coral_ic(N)
|
function coral_ic(N)
|
||||||
u = ones(N, N)
|
u = ones(N, N)
|
||||||
v = zeros(N, N)
|
v = zeros(N, N)
|
||||||
|
|
@ -180,6 +163,6 @@ function coral_ic(N)
|
||||||
return u, v
|
return u, v
|
||||||
end
|
end
|
||||||
|
|
||||||
export blocks_ic, column_ic, squiggle_ic, three_circles_random_ic, circle_ic, center_band_ic, two_rows_edge_distance_ic, coral_ic, stripe_ic
|
export blocks_ic, column_ic, two_rows_edge_distance_ic, circle_ic, three_circles_random_ic, squiggle_ic, coral_ic
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -45,6 +45,19 @@ function reset!(U, V, heat_obs)
|
||||||
heat_obs[] = copy(U)
|
heat_obs[] = copy(U)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
param_box!(grid, row, labeltxt, observable; col)
|
||||||
|
|
||||||
|
Creates a param box
|
||||||
|
|
||||||
|
# Arguments
|
||||||
|
- `grid`: which grid this parameter box is placed in
|
||||||
|
- `row`: row inside the grid
|
||||||
|
- `labeltext`: labeltext in front of param box
|
||||||
|
- `observable`: observable that contains the value for the param
|
||||||
|
- `col`: column inside the grid. Param box uses up 2 columns
|
||||||
|
"""
|
||||||
function param_box!(grid, row, labeltxt, observable::Observable; col=1)
|
function param_box!(grid, row, labeltxt, observable::Observable; col=1)
|
||||||
label_cell = 2 * col - 1
|
label_cell = 2 * col - 1
|
||||||
textbox_cell = 2 * col
|
textbox_cell = 2 * col
|
||||||
|
|
@ -63,12 +76,38 @@ function param_box!(grid, row, labeltxt, observable::Observable; col=1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
multi_step!(state, n_steps, heat_obs::Observable, params_obs::Observable; step_method=step_gray_scott!, dx=1)
|
||||||
|
|
||||||
|
returns a new matrix for the heatmap for n steps of computing with the corresponding step_method
|
||||||
|
|
||||||
|
# Arguments:
|
||||||
|
- `state`: activator and inhibitor matrices
|
||||||
|
- `n_steps`: # of steps
|
||||||
|
- `param_obs`: observable of the params
|
||||||
|
- `step_method`: step_gray_scott! or step_fhn! method
|
||||||
|
- `dx`: dx
|
||||||
|
|
||||||
|
"""
|
||||||
function multi_step!(state, n_steps, heat_obs::Observable, params_obs::Observable; step_method=step_gray_scott!, dx=1)
|
function multi_step!(state, n_steps, heat_obs::Observable, params_obs::Observable; step_method=step_gray_scott!, dx=1)
|
||||||
for _ in 1:n_steps
|
for _ in 1:n_steps
|
||||||
heat_obs[] = step_method(state[1], state[2], params_obs; dx=1)
|
heat_obs[] = step_method(state[1], state[2], params_obs; dx=1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
build_ui(U, V, param_obs_map:, params_obs, heat_obs)
|
||||||
|
|
||||||
|
building the whole ui
|
||||||
|
|
||||||
|
# Arguments:
|
||||||
|
- `U`: activator matrix
|
||||||
|
- `V`: inhibitor matrix
|
||||||
|
- `param_obs_map`: values of the observable
|
||||||
|
- `param_obs`: observable of params
|
||||||
|
- `heat_obs`: used matrix in the heatmap
|
||||||
|
|
||||||
|
"""
|
||||||
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)
|
||||||
|
|
@ -182,7 +221,6 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
|
||||||
heat_obs[] = copy(U)
|
heat_obs[] = copy(U)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Template Control
|
|
||||||
on(btn_cow.clicks) do _
|
on(btn_cow.clicks) do _
|
||||||
# fill matrix with random noise
|
# fill matrix with random noise
|
||||||
U = 0.05 .* (2 .* rand(params_obs[].N, params_obs[].N) .- 1) # noise in [-0.05, 0.05]
|
U = 0.05 .* (2 .* rand(params_obs[].N, params_obs[].N) .- 1) # noise in [-0.05, 0.05]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue