From 2f498367e8dfa7797a8a0192794fd38041cb0559 Mon Sep 17 00:00:00 2001 From: 2211567 Date: Tue, 10 Jun 2025 12:07:13 +0200 Subject: [PATCH] adding a squiggle on the matrix now possible --- src/solver.jl | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/solver.jl b/src/solver.jl index 3ddd9f0..16287aa 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -93,6 +93,33 @@ function circle_ic(N) return vec(u), vec(v) end +function squiggle_ic(N, Lx=400.0, Ly=400.0) + uplus = 0.534522 + vplus = 0.381802 + uminus = -uplus + + # Create coordinate grids + x = LinRange(0, Lx, N) + y = LinRange(0, Ly, N) + X = repeat(x', N, 1) # Transposed to align with meshgrid X + Y = repeat(y, 1, N) # Broadcasted to align with meshgrid Y + + # Squiggle pattern + cos_term = 0.05 * Lx .* sin.(10 * 2π .* Y ./ Ly .+ π * 0.3) + exp_term = exp.(-((Y .- Ly / 2) ./ (0.1 * Ly)) .^ 2) + width = 0.05 * Lx + Z = exp.(-((X .- Lx / 2 .+ cos_term .* exp_term) ./ width) .^ 2) + + + u = fill(uplus, N, N) + v = fill(vplus, N, N) + + # Apply squiggle + u[Z .> 0.8] .= uminus + + return vec(u), vec(v) +end + """ run_simulation(tspan::Tuple{Float64,Float64}, N::Int) @@ -117,12 +144,12 @@ function run_simulation(tspan::Tuple{Float64,Float64}, N::Int) #v0 = vec(0.4 .+ 0.01 .* rand(N, N)) # Or use this - u0, v0 = center_band_ic(N) + u0, v0 = squiggle_ic(N) y0 = vcat(vcat(u0, v0)) prob = ODEProblem(fhn!, y0, tspan, p) - sol = solve(prob, BS3(), saveat=3.0) # You can try `Rosenbrock23()` too + sol = solve(prob, BS3(), saveat=10.0) # You can try `Rosenbrock23()` too return sol end