Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
31a9affd9f | |
|
|
dd3f2d6aab | |
|
|
5df5384285 | |
|
|
2ab795ccad | |
|
|
951574e788 | |
|
|
8271b23e52 | |
|
|
ecaaef4623 | |
|
|
e4cd16564c |
15
README.md
15
README.md
|
|
@ -1,12 +1,10 @@
|
||||||
# SCJ_Projekt
|
# SCJ_Projekt
|
||||||
|
|
||||||
# SCJ Projekt
|
## Setup
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
1. **Aktiviere das Projekt**:
|
1. **Aktiviere das Projekt**:
|
||||||
|
|
||||||
Wechsel in den **Package Manager** von Julia und aktiviere das Projekt:
|
Im **Package Manager** von Julia muss zuerst das Projekt aktiviert werden:
|
||||||
|
|
||||||
```julia
|
```julia
|
||||||
] activate .
|
] activate .
|
||||||
|
|
@ -16,9 +14,10 @@
|
||||||
] instantiate
|
] instantiate
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
es steht erstmal nur so ein möglicher Projekt Dateiaufbau
|
|
||||||
|
|
||||||
## Nutzung
|
## Nutzung
|
||||||
|
|
||||||
Wenn ihr `scripts/run_simulation.jl` ausführt, sollte sich mit **Makie** eine GUI öffnen, die einen **Slider** hat, mit dem man ein paar generierte Frames angucken kann.
|
```bash
|
||||||
|
include("scripts/main.jl")
|
||||||
|
```
|
||||||
|
|
||||||
|
Wenn der obige Befehl in der REPL ausgeführt wird, öffnet sich mit **Makie** eine GUI, wo unser Produkt zu finden ist!
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using GLMakie
|
||||||
|
|
||||||
using .Visualization
|
using .Visualization
|
||||||
|
|
||||||
# GSParams AND FHNParams
|
# CombinedPDEParams
|
||||||
N = 128
|
N = 128
|
||||||
dx = 1.0
|
dx = 1.0
|
||||||
params = (
|
params = (
|
||||||
|
|
@ -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[]))
|
||||||
|
|
||||||
|
# needed 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 CombinedPDEParams
|
||||||
|
`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 CombinedPDEParams
|
||||||
|
`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,28 +1,5 @@
|
||||||
|
# This struct includes all parameters needed for FHN and GrayScott
|
||||||
|
struct CombinedPDEParams
|
||||||
abstract type PDEParams end
|
|
||||||
|
|
||||||
struct FHNParams <: PDEParams
|
|
||||||
N::Int
|
|
||||||
dx::Float64 # grid spacing
|
|
||||||
Du::Float64
|
|
||||||
Dv::Float64
|
|
||||||
ϵ::Float64
|
|
||||||
a::Float64
|
|
||||||
b::Float64
|
|
||||||
end
|
|
||||||
|
|
||||||
struct GSParams <: PDEParams
|
|
||||||
N::Int # grid size
|
|
||||||
dx::Float64 # grid spacing
|
|
||||||
Du::Float64 # diffusion rate U
|
|
||||||
Dv::Float64 # diffusion rate V
|
|
||||||
F::Float64 # feed rate
|
|
||||||
k::Float64 # kill rate
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
struct CombinedPDEParams <: PDEParams
|
|
||||||
N::Int
|
N::Int
|
||||||
dx::Float64
|
dx::Float64
|
||||||
Du::Float64
|
Du::Float64
|
||||||
|
|
|
||||||
|
|
@ -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,23 +76,54 @@ 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.
|
||||||
|
The step_methods have different names because switching models via multi-dispatching is too complex.
|
||||||
|
|
||||||
|
# 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)
|
||||||
fig = Figure(size=(1300, 950))
|
fig = Figure(size=(1500, 950))
|
||||||
|
|
||||||
gh = GridLayout(fig[1, 1])
|
gh = GridLayout(fig[1, 1])
|
||||||
dropdown = Menu(fig, options=collect(zip(["Gray-Scott", "FHN"], [:gray_scott, :fhn])))
|
dropdown = Menu(fig, options=collect(zip(["Gray-Scott", "FHN"], [:gray_scott, :fhn])))
|
||||||
gh[1, 1] = dropdown
|
gh[1, 1] = dropdown
|
||||||
ax = Axis(gh[2, 1])
|
plotgrid = GridLayout()
|
||||||
|
gh[2, 1] = plotgrid
|
||||||
|
|
||||||
|
ax = Axis(plotgrid[1, 1])
|
||||||
|
hm = heatmap!(ax, heat_obs, colormap=:viridis)
|
||||||
|
plotgrid[1, 2] = Colorbar(fig, hm, label="Inhibitor ⇒ Activator")
|
||||||
|
|
||||||
hm = Makie.heatmap!(ax, heat_obs, colormap=:viridis)
|
|
||||||
deactivate_interaction!(ax, :rectanglezoom)
|
deactivate_interaction!(ax, :rectanglezoom)
|
||||||
ax.aspect = DataAspect()
|
ax.aspect = DataAspect()
|
||||||
|
|
||||||
|
|
@ -182,7 +226,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