Skip to content
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

PartialSimpleIdealGasMedium uses different offsets in BaseProperties and in specificInternalEnergy #1530

Closed
modelica-trac-importer opened this issue Jan 15, 2017 · 15 comments
Assignees
Labels
bug Critical/severe issue L: Media Issue addresses Modelica.Media P: high High priority issue

Comments

@modelica-trac-importer
Copy link

Reported by otter on 27 Jun 2014 15:53 UTC
When simulating the test model ModelicaTest.Media.TestAllProperties.SimpleAir an error occurs. The reason are different offsets in the medium model.

In PartialSimpleIdealGasMedium.BaseProperties:

h = specificEnthalpy_pTX(p,T, X);  // = cp_const*(T - T0);
u = h - R*T; // = (cp_const - R)*T - cp_const*T0

In PartialSimpleIdealGasMedium.specificInternalEnergy:

u = (cp_const - R)*(T - T0);  
    // = (cp_const - R)*T - cp_const*T0 - (cp_const - R)*T0

Therefore in the first case the offset is
cp_const*T0
and in the second case it is
(cp_const - R)*T0


Migrated-From: https://trac.modelica.org/Modelica/ticket/1530

@modelica-trac-importer modelica-trac-importer added bug Critical/severe issue L: Media Issue addresses Modelica.Media P: high High priority issue labels Jan 15, 2017
@modelica-trac-importer
Copy link
Author

Comment by hubertus on 27 Jun 2014 21:43 UTC
Fixed in rtunk in 7ed004c. Fixed by setting u = h - R*(T-T0) in BaseProperties.

@modelica-trac-importer
Copy link
Author

Comment by hubertus on 27 Jun 2014 21:52 UTC
fixed in MSL 3.2.1 branch as well, closing !#1350

@modelica-trac-importer
Copy link
Author

Changelog modified by hubertus on 27 Jun 2014 21:52 UTC
Fixed ticket #1350, wrong offset for u in PartialSimpleIdealGasMedium.

@modelica-trac-importer
Copy link
Author

Comment by hnaderan on 5 Dec 2014 14:56 UTC
The issued fix is incorrect. The correct thermodynamic definition of enthalpy is:

h = u + p*v

which for ideal gas becomes:

h = u + R*T

anonymousor if calculating internal energy from enthalpy:

u = h - R*T

So the previous equation in BaseProperties was correct and the one in specificInternalEnergyshould have been changed to:

u = cp_const*(T - T0) - R*T

This will set the internal energy and enthalpy references correctly. In its current form, both internal energy and enthalpy are zero at T0 which is wrong. Also for temperatures less than T0 the internal energy will become greater than enthalpy which is also wrong in thermodynamics.

@modelica-trac-importer
Copy link
Author

Comment by hubertus on 5 Dec 2014 15:09 UTC
I don't think that the comment above is necessarily correct, and it may all be about a different use of terms between "Ideal Gas" and "Perfect Gas". In the references that I know,

  • the enthalpy for an ideal gas can have an arbitrary reference temperature
  • the internal energy, relativ to that reference, can be greater than the enthalpy.

This is consistent with how the much more complex NASA ideal gas is implemented, where the reference temperature can be set to either 0 K or 25 Deg Celsius.

What the commenter writes may however be true for a "Perfect Gas", I'd have to check that, and typically a "Perfect Gas" has a constant cp. This is however not consistent in the literature and a model with a constant cp is also referred to as an "ideal gas".

@modelica-trac-importer
Copy link
Author

Comment by hnaderan on 6 Dec 2014 18:50 UTC
Enthalpy and internal energy are two thermodynamic properties. The definition of enthalpy is:

h = u + p * v

This holds true for every substance, ideal gas, perfect gas or whatever else. Since p and v are both always positive, at any thermodynamic state h is always greater than u regardless of the material model or the reference state.

I mentioned this as an obvious indication for the incorrect formula used in the specificInternalEnergy function. Actually, I stumbled on this bug in a more complex model which I was getting nonphysical results and by creating a simple benchmark test case, I became confident that internal energy calculation was wrong. Indeed reading the code revealed the incorrect formula. If you like, I can send the test case to you.

