Menu

Calculate Bubble Temperature using DTL

2019-05-31
2019-05-31
  • Everton Colling

    Everton Colling - 2019-05-31

    I've just found out about the amazing DWSIM Standalone Thermodynamics Library (DTL) and have been playing with it through Python in Windows using pythonnet.

    I was able to reproduce the VB examples in Python without any problems.

    I'm trying to figure out how to solve a bubble Temperature problem using DTL. I have a mixture of hidrocarbons at a certain liquid phase composition and pressure and using this values I would like to calculate the vapor phase composition at equilibrium and the bubble Temperature.

    Is there a simple way to achieve this objective using DTL? I've noticed that there is a Phase Property called bubbleTemperature, but I haven't found out how to get to this object.

    This is what I got so far is:

    dtlc = Calculator()
    dtlc.Initialize() 
    
    prpp = dtlc.GetPropPackInstance('Peng-Robinson (PR)')
    
    T = Double(30 + 273.15) #K
    P = Double(10 * 101325) #Pa
    
    compounds = Array[String]([
            "Ethane",
            "Propane",
            "Isobutane",
            "N-butane"
    ])
    
    molefractions = Array[Double]([
            0.25,
            0.25,
            0.25,
            0.25
    ])
    
    mix = dtlc.CreateMaterialStream(compounds, molefractions)
    mix.SetPropertyPackage(prpp)
    

    I was able to create a Mixture, but I was not able to define the pressure and determine the bubble temperature.

    Best regards,

    Everton Colling

     

    Last edit: Everton Colling 2019-05-31
  • Everton Colling

    Everton Colling - 2019-05-31

    Thanks for the quick reply Daniel!

    I managed to calculate the bubble temperature correctly using the CalculateEquilibrium2 method, but not the vapor composition.
    The object returns an empty array for the vapor composition.

    I looked into the source code, but I do not have experience with VB, so my insights are limited. I suspect that there are some info that I am not specifing in the mix object. Something related to the expected phases (liquid, vapor) perhaps.

    This is the code snippet I used to calculate the bubble temperature:

    # General Options
    P = 10. * 101325 #Pa
    T = 30. + 273.15 #K
    
    comps = [
            "Ethane", 
            "Propane", 
            "Isobutane", 
            "N-butane"
    ]
    
    z0 = [
            0.25, 
            0.25,
            0.25, 
            0.25
    ]
    
    dtlc = Calculator()
    dtlc.Initialize()
    dtlc.SetDebugLevel(0)
    
    prpp = dtlc.GetPropPackInstance('Peng-Robinson (PR)')
    
    compsn = Array[String](comps)
    xn = Array[Double](z0)
    Pn = Double(P)
    Tn = Double(T)
    
    calctype = Interfaces.Enums.FlashCalculationType.PressureVaporFraction
    
    mix = dtlc.CreateMaterialStream(compsn, xn)
    prpp.set_CurrentMaterialStream(mix)
    
    res2 = prpp.CalculateEquilibrium2(calctype, Pn, 0.0, Tn)
    T2 = res2.CalculatedTemperature
    y2 = res2.get_VaporPhaseMoleAmounts()
    
    print("T =",round(T2,2),"K")
    print("x =",np.round(z0,3))
    print("y =",np.round(y2,3))
    

    This gives me:

    T = 289.69 K
    x = [0.25 0.25 0.25 0.25]
    y = [0. 0. 0. 0.]
    

    Best regards,

    Everton Colling

     

    Last edit: Everton Colling 2019-05-31
  • Daniel Medeiros

    Daniel Medeiros - 2019-05-31

    Try

    y2 = res2.get_VaporPhaseMoleFractions()
    

    Or use the Kvalues property to calculate the vapor composition.

     
  • Everton Colling

    Everton Colling - 2019-05-31

    The Kvalues approach worked like a charm!

    res2 = prpp.CalculateEquilibrium2(calctype, Pn, 0.0, Tn)
    T2 = res2.CalculatedTemperature
    y2 = []
    for i in range(ncomps):
        y2.append(res2.Kvalues[i]*z0[i])
    
    print("T =",round(T2,2),"K")
    print("x =",np.round(z0,3))
    print("y =",np.round(y2,3))
    

    Giving the expected result:

    T = 289.69 K
    x = [0.25 0.25 0.25 0.25]
    y = [0.66  0.197 0.081 0.062]
    

    Thanks for the support!

     
  • Daniel Medeiros

    Daniel Medeiros - 2019-05-31

    Great! get_VaporPhaseMoleAmounts is returning zeroes because it multiplies the vapor phase mole fraction (which is zero because it is a bubble point calculation) by the vapor phase composition... thankfully the Kvalues are there for you to calculate the y vector.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.