【问题标题】:How do I get GEKKO chemical flowsheet mixer object to solve如何获得 GEKKO 化学流程图混合器对象来解决
【发布时间】:2022-10-18 09:59:07
【问题描述】:

我正在探索 Gekko 化学库和流程图实施。我定义了化合物丙烯、丙烷、丁烷和戊烷以及两种具有不同化合物分数和摩尔流速的物流。我想混合这些流并计算组合流的总摩尔流速和摩尔分数。

我得到的结果是: Mole fraction in blended stream is: [[0.25], [0.25], [0.25], [0.25]]。它似乎是出口流的初始化值。

我仔细阅读了这个 StackOverflow 链接 [这里] 1 没有成功。
示例代码在这里:

from gekko import GEKKO, chemical
import numpy as np

m = GEKKO()    #instantiate GEKKO object
f = chemical.Flowsheet(m,stream_level=0)  #instantiate flowsheet object
c = chemical.Properties(m)
c.compound('propylene')    #define compound 1
c.compound('propane')      #define compound 2
c.compound('butane')       #define compound 3
c.compound('pentane')      #define compound 4

s1=f.stream(fixed=True)    #define stream 1
s1.x=np.array([0.5,0.3,0.1,0.1])     #specify mole fraction of compound 1-4 for stream1
s1.ndot=10                 #specify molar flow rate of stream 1

s2=f.stream(fixed=True)    
s2.x=np.array([0.3,0.3,0.2,0.2])     #specify mole fraction of compound 1-4 for stream2
s2.ndot=20                 #specify molar flow rate of stream 2

outlet=f.stream(fixed=False) #define outlet stream that should be solved

mx = f.mixer(ni=2)        #mixer object with two inlet
#mx.inlet[0]=s1
#mx.inlet[1]=s2
f.connect(mx.inlet[0],s1)  #assign stream 1 to mixer inlet 1
f.connect(mx.inlet[1],s2)  #assign stream 2 to mixer inlet 2


mx.outlet=outlet  #connect mixer outlet to outlet stream obj
m.options.SOLVER=1
m.solve()

print('Mole fractions in blended stream is:',  mx.outlet.x)

【问题讨论】:

    标签: python gekko


    【解决方案1】:

    使用以下命令初始化入口流的每个 x[i] 组件:

    inlet1 = [0.5,0.3,0.1,0.1]
    inlet2 = [0.3,0.3,0.2,0.2] 
    for i in range(4):
        s1.x[i].value = inlet1[i]
        s2.x[i].value = inlet2[i]
    

    使用连接函数左侧的stream 对象。连接函数将对象保留在左侧(第一个参数)并删除第二个对象引用(例如f.connect(keep,remove))。出口流也需要一个连接:

    f.connect(outlet,mx.outlet)
    

    这是一个完整的脚本:

    from gekko import GEKKO, chemical
    import numpy as np
    
    m = GEKKO()    #instantiate GEKKO object
    f = chemical.Flowsheet(m,stream_level=0)  #instantiate flowsheet object
    c = chemical.Properties(m)
    c.compound('propylene')    #define compound 1
    c.compound('propane')      #define compound 2
    c.compound('butane')       #define compound 3
    c.compound('pentane')      #define compound 4
    
    s1=f.stream(fixed=True)    #define stream 1
    inlet1 = [0.5,0.3,0.1,0.1]     #specify mole fraction of compound 1-4 for stream1
    s1.ndot=10                 #specify molar flow rate of stream 1
    
    s2=f.stream(fixed=True)    
    inlet2 = [0.3,0.3,0.2,0.2]     #specify mole fraction of compound 1-4 for stream2
    s2.ndot=20                 #specify molar flow rate of stream 2
    
    for i in range(4):
        s1.x[i].value = inlet1[i]
        s2.x[i].value = inlet2[i]
    
    outlet=f.stream(fixed=False) #define outlet stream that should be solved
    
    mx = f.mixer(ni=2)        #mixer object with two inlet
    #mx.inlet[0]=s1
    #mx.inlet[1]=s2
    f.connect(s1,mx.inlet[0])  #assign stream 1 to mixer inlet 1
    f.connect(s2,mx.inlet[1])  #assign stream 2 to mixer inlet 2
    f.connect(outlet,mx.outlet)
    #mx.outlet=outlet  #connect mixer outlet to outlet stream obj
    m.options.SOLVER=1
    m.solve()
    
    print('Mole fractions in blended stream is:',  outlet.x)
    # Open run folder to see more detail from model and results
    # m.open_folder()
    

    这给出了混合解决方案:

     ----------------------------------------------
     Steady State Optimization with APOPT Solver
     ----------------------------------------------
     
     Iter    Objective  Convergence
        0  7.40741E-20  1.11111E+00
        1  1.08350E-35  1.15741E-01
        2  1.08350E-35  1.15741E-01
     Successful solution
     
     ---------------------------------------------------
     Solver         :  APOPT (v1.0)
     Solution time  :   1.279999999678694E-002 sec
     Objective      :   0.000000000000000E+000
     Successful solution
     ---------------------------------------------------
     
    Mole fractions in blended stream is: [[0.4], [0.3], [0.15], [0.15]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2017-08-13
      • 2016-03-21
      • 1970-01-01
      相关资源
      最近更新 更多