Hi everyone,
I’m trying to solving the Swift Hohenberg 2D model as a ODE problem, but it works only on a short time range and reducing the resolution of my grid.
I believe that the problem is not only an optimization problem, but what do you think about? Here’s my code:
using DifferentialEquations
using DiffEqOperators, Setfield, Parameters
using BifurcationKit, LinearAlgebra, Plots, SparseArrays
const BK = BifurcationKit
Nx = 128
Ny = 128
lx = 4pi
ly = 4pi
# we use DiffEqOperators to compute the Laplacian operator
function Laplacian2D(Nx, Ny, lx, ly)
hx = 2*lx/Nx
hy = 2*ly/Ny
D2x = CenteredDifference(2, 2, hx, Nx)
D2y = CenteredDifference(2, 2, hy, Ny)
Qx = Neumann0BC(hx)
Qy = Neumann0BC(hy)
A = kron(sparse(I, Ny, Ny), sparse(D2x * Qx)[1]) + kron(sparse(D2y * Qy)[1], sparse(I, Nx, Nx))
return A
end
function F_sh(u, p, t)
@unpack l , L1 = p
return L1 * u .+ (l .* u)
end
X = -lx .+ 2lx/(Nx) * collect(0:Nx-1)
Y = -ly .+ 2ly/(Ny) * collect(0:Ny-1)
# define parameters for the PDE
Δ = Laplacian2D(Nx, Ny, lx, ly)
L1 = (I + Δ)^2;
#l= -0.1
p = (l= -0.1, L1=L1)
u0= rand(Nx,Ny) |> vec
tspan = (0.0,100.0)
prob = ODEProblem(F_sh,u0,tspan,p)
sol =solve(prob, alg_hints=[:stiff],save_everystep=false, save_start=false)
And the error is returned:
[CVODES WARNING] CVode
Internal t = 0.0446594 and h = 3.61507e-021 are such that t + h = t on the next step. The solver will continue anyway.
[CVODES WARNING] CVode
The above warning has been issued mxhnil times and will not be issued again for this problem.
[CVODES ERROR] CVode
At t = 0.0446594 and h = 3.61829e-023, the corrector convergence test failed repeatedly or with |h| = hmin.
Thank you so much for the help, every comment is welcome!