# Study SH model

Hi everyone,

I’m studying the Swift Hohenberg model with only the linear term of the potential. I see that a tutorial is proposed here (https://rveltz.github.io/BifurcationKit.jl/dev/tutorials2/#Snaking-in-the-2d-Swift-Hohenberg-equation-1) but for the moment I’m not interested to analyze the bifurcation, I wish only to solve the model. My idea was to use DifferentialEquations.jl to solve the equation, but maybe I’ve made some mistakes…
Here my definition of the problem:

``````function F_sh(u, p)
@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)
D = 10
#L1 = D*(I + Δ)^2

p = (l = -0.1 , L1 = D*(I + Δ)^2)

u0=rand(100,100)
tspan = (0.0,100.0)
prob = ODEProblem(F_sh,u0,tspan)

sol =  solve(prob, saveat =[0.2,25.0,50.0,99.0])
``````

(I used the Laplacian construction with sparse matrix used in the SH tutorial).
Thank you for the help, I’m very new to Julia, so every comment is welcome!

without running it, I’d say you have to pass a flat vector because of the sparse matrix:

``````prob = ODEProblem(F_sh,vec(u0),tspan)
``````

In passing, you’d better be using a `SplitProblem` I think

Thank you so much,
I tried using the flat vector vec(u0), but it return the same error as before:

MethodError: no method matching F_sh(::Matrix{Float64}, ::SciMLBase.NullParameters, ::Float64)
Closest candidates are:
F_sh(::Any, ::Any) at In:1

I tried also with SplitODEProblem, splicing F_sh into two functions sh1 and sh2, but still the error is returned:

MethodError: no method matching sh1(::Matrix{Float64}, ::SciMLBase.NullParameters, ::Float64)

Ah, try:

``````function F_sh(u, p, t = 0)
@unpack l, L1 = p
return -L1 * u .+ (l .* u)
end
``````

I’ve already tried this, but the error still remain.
I put here the complete notebook, maybe it could be useful.
Best regards

Francesco

At least it works but slowly because of bad solver options

``````
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)
D = 10
#L1 = D*(I + Δ)^2

p = (l = -0.1 , L1 = D*(I + Δ)^2)

u0=rand(Nx,Ny) |> vec
tspan = (0.0,1.0)
prob = ODEProblem(F_sh,u0,tspan, p)

sol =  solve(prob, Tsit5(), saveat =[0.2,25.0,50.0,99.0])
``````

I did the same, but still the error is returned… I really don’t understand what I’m missing.

``````using DifferentialEquations
using DiffEqOperators, Setfield, Parameters
using BifurcationKit, LinearAlgebra, Plots, SparseArrays
const BK = BifurcationKit

# helper function to plot solution
heatmapsol(x) = heatmap(reshape(x,Nx,Ny)',color=:viridis)

Nx = 151
Ny = 100
lx = 4*2pi
ly = 2*2pi/sqrt(3)

# we use DiffEqOperators to compute the Laplacian operator
function Laplacian2D(Nx, Ny, lx, ly)
hx = 2lx/Nx
hy = 2ly/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)) + kron(sparse(D2y * Qy), sparse(I, Nx, Nx))
return A, D2x
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)
D = 10
#L1 = D*(I + Δ)^2

p = (l= -0.1, L1 = D*(I + Δ)^2);

u0=rand(Nx,Ny) |> vec
tspan = (0.0,100.0)
prob = ODEProblem(F_sh,u0,tspan,p)
sol =  solve(prob, Tsit5(), saveat =[0.2,50.0,99.0])
``````

MethodError: no method matching Vector{Float64}(::SparseMatrixCSC{Float64, Int64})