例外:@error:未找到解决方案 m.solve(disp= False)

Posted

技术标签:

【中文标题】例外:@error:未找到解决方案 m.solve(disp= False)【英文标题】:Exception: @error: Solution Not Found m.solve(disp= False) 【发布时间】:2021-12-27 16:13:54 【问题描述】:

美好的一天。 我在尝试模拟下面的 index-1 DAE 方程组时遇到了麻烦。经过几次调整程序后,我得到了所述的错误。有人可以提供一些帮助或建议吗?

import numpy as np
import math
from gekko import GEKKO
import matplotlib.pyplot as plt
%matplotlib inline

# define the model
m = GEKKO()    # create GEKKO model

#defining the simulation time
tm= np.linspace(0,20,100) # time points
m.time= tm
t=m.Param(value=tm)

# Defining the temperature in degrees kelvin.
T=(100+273);
# Pre-defining the kinetic parameters we have:
k_d=1.99*10**(6)*math.exp(-14842/T);
k_i=1.712*10**(15)*math.exp(-15924/T);
k_iterm=2.019*10**(1)*math.exp(-13810/T);
k_p=1.051*10**(7)*math.exp(-3577/T);
k_trM=2.31*10**(-6)*math.exp(-6377/T);
k_trS=1.8;
k_td=0.99*1.255*10**(9)*math.exp(-844/T);
k_tc=1.255*10**(9)*math.exp(-844/T);
M0=104.15; # molecular mass of Styrene monomer
f = 0.65;  # Initiator efficiency
dm=0.909; # density of styrene monomer
dp=1.000;  # density of Polystyrene
e=(dm-dp)/dp;

# create GEKKO variables
X  = m.Var(0.0) # monomer conversion
M  = m.Var(70.0) # monomer concentration
I  = m.Var(30.0) # initiator concentration
l_0 = m.Var(0.0)
l_1 = m.Var(0.0)
l_2 = m.Var(0.0)
u_0 = m.Var(0.0)
u_1 = m.Var(0.0)
u_2 = m.Var(0.0)
p = m.Var(0.0)
Mn = m.Var(0.0)
Mw = m.Var(0.0)
PDI = m.Var(0.0)
Mm=104.15;

# create GEKKO equations

m.Equation(p==(M/M0))
m.Equation((k_tc+k_p*e*p)*l_0==((2*f*k_d*I)))
m.Equation(((k_trM*M+k_tc*l_0+k_p*e*l_0*p)*l_1==2*f*k_d + k_p*M*l_0+k_trM*M*l_0))
m.Equation((k_i*l_0+k_p*e*p*l_0)*l_2==l_1+((2*k_p*M*l_1)))
m.Equation(u_1.dt()==k_trM*M*l_0+k_tc*l_0*l_1-k_p*u_1*l_0*e*p)
m.Equation((l_0**2)-u_0*l_0*e*k_p*p*u_0.dt()==k_trM*M*l_0+k_td*l_0**2+k_tc*0.5)
m.Equation(M.dt()==-k_p*p*l_0*(1+e*p))
m.Equation(u_2.dt()== k_trM*M*l_2+k_tc*l_0*l_2+k_tc*l_1**2-k_p*u_2*l_0*e*p)
m.Equation(I.dt()==-k_d*I-k_p*I*l_0*e*p)
m.Equation((M0+e*M)*X==(M0-M))
m.Equation((u_0+l_0)*Mn==Mm*(u_1+l_1))
m.Equation((u_1+l_1)*Mw==Mm*(u_2+l_2))
m.Equation(Mn*PDI==Mw)

# solve ODE
m.options.IMODE = (4)
m.solve(disp= False)
m = GEKKO(remote=False)

【问题讨论】:

【参考方案1】:

这是一个具有挑战性的聚苯乙烯生产动力学模型(高度非线性)。有多种策略可帮助您找到成功的解决方案,包括:

良好的初始猜测值,例如Mn=1e4(数均分子量)和Mw=1e5(重均分子量) 使用IMODE=1 作为稳态模拟求解,以找到动态模拟的良好起点。 检查 infeasibilities.txt 以查找可能对求解器造成问题的方程或约束。 将问题简化为只有基本变量和方程,然后逐渐添加方程,直到问题被初始化。 使用变量边界来限制搜索空间,例如 lb=0 的浓度。

这是一个脚本版本,可以帮助解决不可行的解决方案:

import numpy as np
import math
from gekko import GEKKO
import matplotlib.pyplot as plt

# define the model
m = GEKKO(remote=False)    # create GEKKO model

# Defining the temperature in degrees kelvin.
T=(100+273);
# Pre-defining the kinetic parameters we have:
k_d=1.99e6*math.exp(-14842/T);
k_i=1.712e15*math.exp(-15924/T);
k_iterm=2.019e1*math.exp(-13810/T);
k_p=1.051e7*math.exp(-3577/T);
k_trM=2.31e-6*math.exp(-6377/T);
k_trS=1.8;
k_td=0.99*1.255e9*math.exp(-844/T);
k_tc=1.255e9*math.exp(-844/T);
M0=104.15; # molecular mass of Styrene monomer
f = 0.65;  # Initiator efficiency
dm=0.909;  # density of styrene monomer
dp=1.000;  # density of Polystyrene
e=(dm-dp)/dp;

# create GEKKO variables
X  = m.Var(0.1,lb=0,name='x') # monomer conversion
M  = m.Var(70.0,lb=0,name='m') # monomer concentration
I  = m.Var(30.0,lb=0,name='i') # initiator concentration
l_0 = m.Var(1,name='l_0')
l_1 = m.Var(1,name='l_1')
l_2 = m.Var(1,name='l_2')
u_0 = m.Var(1,name='u_0')
u_1 = m.Var(1,name='u_1')
u_2 = m.Var(1,name='u_2')
p = m.Var(30,lb=0,name='p')
Mn = m.Var(1e4,lb=0,name='mn')
Mw = m.Var(1e5,lb=0,name='mw')
PDI = m.Var(2,lb=0,name='pdi')
Mm=104.15;

# create GEKKO equations
m.Equation(p==(M/M0))
m.Equation((k_tc+k_p*e*p)*l_0==((2*f*k_d*I)))
m.Equation(((k_trM*M+k_tc*l_0+k_p*e*l_0*p)*l_1==\
            2*f*k_d + k_p*M*l_0+k_trM*M*l_0))
m.Equation(M.dt()==-k_p*p*l_0*(1+e*p))
m.Equation(I.dt()==-k_d*I-k_p*I*l_0*e*p)
m.Equation((M0+e*M)*X==(M0-M))
m.Equation((u_0+l_0)*Mn==Mm*(u_1+l_1))
m.Equation((u_1+l_1)*Mw==Mm*(u_2+l_2))
m.Equation((k_i*l_0+k_p*e*p*l_0)*l_2==l_1+((2*k_p*M*l_1)))
m.Equation(u_1.dt()==k_trM*M*l_0+k_tc*l_0*l_1-k_p*u_1*l_0*e*p)
m.Equation(u_2.dt()==k_trM*M*l_2+k_tc*l_0*l_2+k_tc*l_1**2-k_p*u_2*l_0*e*p)
m.Equation((l_0**2)-u_0*l_0*e*k_p*p*u_0.dt()==\
           k_trM*M*l_0+k_td*l_0**2+k_tc*0.5)
m.Equation(Mn*PDI==Mw)

try:
    # solve steady-state first
    m.options.IMODE=1
    m.options.SOLVER=1
    m.solve(disp=True)

    # if steady-state is successful, try dynamic simulation
    m.options.IMODE=4
    #defining the simulation time
    tm= np.linspace(0,20,100) # time points
    m.time= tm
    m.solve(disp=True)
except:
    with open(m.path+'/infeasibilities.txt') as f:
        print(f.read())

它目前在运行文件夹中生成模型gk0_model.apm(使用m.open_folder() 打开)。

Model
Variables
    x = 0.0, >= 0
    m = 70.0, >= 0
    i = 30.0, >= 0
    l_0 = 0.01, >= 0
    l_1 = 0.01, >= 0
    l_2 = 0.01, >= 0
    u_0 = 0.01, >= 0
    u_1 = 0.01, >= 0
    u_2 = 0.01, >= 0
    p = 0.01, >= 0
    mn = 0.01, >= 0
    mw = 0.01, >= 0
    pdi = 0.01, >= 0
