IntegrateODE Oddities

I have an experiment that uses IntegrateODE ...

Function DoKinetics(...)

        // initialize parameters from a panel input state
        ...

    IntegrateODE/M=1/U=100000/Q RxnAIP, kvalues, AIP

        return 0
end

Function RxnAIP(pw, tt, yw, dydt)
    wave pw, yw, dydt
    variable tt
   
    // extract parameters
    variable k1f, k1r, k2
    k1f = pw[0]; k1r = pw[1]; k2 = pw[2]
   
    variable dydt0 =  -(k1f*yw[0] - k1r*yw[1])
    variable dydt2 = k2*yw[1]
   
    dydt[0] = dydt0
    dydt[1] = -dydt0 -dydt2
    dydt[2] = dydt2
   
    return 0
end


I set the parameters via an external panel. All input controls on the panel are set to update only after mouse release, and all such updates result in a new call to DoKinetics(...). In most cases, the graph of the kinetic waves (AIP[][%A] ... AIP[][%P] update almost immediately. Some times though, when I change a parameter on the panel, I get the spinning black/white pie slice circle of death (MacOS 10.6.8, Igor 6.22A). This happens even when I change a parameter back to a previous value where the integration ran immediately. In other words, the instability case is unpredictable. I usually end up aborting (command-period) the IntegrateODE run. Thereafter, changing a different parameter sometimes "resets" the integration to happen again immediately. Every so often though, I just resolutely quit Igor and restart the experiment to get back an "instant integration" affect.

Any hints as to what might be happening? Any thoughts on how to fix the problem?


Sounds to me like you're failing to re-initialize something like the initial conditions in the first row of the result wave. There's nothing in IntegrateODE that remembers previous states, except for the contents of the result wave.

If you can't figure it out, send me an example.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
Sounds to me like you're failing to re-initialize something like the initial conditions in the first row of the result wave.


I set this consistently at the top of the DoKinetics(...) function ...

    AIP[][%A] = 1; AIP[][%I] = 0; AIP[][%P] = 0


johnweeks wrote:
... If you can't figure it out, send me an example.


Thanks. I'll play around with it a bit more and see what happens.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
johnweeks wrote:
... If you can't figure it out, send me an example.


The example is now posted as Kinetic Reaction Demo. I've still not been able to understand fully why it hangs sometimes.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Your result wave has four columns, but you're only using three of them. You are causing IntegrateODE to think that you have a system of four equations, but you set only three derivatives. My guess is that occasionally the fourth column has something other than zero, or the dydx wave occasionally has something other than zero in row 3. IntegrateODE does not pre-initialize the dydx wave.

I haven't tested this, but I would bet a nickel that it's the problem.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
Your result wave has four columns, but you're only using three of them. .... I haven't tested this, but I would bet a nickel that it's the problem.


Missed that one. A revision is posted. It appears no longer to hang indefinitely and only take longer in some possibly extreme cases of parameters.

Thanks!

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville