DiffEqCallback and quadrature calculation with IntegratingCallback

a6a3uh
Tue, 27 Feb 2024 09:36:58 +0000
Modelling & Simulations

Hi! I’m trying to calculate some integral along the IVP for some ODE. In particular I’m calculating a running cost for my control system simulation (or value of some functional).

It looks like IntegratingCallback and IntegratingSumCallback are designed exactly for that purpose.

But due to lack of documentation I can’t figure out how to use that functionality.

Here my simplified example. It is very simple equation dx = 1 and running cost again simplest possible - just integral of 1 which should return the total time eventually:

      prob = ODEProblem((u,p,t)->[1.0], [0.0], (0.0,1.0), ())
      integrated = IntegrandValues(Float64, Vector{Float64})
      sol = solve(prob, Euler(),
                  callback = IntegratingCallback(
                      (u, t, integrator) -> 1.0, integrated),
                  dt=0.1)

or this one

      prob = ODEProblem((u,p,t)->[1.0], [0.0], (0.0,1.0), ())
      integrated = IntegrandValuesSum(0.)
      sol = solve(prob, Euler(),
                  callback = IntegratingSumCallback(
                      (u, t, integrator) -> 1.0, integrated),
                  dt=0.1)

Both produce errors complain wrong Fix1 usage. Interestingly if I provide nonempty scalar parameter to ODEProblem I get StackOverflow. And if the parameter is Vector then error is again about Fix1 usage.

Maybe I’m using it wrong or this is not intended for that particular usage at all? Why it even tries to do anything with parameter?

1 post - 1 participant