add function without ode and give GSParams into function
parent
1d3540bfbe
commit
3e283fb94e
|
|
@ -92,9 +92,9 @@ function grayscott!(du, u, p::GSParams, t=0)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run simulation
|
# 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
|
# 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
|
# Initial conditions: U = 1, V = 0 everywhere
|
||||||
U = ones(N, N)
|
U = ones(N, N)
|
||||||
|
|
@ -109,7 +109,45 @@ function run_simulationG(tspan::Tuple{Float64,Float64}, N::Int)
|
||||||
y0 = vcat(vec(U), vec(V))
|
y0 = vcat(vec(U), vec(V))
|
||||||
|
|
||||||
prob = ODEProblem(grayscott!, y0, tspan, p)
|
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
|
return sol
|
||||||
end
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue