usnistgov / REFPROP-wrappers

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

Fix Mathcad Mixture CRITPdll Calls and Search Virtual Store for Custom Functions #466

Closed henningjp closed 2 years ago

henningjp commented 2 years ago

Description of the Change

Fixes two issues that were occurring in the Mathcad wrapper interface:

  1. Previous patch exposed a bug in the wrapper when calling CRITPdll for mixtures. Two changes made to correct this issue:
    • Calls to CRITPdll checked for (ierr != 0), which failed when REFPROP returned warnings. Changed this to check for (ierr > 0) when throwing an error to ignore REFPROP warnings (negative ierr return values). Changed this behavior for ALL instances of (ierr != 0) in the wrapper code as a best practice.
    • Modified passing of mole fraction array variable, x, to be consistent with other pass-by-reference instances using &x[0] for consistency.
  2. Mathcad wrapper now checks for .MIX files in the default MIXTURES directory. If not found, tries to locate the .MIX file in the user's Virtual Store where the REFPROP GUI stores it when it can't write to the C: drive.

Additional Items:

Benefits

  1. Mixture property calls now behave as expected.
  2. SATSPLN now called by default when new mixtures are loaded for better saturation curve behavior
  3. Custom mixtures created by the REFPROP GUI are now found in the user's Virtual Store if REFPROP can't save the custom mixture to the user's C: drive.

Possible Drawbacks

SATSPLNdll is now called by default on the legacy function calls whenever a new mixture fluid is loaded (ncomp > 1). This is the default behavior for the REFPROP GUI. However, there may be fluid mixtures that do not benefit from the spline calls or there may be situations where the splines are not desired. Potentially, a Mathcad wrapper function could be created that would set a flag to disable this default behavior if needed.

Lots of files changed in this PR due to "untabify" operation on files being worked on. Will untabify the remaining files in a separate PR to keep future code mod PR's cleaner.

Verification Process

Applicable Issues (none)

Closes #464 Closes #465

henningjp commented 2 years ago

@ianhbell - This is tested and ready to merge. More PRs coming as I get time over the summer.

henningjp commented 2 years ago

Here's some validation of this patch in Mathcad Prime that demonstrates:

  1. Pre-defined mixture (Amarillo gas) being loaded correctly
  2. SATSPLN called by default (plot looks awful when it's not)
  3. CRITPdll called correctly (Tcrit and Pcrit) and not throwing errors

image

ianhbell commented 2 years ago

Are we ready to merge?

henningjp commented 2 years ago

Yes