SciML / SciMLExpectations.jl

Fast uncertainty quantification for scientific machine learning (SciML) and differential equations
https://docs.sciml.ai/SciMLExpectations/stable/
Other
66 stars 20 forks source link

Adding an additional Callback function #146

Closed lakshaya17 closed 7 months ago

lakshaya17 commented 9 months ago

Hey,

I am trying to add one or two more callback functions for a 3D model. I am considering the stopping condition to be x and y are equal to zero or all x, y ,z are equal to zero. For some reason, I am not able to get results. Should it be like the following code?

condition_1(u, t, integrator) = u[1]
cb_1 = ContinuousCallback(condition_1, terminate!)

condition_2(u, t, integrator) = u[2] 
cb_2 = ContinuousCallback(condition_2, terminate!)

# condition_3(u, t, integrator) = u[3]
# cb_3 = ContinuousCallback(condition_3, terminate!)

cb_p = CallbackSet(cb_1, cb_2)
# cb_p = CallbackSet(cb_1, cb_2, cb_3)

Also, what if I want to make all 6 states equal to zero? For example, when x = 0 then x_dot = 0.

In anticipation of your reply.

Regards

ChrisRackauckas commented 7 months ago

I am considering the stopping condition to be x and y are equal to zero or all x, y ,z are equal to zero.

Inside of the affect! function, just check that the other value is sufficiently close to zero. You only need one condition for that. What you wrote there is x or y or z is zero.