From c1c5c347708fc22ea35ff18142ec4135365feea7 Mon Sep 17 00:00:00 2001 From: dpachner02 Date: Tue, 10 Jun 2025 21:31:33 +0200 Subject: [PATCH] not stable yet --- scripts/run_simulation.jl | 85 ++++++++++++++++++++++++++++++++++++--- src/constants.jl | 2 +- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/scripts/run_simulation.jl b/scripts/run_simulation.jl index 84e01c2..82a719c 100644 --- a/scripts/run_simulation.jl +++ b/scripts/run_simulation.jl @@ -7,15 +7,21 @@ using .Constants N = 128 dx = 1.0 # diffusion rates of substance 'u' and 'v' -Du, Dv = Observable(0.16), Observable(0.08) +Du, Dv = Observable(0.142), Observable(0.078) # feed rate of 'u' and kill rate of 'v' -F, k = Observable(0.060), Observable(0.062) +F, k = Observable(0.0617), Observable(0.062) dt = 1.0 params_obs = Observable(GSParams(N, dx, Du[], Dv[], F[], k[])) + +function current_params() + println(params_obs) +end + function update_params!(params_obs, u, v, feed, kill) old = params_obs[] params_obs[] = GSParams(old.N, old.dx, u, v, feed, kill) + current_params() end # Whenever a value gets changed via the textbox, update params object to reflect changes in simulation @@ -27,8 +33,40 @@ V = zeros(N, N) center = N ÷ 2 radius = 10 # set a cube in the center with starting concentrations for 'u' and 'v' -U[center-radius:center+radius, center-radius:center+radius] .= 0.50 -V[center-radius:center+radius, center-radius:center+radius] .= 0.25 + +jitter_amount = 5 # maximale Verschiebung in Pixeln +margin = radius + 2 # Abstand zum Rand + +# Manuell definierte gleichverteilte Positionen (6 Punkte) +positions = [ + (1/4, 1/4), + (3/4, 1/4), + (1/2, 1/2), + (1/4, 3/4), + (3/4, 3/4), + (1/2, 1/8) +] + +centers = [] + +for (px, py) in positions + # Position relativ zu Feldgröße + Jitter + cx = clamp(round(Int, px * N) + rand(-jitter_amount:jitter_amount), margin, N - margin) + cy = clamp(round(Int, py * N) + rand(-jitter_amount:jitter_amount), margin, N - margin) + + push!(centers, (cx, cy)) + + for x in (cx - radius):(cx + radius) + for y in (cy - radius):(cy + radius) + if x > 0 && x ≤ N && y > 0 && y ≤ N + if sqrt((x - cx)^2 + (y - cy)^2) ≤ radius + U[x, y] = 0.5 + V[x, y] = 0.25 + end + end + end + end +end # Observable holding current U for heatmap heat_obs = Observable(U) @@ -124,12 +162,47 @@ param_box!(4, "kill", k) # Timer and state for animation running = Observable(false) function reset!(U, V, heat_obs) + current_params() U .= 1.0 V .= 0.0 center = size(U, 1) ÷ 2 radius = 10 - U[center-radius:center+radius, center-radius:center+radius] .= 0.50 - V[center-radius:center+radius, center-radius:center+radius] .= 0.25 + +num_spots = 6 +jitter_amount = 5 # maximale Verschiebung in Pixeln +margin = radius + 2 # Abstand zum Rand + +# Manuell definierte gleichverteilte Positionen (6 Punkte) +positions = [ + (1/4, 1/4), + (3/4, 1/4), + (1/2, 1/2), + (1/4, 3/4), + (3/4, 3/4), + (1/2, 1/8) +] + +centers = [] + +for (px, py) in positions + # Position relativ zu Feldgröße + Jitter + cx = clamp(round(Int, px * N) + rand(-jitter_amount:jitter_amount), margin, N - margin) + cy = clamp(round(Int, py * N) + rand(-jitter_amount:jitter_amount), margin, N - margin) + + push!(centers, (cx, cy)) + + for x in (cx - radius):(cx + radius) + for y in (cy - radius):(cy + radius) + if x > 0 && x ≤ N && y > 0 && y ≤ N + if sqrt((x - cx)^2 + (y - cy)^2) ≤ radius + U[x, y] = 0.5 + V[x, y] = 0.25 + end + end + end + end +end + heat_obs[] = copy(U) end diff --git a/src/constants.jl b/src/constants.jl index c06f46c..d17edbe 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -16,7 +16,7 @@ struct FHNParams end struct GSParams - N::Int # grid size + N::Int64 # grid size dx::Float64 # grid spacing Du::Float64 # diffusion rate U Dv::Float64 # diffusion rate V