modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
451 stars 165 forks source link

MoistAir, error in massFraction_pTphi #4058

Open GaelEnee opened 1 year ago

GaelEnee commented 1 year ago

Hello,

I would like to report an error in Modelica.Media.Air.MoistAir.massFraction_pTphi.

I suggest the replacement of :

protected 
  constant Real k=0.621964713077499 "Ratio of molar masses";
  AbsolutePressure psat=saturationPressure(T) "Saturation pressure";
algorithm 
  X_steam := phi*k/(k*phi + p/psat - phi);

by :

protected 
  AbsolutePressure psat=saturationPressure(T) "Saturation pressure";
algorithm 
  X_steam := phi*k_mair/(p/psat - phi);

Thanks !

GaelEnee commented 1 year ago

Apologies,

After a double check, I would rather modify the expression in Modelica.Media.Air.ReferenceMoistAir.massFraction_pTphi :

X := {phi*k_mair/(p/pds - phi),1 - phi*k_mair/(p/pds - phi)};

by:

X := {k_mair/(k_mair + p/pds/phi -1),1 - k_mair/(k_mair + p/pds/phi -1)};

Sorry.

thorade commented 1 year ago

Adding a link to the two functions in question directly

Moist Air https://github.com/modelica/ModelicaStandardLibrary/blob/c15f9d3bea31db7a03904248c81c77f26bb6cb2f/Modelica/Media/Air/MoistAir.mo#L242-L257

ReferenceMoistAir https://github.com/modelica/ModelicaStandardLibrary/blob/c15f9d3bea31db7a03904248c81c77f26bb6cb2f/Modelica/Media/Air/ReferenceMoistAir.mo#L232-L245

thorade commented 1 year ago

@GaelEnee Could you help me understand this quicker by elaborating what is wrong and why? Is the corrected version taken from any reference? Do you possibly have a test model that demoes the wrong result?

GaelEnee commented 1 year ago

I'm sorry for the delay, here is the demonstration:

X_steam = m_steam / (m_steam + m_air) = n_steam ' M_H2O / (n_steam ' M_H2O + n_air ' M_air) = n_steam / (n_steam + n_air ' M_air/M_H2O) = (n_steam/n_sat) / (n_steam/n_sat + n_air/n_sat *' M_air/M_H2O)

with ideal gas assumption : pV = nRT = (p_steam/p_sat) / (p_steam/p_sat + p_air/p_sat *' M_air/M_H2O)

by definition : phi = p_steam/p_sat = phi / (phi + p_air/p_sat *' M_air/M_H2O)

with p_air = p - p_steam = phi / (phi + (p - p_steam)/p_sat ' M_air/M_H2O) = phi / (phi + (p - phi ' p_sat)/p_sat ' M_air/M_H2O) = phi / (phi + (p/p_sat - phi) ' M_air/M_H2O) = phi ' M_H2O/M_air / (phi ' M_H2O/M_air + p/p_sat - phi)

with k = M_H2O/M_air, X_steam = phi'k / (phi'k + p/p_sat - phi)

According to this, the function is MoistAir.massFraction_pTphi is correct and the one ReferenceMoistAir.massFraction_pTphi is to be corrected

mestinso commented 1 year ago

Just glancing quickly at this, there appears to be at least one wrong assumption that may be guiding you to a wrong conclusion: Note that ReferenceMoistAir doesn't follow ideal gas law (like the non-reference version).

GaelEnee commented 1 year ago

Hello, The presumed mistake I reported looks much like a scripting mistake to me. Getting rid of the ideal gas assumption for passing from the 4th to the 5th equation would involve the compressibility modulus Z of steam and air (pV=Z(p, T)nRT) and would result in a much more complicated final expression for X_steam. If you can get in touch with the original author of the function, he might provide an relevant advice about it.