cadCAD-org/cadCAD

First PSUB at first timestep has a timestep equals to 0 instead of 1

Closed this issue · 4 comments

On cadCAD 0.4.23, calling the 'timestep' variable on the first PSUB (substep=1) and on the first timestep will get you 0 instead of the expected 1. If you move the PSUB to let's say the second position (substep=2), then you get the timestep as being 1.

This can introduce unexpected behaviour when changing the location of a given PSUB.

I've always found that a bit annoying but I like that it's consistent: timestep is just another state variable, so when you read it in substep=1 it will return its value before the substep's execution, so the previous timestep. I don't think it should be a special state variable that behaves differently, but maybe we could add a native helper function like this one to the package and advocate using it instead of directly accessing the timestep state variable?

I agree with @markusbkoch.

In dynamical systems, you start with state $x_0$ and the system procedes to evolve for $t>0$.

Marked as won't do