Skip to content

Commit c525537

Browse files
chrishauptmannAtEsiGroupChris Hauptmann
and
Chris Hauptmann
authored
Added second_partial_deriv and first_two_phase_deriv (CoolProp#2291)
* Added AbstractState_second_partial_deriv and AbstractState_first_two_phase_deriv to CoolProp.dll * added functions: first_two_phase_deriv_splined, second_two_phase_deriv --------- Co-authored-by: Chris Hauptmann <[email protected]>
1 parent 7dd3391 commit c525537

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

include/CoolPropLib.h

+66
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,72 @@ EXPORT_CODE double CONVENTION AbstractState_first_saturation_deriv(const long ha
462462
EXPORT_CODE double CONVENTION AbstractState_first_partial_deriv(const long handle, const long Of, const long Wrt, const long Constant, long* errcode,
463463
char* message_buffer, const long buffer_length);
464464

465+
/**
466+
* @brief Calculate the second partial derivative in homogeneous phases from the AbstractState using integer values for the desired parameters
467+
* @param handle The integer handle for the state class stored in memory
468+
* @param Of1 The parameter of which the derivative is being taken
469+
* @param Wrt1 The parameter that the derivative is taken with respect to in the first derivative
470+
* @param Constant1 The parameter that is held constant in the first derivative
471+
* @param Wrt2 The parameter that the derivative is taken with respect to in the second derivative
472+
* @param Constant2 The parameter that is held constant in the second derivative
473+
* @param errcode The errorcode that is returned (0 = no error, !0 = error)
474+
* @param message_buffer A buffer for the error code
475+
* @param buffer_length The length of the buffer for the error code
476+
* @return
477+
*/
478+
479+
EXPORT_CODE double CONVENTION AbstractState_second_two_phase_deriv(const long handle, const long Of1, const long Wrt1, const long Constant1,
480+
const long Wrt2, const long Constant2, long* errcode, char* message_buffer,
481+
const long buffer_length);
482+
/**
483+
* @brief Calculate the second partial derivative int two-phase region from the AbstractState using integer values for the desired parameters
484+
* @param handle The integer handle for the state class stored in memory
485+
* @param Of1 The parameter of which the derivative is being taken
486+
* @param Wrt1 The parameter that the derivative is taken with respect to in the first derivative
487+
* @param Constant1 The parameter that is held constant in the first derivative
488+
* @param Wrt2 The parameter that the derivative is taken with respect to in the second derivative
489+
* @param Constant2 The parameter that is held constant in the second derivative
490+
* @param errcode The errorcode that is returned (0 = no error, !0 = error)
491+
* @param message_buffer A buffer for the error code
492+
* @param buffer_length The length of the buffer for the error code
493+
* @return
494+
*/
495+
496+
EXPORT_CODE double CONVENTION AbstractState_second_partial_deriv(const long handle, const long Of1, const long Wrt1, const long Constant1,
497+
const long Wrt2, const long Constant2, long* errcode, char* message_buffer,
498+
const long buffer_length);
499+
500+
/**
501+
* @brief Calculate the first partial derivative in two-phase region with Spline - Approach from the AbstractState using integer values for the desired parameters
502+
Spline Approach "Methods to Increase the Robustness of Finite-Volume FlowModels in Thermodynamic Systems: Sylvain Quoilin, Ian Bell, Adriano Desideri, Pierre Dewallef and Vincent Lemort"
503+
* @param handle The integer handle for the state class stored in memory
504+
* @x_end constant parameter for defining range of the spline, (usually 0.1 is used, 0..1 is possible)
505+
* @param Of The parameter of which the derivative is being taken
506+
* @param Wrt The derivative with with respect to this parameter
507+
* @param Constant The parameter that is not affected by the derivative
508+
* @param errcode The errorcode that is returned (0 = no error, !0 = error)
509+
* @param message_buffer A buffer for the error code
510+
* @param buffer_length The length of the buffer for the error code
511+
* @return
512+
*/
513+
514+
515+
EXPORT_CODE double CONVENTION AbstractState_first_two_phase_deriv_splined(const long handle, const long Of, const long Wrt, const long Constant,
516+
const double x_end,long* errcode, char* message_buffer, const long buffer_length);
517+
/**
518+
* @brief Calculate the first partial derivative in homogeneous phases from the AbstractState using integer values for the desired parameters
519+
* @param handle The integer handle for the state class stored in memory
520+
* @param Of The parameter of which the derivative is being taken
521+
* @param Wrt The derivative with with respect to this parameter
522+
* @param Constant The parameter that is not affected by the derivative
523+
* @param errcode The errorcode that is returned (0 = no error, !0 = error)
524+
* @param message_buffer A buffer for the error code
525+
* @param buffer_length The length of the buffer for the error code
526+
* @return
527+
*/
528+
529+
EXPORT_CODE double CONVENTION AbstractState_first_two_phase_deriv(const long handle, const long Of, const long Wrt, const long Constant,
530+
long* errcode, char* message_buffer, const long buffer_length);
465531
/**
466532
* @brief Update the state of the AbstractState and get an output value five common outputs (temperature, pressure, molar density, molar enthalpy and molar entropy)
467533
* @brief from the AbstractState using pointers as inputs and output to allow array computation.

src/CoolPropLib.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,64 @@ EXPORT_CODE double CONVENTION AbstractState_first_partial_deriv(const long handl
692692
return _HUGE;
693693
}
694694

695+
EXPORT_CODE double CONVENTION AbstractState_second_partial_deriv(const long handle, const long Of1, const long Wrt1, const long Constant1,
696+
const long Wrt2, const long Constant2, long* errcode, char* message_buffer,
697+
const long buffer_length) {
698+
*errcode = 0;
699+
try {
700+
shared_ptr<CoolProp::AbstractState>& AS = handle_manager.get(handle);
701+
return AS->second_partial_deriv(static_cast<CoolProp::parameters>(Of1), static_cast<CoolProp::parameters>(Wrt1),
702+
static_cast<CoolProp::parameters>(Constant1), static_cast<CoolProp::parameters>(Wrt2),
703+
static_cast<CoolProp::parameters>(Constant2));
704+
} catch (...) {
705+
HandleException(errcode, message_buffer, buffer_length);
706+
}
707+
return _HUGE;
708+
}
709+
710+
EXPORT_CODE double CONVENTION AbstractState_second_two_phase_deriv(const long handle, const long Of1, const long Wrt1, const long Constant1,
711+
const long Wrt2, const long Constant2, long* errcode, char* message_buffer,
712+
const long buffer_length) {
713+
*errcode = 0;
714+
try {
715+
shared_ptr<CoolProp::AbstractState>& AS = handle_manager.get(handle);
716+
return AS->second_two_phase_deriv(static_cast<CoolProp::parameters>(Of1), static_cast<CoolProp::parameters>(Wrt1),
717+
static_cast<CoolProp::parameters>(Constant1), static_cast<CoolProp::parameters>(Wrt2),
718+
static_cast<CoolProp::parameters>(Constant2));
719+
} catch (...) {
720+
HandleException(errcode, message_buffer, buffer_length);
721+
}
722+
return _HUGE;
723+
}
724+
725+
EXPORT_CODE double CONVENTION AbstractState_first_two_phase_deriv(const long handle, const long Of, const long Wrt, const long Constant,
726+
long* errcode, char* message_buffer, const long buffer_length) {
727+
*errcode = 0;
728+
try {
729+
shared_ptr<CoolProp::AbstractState>& AS = handle_manager.get(handle);
730+
return AS->first_two_phase_deriv(static_cast<CoolProp::parameters>(Of), static_cast<CoolProp::parameters>(Wrt),
731+
static_cast<CoolProp::parameters>(Constant));
732+
} catch (...) {
733+
HandleException(errcode, message_buffer, buffer_length);
734+
}
735+
return _HUGE;
736+
}
737+
738+
EXPORT_CODE double CONVENTION AbstractState_first_two_phase_deriv_splined(const long handle, const long Of, const long Wrt, const long Constant,
739+
const double x_end, long* errcode, char* message_buffer,
740+
const long buffer_length) {
741+
*errcode = 0;
742+
try {
743+
shared_ptr<CoolProp::AbstractState>& AS = handle_manager.get(handle);
744+
return AS->first_two_phase_deriv_splined(static_cast<CoolProp::parameters>(Of), static_cast<CoolProp::parameters>(Wrt),
745+
static_cast<CoolProp::parameters>(Constant), x_end);
746+
} catch (...) {
747+
HandleException(errcode, message_buffer, buffer_length);
748+
}
749+
return _HUGE;
750+
}
751+
752+
695753
EXPORT_CODE void CONVENTION AbstractState_update_and_common_out(const long handle, const long input_pair, const double* value1, const double* value2,
696754
const long length, double* T, double* p, double* rhomolar, double* hmolar,
697755
double* smolar, long* errcode, char* message_buffer, const long buffer_length) {

src/CoolPropLib.def

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ EXPORTS
1010
AbstractState_update = _AbstractState_update@36
1111
AbstractState_first_saturation_deriv = _AbstractState_first_saturation_deriv@24
1212
AbstractState_first_partial_deriv = _AbstractState_first_partial_deriv@28
13+
AbstractState_second_partial_deriv = _AbstractState_second_partial_deriv@28
14+
AbstractState_second_two_phase_deriv = _AbstractState_second_two_phase_deriv@28
15+
AbstractState_first_two_phase_deriv= _AbstractState_first_two_phase_deriv@28
16+
AbstractState_first_two_phase_deriv_splined= _AbstractState_first_two_phase_deriv_splined@28
1317
AbstractState_specify_phase = _AbstractState_specify_phase@20
1418
AbstractState_unspecify_phase = _AbstractState_unspecify_phase@16
1519
AbstractState_update_and_1_out = _AbstractState_update_and_1_out@40

0 commit comments

Comments
 (0)