Reputation: 997
I'm doing a dynamic simulation with 'IMODE=4'. I'm wondering if there is an option in the GEKKO to set the steady-state simulation result with 'IMODE=1' as an initial value of the dynamic simulation.
Or, do I need to run the steady-state simulation and set the values before running the dynamic simulation separately?
Upvotes: 4
Views: 390
Reputation: 14346
Gekko automatically uses the values from a steady-state simulations of IMODE
= 1 (SS) or 3 (RTO) to give initial values such as initial conditions for other modes. It is designed this way so that models can be initialized with a steady-state solution before starting dynamic modes such as simulation, moving horizon estimation, or model predictive control (see IMODE summary).
Here is a minimal example script that demonstrates the initialization.
from gekko import GEKKO
m = GEKKO()
p = m.Param(5)
x = m.Var(3)
m.Equation(p==x.dt()+x)
# steady-state (SS) simulation
m.options.IMODE=1
m.solve(disp=False)
print(x.value)
# dynamic simulation initialized with SS solution
m.time = [0,1,2,3,4]
p.value = 4
m.options.IMODE=4
m.solve(disp=False)
print(x.value)
There is a default value of x=3
. The steady state simulation solves with p=5
to give x=5
from the steady-state equation 5=0+x
. The dynamic simulation then solves the ODE with equation 4=dx/dt+x
to give a solution [5.0, 4.5, 4.25, 4.125, 4.0625]
at the requested time points of [0,1,2,3,4]
. Note that the initial condition is 5
, not 3
, because the dynamic simulation is initialized from the steady-state solution.
Upvotes: 2