AbstractState functions for CoolPropLib#2135
Conversation
244c423 to
8782f2e
Compare
AbstractState_get_mole_fractions_satState AbstractState_keyed_output_satState AbstractState_backend_name add_fluids_as_JSON changes to AbstractState_get_phase_envelope_data
8782f2e to
8dfdb7c
Compare
|
I prefer no breaking changes to the C interface exposed in the DLL, so please make a new function rather than modifying the existing one. |
That makes sense. I've implemented an overloaded function (as it basically is the same function, just more input and output variables). If this is not wanted and I should reimplement it as a function with a different name, I'll do that of course. |
|
Overloads are not possible in C, they are exported with the same symbol. Please rename somehow. I like your changes, but I don't want to break code. |
|
Thanks for the updates. Please address my comments and then we can merge |
|
I can't see any comments, what do you mean? |
|
See above in this thread, or the Files Changed tab |
| } | ||
| *N = _fractions.size(); | ||
| if (*N <= maxN) { | ||
| for (int i = 0; i < *N; i++) |
There was a problem hiding this comment.
Always use { } with for loops
|
|
||
| try { | ||
| shared_ptr<CoolProp::AbstractState>& AS = handle_manager.get(handle); | ||
| strcpy(backend, AS->backend_name().c_str()); |
There was a problem hiding this comment.
Need to check it can fit in buffer before copying
|
Sorry my bad, they were pending |
| std::vector<double> _fractions; | ||
| double quality = AS->Q(); | ||
| if (0 <= quality && quality <= 1) { | ||
| if (strcmp("liquid", saturated_state) == 0) { |
There was a problem hiding this comment.
It is bad practice to use strcmp in C++, please change to normal comparisons (e.g. saturated_state == "liquid" throughout)
There was a problem hiding this comment.
I hadn't realized you were doing the string comparison with the C char buffer, anyhow better with the std::string
| std::string string_state(saturated_state); | ||
| if (0 <= quality && quality <= 1) { | ||
| if (string_state == "liquid") { | ||
| _fractions = AS->mole_fractions_liquid(); | ||
| } else if (string_state == "gas") { | ||
| _fractions = AS->mole_fractions_vapor(); |
There was a problem hiding this comment.
had to convert char* to std::string for comparison
| std::string string_state(saturated_state); | ||
| if (0 <= quality && quality <= 1) { | ||
| if (string_state == "liquid") { | ||
| return AS->saturated_liquid_keyed_output(static_cast<CoolProp::parameters>(param)); | ||
| } else if (string_state == "gas") { | ||
| return AS->saturated_vapor_keyed_output(static_cast<CoolProp::parameters>(param)); |
* Add AbstractState functions to CoolPropLib AbstractState_get_mole_fractions_satState AbstractState_keyed_output_satState AbstractState_backend_name add_fluids_as_JSON * Overloaded AbstractState_get_phase_envelope_data and appended checkedMemory to function name


Description of the Change
AbstractState_get_mole_fractions_satState returns mole fractions for saturated "liquid" or "gas" phases
AbstractState_keyed_output_satState returns keyed output for saturated "liquid" or "gas" phases
AbstractState_backend_name returns the backend name for an AbstractState
add_fluids_as_JSON can be called from the High-Level.
Changes to AbstractState_get_phase_envelope_data
Benefits
Adds functionality to the High-Level-Interface.
AbstractState_get_phase_envelope_data returns the actual length of the array and throws an error should there not be enough memory allocated.
Possible Drawbacks
Changes to AbstractState_get_phase_envelope_data might imply refactoring of wrappers (could only find it in Julia wrapper)
Verification Process
Functions were tested using the Mathematica wrapper, see PR #2085
Applicable Issues
Based on PR #2133 and #2134