Repository navigation
Generator: computeVariables() recomputes what computeRates() has just computed #1481
Description
Activity
avoiding duplication seems good. As long as its clear to users that
computeRates()should always be called before callingcomputeVariables()then that seems ok to me. I'd probably expect the name of the method to change, but not sure what to -computeNonStateVariables()orcomputeNonRateDependentVariables()doesn't sound good :)I do, however, like the idea of a single
computeVariables()method being generated that would give me a single call to update all variables in a model to correspond to the current state and also mean not having to come up with a new method name.avoiding duplication seems good. As long as its clear to users that
computeRates()should always be called before callingcomputeVariables()then that seems ok to me.That's the idea: mention in the API documentation that
computeRates()must be called before callingcomputeVariables().I'd probably expect the name of the method to change, but not sure what to -
computeNonStateVariables()orcomputeNonRateDependentVariables()doesn't sound good :)Yeah, I was also thinking of changing the name, but couldn't come up with a good alternative either. :/
I do, however, like the idea of a single
computeVariables()method being generated that would give me a single call to update all variables in a model to correspond to the current state and also mean not having to come up with a new method name.But that single
computeVariables()method would be the same as callingcomputeRates()and the 'new'computeVariables()? If so, it would mainly be a convenience method, right? If so, yes, it might be nice, but this would generate more code just for the sake of convenience. So, not sure I am too keen.But that single
computeVariables()method would be the same as callingcomputeRates()and the 'new'computeVariables()? If so, it would mainly be a convenience method, right? If so, yes, it might be nice, but this would generate more code just for the sake of convenience. So, not sure I am too keen.Convenience for users is important. Generating a little duplicated code makes no difference to the generator.
Does the computeVariables() funciton only update algebraic variables? Is that the right name for that function?
Does the computeVariables() funciton only update algebraic variables? Is that the right name for that function?
computeVariables()computes both algebraic and external variables, incl. through an NLA system.Convenience for users is important. Generating a little duplicated code makes no difference to the generator.
At this point, I would have
computeRates(),computeVariables(), and if really neededcomputeRatesAndVariables().computeRatesAndVariables()would just be a wrapper aroundcomputeRates()andcomputeVariables().Maybe for another issue? If so, feel free to create that issue @nickerso.
At this point, I would have
computeRates(),computeVariables(), and if really neededcomputeRatesAndVariables().Maybe this just becomes
computeUpdate()?At this point, I would have
computeRates(),computeVariables(), and if really neededcomputeRatesAndVariables().Maybe this just becomes
computeUpdate()?You mean
computeUpdate()instead ofcomputeRatesAndVariables()? I am not a fan ofcomputeUpdate(). Doesn't tell me what is updated. It could be anything. That's why we havecomputeRates()andcomputeVariables()in the first place. We know what we are computing.Maybe for another issue? If so, feel free to create that issue @nickerso.
But discussing how to best address this issue is what this issue is about, right?
computeRatesAndVariables()would just be a wrapper aroundcomputeRates()andcomputeVariables().I'm thinking there would be
computeRates()which is what a user would use with their integrator andcomputeVariables()would just have all the code in it to update all variables in the model to the current state.But as I mentioned before, as long as
computeVariables()has a relevant name and the documentation is clear on how the generated methods should be used, then that would be acceptable. I don't think its acceptable to have a method generated callcomputeVariables()when that is not what the method does.Maybe for another issue? If so, feel free to create that issue @nickerso.
But discussing how to best address this issue is what this issue is about, right?
Sure, of course!
computeRatesAndVariables()would just be a wrapper aroundcomputeRates()andcomputeVariables().I'm thinking there would be
computeRates()which is what a user would use with their integrator andcomputeVariables()would just have all the code in it to update all variables in the model to the current state.But as I mentioned before, as long as
computeVariables()has a relevant name and the documentation is clear on how the generated methods should be used, then that would be acceptable. I don't think its acceptable to have a method generated callcomputeVariables()when that is not what the method does.I believe the API documentation mentions what it is about. But, at this stage, I am happy to go with whatever. Just need to be told what.
In the meantime, I shall use PR #1482 in [lib]OpenCOR (together with PR #1473, PR #1475, and PR #1477).
Note: this assumes that PR #1473 has been merged in.
computeVariables()is to be computed every time a model is integrated, so that variables that depend on states are up to date. However, some variables may also depend on rates and rates themselves may depend on states. The bottom line is that, once a model has been integrated, we should call bothcomputeRates()andcomputeVariables().Now, the issue is that
computeVariables()recomputes most of whatcomputeRates()has just computed while it should only compute what wasn't computed bycomputeRates(). So, we end up computing the same thing twice for no good reason, i.e. waste of computing time.Example (
k0is a constant)computeRates()computesa,b,candd, withrates[0]computed befored:Yet
computeVariables()recomputes all four of them:Adding an unrelated equation,
r = cos(t), means thataandc(nowalgebraicVariables[1]andalgebraicVariables[2]) are no longer recomputed, butbanddstill are:Only
rneeds computing here.Proposal
computeVariables()requirescomputeRates()to have been executed first, at the same point.computeVariables()without the equations thatcomputeRates()computes, so that it only computes the variables thatcomputeRates()doesn't need (rin the second example).