DifferentialEquations and DAEProblem... strange error messages

OK – I used the DAE solver a year ago without problems. Now, it doesn’t work for me:

using Plots; pyplot();
using DifferentialEquations;
using Sundials;

If I run the example at DAE documentation, there are no problems – I get the expected solution.

Next, I try to solve a simple tank model with mass balance \frac{dm}{dt} = \dot{m}_i - \dot{m}_e (1) where the effluent by gravity is given by some Bernoulli model, \dot{m}_e = K\sqrt{\frac{h}{h^\varsigma}} (2), mass and volume are related by m=\rho V (3), and volume and level are related by V=Ah (4).
So… I have a DAE with 4 equations, (1)-(4) and 4 unknowns, w = [m,V,h,\dot{m}_e] – or w = [m,V,h,md_e] in Julia syntax. In addition, I have an input function \dot{m}_i(t) which I denote md_i(t), and four parameters \theta = [\rho, A, K, h^\varsigma] or p = [rho,A,K,h_s] in Julia.

In Julia, I specify the DAE model:

function tank(err,dw,w,p,t)
    rho,A,K,h_s = p
    m,V,h,md_e = w
    dm = dw[1]
    #
    err[1] = md_i(t) - md_e - dm
    err[2] = md_e - K*sqrt(h/h_s)
    err[3] = m-rho*V
    err[4] = V-A*h
end
#
diff_var = [true, false, false, false];
#
function md_i(t)
    return 1.5
end
;

Next, I define values:

# Parameters
rho = 1. # kg/L
A = 5.    # dm^2
K = 3.    # kg/s
h_s = 4. # dm
p = [rho,A,K,h_s]
# Initial values, etc.
h0 = 1.5 # dm
V0 = A*h0
m0 = rho*V0
md_e0 = K*sqrt(h0/h_s)
#
w0 = [m0,V0,h0,md_e0]
dw0 = [0.0,0.0,0.0,0.0]
tspan = (0.0,50.0)

and finally specify the problem and solve the model:

prob = DAEProblem(tank,dw0,w0,tspan,differential_vars=diff_var)
#
sol = solve(prob,IDA())

Instead of getting an expected solution, I get a lengthy error message…

MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:568
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:568
  iterate(!Matched::ExponentialBackOff) at error.jl:199
  ...

Stacktrace:
 [1] indexed_iterate(::Nothing, ::Int64) at .\tuple.jl:66
 [2] tank(::Array{Float64,1}, ::Array{Float64,1}, ::Array{...

I’m sure I’ve done a stupid mistake, but does anyone have a clue?

Dont now if this is important but where in prob is your p = [rho,A,K,h_s] ?

EDIT: Oh ist has to be prob = DAEProblem(tank,dw0,w0,tspan,p,differential_vars=diff_var)
https://github.com/JuliaDiffEq/DiffEqBase.jl/blob/master/src/problems/dae_problems.jl

1 Like

Oops. Ahem… You’re right. In the hurry, I just cloned the example on the documentation page, and didn’t think of that that example didn’t use the p argument…

If you update it should give you an error message about missing parameters as of last week. We found a way to throw a better message here :slight_smile:

1 Like

Does it work with Julia 1.2? I haven’t upgraded yet… :-o

It’s also v1.1

1 Like