adding a squiggle on the matrix now possible

pull/4/head
2211567 2025-06-10 12:07:13 +02:00
parent 7b761e7ff9
commit 2f498367e8
1 changed files with 29 additions and 2 deletions

View File

@ -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