I know the normal method. For example...
m.Equation(x.dt() == v)
But what about for something like a PFR? It is assumed steady state but the flowrates are dependent on the volume of the reactor (or length). I feel IMODE = 3 is the best if I wanted to optimize something in the model as well. I would think it would look something this.
m.Equation(Fa.dVr() == -ra)
Any help? Do I just treat dt() as dVr()? and declare m.time as the Volume array? Is it considered a dynamic system dependent on volume instead?
I just tested this. This below produced the same result from when I did it in odeint
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
k = .00384
Keq = 4
KB = .46
KW = 3.20
Ca_0 = 1.5
Cb_0 = 1.5
Cc_0 = 0
Cd_0 = 0
Fa_0 = 1 # mol/h
v = Fa_0/Ca_0
Fb_0 = Cb_0*v
Fc_0 = 0
Fd_0 = 0
m = GEKKO()
m.time = np.linspace(0, 4000, 1000)
Fa = m.Var(Fa_0)
Fb = m.Var(Fb_0)
Fc = m.Var(Fc_0)
Fd = m.Var(Fd_0)
Ca = m.Intermediate(Fa/v)
Cb = m.Intermediate(Fb/v)
Cc = m.Intermediate(Fc/v)
Cd = m.Intermediate(Fd/v)
r = m.Intermediate(k*(Ca*Cb - Cc*Cd/Keq)/\
( 1 + KB*Cb + KW*Cd))
m.Equation(Fa.dt() == -r)
m.Equation(Fb.dt() == -r)
m.Equation(Fc.dt() == r)
m.Equation(Fd.dt() == r)
m.options.IMODE = 4
m.solve(disp=False)
plt.plot(m.time, Fa.value, label='Fa')
plt.plot(m.time, Fb.value, label='Fb')
plt.plot(m.time, Fc.value, label='Fc')
plt.plot(m.time, Fd.value, label='Fd')
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
k = .00384
Keq = 4
KB = .46
KW = 3.20
Ca_0 = 1.5
Cb_0 = 1.5
Cc_0 = 0
Cd_0 = 0
Fa_0 = 1 # mol/h
v = Fa_0/Ca_0
Fb_0 = Cb_0*v
Fc_0 = 0
Fd_0 = 0
def f(F, W):
Fa, Fb, Fc, Fd = F
Ca, Cb, Cc, Cd = Fa/v, Fb/v, Fc/v, Fd/v
r = k*(Ca*Cb - Cc*Cd/Keq)/( 1 + KB*Cb + KW*Cd)
return -r, -r, r, r
W = np.linspace(0, 4000, 1000)
Fa1, Fb1, Fc1, Fd1 = odeint(f, [Fa_0, Fb_0, Fc_0, Fd_0], W).T
plt.plot(W, Fa1, label='Fa')
plt.plot(W, Fb1, label='Fb')
plt.plot(W, Fc1, label='Fc')
plt.plot(W, Fd1, label='Fd')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.