Menu

DWSIM inbuilt python functins

2021-08-12
2021-08-13
  • Amir Nematollahi

    Hello,
    I just create a stream with multiple components and I want to extract properties of stream via python scripting.
    i want to extract Temperature, Pressure, and component mole fractions. i used GetProp function as below:

    ims1.GetProp('Temperature', 'Overall', None, '','')
    ims1.GetProp('Pressure', 'Overall', None, '','')

    ims1.GetProp('fraction', 'Overall', Ethylene, '', 'mole')
    ims1.GetProp('fraction', 'Overall', Oxygen, '', 'mole')

    but an Error occurs:
    Error UO-01: CapeComputationException : Error in the application.
    at DWSIM.Thermodynamics.Streams.MaterialStream.ThrowCAPEException(Exception& ex, String name, String description, String interf, String moreinfo, String operation, String scope, Int32 code) in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM.Thermodynamics\Material Stream\MaterialStream.vb:line 6015
    at DWSIM.Thermodynamics.Streams.MaterialStream.GetProp(String property, String phase, Object compIds, String calcType, String basis) in C:\Users\Daniel\source\repos\DanWBR\dwsim6\DWSIM.Thermodynamics\Material Stream\MaterialStream.vb:line 3307

    what does it mean and what should I do?
    I also want to set new properties to the oms1 and I think I will encounter the same Error as well. also, I have not found any documentation of DWSIM inbuilt python function like above. where can I find the documentation( with explanation and example) too?
    Regards

     
  • Daniel Medeiros

    Daniel Medeiros - 2021-08-12

    Hi Amir,

    you can just do

    ims1.GetTemperature()
    ims1.GetPressure()
    ims1.GetOverallComposition()
    

    to set properties:

    oms1.SetTemperature(t)
    oms1.SetPressure(p)
    oms1.SetMassEnthalpy(h)
    oms1.SetOverallComposition(compvector)
    oms1.SetFlashSpec('PT')
    

    https://dwsim.inforside.com.br/api_help60/html/T_DWSIM_Thermodynamics_Streams_MaterialStream.htm

     
  • Amir Nematollahi

    Hello Daniel,
    Thanks for your guidance. I really appreciate your help! The documentations helps me a lot.
    I have some questions in my mind. I wonder how the Get.overallcompostion() return the value, because I did not see any explanation in source. For example:
    if I have 4 components with various mole fractions :
    Mole_Fractions = ims1.Getoverallcomposition()
    is Mole_Fractions a vector with 4 values? like [mole_frac1, mole_frac2, mole_frac3, mole_frac4]
    Also, How can i see the value of the variables in DWSIM python scripting?
    in python, I mostly use print(), is there any function like this in DWSIM?
    Regards

     
  • Daniel Medeiros

    Daniel Medeiros - 2021-08-13

    Hi Amir,

    Mole_Fractions is a vector. To see the variable values you can either put a breakpoint somewhere and run the script in the debug mode (third PLAY icon in the menubar) or do

    Flowsheet.WriteMessage(text)
    
     
    ❤️
    1
    • Amir Nematollahi

      So much appreciation Mr Medeiros! These tips help me out a lot.

       
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.