#5558 closed defect (invalid)
Specific Heat Issue
Reported by: | anonymous | Owned by: | Adeel Asghar |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | OMEdit | Version: | v1.13.2 |
Keywords: | SpecificHeat | Cc: |
Description
Hello, everyone!
I need to calculate the specific heat capacity of R134a on the transition to gas (quality = 1). Here it follows a simple code that represents what I`m trying to do (note that here I vary the pressure as sin wave with respect to time)
model Test
package Medium = AixLib.Media.Refrigerants.R134a.R134a_IIR_P1_395_T233_455_Horner;
parameter Modelica.SIunits.AbsolutePressure p = 1e5;
Modelica.SIunits.AbsolutePressure p_in;
Modelica.SIunits.SpecificHeatCapacityAtConstantPressure C_pv;
Modelica.SIunits.SpecificEnthalpy h_dew;
Medium.ThermodynamicState state_ph;
Medium.SaturationProperties sat_p;
equation
p_in = p*sin(time) + p;
C_pv = Medium.specificHeatCapacityCp(state_ph);
state_ph = Medium.setState_ph(p_in, h_dew);
sat_p = Medium.setSat_p(p_in);
h_dew = Medium.dewEnthalpy(sat_p);
end Test;
The problem is that for some instants of time the cp value is being calculated as if it were inside the two-phase region (which results in an nearly infinite value of about 1060). This would be right if I wanted its value inside the two-phase region (were temperature is constant for a fiven pressure and cp is almost infinite), but I want it to be calculated in the gas phase boundary for quality = 1, which should return me a value around 800 - 1000 J/kg.k
For most of the simulation time, the calculation is correct, but for a few instants the error listed above happens. What can I do to assure that cp is calculated only for quality = 1 at all instants of time?
Change History (10)
comment:1 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 5 years ago
Thanks for the reply!
I just used the setDewState function, but I continue to have similar issues.
model Test
package Medium = AixLib.Media.Refrigerants.R134a.R134a_IIR_P1_395_T233_455_Horner;
parameter Modelica.SIunits.AbsolutePressure p = 1e5;
Modelica.SIunits.AbsolutePressure p_in;
Modelica.SIunits.SpecificHeatCapacityAtConstantPressure C_pv;
Modelica.SIunits.SpecificEnthalpy h_dew;
Medium.ThermodynamicState state_ph;
Medium.SaturationProperties sat_p;
Medium.ThermodynamicState state_dew;
equation
p_in = p*sin(time) + p;
state_ph = Medium.setState_ph(p_in, h_dew);
sat_p = Medium.setSat_p(p_in);
h_dew = Medium.dewEnthalpy(sat_p);
state_dew = Medium.setDewState(sat_p,1);
C_pv = Medium.specificHeatCapacityCp(state_dew);
end Test;
comment:3 by , 5 years ago
I tried this model with the Modelica.Media R134a model:
model TestRefrigerant package Medium = Modelica.Media.R134a.R134a_ph; parameter Modelica.SIunits.AbsolutePressure p = 1e5; Modelica.SIunits.AbsolutePressure p_in; Modelica.SIunits.SpecificHeatCapacityAtConstantPressure C_pv; Modelica.SIunits.SpecificEnthalpy h_dew; Medium.SaturationProperties sat_p; Medium.ThermodynamicState state_dew; equation p_in = p*sin(time) + p; sat_p = Medium.setSat_p(p_in); h_dew = Medium.dewEnthalpy(sat_p); state_dew = Medium.setDewState(sat_p,1); C_pv = Medium.specificHeatCapacityCp(state_dew); end TestRefrigerant;
I had to remove the call to setState_ph
because (not surprisingly) it was causing lots of events.
The computed value is C_pv = 0
. However, I tried out the same model in Dymola and I got the same result.
The simulation results show that state_dew.phase = 0
, which is wrong, because the phase should be set to 1. In fact, the body of the setDewState
function is
redeclare function extends setDewState "Return the thermodynamic state on the dew line" algorithm if sat.psat < Modelica.Media.R134a.R134aData.data.FPCRIT then state.p := sat.psat; state.T := saturationTemperature(sat.psat); state.d := dewDensity(sat); state.h := dewEnthalpy(sat); else assert(sat.psat < Modelica.Media.R134a.R134aData.data.FPCRIT, "Function setDewState is only valid in two-phase regime"); end if; end setDewState;
so it doesn't bother to set state.phase = 1
. If it did, then the specificHeatCapacityCp
model would have produced the right result.
I will open a pull request on Modelica.Media to fix this.
comment:4 by , 5 years ago
I ran the test case in comment:2 with the latest nightly build of OpenModelica and it went just fine. If you are using 1.13.2, I guess you need some of the more recent fixes, please try the latest nightly build and the forthcoming 1.14.0 beta when it becomes available.
BTW, are you interested at including AixLib
in the OpenModelica testsuite? All models with annotation(experiment(StopTime))
are automatically selected and simulated; optionally the results compared to reference files, if you provide them. You get automated coverage reports such as this one and reports about regressions every time the library or the OpenModelica source code get changed.
We can do that just by adding one line with the GIT repo URL to a script, so for us it is not a big deal.
comment:5 by , 5 years ago
I have been wanting to ask this for a long time, casella: Is there a possible (easy?) way for an OM user to run the test suite locally, on their own code/package, to simulate and compare to reference results? That would possibly be a nice way to do (unit) testing.
comment:6 by , 5 years ago
@Christoph: it is possible, but currently, only if you have Linux.
The scripts that do the library testing are here:
https://github.com/OpenModelica/OpenModelicaLibraryTesting
You can see here what is done to run a test for a library:
https://github.com/OpenModelica/OpenModelicaLibraryTesting/blob/master/.CI/Jenkinsfile#L492
I think we would need some other way to do it, possibly from OMEdit, which should be easier to do by users.
comment:7 by , 5 years ago
oh my. thanks! that would be awesome, I miss the power+simplicity of pytest and friends with OM. :-/
comment:8 by , 5 years ago
Personally, I'm trying to have the OSMC servers do it for me :)
If the library is open source, we already have the infrastructure, and adding more test cases is just good for the compiler development.
For closed-source libraries and models, we plan to offer this paid service to OSMC members anytime soon. Would you be interested?
comment:9 by , 5 years ago
Yeah, that is a good way, but I typically prefer local testing because of the faster feedback/iteration.
Thanks for the offer, not at this point, what I am doing is tinkering/small models so far, and I was/am on the lookout for good Modelica testing solutions.
comment:10 by , 5 years ago
Then feel free to play around with our sources, and please report about the outcome and issues!
@anonymous, I understand you always want to compute the cp of saturated vapour. To do so reliably, you should use these functions
the second argument of
setDewState
tells the compiler you want to compute the properties on the one-phase side.BTW, this is not really an OpenModelica issue :)