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.densityif(densobj<>None):currval=densobj# get massFrac of NaOHm_fr=matstr.GetPhase('OverallLiquid').Compounds['Sodium Hydroxide'].MassFraction*100# updateif(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 Kelvinm_temp=matstr.GetTemperature()# calculate caustic density # Multiple regression via Excel Anaysis toolkitpropval=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=currvalelse: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
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The density routine for mixtures use molar fractions for density calculations for mixtures. However I have found that mass fractions produce more proper results, close to reality. For instance ∑ [xi * ρi] leads to less values while ∑ [mi * ρi] produce much better result
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.
Firstly I updated density of NaOH + H2O mixture using this code [https://dwsim.org/wiki/index.php?title=Overriding_Calculated_Properties]
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
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
The call to your overriding routines is done after the mass flow is updated and equilibrium is calculated. https://github.com/DanWBR/dwsim/blob/windows/DWSIM.Thermodynamics/MaterialStream/MaterialStream.vb#L784
Lets ditch Override & use scripts dialogue . SetProp is not working here, It should be straight word as per API
Attached to event of solver start...
Script throws no error but fails to accomplish density update
Last edit: ioncube 2023-11-20
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.
I did that but no success, there is a problem with this line
The density routine for mixtures use molar fractions for density calculations for mixtures. However I have found that mass fractions produce more proper results, close to reality. For instance ∑ [xi * ρi] leads to less values while ∑ [mi * ρi] produce much better result
These lines https://github.com/DanWBR/dwsim/blob/554110f200ea055a29a872f216879744385efa31/DWSIM.Thermodynamics/PropertyPackages/PropertyPackage.vb#L5327C1-L5332C23
Can be configured (option for user) to use mass fraction.
Last edit: ioncube 2023-11-22
that is not the actual mixture density calculation routine, this is the one: https://github.com/DanWBR/dwsim/blob/554110f200ea055a29a872f216879744385efa31/DWSIM.Thermodynamics/PropertyPackages/PropertyPackage.vb#L7295
The Vx argument is the mass fractions vector.
Please give me a few days as I'm working on some personal stuff here.
Thanks
Daniel
Your script should be linked to the material stream's post-calc event and do something like this:
Then you'll also need to update the Mixture density and volumetric flow accordingly, using the current value for mass flow.
Last edit: Daniel Medeiros 2023-11-24
SOLVED