Spetrum method and DifferentialEquaitons

Hi,
I use Differentialequantions to solve the pde,

\left\{\begin{array}{l} \frac{\partial u}{\partial t}=\varepsilon \frac{\partial^{2} u}{\partial x^{2}}+u-u^{3}, \quad-1<x<1 \\ \left.u\right|_{x=\pm 1}=\pm 1 \\ \left.u\right|_{t=0}=0.53 x-0.47 \sin (1.5 \pi x) \end{array}\right.

the spartial discrete using spectrum method,but the result as not I want

using LinearAlgebra
using Plots
using OrdinaryDiffEq

function cheb(n)
    @assert n>0 "N should great than 1"
    
    x=cos.(π*(0:n)./n)
    c=vcat(2,ones(n-1),2).*(-1).^(0:n)
    X=repeat(x,1,n+1)
    ΔX=X-X'
    D=(c*(1 ./c)')./(ΔX+I)
    D-=diagm(sum(D,dims=2)[:])
    D,x
end

meshgrid(x,y)=repeat(x',length(x),1),repeat(y,1,length(y))

L=2;N=20
D,x=cheb(N);D=D./(L/2)
x=(L/2).*x;D2=D^2
#initial condition
u₀=@. 0.53x-0.47*sin(1.5π*x)
function allen_cahn(du,u,p,t,D2)
    ϵ=p
    du=ϵ*D2*u+u-u.^3.0
    du[1]=0.0;du[end]=0.0
    du
end
tspan=(0.0,100.0);ϵ=0.01
prob=ODEProblem((du,u,p,t)->allen_cahn(du,u,p,t,D2),u₀,tspan,ϵ)
sol=solve(prob,Tsit5();saveat=2,reltol=1e-8,abstol=1e-8);
surface(sol.t,x,sol[:,:],xlabel="t",ylabel="x",zlabel="u")

the u not integrate,how do I choose ode alg or something

You didn’t mutate the vector.

function allen_cahn(du,u,p,t,D2)
    ϵ=p
    du.=ϵ*D2*u+u-u.^3.0
    du[1]=0.0;du[end]=0.0
    nothing
end

is the easiest fix, but it’s still allocating of course.

Hi,ChrisRackauckas
result correct,thank