Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event support in integrator class #3682

Open
7 of 12 tasks
jaeandersson opened this issue May 1, 2024 · 0 comments
Open
7 of 12 tasks

Event support in integrator class #3682

jaeandersson opened this issue May 1, 2024 · 0 comments
Assignees
Milestone

Comments

@jaeandersson
Copy link
Member

jaeandersson commented May 1, 2024

With the improving support for Modelica (#3670, #3671) and FMI (e.g. #3160), it becomes natural to model hybrid systems, i.e. systems with events dynamics. In order to simulate such systems in CasADi, the integrator class needs to be generalized.

Implementation steps:

  • Add a zero-crossing field to the DAE oracle function
  • Add an option in the integrator class corresponding to the maximum number of events allowed (e.g. 20). Memory will need to be allocated for each event. If the number of events is exceeded during integration, an error will be thrown
  • Add an option to the integrator class corresponding to a transition function for the state and guess for algebraic variables. When a zero crossing (from negative to positive) happens, the transition function will be called, updating the state and algebraic variables accordingly. If no function, assume continuous state trajectory. Event handling can still be useful, e.g. if there is a discontinuity in the ODE right-hand-side.
  • During integration, have the integrator class project at what time the next event will happen by linear extrapolation. That is, before the integration starts for a particular control/output interval, the value for each zero crossing function is calculated along with its time derivative. If a particular zero crossing function is negative and its time derivative is positive, we can get an estimate of then the event will occur. If any event is expected to happen before the end of the interval, adjust the end time to only integrate to that time.
  • If an "event step", iteratively find the event time using linear extrapolation (should converge much faster than bisection). Make sure that the no other zero-crossing happened before it (in which case the procedure needs to be repeated for that other zero-crossing) and that the output time wasn't reached before the event happened.
  • Even if no event, we should still check if an event occurred as the linear extrapolation might have missed it
  • Numeric forward sensitivity analysis support
  • Numeric adjoint sensitivity analysis support
  • Support for forward sparsity pattern propagation
  • Support for reverse sparsity pattern propagation
  • Symbolic forward sensitivity analysis support
  • Symbolic adjoint sensitivity analysis support
@jaeandersson jaeandersson self-assigned this May 1, 2024
jaeandersson added a commit that referenced this issue May 6, 2024
Only in signature, not yet implemented
jaeandersson added a commit that referenced this issue May 8, 2024
New signature can be generated using a Switch instance
jaeandersson added a commit that referenced this issue May 8, 2024
x -> ode in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
z -> alg in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
rx -> adj_x in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
rp -> adj_quad in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
rx0 -> adj_xf in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
uqf -> adj_u in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
rqf -> adj_p in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
rxf -> adj_x0 in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
jaeandersson added a commit that referenced this issue May 8, 2024
adj_p -> adj_p0 to avoid name conflict
jaeandersson added a commit that referenced this issue May 8, 2024
jaeandersson added a commit that referenced this issue May 8, 2024
x_prev -> ode in IntegratorMemory
jaeandersson added a commit that referenced this issue May 8, 2024
x_prev -> x in sparsity propagation
jaeandersson added a commit that referenced this issue May 8, 2024
jaeandersson added a commit that referenced this issue May 8, 2024
rz -> adj_z in IntegratorMemory
jaeandersson added a commit that referenced this issue May 8, 2024
Updated ImpulseB signature
jaeandersson added a commit that referenced this issue May 8, 2024
rp -> adj_q in IntegratorMemory
jaeandersson added a commit that referenced this issue May 8, 2024
rx -> adj_x in IntegratorMemory
jaeandersson added a commit that referenced this issue May 8, 2024
rz -> adj_alg in bquad_sp_forward
jaeandersson added a commit that referenced this issue May 8, 2024
jaeandersson added a commit that referenced this issue May 8, 2024
rz -> adj_z in bquad_sp_reverse
jaeandersson added a commit that referenced this issue May 8, 2024
jaeandersson added a commit that referenced this issue May 8, 2024
jaeandersson added a commit that referenced this issue May 9, 2024
Input/output signature event transition functions
jaeandersson added a commit that referenced this issue May 10, 2024
Helper function to create event transition functions
jaeandersson added a commit that referenced this issue May 10, 2024
The event handling can cause the stopping time to decrease to a smaller value than the
internal time reached by Sundials variable step size solver.
When this happens, simply do not enforce the stopping time
jaeandersson added a commit that referenced this issue May 12, 2024
jaeandersson added a commit that referenced this issue May 12, 2024
jaeandersson added a commit that referenced this issue May 12, 2024
jaeandersson added a commit that referenced this issue May 13, 2024
Ensures that e.g. zero crossing functions that are linear in t will converge in first iteration
jaeandersson added a commit that referenced this issue May 13, 2024
Falls back to bisection when linear prediction fails.
Also, code cleanup
jaeandersson added a commit that referenced this issue May 13, 2024
Does not seem to work - fails for bouncing ball example
jaeandersson added a commit that referenced this issue May 13, 2024
@jaeandersson jaeandersson added this to the Version 3.7 milestone May 13, 2024
jaeandersson added a commit that referenced this issue May 16, 2024
Old implementations failed to continue after events for breaking chain example
jaeandersson added a commit that referenced this issue May 16, 2024
Now seems to work well.
jaeandersson added a commit that referenced this issue May 16, 2024
jaeandersson added a commit that referenced this issue May 22, 2024
jaeandersson added a commit that referenced this issue May 22, 2024
jaeandersson added a commit that referenced this issue May 22, 2024
Will simplify the main integration algorithm a lot and also allow for other rootfinding algoriths
jaeandersson added a commit that referenced this issue May 22, 2024
Moving it to the generalized Integrator::advance
jaeandersson added a commit that referenced this issue May 22, 2024
advance now proceeds to intergrate until next output time or next event, whatever comes first
jaeandersson added a commit that referenced this issue May 22, 2024
Maximum number of events during the whole interval is the more natural option, which also corresponds to the amount of memory that needs to be allocated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant