From 91704a450b9fc45f9edb954ffa8a396d3d2a644f Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 17 Oct 2016 19:55:25 -0600 Subject: [PATCH] Export critical points in DLL; closes #1274 --- include/CoolPropLib.h | 17 +++++++++++++++++ src/CoolPropLib.cpp | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/CoolPropLib.h b/include/CoolPropLib.h index a0876202..c3992438 100644 --- a/include/CoolPropLib.h +++ b/include/CoolPropLib.h @@ -457,6 +457,23 @@ */ EXPORT_CODE void CONVENTION AbstractState_get_phase_envelope_data(const long handle, const long length, double* T, double* p, double* rhomolar_vap, double *rhomolar_liq, double *x, double *y, long *errcode, char *message_buffer, const long buffer_length); + /** + * @brief Calculate all the critical points for a given composition + * @param handle The integer handle for the state class stored in memory + * @param length The length of the buffers passed to this function + * @param T The pointer to the array of temperature (K) + * @param p The pointer to the array of pressure (Pa) + * @param rhomolar The pointer to the array of molar density (m^3/mol) + * @param stable The pointer to the array of boolean flags for whether the critical point is stable (1) or unstable (0) + * @param errcode The errorcode that is returned (0 = no error, !0 = error) + * @param message_buffer A buffer for the error code + * @param buffer_length The length of the buffer for the error code + * @return + * + * @note If there is an error in an update call for one of the inputs, no change in the output array will be made + */ +EXPORT_CODE void CONVENTION AbstractState_all_critical_points(const long handle, const long length, double *T, double *p, double *rhomolar, long *stable, long *errcode, char *message_buffer, const long buffer_length); + // ************************************************************************************* // ************************************************************************************* // ***************************** DEPRECATED ******************************************* diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 30d91e1d..602adca4 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -627,6 +627,26 @@ EXPORT_CODE void CONVENTION AbstractState_get_phase_envelope_data(const long han } } +EXPORT_CODE void CONVENTION AbstractState_all_critical_points(const long handle, long length, double *T, double *p, double *rhomolar, long *stable, long *errcode, char *message_buffer, const long buffer_length) { + *errcode = 0; + try { + shared_ptr &AS = handle_manager.get(handle); + std::vector pts = AS->all_critical_points(); + if (pts.size() > length){ + throw CoolProp::ValueError(format("Length of critical point vector [%d] is greater than allocated buffer length [%d]", static_cast(pts.size()), static_cast(length))); + } + for (int i = 0; i < pts.size(); ++i){ + *(T+i) = pts[i].T; + *(p+i) = pts[i].p; + *(rhomolar+i) = pts[i].rhomolar; + *(stable+i) = pts[i].stable; + } + } + catch (...) { + HandleException(errcode, message_buffer, buffer_length); + } +} + /// ********************************************************************************* /// ********************************************************************************* /// EMSCRIPTEN (for javascript)