IfLifting is an additional pass of mtkcompile():
mtkcompile(sys, additional_passes = list(IfLifting)). Every condition
f < 0 of an if-then-else (IfElse()) that depends on time, and every
abs, max, min, %%, %/%, floor and ceiling (rewritten as
if-then-else or stopped at their jumps), becomes a parameter
that holds the value of the condition, and a continuous event at the zero
crossings of f updates it. The integrator then never steps across a
discontinuity: it stops on it and continues on the other branch. Wrap an
expression in no_if_lift() to keep it as it is. This is an experimental
pass, as in ModelingToolkit.
Arguments
- sys
A system returned by
mtkcompile().
Examples
t <- t_nounits; D <- D_nounits
x <- Variable("x", t); y <- Variable("y", t)
sys <- System(list(D(x) ~ abs(y), y ~ sin(t)), t, name = "absy")
lifted <- mtkcompile(sys, additional_passes = list(IfLifting))
equations(lifted); parameters(lifted)
#> [[1]]
#> Derivative(x(t), t) ~ Piecewise((-y(t), Ne(cond#1, 0)), (y(t), True))
#>
#> [[1]]
#> cond#1
#>
sol <- solve(ODEProblem(lifted, list(x ~ 0), c(0, 5)))
sol(pi + 1, idxs = x) # 3 + cos(pi + 1)
#> [1] 2.459643