debug_system(sys) wraps the functions listed in functions in the
equations and observed equations of sys, so that an error, or a
nonfinite result when error_nonfinite = TRUE, stops with the symbolic
call and its numeric inputs, for example
Function sqrt(u1(t)) output non-finite value NaN with input u1(t) => -0.1.
"/" and "inv" wrap divisions (negative powers), "sqrt" square roots
and "^" other powers.
Usage
debug_system(
sys,
functions = c("log", "sqrt", "^", "/", "inv", "asin", "acos"),
error_nonfinite = TRUE
)Details
It also adds the parameter ASSERTION_LOG_VARIABLE, with value 1, so the
message of every failing assertion of the system is shown when the
right-hand side is evaluated. Assertions are given to System() as
assertions = list(list(condition, "message")); the generated right-hand
side becomes NaN while one fails, which makes the solver reject the
step.
Examples
t <- t_nounits; D <- D_nounits
u <- Variable("u", t)
sys <- mtkcompile(System(list(D(u) ~ -sqrt(u)), t, name = "sys"))
dsys <- debug_system(sys, functions = "sqrt")
prob <- ODEProblem(dsys, list(u ~ 1), c(0, 10))
try(solve(prob))
#> Error : Function sqrt(u(t)) output non-finite value NaN with input
#> u(t) => -0.0002650334