Skip to content

handling of if-else-end conditionals in an MTK model (not requiring IfElse.jl) #1070

Open
@anandijain

Description

@anandijain

maybe related to #38, not sure.

if x < 0
    y = sqrt(-x)
else
    y = sqrt(x)
end

There are a collection of these type branches in my model (including nested). In MATLAB, the solver is able to handle this, but MTK currently cannot and modelingtoolkitize will fail.

I started working on a macro but I didn't know how to handle the original case all that well. It handles the very most basic case but nothing more.

function _toifelse(ex::Expr)
    args = map(_toifelse, ex.args)
    ex.head == :if ? Expr(:call, :ifelse, args...) : Expr(ex.head, args...)
end
_toifelse(x) = x
macro ifelse(ex)
    _toifelse(ex)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions