From 3e283fb94e0b04f23f1c309aff8591e70c383488 Mon Sep 17 00:00:00 2001 From: Niki Laptop <2212719@stud.hs-mannheim.de> Date: Sun, 8 Jun 2025 18:56:06 +0200 Subject: [PATCH] add function without ode and give GSParams into function --- src/solver.jl | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/solver.jl b/src/solver.jl index 510cc69..259b5d8 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -92,9 +92,9 @@ function grayscott!(du, u, p::GSParams, t=0) end # Run simulation -function run_simulationG(tspan::Tuple{Float64,Float64}, N::Int) +function run_simulationG(tspan::Tuple{Float64,Float64}, N::Int, GSP::GSParams) # Replace this in run_simulation - p = GSParams(N, 1.0, 0.16, 0.08, 0.060, 0.062) + p = GSP # Initial conditions: U = 1, V = 0 everywhere U = ones(N, N) @@ -109,7 +109,45 @@ function run_simulationG(tspan::Tuple{Float64,Float64}, N::Int) y0 = vcat(vec(U), vec(V)) prob = ODEProblem(grayscott!, y0, tspan, p) - sol = solve(prob, BS3(), saveat=100.0) # or Rosenbrock23() + sol = solve(prob, BS3(), saveat=10.0) # or Rosenbrock23() return sol end + +function run_simulationG_no_ode(tspan::Tuple{Float64,Float64}, N::Int, GSP::GSParams) + p = GSP + dx2 = p.dx^2 + dt = 1.0 # fixed timestep + + # Initialize U and V + U = ones(N, N) + V = zeros(N, N) + + # Seed pattern in the center + center = N รท 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 + + # Store history for visualization (optional) + snapshots = [] + + for i in 1:tspan[2] + print("Running $i/$(tspan[2])\r") + + lap_U = laplacianA(U, N, p.dx) + lap_V = laplacianA(V, N, p.dx) + + UVV = U .* V .* V + dU = p.Du * lap_U .- UVV .+ p.F * (1 .- U) + dV = p.Dv * lap_V .+ UVV .- (p.F + p.k) .* V + + U .+= dU * dt + V .+= dV * dt + + if i % 100 == 0 # save every 100 steps + push!(snapshots, (copy(U), copy(V))) + end + end + return snapshots +end