You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And document the generation of the sparsity pattern:
using OrdinaryDiffEq, RecursiveArrayTools, LinearAlgebra, Test
# Define the constants for the PDEconst α₂ =1.0const α₃ =1.0const β₁ =1.0const β₂ =1.0const β₃ =1.0const r₁ =1.0const r₂ =1.0const D =100.0const γ₁ =0.1const γ₂ =0.1const γ₃ =0.1const N =32const X =reshape([i for i in1:N for j in1:N],N,N)
const Y =reshape([j for i in1:N for j in1:N],N,N)
const α₁ =1.0.*(X.>=4*N/5)
const Mx =Tridiagonal([1.0for i in1:N-1],[-2.0for i in1:N],[1.0for i in1:N-1])
const My =copy(Mx)
Mx[2,1] =2.0
Mx[end-1,end] =2.0
My[1,2] =2.0
My[end,end-1] =2.0# Define the discretized PDE as an ODE functionfunctionf(du,u,p,t)
A =@view u[:,:,1]
B =@view u[:,:,2]
C =@view u[:,:,3]
dA =@view du[:,:,1]
dB =@view du[:,:,2]
dC =@view du[:,:,3]
mul!(MyA,My,A)
mul!(AMx,A,Mx)
@. DA = D*(MyA + AMx)
@. dA = DA + α₁ - β₁*A - r₁*A*B + r₂*C
@. dB = α₂ - β₂*B - r₁*A*B + r₂*C
@. dC = α₃ - β₃*C + r₁*A*B - r₂*C
endusing ModelingToolkit
# Define the initial condition as normal arrays@variables du[1:N,1:N,1:3] u[1:N,1:N,1:3] MyA[1:N,1:N] AMx[1:N,1:N] DA[1:N,1:N]
f(du,u,nothing,0.0)
J = ModelingToolkit.jacobian(vec(du),vec(u),simplify=false)
using SparseArrays
sJ =sparse(J)
Iy =SparseMatrixCSC(I,N,N)
Ix =SparseMatrixCSC(I,N,N)
fJ =ones(3,3)
Dz = [100000000]
A =kron(Dz,Iy,sparse(Mx)) +kron(Dz,sparse(My),Ix) +kron(fJ,Iy,Ix)
all(iszero.(sJ) .==iszero.(A))
The text was updated successfully, but these errors were encountered: