NREL / EnergyPlus

EnergyPlus™ is a whole building energy simulation program that engineers, architects, and researchers use to model both energy consumption and water use in buildings.
https://energyplus.net
Other
1.05k stars 379 forks source link

Expand Functional API Capabilties #8047

Open bonnema opened 4 years ago

bonnema commented 4 years ago

Issue overview

Expand the capabilities of the glycol class in the functional API.

  1. Add capability to calculate enthalpy based on temperature and pressure
  2. Add capability to calculate temperature based on enthalpy and pressure,

Details

https://nrel.github.io/EnergyPlus/api/python/func.html

Checklist

mitchute commented 4 years ago

@bonnema E+ fluid property routines aren't too fancy, so I don't believe we can consider pressure at this point. Regardless, this seems like it should be straightforward to implement.

Of course, there's also this problem:

https://github.com/NREL/EnergyPlus/blob/14e6c4e417aac46197739e6a26df07599230338c/src/EnergyPlus/api/func.py#L15-L19

@Myoldmopar will have suggestions on how we could (eventually) tackle adding the other fluids, but I think this could be handled easy enough.

bonnema commented 4 years ago

@mitchute, this may be exactly what you're proposing, but could this be handled in two parts?

  1. Add the methods just for water
  2. Extend the methods for other fluids if/when they're added?

I am currently using water.

mitchute commented 4 years ago

Yeah, that's what I'm proposing. Adding the methods for computing enthalpy and temperature within E+, and then exposing those methods to the API will be simple enough. Expanding the API to handle other fluids is going to take more work which could potentially affect the API design.

mitchute commented 4 years ago

OK, so what I thought would be a simple addition has sent me down the rabbit hole of validating E+ properties. Since we're interested in computing enthalpy, I'll start with specific heat for propylene glycol.

EnergyPlus Cp Error - Compared to CoolProp [1] [2]

Concentration from 0.1-0.6; Temperature from 0-100 C

0.1 0.2 0.3 0.4 0.5 0.6
0 -0.42% -0.18% -0.25% -0.15% 0.05% 0.01%
10 -0.21% -0.13% -0.26% -0.14% 0.04% 0.00%
20 -0.03% -0.09% -0.23% -0.13% 0.05% -0.04%
30 0.07% -0.10% -0.23% -0.10% 0.04% -0.08%
40 0.14% -0.08% -0.19% -0.08% 0.06% -0.11%
50 0.19% -0.05% -0.17% -0.04% 0.08% -0.14%
60 0.21% -0.03% -0.11% 0.00% 0.07% -0.16%
70 0.22% 0.01% -0.06% 0.05% 0.09% -0.18%
80 0.24% 0.06% 0.02% 0.11% 0.09% -0.19%
90 0.26% 0.13% 0.09% 0.17% 0.11% -0.19%
100 0.31% 0.20% 0.21% 0.24% 0.13% -0.15%

OK, that actually looks pretty good. So theoretically, since:

we should be able to compute enthalpy values from the specific heat and temperature. CoolProp is a pretty robust library that's been validated pretty heavily and is used all over the place, so I'm pretty confident in the results it produces.

Comparing Delta h, (with enthalpy in E+ being computed as cp * T) against CoolProp for Temperatures of 0-100 C and concentrations from 0.1-0.6, we get some pretty significant errors.

C Max Error % Ave Error %
0.1 3.91 2.54
0.2 6.21 4.20
0.3 7.38 6.94
0.4 10.00 9.35
0.5 13.18 11.96
0.6 15.97 14.56

However, if we do some actual numerical integration of Cp(t) dt with dt = 10C, the error for C=0.1 goes from 3.9% & 2.5% down to 0.5% and 0.4%. So, it looks like this is going to need a more involved solution which integrates the glycol specific heat function. I haven't checked this for the other concentrations, but this seems like the right path forward.

Or would it be better to just add the enthalpy data from a proper numerically integrated solution to FluidProperties.cc? That way we can avoid hitting the GetSpecificHeatGlycol function a bunch of times for each call to GetEnthalpyGlycol?

bonnema commented 4 years ago

@mitchute here are results from EES if you want another data comparison point: cp.xlsx

