Skip to content

What does "variable was actually zero" internal error mean when using ifelse? #3897

@hersle

Description

@hersle

I am using ifelse in an ODE like this:

using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D

@variables x(t) # position
eqs = [D(D(x)) ~ ifelse(x < 5, 1, 0)] # accelerate for first 5 meters
ics = [x ~ 0, D(x) ~ 0]
@named sys = ODESystem(eqs, t; initialization_eqs = ics)
ssys = mtkcompile(sys)
prob = ODEProblem(ssys, [], (0.0, 10.0))
sol = solve(prob, Tsit5())

The call to mtkcompile(sys) warns

┌ Warning: Internal error: Variable x(t) was marked as being in Differential(t)(Differential(t)(x(t))) ~ ifelse(x(t) < 5, 1, 0), but was actually zero
└ @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/OViQH/src/structural_transformation/utils.jl:292

What does this mean? Should I worry about it?

The solution looks fine to me. Apologies if I am overlooking something trivial!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions