Menu

Access latent heat of evaporation within a Python Script Unit Operation

2018-10-26
2018-10-29
  • Christian Hermsdorf

    Hello!

    How do I access the latent heat of evaporation or alternatively the specific enthalpy at boiling and dew point of a material stream from withtin a Python Script Unit Operation? I could not manage to find anything in this Forum or teh API documentation.

    BR
    Christian

     
  • Daniel Medeiros

    Daniel Medeiros - 2018-10-29
    import clr
    import System
    import DWSIM
    from System import *
    clr.AddReference("System.Core")
    clr.ImportExtensions(System.Linq)
    
    ms = Flowsheet.GetFlowsheetSimulationObject("MSTR-000")
    
    pp = ms.PropertyPackage
    pp.CurrentMaterialStream = ms
    
    # get mixture composition
    Vz = ms.Phases[0].Compounds.Values.Select(lambda x: x.MoleFraction).Cast[Double]().ToArray()
    # get temperature
    T = ms.Phases[0].Properties.temperature
    # get pressure
    P = ms.Phases[0].Properties.pressure
    
    # calculate mixture enthalpy as vapor
    hv = pp.DW_CalcEnthalpy(Vz, T, P, DWSIM.Thermodynamics.PropertyPackages.State.Vapor) 
    # calculate mixture enthalpy as liquid
    hl = pp.DW_CalcEnthalpy(Vz, T, P, DWSIM.Thermodynamics.PropertyPackages.State.Liquid) 
    
    # enthalpy of vaporization
    hvap = hv-hl 
    
    # kJ/kg
    print str(hvap) 
    
     
  • Christian Hermsdorf

    Hi Daniel,

    thank you very much for the quick response. Works like charm!

    However, I am still a bit confused regarding the function calls and assignments and I was wondering if you could explain a bit what is actually happening with the following code:

    pp = ms.PropertyPackage
    pp.CurrentMaterialStream = ms
    

    Translated this looks like the following to me:

    ms.PropertyPackage.CurrentMaterialStream = ms
    

    So, the object 'ms', which is an instance of Class 'MaterialStream' has the Property 'PropertyPackage', which again has the property 'CurrentMaterialStream', which is then set to 'ms', the "root" object itself. I would have assumed that the MaterialStream-object 'ms' should already now that its CurrentMaterialstream is 'itself'. Somehow I am missing something ...

    Another curiosity regards your temperature call

    T = ms.Phases[0].Properties.temperature
    

    because I would have used the following instead:

    T = fluid.GetPhase('Liquid1').Properties.temperature
    

    Can you explain what is the difference? And what is the '[0]' referring to behind 'Phases'?

    Best regards
    Christian

     
  • Daniel Medeiros

    Daniel Medeiros - 2018-10-29

    Hi Christian,

    For the first question:

    • Every object in the flowsheet has an associated property package, if not explicitly then the default one is selected. Although the object knows about the property package, the opposite is not true.
    • The property package can only make calculations using only one material stream at a time, and it can be associated with another "foreign" stream when you get a reference to it from your stream.
    • Before making a calculation, we must associate the material stream with the property package so it can get the properties from that stream. This is done through the CurrentMaterialStream property.

    For the second question:

     
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.