Does anyone know how to run a dynamic simulation in GEKKO Python (IMODE 7) until a certain variable takes on the desired value? For example, I have a differential equation and I need to do the calculation until the pressure is 1 bar. I understand how to make a calculation for 100 seconds, 200 seconds, etc., but I do not understand how to let it run until I have a variable of a specific desired value.
The code that I have is kind of large, so in principle this code that I want to modify:
I want to have it without a while statement because every while statement creates a new model that takes time. And I have much bigger code and this time makes a negative impact.
#Start calculation
pressure_final = 0
t_guess = 10
while pressure_final < 1:
m = GEKKO(remote = False) # Create GEKKO model
k = 0.1
P = m.Var(0.1)
#Time discretization
tf = t_guess
nt = int(tf/1) + 1
m.time = np.linspace(0,tf,nt)
#Left boundary pressure
m.Equation(P.dt() == k*P)
print("Start Pressurization")
m.options.IMODE = 7
m.solve(disp = False)
print("Finished pressurization")
t_guess = t_guess + 1
pressure_final = P[-1]
I will be very grateful for the answer!