End Variables
Equations
    p=((m)/(104.15))
    (((130602226.78465715+((-65.43973468411447)*(p))))*(l_0))=((1.354673906019174e-11)*(i))
    ((((((8.683403179277924e-14)*(m))+((130602226.78465715)*(l_0)))+((((-65.43973468411447)*(l_0)))*(p))))*(l_1))=((1.354673906019174e-11+((((719.1179635616977)*(m)))*(l_0)))+((((8.683403179277924e-14)*(m)))*(l_0)))
    $m=((((((-719.1179635616977)*(p)))*(l_0)))*((1+((-0.09099999999999997)*(p)))))
    $i=(((-1.04205685078398e-11)*(i))-((((((((719.1179635616977)*(i)))*(l_0)))*(-0.09099999999999997)))*(p)))
    (((104.15+((-0.09099999999999997)*(m))))*(x))=(104.15-m)
    (((u_0+l_0))*(mn))=((104.15)*((u_1+l_1)))
    (((u_1+l_1))*(mw))=((104.15)*((u_2+l_2)))
    (((((0.0004928772821909254)*(l_0))+((((-65.43973468411447)*(p)))*(l_0))))*(l_2))=(l_1+((((1438.2359271233954)*(m)))*(l_1)))
    $u_1=((((((8.683403179277924e-14)*(m)))*(l_0))+((((130602226.78465715)*(l_0)))*(l_1)))-((((((((719.1179635616977)*(u_1)))*(l_0)))*(-0.09099999999999997)))*(p)))
    $u_2=(((((((8.683403179277924e-14)*(m)))*(l_2))+((((130602226.78465715)*(l_0)))*(l_2)))+((130602226.78465715)*(((l_1)^(2)))))-((((((((719.1179635616977)*(u_2)))*(l_0)))*(-0.09099999999999997)))*(p)))
    (((l_0)^(2))-((((((((((u_0)*(l_0)))*(-0.09099999999999997)))*(719.1179635616977)))*(p)))*($u_0)))=((((((8.683403179277924e-14)*(m)))*(l_0))+((129296204.51681055)*(((l_0)^(2)))))+65301113.392328575)
    mw=((mn)*(pdi))
End Equations

End Model

不可行性报告确定了两个无法用当前约束和方程求解的方程:

************************************************
***** POSSIBLE INFEASBILE EQUATIONS ************
************************************************
____________________________________________________________________________
EQ Number   Lower        Residual     Upper        Infeas.     Name
        11   0.0000E+00  -4.3117E-03   0.0000E+00   4.3117E-03  ss.Eqn(11): 0 = $u_2-((((((((8.683403179277924e-14)*(m)))*(l_2))+((((130602226.78465715)*(l_0)))*(l_2)))+((130602226.78465715)*(((l_1)^(2)))))-((((((((719.1179635616977)*(u_2)))*(l_0)))*(-0.09099999999999997)))*(p))))
 Variable   Lower        Value        Upper        $Value      Name
         2   0.0000E+00   0.0000E+00   1.2346E+20   0.0000E+00  ss.m
         4  -1.2346E+20   0.0000E+00   1.2346E+20   0.0000E+00  ss.l_0
         5  -1.2346E+20   5.7458E-06   1.2346E+20   0.0000E+00  ss.l_1
         6  -1.2346E+20  -2.6903E+02   1.2346E+20   0.0000E+00  ss.l_2
         9  -1.2346E+20   2.6903E+02   1.2346E+20   0.0000E+00  ss.u_2
        10   0.0000E+00   0.0000E+00   1.2346E+20   0.0000E+00  ss.p
         9  -1.2346E+20   2.6903E+02   1.2346E+20   0.0000E+00  ss.u_2
____________________________________________________________________________
EQ Number   Lower        Residual     Upper        Infeas.     Name
        12   0.0000E+00  -6.5301E+07   0.0000E+00   6.5301E+07  ss.Eqn(12): 0 = (((l_0)^(2))-((((((((((u_0)*(l_0)))*(-0.09099999999999997)))*(719.1179635616977)))*(p)))*($u_0)))-(((((((8.683403179277924e-14)*(m)))*(l_0))+((129296204.51681057)*(((l_0)^(2)))))+65301113.392328575))
 Variable   Lower        Value        Upper        $Value      Name
         2   0.0000E+00   0.0000E+00   1.2346E+20   0.0000E+00  ss.m
         4  -1.2346E+20   0.0000E+00   1.2346E+20   0.0000E+00  ss.l_0
         7  -1.2346E+20  -4.3536E+02   1.2346E+20   0.0000E+00  ss.u_0
        10   0.0000E+00   0.0000E+00   1.2346E+20   0.0000E+00  ss.p
         7  -1.2346E+20  -4.3536E+02   1.2346E+20   0.0000E+00  ss.u_0

【讨论】:

非常感谢@John Hedengren。我将按照建议处理方程式。

以上是关于例外:@error:未找到解决方案 m.solve(disp= False)的主要内容,如果未能解决你的问题,请参考以下文章

未解决的 SBT 依赖 com.google.errorprone#error_prone_annotations;[2.3.2,2.3.3]:未找到

如何解决 Jitpack “错误:未找到构建工件”?

npm 错误! 404 未找到 - 获取 https://registry.npmjs.org/error-ex

例外:CocoaPods 未安装或未处于有效状态

关于oracle存储过程select into 未找到数据问题

Oracle学习笔记