Menu

Python module with phase change

Alex
2025-04-11
2025-04-14
  • Alex

    Alex - 2025-04-11

    Hi all,

    I'm writing a simple python module, which would be able to process water steam + CO2 mixture. I want to change the enthalpy of the mixture so that the water is partially condensed at the outlet.

    I used a template to set up the outlet stream properties (pressure, enthalpy, molar fractions, flowrate) and then call DW_CalcEquilibrium function. As I understand, the vapor fraction in this case is set to 1, even if the actual enthalpy value is below the saturation value for water at the given partial pressure. As a result, the outlet stream is single phase, and the enthalpy value is being automatically adjusted so that it matches the saturation value.

    At the same time, if I click on the python module and run "Debug", the vapor fraction of the outlet stream would be set to approx. 0.9 (which I believe is correct). Further running "Recalculate" for the outlet stream only will compute the correct values for the outlet stream (two phase mixture).

    Could someone help me to understand why this is happening? And what is the proper way to specify the outlet stream properties, when phase change is present?

    Test example:

     
    • Daniel Medeiros

      Daniel Medeiros - 2025-04-11

      try this one:

       
      • Alex

        Alex - 2025-04-14

        Daniel, thank you for the quick response!

        Could you please explain, why you do not call the DW_CalcEquilibrium function, but instead only specify the flash type with SetFlashSpec?

        When I calculate the flowsheet from your file I see in the output panel that x2 equals 1.0. At the same time the pop-up table for the outlet stream shows that the stream is V + L, and the vapor fraction is 0.99957. It looks like the output for x2 value is incorrect.

        Another confusing thing is that I have the same results for different values of power (vapor fraction 0.99957 and temperature 95.4 degC. I tested the following values:
        power = -10000 / mweight # kJ/kg
        power = -15000 / mweight # kJ/kg
        power = -20000 / mweight # kJ/kg
        power = -25000 / mweight # kJ/kg

        When I use:
        power = -30000 / mweight # kJ/kg
        the outlet vapor fraction becomes 0.2624, while the x2 variable is still 1.0.

        Could it be a problem with my DWSim installation?

        Thank you again!

         
  • Alex

    Alex - 2025-04-14

    I added the following line to the script after the SetFlashSpec() function call:
    outlet.PropertyPackage.DW_CalcEquilibrium(PropertyPackages.FlashSpec.P, PropertyPackages.FlashSpec.H)

    I get an error:
    This error was raised during the calculation of a Unit Operation or Material Stream.
    System.Exception: Python Script error, line 27: Object reference not set to an instance of an object.
    at DWSIM.UnitOperations.UnitOperations.CustomUO.Calculate(Object args) in C:\Users\Daniel\source\repos\DanWBR\dwsim\DWSIM.UnitOperations\UnitOperations\PythonScriptUO.vb:line 301

     
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.