Compare commits

...

8 Commits

Author SHA1 Message Date
2211567 31a9affd9f updated readme again 2025-06-18 11:07:51 +02:00
2211567 dd3f2d6aab added colorbar next to heatmap 2025-06-18 10:59:17 +02:00
2211567 5df5384285 updated some docs 2025-06-18 10:58:49 +02:00
2211567 2ab795ccad removed PDEParams 2025-06-18 10:53:06 +02:00
2211567 951574e788 updated README.md 2025-06-18 10:52:56 +02:00
Nikola Sebastian Munder 8271b23e52 remove unused params 2025-06-18 09:34:31 +02:00
Nikola Sebastian Munder ecaaef4623 improve docs 2025-06-18 09:34:20 +02:00
Ruben-FreddyLoafers e4cd16564c added docs 2025-06-18 09:27:38 +02:00
8 changed files with 100 additions and 64 deletions

View File

@ -1,12 +1,10 @@
# SCJ_Projekt
# SCJ Projekt
## Installation
## Setup
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
] activate .
@ -16,9 +14,10 @@
] instantiate
```
es steht erstmal nur so ein möglicher Projekt Dateiaufbau
## 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!

View File

@ -6,7 +6,7 @@ using GLMakie
using .Visualization
# GSParams AND FHNParams
# CombinedPDEParams
N = 128
dx = 1.0
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[]))
# 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
params_obs[] = CombinedPDEParams(N, dx, Du, Dv, F, k, ϵ, a, b)
end

View File

@ -8,6 +8,18 @@ using Observables
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)
p = params_obs[]

View File

@ -6,6 +6,17 @@ using Observables
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)
# Extract parameters
p = params_obs[]

View File

@ -1,28 +1,5 @@
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
# This struct includes all parameters needed for FHN and GrayScott
struct CombinedPDEParams
N::Int
dx::Float64
Du::Float64

View File

@ -1,5 +1,14 @@
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)
h2 = dx^2
center = U[2:end-1, 2:end-1]

View File

@ -3,6 +3,7 @@
module Templates
# square in the center
function blocks_ic(N)
u = fill(1.0, N, N)
v = fill(0.0, N, N)
@ -21,6 +22,7 @@ function blocks_ic(N)
return u, v
end
# column that fills center of matrix. column as wide a 1 / col_width of the matrix
function column_ic(N)
u = fill(0.01, N, N)
v = fill(0.99, N, N)
@ -36,17 +38,8 @@ function column_ic(N)
return u, v
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)
row_width = 8
distance_from_edge = 50
@ -83,20 +76,7 @@ function two_rows_edge_distance_ic(N)
return u, v
end
function center_band_ic(N)
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
# circle in the center of matrix
function circle_ic(N)
u = fill(0.01, N, N)
v = fill(0.99, N, N)
@ -112,6 +92,7 @@ function circle_ic(N)
return u, v
end
# place three circles at random places of matrix
function three_circles_random_ic(N)
u = fill(0.01, 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.")
end
for _ in 1:5 # Place 3 circles
for _ in 1:3 # Place # of circles
# Generate random center coordinates
cx = rand(min_coord:max_coord)
cy = rand(min_coord:max_coord)
@ -141,6 +122,7 @@ function three_circles_random_ic(N)
return u, v
end
# like column_ic() but with a squiggle in the middle
function squiggle_ic(N, Lx=400.0, Ly=400.0)
uplus = 0.01
vplus = 0.99
@ -168,6 +150,7 @@ function squiggle_ic(N, Lx=400.0, Ly=400.0)
return u, v
end
# places patches for coral pattern
function coral_ic(N)
u = ones(N, N)
v = zeros(N, N)
@ -180,6 +163,6 @@ function coral_ic(N)
return u, v
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

View File

@ -45,6 +45,19 @@ function reset!(U, V, heat_obs)
heat_obs[] = copy(U)
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)
label_cell = 2 * col - 1
textbox_cell = 2 * col
@ -63,23 +76,54 @@ function param_box!(grid, row, labeltxt, observable::Observable; col=1)
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)
for _ in 1:n_steps
heat_obs[] = step_method(state[1], state[2], params_obs; dx=1)
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)
reset!(U, V, heat_obs)
fig = Figure(size=(1300, 950))
fig = Figure(size=(1500, 950))
gh = GridLayout(fig[1, 1])
dropdown = Menu(fig, options=collect(zip(["Gray-Scott", "FHN"], [:gray_scott, :fhn])))
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)
ax.aspect = DataAspect()
@ -182,7 +226,6 @@ function build_ui(U, V, param_obs_map::NamedTuple, params_obs, heat_obs)
heat_obs[] = copy(U)
end
# Template Control
on(btn_cow.clicks) do _
# fill matrix with random noise
U = 0.05 .* (2 .* rand(params_obs[].N, params_obs[].N) .- 1) # noise in [-0.05, 0.05]