usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
190 stars 127 forks source link

Fortran (C) Results not matching GUI #344

Closed jadepgit closed 3 years ago

jadepgit commented 3 years ago

Description

Prepared a liquid phase test case of 0.5 Propane, 0.5 nButane in GUI at 291.5K and 0.515 MPa (65F, 60 psig/74.7psia) Density matched expected. Enthalpy looked "reasonable" by comparing to saturated vapor on the P-H chart. Enthalpy reported as 244 kJ/kg. Density 546 kg/m^3

Ran same with REPROP1dll to check QMOLE. Code -998. Doc states Code typically means liquid with P>Pc, which is not right. Ran same with ABFLSHdll as a blind flash. Same Q, -998. "D" matched GUI. Dl = Dv = 10.7 (very low Dl) Enthaply = 637.6 kJ/kg, which is very high, acting like vapor phase.

Since the GUI is performing as expected, the problem is on my side. However I ran a previous test case with a 2-phase mix and REPROPdll worked fine. Do I need to set some flags that I've skipped? Currently I call SETPATH and SETFLUIDS, then I set the "nc" to 2. That's all I'm doing for set-up. Thanks for your help.

Steps to Reproduce

  1. GUI: 50/50 mol% propane/nButane. 291.5K, 0.515 MPa.
  2. ABFLASH: same mix. ab = TP, z[0] = 0.5, z[1] = 0.5, 291.5K, 515 kPa. iFlag 002. Using GETENUM result for "English" for units. For ABFLASH call I'm entering the SI for "a" and "b" (K/kPa).

**Expected behavior: Reasonable Q since P<<Pc. h = 244.7. Dl = 546.8

Actual behavior: Q= -998, h = 637.6, Dl = 10.7, D = 546.8

Versions

REFPROP Version: 10.0
Operating System and Version: Artix Linux / Wine Access Method:** refpropdll library from C program

Additional Information

I'd like to replicate the GUI "Calculate->Specified State Points functionality in code.

Thanks for your help.

EricLemmon commented 3 years ago

Check out the information here about reference states:

https://pages.nist.gov/REFPROP-docs/#reference-states-enthalpy-and-entropy-differences

Then search this github site with the word "SATSPLN" and you'll find lots of good information.

Let us know which questions these do not answer.

jadepgit commented 3 years ago

Enthalpy difference now makes sense. So use REFPROP SETREF with hout="OTH;etc.." and match the GUI options to make checking results easy. Q1: I'm going to go with "apply ref state to: each pure component". This means sending a=2 when using REFPROP SETREF. Please confirm. Q2: I'm assuming "a=2" makes apples to apples comparisons better, e.g. if you flash a mixture, separate the vapor and combine it with another vapor stream of a different composition, the accounting is easier if everything is referenced to the pure components. Please comment.

On the spline, I'm assuming that has to deal with the density question. I'll check it out.
Thanks for your reply.

EricLemmon commented 3 years ago

Take a look at the following to help understand the "a=2" input:

https://github.com/usnistgov/REFPROP-issues/issues/222

jadepgit commented 3 years ago

I'm good on the reference states now. My problem lies with calling ABFLSHdll. Note I never call SETUP. Instead I use SETPATHdll, SETFLUIDdll, and FLAGSdll to set nc = 2. The doc I have didn't have SETUPdll in the High-Level API function listing, so I originally missed it. This might be a factor. However REFPROPdll works fine.

I tried a new problem (same 50/50 mole% Propane/nButane) where I am in the 2 phase region, with T = 302.6K and P = 515 kPa. I call SATSPLNdll and then call REFPROP1dll with hOut = QMOLE which returns 0.619. Then I call ABFLSHdll. q comes back same at 0.619. D = 18.41, Dv = .23, and Dl = 10.19. Looks like D and Dl are swapped, and Dl is off by an order of magnitude. Should be around 550.

I run the same case with REFPROPdll and Dvap and Dliq are correct. q matches at 0.619. Note I have REFPROPdll set up with english units. Dvap = 0.71, Dliq = 34.1, hvap = 267.5 btu/lbm, and hliq = 116.7 ABFLSHdll returned the mixture enthalpy of 530.8 btu/lbm

I'm screwing up ABFLSHdll somehow. Enthalpy and density don't make sense.

EricLemmon commented 3 years ago

There is an unfortunate bug that was not caught in Version 10.0 when using mass units in ABFLSHdll. We've put together a new routine called ABFLASHdll to deal with this, but it's not quite ready for distribution. I would recommend to always use REFPROP1dll or just REFPROPdll instead unless speed is very important. The additional overhead required is quite negligible for most cases.

I'm going to transfer your issue to the wrappers website, so make note of the new address when it comes through.

jadepgit commented 3 years ago

I actually like the REFPROPdll routine and prefer to use it. However I switched over to ABFLSH because I was originally dealing with a subcooled liquid. According to the doc it seems like I can't get a liquid enthalpy or Density on a sub cooled liquid using REFPROPdll (hOut = "HLIQ DLIQ"). If that's the case, using ABFLSHdll with molar units appears to be an option. Let me know if that is correct. Again, thanks for your time.

EricLemmon commented 3 years ago

You can use the symbols > and < on the inputs to force it to do a liquid or vapor phase calculation. Thus "TP>" will search given T and P in the liquid phase only, "PH<" will search with P and H in the vapor phase, and so on. You could also use L and V, such as "TPL" or "PHV".

Everything available in ABLFSHdll should also be available in REFPROPdll.

jadepgit commented 3 years ago

Just to be clear, I've noticed this in the docs for "LIQ", (e.g. "HLIQ") in the docs: "LIQ:(where * is T, P, D, etc.) Return the liquid saturation properties for the property listed as the first letter. This is only valid for saturation states or 2-phase states." Does TP< override this and thus return the subcooled enthalpy with hOut = HLIQ? Is there some other way to return enthalpy and density? Thanks.

jadepgit commented 3 years ago

TP> or TPL. Typo.

jadepgit commented 3 years ago

Ran two cases with subcooled liquids at different temperatures. Enthalpy and Density definitely changed and are now reasonable. Used REFPROP TPL and HLIQ and DLIQ. This solves the problem and I'm closing the issue. Thanks for your help.

EricLemmon commented 3 years ago

Glad to hear you figured it out! Most of the details are in the manual, but not all. Let us know if any are unclear or something is missing and we'll fix/add it.