pyomo
pyomo copied to clipboard
pyomo.dae extract integrator timesteps from CasADi
Summary
When using the DAE simulator (e.g., CasADi), extract the adaptive time steps from cvodes or idas integrator.
Rationale
For stiff systems, it is increadibly helpful to get the adaptive timesteps. These timesteps can then be used to place collocation points.
Description
ChatGPT 5o suggested this is easy to do with CasADi 3.5 or later using the monitor option:
opts = {"t0": 0, "tf": 10, "monitor": ["t", "x"]}
F = ca.integrator("F", "idas", dae, opts)
res = F(x0=x0, z0=z0, p=p)
print(F.stats()["monitor"]["t"])
I have not tried this code sample yet, but I think it may just require a few modifications here: https://github.com/Pyomo/pyomo/blob/613f2ad1f64d8dead2ff15fd9c33a6b591b9bb93/pyomo/dae/simulator.py#L998
Additional information
@djlaky what do you think?