-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modelica.Media.R134a problem #3163
Comments
The bug-report lacks two parts:
|
True. Hopefully @wischhusen has enough information for an analysis. |
As for the desired result I believe that it can be computed as follows:
|
@casella Maybe you can help out here. Thanks. |
@beutlich this model was implemented by @wischhusen, if I am not mistaken, I hope he or someone from his company can have a look and decide whether this is a quick fix or not. I don't think I can manage to do this unless I take three days off to study the problem thoroughly, which is unlikely to happen for a while. |
I resolved the problem like this: redeclare function extends setState_dTX
"Set state for density and temperature (X not used since single substance)"
protected
Modelica.Media.Common.HelmholtzDerivs f "Helmholtz derivatives";
Modelica.SIunits.SpecificHeatCapacity R "Specific gas constant";
SaturationProperties sat "Saturation temperature and pressure";
Modelica.SIunits.Density dl "Liquid density";
Modelica.SIunits.Density dv "Vapor density";
algorithm
R := R134aData.R;
sat := setSat_T(T);
dl := bubbleDensity(sat);
dv := dewDensity(sat);
if d < dl and d > dv and T<R134aData.data.FTCRIT then
f := Common.HelmholtzDerivs(d=d, T=T, R=R, delta=0, tau=0, f=0, fdelta=0,
fdeltadelta=0, ftau=0, ftautau=0, fdeltatau=0);
state.p := saturationPressure(T);
state.h := 1/(dl/dv + 1)*(dewEnthalpy(sat) - bubbleEnthalpy(sat))
+ bubbleEnthalpy(sat);
state.phase := 2;
else
f := f_R134a(d=d, T=T);
state.p := d*R*T*f.delta*f.fdelta;
state.h := R*T*(f.tau*f.ftau + f.delta*f.fdelta);
state.phase := 1;
end if;
state.T := T;
state.d := d;
annotation (Documentation(revisions="<html>
<p>2019-12-17 Stefan Wischhusen: Two-phase calculation corrected.</p>
<p>2012-08-01 Stefan Wischhusen: Corrected passing-error of inputs.</p>
</html>",
info="<html>
<p>Although the medium package is explicit for pressure and specific enthalpy, this function may be used in order to calculate the thermodynamic state record used as input by many functions. It will calculate the missing states:</p>
<ul>
<li>pressure</li>
<li>specific enthalpy</li>
</ul>
<p>
Example:
</p>
<pre>
parameter Medium.Density d = 4;
parameter Medium.Temperature T = 298;
Medium.SpecficEntropy s;
<strong>equation</strong>
s = Medium.specificEntropy(setState_dTX(d, T, fill(0, Medium.nX)));
</pre>
</html>"));
end setState_dTX; @beutlich could you be so kind to create a pull request before I mess the whole thing again with my outdated fork? |
When I managed to mess up my fork too much I found
Obviously don't do it if your fork contains anything useful. |
Implemented last line. Result is somehow unchanged for gas fraction but never mind. Thanks @HansOlsson for the tipp on GIT but the reset process got stuck again. I will try again next year. redeclare function extends setState_dTX
"Set state for density and temperature (X not used since single substance)"
protected
Modelica.Media.Common.HelmholtzDerivs f "Helmholtz derivatives";
Modelica.SIunits.SpecificHeatCapacity R_s "Specific gas constant";
SaturationProperties sat "Saturation temperature and pressure";
Modelica.SIunits.Density dl "Liquid density";
Modelica.SIunits.Density dv "Vapor density";
algorithm
R_s := R134aData.data.R_s;
sat := setSat_T(T);
dl := bubbleDensity(sat);
dv := dewDensity(sat);
if d < dl and d > dv and T < R134aData.data.FTCRIT then
f := Modelica.Media.Common.HelmholtzDerivs(
d=d, T=T, R_s=R_s, delta=0, tau=0, f=0, fdelta=0,
fdeltadelta=0, ftau=0, ftautau=0, fdeltatau=0);
state.p := saturationPressure(T);
state.h := (dl*dv/d*(dewEnthalpy(sat) - bubbleEnthalpy(sat))
- dv*dewEnthalpy(sat) + dl*bubbleEnthalpy(sat))/(dl - dv);
state.phase := 2;
else
f := f_R134a(d=d, T=T);
state.p := d*R_s*T*f.delta*f.fdelta;
state.h := R_s*T*(f.tau*f.ftau + f.delta*f.fdelta);
state.phase := 1;
end if;
state.T := T;
state.d := d;
annotation (Documentation(revisions="<html>
<p>2012-08-01 Stefan Wischhusen: Corrected passing-error of inputs.</p>
</html>",
info="<html>
<p>Although the medium package is explicit for pressure and specific enthalpy, this function may be used in order to calculate the thermodynamic state record used as input by many functions. It will calculate the missing states:</p>
<ul>
<li>pressure</li>
<li>specific enthalpy</li>
</ul>
<p>
Example:
</p>
<pre>
parameter Medium.Density d = 4;
parameter Medium.Temperature T = 298;
Medium.SpecficEntropy s;
<strong>equation</strong>
s = Medium.specificEntropy(setState_dTX(d, T, fill(0, Medium.nX)));
</pre>
</html>"));
end setState_dTX; |
@wischhusen, I would suggest that we add some test to cross check that results with setState_ph and setState_dT are consistent. I can do that if you don't have time |
@casella many thanks! I am leaving for christmas vacation. I could do it from Jan. 6th. If you have time I would really appreciate! |
I'll see what I can do. |
Reported by CTG on 15 Oct 2019 07:56 UTC
Although it is not an OpenModelica related problem, I would like to share the following experience.
While checking my own media libraries compatible with Modelica.Media, I have found what I think is a bug in the Modelica.Media.R134a package. The calculation fail is shown in the attached file. Coming from a density between bubble and dew densities, it fails in the calculation of the vapor quality. The origin of the problem seems a bad implementation of the setState_dTX function: the calculation of Helmholtz derivatives and specific enthalpy is done before to check the phase fractions, as if the given density would be a one phase density. This produces a complete fail for calculations in the two phase region coming from density and temperature.
I do not know if this is a known bug, or I am wrong in some point.
ModelicaTests.mo
Originally reported at https://openmodelica.org/forum/default-topic/2801-modelica-media-r134a-problem#p9417
The text was updated successfully, but these errors were encountered: