Search code examples
differential-equationspyomo

pyomo dae differential equation is applying ode "retroactively"


Sorry for the awkward choice of words in the title.

The thing is: I have a concrete model with a continuous set variable to express time and a very simple ode, where the derivative of a variable, let's call it dadt, equals the difference between two other variables b and c which are not dependent on a (in other words, a is just the difference of b and c multiplied by time). Unfortunately, it seems that the programm applies the intgration backwards meaning that if dadt is,say, 20 at time=20s, then a increases by 20*dadt between 0s and 20s. This way, the differential equation constraint does not really apply to time=0s and therefore renders the optimization useless. Is it intended this way or did I make a mistake along the way? I should add the Lagrange-Radau collocation. Is it the this kind of collocation's standard way of interpreting the direction of the integration, meaning "backward"?

Thanks.


Solution

  • You can use the next(i) and prev(i) methods on the ContinuousSet to get the neighboring points. For example,

    Model.A[model.t.next(i)] == Model.B[i]
    

    WARNING: This will only work consistently if you declare the constraint AFTER applying a discretization