Menu

Overriding Density Does Not Update MassFlow

ioncube
2023-11-20
2023-11-24
  • ioncube

    ioncube - 2023-11-20

    Firstly I updated density of NaOH + H2O mixture using this code [https://dwsim.org/wiki/index.php?title=Overriding_Calculated_Properties]

    densobj = matstr.GetPhase('OverallLiquid').Properties.density
    if (densobj <> None):
        currval = densobj
        # get massFrac of NaOH
        m_fr = matstr.GetPhase('OverallLiquid').Compounds['Sodium Hydroxide'].MassFraction * 100
        # update
        if (m_fr > 0):
            # write current value to the flowsheet (kg/m3)
            flowsheet.WriteMessage('current liquid mixture density value (kg/m3): ' + str(currval))
            # get temperature in Kelvin
            m_temp = matstr.GetTemperature()
            # calculate caustic density  
            # Multiple regression via Excel Anaysis toolkit
            propval = 1239.652 + 9.722088*m_fr - 0.68301*m_temp
            #flowsheet.WriteMessage('T(K): ' + str(m_temp))
            flowsheet.WriteMessage('updated liquid mixture density value (kg/m3): ' + str(propval))
        else:
            propval = currval
    else:
        propval = 0.0    
    

    It worked however massflow was not updated & was using previous density? As a workaround I manually added a script to update massflow & binded it to feed flow material stream

    stream = Flowsheet.GetFlowsheetSimulationObject('FNaOH')
    densobj = stream.GetPhase('OverallLiquid').Properties.density
    volobj = stream.GetVolumetricFlow() # value must be in m3/s
    calcmass = densobj * volobj
    stream.SetMassFlow(calcmass)
    Flowsheet.WriteMessage('FNaOH mass flow updated ' + str(densobj))
    

    Shouldn't it update massflow automatically or I suppose the sequence is different. After updatng massflow, molarflow however was OK

     

    Last edit: ioncube 2023-11-20
  • ioncube

    ioncube - 2023-11-20

    Lets ditch Override & use scripts dialogue . SetProp is not working here, It should be straight word as per API

    matstr = Flowsheet.GetFlowsheetSimulationObject('FNaOH')
    densobj = matstr.GetPhase('OverallLiquid').Properties.density
    Flowsheet.WriteMessage('Echo1 ' + str(densobj))
    m_fr = matstr.GetPhase('OverallLiquid').Compounds['Sodium Hydroxide'].MassFraction * 100
    m_temp = matstr.GetTemperature()
    propval = 1239.652 + 9.722088*m_fr - 0.68301*m_temp
    matstr.SetProp('density', 'OverallLiquid', '', '', '', propval)
    densobj = matstr.GetPhase('OverallLiquid').Properties.density
    Flowsheet.WriteMessage('Echo2 ' + str(densobj))
    

    Attached to event of solver start...
    Script throws no error but fails to accomplish density update

     

    Last edit: ioncube 2023-11-20
    • Daniel Medeiros

      Daniel Medeiros - 2023-11-21

      if you attach to solver start, it will be overriden by the actual calculation routine. The correct attachment would be to the material stream's calculation finished event.

       
      • ioncube

        ioncube - 2023-11-21

        I did that but no success, there is a problem with this line

        matstr.SetProp('density', 'OverallLiquid', '', '', '', propval)
        or
        matstr.SetProp('density', 'OverallLiquid', '', 'Mixture', '', propval)
        
         
  • Daniel Medeiros

    Daniel Medeiros - 2023-11-22

    Please give me a few days as I'm working on some personal stuff here.

    Thanks
    Daniel

     
    👍
    1
  • Daniel Medeiros

    Daniel Medeiros - 2023-11-24

    Your script should be linked to the material stream's post-calc event and do something like this:

    • If you have only one liquid phase, update the density for phaase 'Liquid1'. If you have two, update it for 'Liquid1' and 'Liquid2', then update it for 'OverallLiquid'. Some unit ops will see Liquid1 only and others will see OverallLiquid, it depends.
    matstr.GetPhase('Liquid1').Properties.density = 800 # kg/m3
    matstr.GetPhase('Liquid2').Properties.density = 1000 # kg/m3
    matstr.GetPhase('OverallLiquid').Properties.density = 900 # kg/m3
    

    Then you'll also need to update the Mixture density and volumetric flow accordingly, using the current value for mass flow.

    mf = matstr.GetMassFlow() # kg/s
    
    mixdens = 900 # kg/m3
    
    matstr.GetPhase('Mixture').Properties.density = 900
    matstr.SetVolumetricFlow(mf/mixdens) # m3/s
    
     
    👍
    1

    Last edit: Daniel Medeiros 2023-11-24
  • ioncube

    ioncube - 2023-11-24

    SOLVED

     
    🎉
    1

Log in to post a comment.