Further reading down the code, the formula for calculation of specificHelholtzEnergy function is also incorrect. It says:

f := (cp_const - R_gas)*(state.T - T0) - state.T*specificEntropy(state);

which the first term on the right hand side is inconsistent with the enthalpy reference taken at T0. I have changed my version of this function to:

f := specificInternalEnergy(state) - state.T*specificEntropy(state);

This way, the fix to the specificInternalEnergy does not have to be duplicated here.

H.Naderan

Assistant professor

Mechanical Engineering Department

Amirkabir University of Technology

@modelica-trac-importer
Copy link
Author

Comment by otter on 6 Jan 2015 18:56 UTC
Replying to [comment:4 hubertus]:

I don't think that the comment above is necessarily correct, and it may all be about a different use of terms between "Ideal Gas" and "Perfect Gas". In the references that I know,

  • the enthalpy for an ideal gas can have an arbitrary reference temperature
  • the internal energy, relativ to that reference, can be greater than the enthalpy.

This is consistent with how the much more complex NASA ideal gas is implemented, where the reference temperature can be set to either 0 K or 25 Deg Celsius.

What the commenter writes may however be true for a "Perfect Gas", I'd have to check that, and typically a "Perfect Gas" has a constant cp. This is however not consistent in the literature and a model with a constant cp is also referred to as an "ideal gas".

In SingleGasNasa the following equations are present:

h = IdealGases.Common.Functions.h_T(data,state.T);
u = IdealGases.Common.Functions.h_T(data,state.T) - data.R*state.T;

I did not find the place where the reference temperature is set. But independently of the reference point (assuming that the same "data" is used), then it follows from the above equations:

u = h - data.R*state.T
# h - state.p/d

Therefore, also for the NASA medium the equation h = u + p*v holds, as it should be.

My conclusion: The medium should be fixed as proposed in the ticket.

@modelica-trac-importer
Copy link
Author

Comment by hubertus on 6 Jan 2015 21:08 UTC
Fixed in trunk (cc794ba) and 3.2.1 maintenance (7eca10b).

@modelica-trac-importer
Copy link
Author

Comment by mwetter on 9 Jan 2015 16:56 UTC
cc794ba on the trunk and 7eca10b on maintenance/3.1/Modelica/Media/package.mo are wrong.

The line 6690 is currently

u := cp_const*(T - T0) - R*T;

but should be

u := cp_const*(state.T - T0) - R*state.T;

as there is no variable T in scope.

@modelica-trac-importer
Copy link
Author

Modified by mwetter on 9 Jan 2015 16:57 UTC

@modelica-trac-importer
Copy link
Author

Comment by hubertus on 13 Jan 2015 19:28 UTC
Fixed in 6c57d81 and bd61490.

@modelica-trac-importer
Copy link
Author

Comment by efredriksson on 19 Feb 2015 13:20 UTC
After commit cc794ba and 6c57d81 the test ModelicaTest.Media.TestAllProperties.SimpleAir is broken (Dymola and JModelic.org tested).

@modelica-trac-importer
Copy link
Author

Modified by beutlich on 4 Mar 2015 21:40 UTC

@modelica-trac-importer modelica-trac-importer changed the title PartialSimpleIdealGasMedium uses different offsets in BaseProperties and in specifidInternalEnergy PartialSimpleIdealGasMedium uses different offsets in BaseProperties and in specificInternalEnergy Jan 15, 2017
@modelica-trac-importer
Copy link
Author

Comment by hubertus on 22 Jun 2015 14:27 UTC
This has been fixed for some in trunk (8e5c1bf), and has only not been closed because it was not merged to the 3.2.1.

@modelica-trac-importer
Copy link
Author

Comment by hubertus on 22 Jun 2015 15:00 UTC
Fixed in the release branch 3.2.1 in 8400060

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Critical/severe issue L: Media Issue addresses Modelica.Media P: high High priority issue
Projects
None yet
Development

No branches or pull requests

2 participants