- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 233
 
Open
Description
reinit!(integrator, u0) currently allocates a lot due to reinit_dae. It would be great if these allocations could be reduced.
In this MWE, reinit_dae causes around 1000 allocations:
using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: D_nounits as D, t_nounits as t, setu, setp, getu
Ts = 0.1
@mtkmodel Pendulum begin
    @parameters begin
        g = 9.8
        L = 0.4
        K = 1.2
        m = 0.3
        τ = 0.0 # input
    end
    @variables begin
        θ(t) = 0.0 # state
        ω(t) = 0.0 # state
        y(t) # output
    end
    @equations begin
        D(θ)    ~ ω
        D(ω)    ~ -g/L*sin(θ) - K/m*ω + τ/m/L^2
        y       ~ θ * 180 / π
    end
end
@mtkbuild mtk_model = Pendulum()
prob = ODEProblem(mtk_model, nothing, (0.0, Ts))
integrator = OrdinaryDiffEq.init(prob, Tsit5(); dt=Ts, abstol=1e-8, reltol=1e-8, save_on=false, save_everystep=false)
@time reinit!(integrator; reinit_dae=true) # 1.05k allocs
@time reinit!(integrator; reinit_dae=false) # 6 allocs
From this discussion on discourse.
Metadata
Metadata
Assignees
Labels
No labels