AbstractState functions for CoolPropLib by friederikeboehm · Pull Request #2135 · CoolProp/CoolProp · GitHub
Skip to content

AbstractState functions for CoolPropLib#2135

Merged
ibell merged 5 commits into
CoolProp:masterfrom
friederikeboehm:CoolPropLib
Jun 7, 2022
Merged

AbstractState functions for CoolPropLib#2135
ibell merged 5 commits into
CoolProp:masterfrom
friederikeboehm:CoolPropLib

Conversation

@friederikeboehm

Copy link
Copy Markdown
Contributor

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

@ibell

ibell commented May 18, 2022

Copy link
Copy Markdown
Contributor

AbstractState_get_mole_fractions_satState
AbstractState_keyed_output_satState
AbstractState_backend_name
add_fluids_as_JSON

changes to AbstractState_get_phase_envelope_data
@ibell

ibell commented May 22, 2022

Copy link
Copy Markdown
Contributor

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.

@friederikeboehm

Copy link
Copy Markdown
Contributor Author

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.

@ibell

ibell commented May 24, 2022

Copy link
Copy Markdown
Contributor

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.

@ibell

ibell commented May 24, 2022

Copy link
Copy Markdown
Contributor

Thanks for the updates. Please address my comments and then we can merge

@friederikeboehm

Copy link
Copy Markdown
Contributor Author

I can't see any comments, what do you mean?

@ibell

ibell commented May 27, 2022

Copy link
Copy Markdown
Contributor

See above in this thread, or the Files Changed tab

@friederikeboehm

Copy link
Copy Markdown
Contributor Author

That's were I looked and I can't see any comments
There are no conversations going on according to GitHub:
grafik

Comment thread src/CoolPropLib.cpp Outdated
}
*N = _fractions.size();
if (*N <= maxN) {
for (int i = 0; i < *N; i++)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use { } with for loops

Comment thread src/CoolPropLib.cpp Outdated

try {
shared_ptr<CoolProp::AbstractState>& AS = handle_manager.get(handle);
strcpy(backend, AS->backend_name().c_str());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check it can fit in buffer before copying

@ibell

ibell commented May 28, 2022

Copy link
Copy Markdown
Contributor

Sorry my bad, they were pending

Comment thread src/CoolPropLib.cpp Outdated
std::vector<double> _fractions;
double quality = AS->Q();
if (0 <= quality && quality <= 1) {
if (strcmp("liquid", saturated_state) == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is bad practice to use strcmp in C++, please change to normal comparisons (e.g. saturated_state == "liquid" throughout)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't realized you were doing the string comparison with the C char buffer, anyhow better with the std::string

Comment thread src/CoolPropLib.cpp
Comment on lines +580 to +585
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();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to convert char* to std::string for comparison

Comment thread src/CoolPropLib.cpp
Comment on lines +901 to +906
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));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

@friederikeboehm friederikeboehm requested a review from ibell June 7, 2022 11:32
@ibell

ibell commented Jun 7, 2022

Copy link
Copy Markdown
Contributor

@ibell ibell merged commit c4cf52b into CoolProp:master Jun 7, 2022
@friederikeboehm friederikeboehm deleted the CoolPropLib branch June 7, 2022 15:51
zmeri pushed a commit to zmeri/CoolProp that referenced this pull request Aug 26, 2022
* 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
@jowr jowr added this to the v6.4.2 milestone Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants