Closed agarny closed 1 year ago
Would it work if users were allowed to specify the type of the external variable? i.e., its different when its a constant computed outside the model versus turning a parameter into a state variable...
Would it work if users were allowed to specify the type of the external variable? i.e., its different when its a constant computed outside the model versus turning a parameter into a state variable...
Right now, external variables are just that: external. As far as the analyser (and generator) is concerned, it just knows that a variable is computed "outside", but has no idea whether it's actually a constant, an algebraic, a state, etc.
What you are suggesting goes quite a bit beyond what I originally had in mind when it comes to external variables. I can see cases where it could be useful to know the exact type of an external variable. For instance, if we knew that it was a constant then code generation could be optimised. However, if the user was to specify that an external variable is actually a state variable, there is no guarantee that it would rely on the same variable of integration. Also, what if our model is a pure algebraic model and an external variable is a state? What about the case where an external variable is "computed" using a lookup table containing some experimental data (e.g., to simulate an action potential clamp protocol)? What would be the type of that external variable?
Yeah, the more I think about typing an external variable, the more questions I have. Still, happy for us to discuss it at one of our next libCellML meetings.
Right now, when we analyse a model, we first determine the type of each variable and then check whether there are variables that should be marked as external which. This works fine even though a
VARIABLE_BASED_CONSTANT
equation may have to be requalified as anALGEBRAIC
equation in case it (in)directly depends on an external variable.Our current approach works fine, but it might become tedious once we have variables that need to be computed using a non-linear algebraic solver (e.g., KINSOL; see issue #882).
So, rather than handling external variables after determining the type of each variable, we probably ought to take them into account when actually determing the type of each variable. To do so will prevent us from having to requalify some equations, something that requires us to think about all possible cases where an equation might need to be requalified.