usnistgov / REFPROP-wrappers

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

Mathcad Wrapper Mixture Enhancements #478

Closed henningjp closed 2 years ago

henningjp commented 2 years ago

Description of the Change

The Mathcad wrapper was originally written with pure fluids in mind. Added functionality and some additional functions for better handling and evaluation of mixtures.

Modified rp_getname, which calls NAMEdll to return the mixture name from the first line of the mixture file. REFPROP 10 does this by calling NAMEdll with icomp = 0, but REFPROP 9.1 does not. This function now works for both.

New functions to assist with retrieving saturation curve information for mixtures (vapor & liquid do not overlap for mixtures) following naming convention of all other thermodynamic functions in the Mathcad wrapper:

  1. Saturation Temperature (rp_tsatpf(fluid,p) for saturated liquid, rp_tsatpg(fluid,p) for saturated vapor)
  2. Saturation Pressure (rp_psattf(fluid,t) for saturated liquid, rp_psattg(fluid,t) for saturated vapor)
  3. Cricondentherm & Cricondenbar (rp_maxX(fluid,X)
    • X = "T" for Cricondentherm
    • X = "P" for Cricondenbar
    • Returns an array of Temperature, Pressure, and Density at the requested point based on X
    • If pure fluid is loaded, simply returns the Critical Point values in both cases.
  4. Get the composition of the most recently loaded fluid (rp_getx(fluid))
    • Returns array of mole fractions
    • fluid may be an empty string "", a blank space " ", or the previous mixture string loaded.
    • If fluid is a new mixture, that mixture is loaded and its mixture composition is returned.
  5. Change composition without loading a new mixture/file (rp_setx(mfrac))
    • Pass mfrac as an array of mole fractions
    • Length of array must match number of components in currently loaded fluid
    • Mole fractions must sum to unity
    • If all is well, LIMITS & Molecular weight are recalculated and SATSPLN is called with the new composition

Additional Items:

Benefits

  1. These functions allow better flexibility in handling mixtures and retrieving accurate saturation data from the saturation splines.
  2. Provides ability to extract T, P, and D at the Cricondentherm and Cricondenbar.

Possible Drawbacks

Mathcad unit handling include file (REFPROP_units.mcdx) is a Mathcad worksheet and a binary file. It is updated in this PR to handle the functions above, as well as the derived quantity functions in PR #475 . It will need to be updated one more time to include the planned REFPROP 10 high-level API function additions to the Mathcad wrapper (coming soon).

Verification Process

Applicable Issues

henningjp commented 2 years ago

@ianhbell - Squash merge will be fine. Testing complete (see verification PDF above) & ready to go. This is the last set of low level functions. Next PR will implement the REFPROP 10 High-Level API functions ,specifically REFPROP(), to better simplify and extend add-in functionality.

ianhbell commented 2 years ago

Thanks as usual