mitchute commented 4 years ago

@bonnema just confirming -- the data was for Propylene Glycol?

bonnema commented 4 years ago

@mitchute yes. The EES call was: cp=specheat(PG,T=T,C=C)

mitchute commented 4 years ago

@bonnema can you upload the Ethylene Glycol results from EES sometime?

bonnema commented 4 years ago

@bonnema can you upload the Ethylene Glycol results from EES sometime?

@mitchute please find them here. The EES equation this time was: cp=specheat(EG,T=T,C=C). I'm sure you figured this out, but I should have mentioned that the units are kJ/kg-K.

mitchute commented 4 years ago

Well, this has been an interesting adventure. Even after integrating the EnergyPlus cp values wrt temperature using the scipy interpolate and integration functions, the Delta h values computed are pretty terrible when compare to CoolProp.

EnergyPlus Propylene Glycol

C [-] Max Abs Error [%] Ave Abs Error [%]
0.1 0.35 0.19
0.2 6.77 3.30
0.3 6.21 4.54
0.4 7.81 5.97
0.5 9.74 7.52
0.6 11.75 9.00

EnergyPlus Ethylene Gycol

C [-] Max Abs Error [%] Ave Abs Error [%]
0.1 30.83 24.06
0.2 35.17 28.19
0.3 7.41 5.65
0.4 9.40 6.63
0.5 11.53 7.58
0.6 13.92 8.87

Just for comparison, I compared the EES and ASHRAE data by taking the cp values, integrating wrt temperature, and then comparing to CoolProp as was done with the EnergyPlus cp values.

EES Propylene Glycol

C [-] Max Abs Error [%] Ave Abs Error [%]
0.1 3.49 1.4
0.2 6.5 3.18
0.3 10.07 5.74
0.4 14.78 9.23
0.5 20.87 13.65
0.6 28.2 18.9

EES Ethylene Glycol

C [-] Max Abs Error [%] Ave Abs Error [%]
0.1 4.04 2.53
0.2 8.55 5.52
0.3 14.29 9.43
0.4 21.42 14.22
0.5 29.83 19.75
0.6 39.73 26.42

ASHRAE Propylene Glycol

C [-] Max Abs Error [%] Ave Abs Error [%]
0.1 0.30 0.20
0.2 0.16 0.07
0.3 0.25 0.12
0.4 0.20 0.09
0.5 0.12 0.08
0.6 0.19 0.14

ASHRAE Ethylene Glycol

C [-] Max Abs Error [%] Ave Abs Error [%]
0.1 2.30 1.05
0.2 2.30 1.53
0.3 1.96 1.72
0.4 1.83 1.66
0.5 1.96 1.66
0.6 1.98 1.53

EES is way off, and ASHRAE looks really good. One caveat is that I'm currently uncertain whether the E+ concentration values are mass-based or volume-based. However, when comparing the differences, it appears to only change the results by a few percent and not the 20+% differences we're seeing. I suspect this could be part of the cause for the EES differences, but I don't think it explains it totally.

I haven't compared E+ to EES, but it looks like ASHRAE and CoolProp agree pretty well. I suggest we make a couple of changes. First, we should at least clarify whether the glycol concentrations are mass- or volume-based. That's probably just a docs update. Second, we should update the cp values for PG, EG, and maybe water to be closer to the ASHRAE values. ASHRAE values are volume-based but I suspect we would want to keep it defined as mass-based in E+. Third, someone -- which is probably me -- should take a look at the rest of the properties and make sure they square with current sources. This can come incrementally, later.

bonnema commented 4 years ago

@mitchute I was surprised that EES was so far off. I double-checked, and I had the units wrong. EES is expecting a percent for concentration. I re-ran, and new values are here. Does this look any better? I included the EES table headers this time, the units are there. Sorry...

mitchute commented 4 years ago

Yes, that's much better. Both are less than 0.01% error. Now we have a consensus between EES, ASHRAE, and CoolProp. I'll update the cp values for EG and PG. I'll check the water values, but I expect they'll need to be updated too. I'll add the hardcoded Delta h values in the new CalcEnthalpyGlycol function.