DifferentialEquations.jl icon indicating copy to clipboard operation
DifferentialEquations.jl copied to clipboard

Possible broadcast overload when using ArrayPartition with DEDataMatrix and ODEProblems with Control

Open vnvasquez opened this issue 6 years ago • 1 comments

The problem I am having in my larger model is replicated in a toy example here, which throws the same errors in (1) creating the ODE problem and (2) solving it as are caused in the larger model:

using RecursiveArrayTools, DifferentialEquations
using LinearAlgebra

r0 = [1131.340, -2282.343]
v0 = [-5.64305 4.30333; 
    2.42879 3.76543]
m0 = [1.0]
μ = 300.0
s = 5.0
rv0 = ArrayPartition(r0,v0,m0)

mutable struct SimType{T} <: DEDataMatrix{T}
    x::ArrayPartition{T}
    f1::T
end

u0 = SimType(rv0, 0.0)
tspan = (0.0,10.0) 
params = [μ , s]

function fd(du, u, params, t)
    r = norm(u.x[1])
    ele1 = u.x[1]
    ele2 = u.x[2]
    ele3 = u.x[3]
    for i in 1:2
        du.x[1][i] = ele1[i] + u.f1
        for j in 1:2
            du.x[2][i,j] = -μ * ele2[i,j] / r^3
        end
    end
    du.x[3][1] = ele3[1] * 2 + s 
end

const tstop1 = [2.]

function condition1(u, t, integrator)
    t in tstop1
end

function effect1!(integrator)
    for c in full_cache(integrator)
        c.f1 = 10.0           
    end
end

save_positions = (true, true)
cb1 = DiscreteCallback(condition1, effect1!, save_positions=save_positions)

prob = ODEProblem(fd, u0, tspan, params)
const tstop = [2.]
sol = solve(prob, Vern8(), callback = cb1, tstops = tstop)

The error for creating the problem reads BoundsError: attempt to access (Base.OneTo(7),) at index [2] while the error for solving reads type Array has no field x

vnvasquez avatar May 20 '19 20:05 vnvasquez

Transferred to DiffEq since it seems to be a downstream issue with the similar overload.

ChrisRackauckas avatar May 21 '19 19:05 ChrisRackauckas