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
Solving a system of differential equations with one vector variable and one scalar variable packed into a ComponentVectorworks fine for medium system sizes but produces an error when the system size is made larger when no solver is specified in solve. I'm guessing that the default solver algorithm changes to a different solver when system size gets large enough, but that some of these solvers are not working properly with ComponentArrays. I wasn't sure whether to put this issue here or in the repo for ComponentArrays. Let me know if I should put it there instead.
Expected behavior
I expected no error to be raised when changing system size.
Minimal Reproducible Example 👇
Here is a (somewhat) minimal example that works/doesn't work depending on system size. The following code runs fine:
using DifferentialEquations
using ComponentArrays
functionode_fun!(du, u, p, t)
x = u.x
y = u.y
du.y = p.a -sum(bi*xi for (bi, xi) inzip(p.b, x))*y
@. du.x = (p.b*y - p.c)*x + p.d
returnnothingendfunctionrun_ode(u0, p, t_end)
ode_prob =ODEProblem{true}(ode_fun!, u0, (0.0, t_end), p)
ode_sol =solve(ode_prob; reltol =1e-6, abstol =1e-6)
end
S =151
b =0.9*[exp( -0.5*(zi)^2 ) for zi ∈range(-3, 3; length = S)]
p = (a =1.0, b = b, c =0.1, d =0.05)
u0 =ComponentVector(x =fill(p.d/p.c, S), y =1.0)
t_end =1e5
ode_sol =run_ode(u0, p, t_end)
However, changing the system size S produces an error:
S =501
b =0.9*[exp( -0.5*(zi)^2 ) for zi ∈range(-3, 3; length = S)]
p = (a =1.0, b = b, c =0.1, d =0.05)
u0 =ComponentVector(x =fill(p.d/p.c, S), y =1.0)
t_end =1e5
ode_sol =run_ode(u0, p, t_end)
The underlying issue here is that ComponentArrays seems to be incompatible with Krylov.jl. Probably the right thing to do is to add a specialization on ldiv!(B::Vector{Float64}, D::LinearAlgebra.Diagonal{Float64, ComponentVector{…}}, A::Vector{Float64}).
Note that the easy workaround is to just choose a method like FBDF(). The issue is that when it gets too large, it switches to FBDF(linsolve=KrylovJL_GMRES()) and it's the GMRES that's failing.
Describe the bug 🐞
Solving a system of differential equations with one vector variable and one scalar variable packed into a
ComponentVector
works fine for medium system sizes but produces an error when the system size is made larger when no solver is specified insolve
. I'm guessing that the default solver algorithm changes to a different solver when system size gets large enough, but that some of these solvers are not working properly withComponentArrays
. I wasn't sure whether to put this issue here or in the repo forComponentArrays
. Let me know if I should put it there instead.Expected behavior
I expected no error to be raised when changing system size.
Minimal Reproducible Example 👇
Here is a (somewhat) minimal example that works/doesn't work depending on system size. The following code runs fine:
However, changing the system size
S
produces an error:Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: