|
This is a fundamental issue with all large scale DAE (differential-algebraic-equation) [1] systems, regardless of modeling environment. DAEs are different from ODEs in that it's really difficult to design a solver that will reliably solve every single DAE out there -- numerically so many things can go wrong, so it is up to the modeler to write models in such a way as to promote algorithm convergence. For instance, even finding a set of consistent initial condition requires the solution of a typically nonconvex nonlinear system of equations, which in turn requires a good initial guess (where domain knowledge is needed -- arbitrary guesses may work but often don't). This is a "solved" problem in a sense that algorithms exist that do this, but anyone who's done numerical work know how hard it is to reliably find the solution of an arbitrary nonlinear system of equations -- there's a significant element of luck involved, even with heuristics. Formulating good models is an art. Good modelers know to avoid issues with numerical scaling (by changing units of measure, doing log or linear scaling, or simply avoiding computation of certain intermediate quantities) and avoidance of singularities (e.g. instead of x/y = z, a better and equivalent formulation is x = y * z because if y is ever 0 during iteration, one avoids div-by-0 errors). It gets even tougher with hybrid models that have discontinuities (switching behavior), because the integrator needs to do a reinitialization every time a switch is encountered. Most solvers do this well (the integrated system up to that point is usually a good initial guess for the NLE system), but not 100% of the time. When I was doing this stuff full-time, I've often thought of writing a linter that detected poor formulations and suggested improved ones -- sort of like a spell-checker for mathematical models. I never pursued it. These days I guess this can be done using a language server that can parse equations and generate ASTs. I'm no longer interested in these problems, but I do wonder if anyone has tried to do something like this. [1] DAEs take the following (implicit) form: f(ẋ, x, z, θ) = 0, x(0) = x₀ g(x, z, θ) = 0 where x = differential vars, z = algebraic vars, θ = constants. The form is very general and can be used to model any number of continuous dynamic systems. Hybrid systems can be modeled by introducing discrete variables into the mix. |