From a1d2a2a9be98a48394ff7a66afaa0bd72d5c705e Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Thu, 18 Dec 2014 11:28:23 +0100 Subject: [PATCH 1/4] Added the external REFPROP header and removed the constants from the cpp file, replaced tabs with 4 spaces --- .gitmodules | 3 + externals/REFPROP-headers | 1 + .../REFPROP/REFPROPMixtureBackend.cpp | 168 +++++------ src/Backends/REFPROP/REFPROP_lib.h | 273 ------------------ 4 files changed, 79 insertions(+), 366 deletions(-) create mode 160000 externals/REFPROP-headers delete mode 100644 src/Backends/REFPROP/REFPROP_lib.h diff --git a/.gitmodules b/.gitmodules index 144f8fd5..95f5a097 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "externals/Eigen"] path = externals/Eigen url = https://github.com/RLovelett/eigen.git +[submodule "externals/REFPROP-headers"] + path = externals/REFPROP-headers + url = https://github.com/CoolProp/REFPROP-headers.git diff --git a/externals/REFPROP-headers b/externals/REFPROP-headers new file mode 160000 index 00000000..e001c2fb --- /dev/null +++ b/externals/REFPROP-headers @@ -0,0 +1 @@ +Subproject commit e001c2fbd1d9b93bd31b938e7bcbdee57b809170 diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 4a2d1c0b..0529f781 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -46,7 +46,7 @@ surface tension N/m #endif enum DLLNameManglingStyle{ NO_NAME_MANGLING = 0, LOWERCASE_NAME_MANGLING, LOWERCASE_AND_UNDERSCORE_NAME_MANGLING }; - + #include "REFPROP_lib.h" #include "REFPROPMixtureBackend.h" #include "Exceptions.h" @@ -68,26 +68,8 @@ enum DLLNameManglingStyle{ NO_NAME_MANGLING = 0, LOWERCASE_NAME_MANGLING, LOWERC #include #endif -// Some constants for REFPROP... defined by macros for ease of use -#define refpropcharlength 255 -#define filepathlength 255 -#define lengthofreference 3 -#define errormessagelength 255 -#define ncmax 20 // Note: ncmax is the max number of components -#define numparams 72 -#define maxcoefs 50 - std::string LoadedREFPROPRef; -// Some constants for REFPROP... defined by macros for ease of use -#define refpropcharlength 255 -#define filepathlength 255 -#define lengthofreference 3 -#define errormessagelength 255 -#define ncmax 20 // Note: ncmax is the max number of components -#define numparams 72 -#define maxcoefs 50 - // Check windows #if _WIN32 || _WIN64 #if _WIN64 @@ -129,15 +111,15 @@ static char default_reference_state[] = "DEF"; void *getFunctionPointer(const char * name, DLLNameManglingStyle mangling_style = NO_NAME_MANGLING) { - std::string function_name; - switch(mangling_style){ - case NO_NAME_MANGLING: - function_name = name; break; - case LOWERCASE_NAME_MANGLING: - function_name = lower(name); break; - case LOWERCASE_AND_UNDERSCORE_NAME_MANGLING: - function_name = lower(name) + "_"; break; - } + std::string function_name; + switch(mangling_style){ + case NO_NAME_MANGLING: + function_name = name; break; + case LOWERCASE_NAME_MANGLING: + function_name = lower(name); break; + case LOWERCASE_AND_UNDERSCORE_NAME_MANGLING: + function_name = lower(name) + "_"; break; + } #if defined(__ISWINDOWS__) return (void *) GetProcAddress(RefpropdllInstance, function_name.c_str()); #elif defined(__ISLINUX__) @@ -159,30 +141,30 @@ double setFunctionPointers() printf("REFPROP is not loaded, make sure you call this function after loading the library.\n"); return -_HUGE; } - /* First determine the type of name mangling in use. - * A) RPVersion -> RPVersion - * B) RPVersion -> rpversion - * C) RPVersion -> rpversion_ - */ - DLLNameManglingStyle mangling_style = NO_NAME_MANGLING; // defaults to no mangling - - SETUPdll = (SETUPdll_POINTER) getFunctionPointer("SETUPdll"); - if (SETUPdll == NULL){ // some mangling in use - SETUPdll = (SETUPdll_POINTER) getFunctionPointer("setupdll"); - if (SETUPdll != NULL){ - mangling_style = LOWERCASE_NAME_MANGLING; - } - else{ - SETUPdll = (SETUPdll_POINTER) getFunctionPointer("setupdll_"); - if (SETUPdll != NULL){ - mangling_style = LOWERCASE_AND_UNDERSCORE_NAME_MANGLING; - } - else{ - throw CoolProp::ValueError("Could not load the symbol SETUPdll or any of its mangled forms; REFPROP shared library broken"); - } - } - } - + /* First determine the type of name mangling in use. + * A) RPVersion -> RPVersion + * B) RPVersion -> rpversion + * C) RPVersion -> rpversion_ + */ + DLLNameManglingStyle mangling_style = NO_NAME_MANGLING; // defaults to no mangling + + SETUPdll = (SETUPdll_POINTER) getFunctionPointer("SETUPdll"); + if (SETUPdll == NULL){ // some mangling in use + SETUPdll = (SETUPdll_POINTER) getFunctionPointer("setupdll"); + if (SETUPdll != NULL){ + mangling_style = LOWERCASE_NAME_MANGLING; + } + else{ + SETUPdll = (SETUPdll_POINTER) getFunctionPointer("setupdll_"); + if (SETUPdll != NULL){ + mangling_style = LOWERCASE_AND_UNDERSCORE_NAME_MANGLING; + } + else{ + throw CoolProp::ValueError("Could not load the symbol SETUPdll or any of its mangled forms; REFPROP shared library broken"); + } + } + } + /* Set the pointers, platform independent * * Example: RPVersion = (RPVersion_POINTER) getFunctionPointer(STRINGIFY(RPVersion)); @@ -201,9 +183,9 @@ double setFunctionPointers() std::string get_REFPROP_fluid_path() { std::string rpPath = refpropPath; - // Allow the user to specify an alternative REFPROP path by configuration value - std::string alt_refprop_path = CoolProp::get_config_string(ALTERNATIVE_REFPROP_PATH); - if (!alt_refprop_path.empty()){ rpPath = alt_refprop_path; } + // Allow the user to specify an alternative REFPROP path by configuration value + std::string alt_refprop_path = CoolProp::get_config_string(ALTERNATIVE_REFPROP_PATH); + if (!alt_refprop_path.empty()){ rpPath = alt_refprop_path; } #if defined(__ISWINDOWS__) return rpPath; #elif defined(__ISLINUX__) @@ -220,7 +202,7 @@ bool load_REFPROP() // If REFPROP is not loaded if (RefpropdllInstance==NULL) { - + // Load it #if defined(__ISWINDOWS__) /* We need this logic on windows because if you use the bitness @@ -284,16 +266,16 @@ bool load_REFPROP() } #endif #endif - + if (setFunctionPointers()!=COOLPROP_OK) { printf("There was an error setting the REFPROP function pointers, check types and names in header file.\n"); throw CoolProp::AttributeError("There was an error setting the REFPROP function pointers, check types and names in header file."); return false; } - char rpv[255]; - RPVersion(rpv); - RPVersion_loaded = rpv; + char rpv[255]; + RPVersion(rpv); + RPVersion_loaded = rpv; return true; } return true; @@ -332,7 +314,7 @@ REFPROPMixtureBackend::~REFPROPMixtureBackend() { //delete RefpropdllInstance; RefpropdllInstance = NULL; #endif - LoadedREFPROPRef = ""; + LoadedREFPROPRef = ""; } } @@ -385,7 +367,7 @@ bool REFPROPMixtureBackend::REFPROP_supported () { void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &fluid_names) { long ierr=0; - this->fluid_names = fluid_names; + this->fluid_names = fluid_names; char component_string[10000], herr[errormessagelength]; std::string components_joined = strjoin(fluid_names,"|"); std::string components_joined_raw = strjoin(fluid_names,"|"); @@ -397,15 +379,15 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f throw NotImplementedError("You cannot use the REFPROPMixtureBackend."); } - // Load REFPROP if it isn't loaded yet - load_REFPROP(); // This should not be needed. + // Load REFPROP if it isn't loaded yet + load_REFPROP(); // This should not be needed. - // If the name of the refrigerant doesn't match + // If the name of the refrigerant doesn't match // that of the currently loaded refrigerant if (LoadedREFPROPRef == components_joined_raw) { if (dbg_refprop) std::cout << format("%s:%d: The current fluid can be reused; %s and %s match \n",__FILE__,__LINE__,components_joined_raw.c_str(),LoadedREFPROPRef.c_str()); - this->Ncomp = N; + this->Ncomp = N; mole_fractions.resize(N); mole_fractions_liq.resize(N); mole_fractions_vap.resize(N); @@ -413,18 +395,18 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f } else { - // Loop over the file names - first we try with nothing, then .fld, then .FLD, then .ppf - means you can't mix and match - for (unsigned int k = 0; k < number_of_endings; k++) - { - // Build the mixture string - for (unsigned int j = 0; j < (unsigned int)N; j++) - { - if (j == 0){ - components_joined = fdPath + upper(fluid_names[j])+endings[k]; - } - else{ - components_joined += "|" + fdPath + upper(fluid_names[j])+endings[k]; - } + // Loop over the file names - first we try with nothing, then .fld, then .FLD, then .ppf - means you can't mix and match + for (unsigned int k = 0; k < number_of_endings; k++) + { + // Build the mixture string + for (unsigned int j = 0; j < (unsigned int)N; j++) + { + if (j == 0){ + components_joined = fdPath + upper(fluid_names[j])+endings[k]; + } + else{ + components_joined += "|" + fdPath + upper(fluid_names[j])+endings[k]; + } } if (dbg_refprop) std::cout << format("%s:%d: The fluid %s has not been loaded before, current value is %s \n",__FILE__,__LINE__,components_joined_raw.c_str(),LoadedREFPROPRef.c_str()); @@ -454,13 +436,13 @@ void REFPROPMixtureBackend::set_REFPROP_fluids(const std::vector &f return; } else if (k < number_of_endings-1){ // Keep going - continue; - } + continue; + } else { throw ValueError(format("Could not load these fluids: %s", components_joined_raw.c_str())); } - } + } } } void REFPROPMixtureBackend::set_mole_fractions(const std::vector &mole_fractions) @@ -550,12 +532,12 @@ long double REFPROPMixtureBackend::calc_rhomolar_critical(){ }; long double REFPROPMixtureBackend::calc_T_reducing(){ double rhored_mol_L = 0, Tr = 0; - REDXdll(&(mole_fractions[0]), &Tr, &rhored_mol_L); + REDXdll(&(mole_fractions[0]), &Tr, &rhored_mol_L); return static_cast(Tr); }; long double REFPROPMixtureBackend::calc_rhomolar_reducing(){ - double rhored_mol_L = 0, Tr = 0; - REDXdll(&(mole_fractions[0]), &Tr, &rhored_mol_L); + double rhored_mol_L = 0, Tr = 0; + REDXdll(&(mole_fractions[0]), &Tr, &rhored_mol_L); return static_cast(rhored_mol_L*1000); }; long double REFPROPMixtureBackend::calc_Ttriple(){ @@ -1220,22 +1202,22 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu _cvmolar = cvmol; _cpmolar = cpmol; _speed_sound = w; - _tau = calc_T_critical()/_T; - _delta = _rhomolar/calc_rhomolar_critical(); + _tau = calc_T_critical()/_T; + _delta = _rhomolar/calc_rhomolar_critical(); } long double REFPROPMixtureBackend::call_phixdll(long itau, long idel) { - double val = 0, tau = _tau, delta = _delta; - if (PHIXdll == NULL){throw ValueError("PHIXdll function is not available in your version of REFPROP. Please upgrade");} - PHIXdll(&itau, &idel, &tau, &delta, &(mole_fractions[0]), &val); - return static_cast(val)/pow(static_cast(_delta),idel)/pow(static_cast(_tau),itau); + double val = 0, tau = _tau, delta = _delta; + if (PHIXdll == NULL){throw ValueError("PHIXdll function is not available in your version of REFPROP. Please upgrade");} + PHIXdll(&itau, &idel, &tau, &delta, &(mole_fractions[0]), &val); + return static_cast(val)/pow(static_cast(_delta),idel)/pow(static_cast(_tau),itau); } long double REFPROPMixtureBackend::call_phi0dll(long itau, long idel) { throw ValueError("Temporarily the PHI0dll function is not available for REFPROP"); - double val = 0, tau = _tau, delta = _delta, __T = T(), __rho = rhomolar()/1000; - if (PHI0dll == NULL){throw ValueError("PHI0dll function is not available in your version of REFPROP. Please upgrade");} - PHI0dll(&itau, &idel, &__T, &__rho, &(mole_fractions[0]), &val); + double val = 0, tau = _tau, delta = _delta, __T = T(), __rho = rhomolar()/1000; + if (PHI0dll == NULL){throw ValueError("PHI0dll function is not available in your version of REFPROP. Please upgrade");} + PHI0dll(&itau, &idel, &__T, &__rho, &(mole_fractions[0]), &val); return static_cast(val)/pow(delta,idel)/pow(tau,itau); } diff --git a/src/Backends/REFPROP/REFPROP_lib.h b/src/Backends/REFPROP/REFPROP_lib.h deleted file mode 100644 index 29462ab5..00000000 --- a/src/Backends/REFPROP/REFPROP_lib.h +++ /dev/null @@ -1,273 +0,0 @@ - -#ifndef REFPROP_LIB_H -#define REFPROP_LIB_H - -/* See http://stackoverflow.com/a/148610 - * See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511 - * This will be used to generate function names, pointers, etc. below - */ -#define LIST_OF_REFPROP_FUNCTION_NAMES \ - X(RPVersion) \ - X(SETPATHdll) \ - X(ABFL1dll) \ - X(ABFL2dll) \ - X(ACTVYdll) \ - X(AGdll) \ - X(CCRITdll) \ - X(CP0dll) \ - X(CRITPdll) \ - X(CSATKdll) \ - X(CV2PKdll) \ - X(CVCPKdll) \ - X(CVCPdll) \ - X(DBDTdll) \ - X(DBFL1dll) \ - X(DBFL2dll) \ - X(DDDPdll) \ - X(DDDTdll) \ - X(DEFLSHdll) \ - X(DHD1dll) \ - X(DHFL1dll) \ - X(DHFL2dll) \ - X(DHFLSHdll) \ - X(DIELECdll) \ - X(DOTFILLdll) \ - X(DPDD2dll) \ - X(DPDDKdll) \ - X(DPDDdll) \ - X(DPDTKdll) \ - X(DPDTdll) \ - X(DPTSATKdll) \ - X(DSFLSHdll) \ - X(DSFL1dll) \ - X(DSFL2dll) \ - X(ENTHALdll) \ - X(ENTROdll) \ - X(ESFLSHdll) \ - X(FGCTYdll) \ - X(FUGCOFdll) \ - X(FPVdll) \ - X(GERG04dll) \ - X(GETFIJdll) \ - X(GETKTVdll) \ - X(GIBBSdll) \ - X(HSFLSHdll) \ - X(INFOdll) \ - X(LIMITKdll) \ - X(LIMITSdll) \ - X(LIMITXdll) \ - X(MELTPdll) \ - X(MELTTdll) \ - X(MLTH2Odll) \ - X(NAMEdll) \ - X(PASSCMNdll) \ - X(PDFL1dll) \ - X(PDFLSHdll) \ - X(PEFLSHdll) \ - X(PHFL1dll) \ - X(PHFLSHdll) \ - X(PHIXdll) \ - X(PHI0dll) \ - X(PQFLSHdll) \ - X(PREOSdll) \ - X(PRESSdll) \ - X(PSFL1dll) \ - X(PSFLSHdll) \ - X(PUREFLDdll) \ - X(QMASSdll) \ - X(QMOLEdll) \ - X(RESIDUALdll) \ - X(REDXdll) \ - X(RMIX2dll) \ - X(SATDdll) \ - X(SATEdll) \ - X(SATHdll) \ - X(SATPdll) \ - X(SATSdll) \ - X(SATTdll) \ - X(SATSPLNdll) \ - X(SETAGAdll) \ - X(SETKTVdll) \ - X(SETMIXdll) \ - X(SETMODdll) \ - X(SETREFdll) \ - X(SETUPdll) \ - X(SPECGRdll) \ - X(SUBLPdll) \ - X(SUBLTdll) \ - X(SURFTdll) \ - X(SURTENdll) \ - X(TDFLSHdll) \ - X(TEFLSHdll) \ - X(THERM0dll) \ - X(THERM2dll) \ - X(THERM3dll) \ - X(THERMdll) \ - X(THFLSHdll) \ - X(TPFLSHdll) \ - X(TPFL2dll) \ - X(TPRHOdll) \ - X(TQFLSHdll) \ - X(TRNPRPdll) \ - X(TSFLSHdll) \ - X(VIRBdll) \ - X(VIRCdll) \ - X(WMOLdll) \ - X(XMASSdll) \ - X(XMOLEdll) - -// Get the platform identifiers -#include "CoolPropTools.h" - -// Define compiler specific calling conventions -// for the shared library. -#if defined(__ISWINDOWS__) - #define CALLCONV __stdcall -#else - #define CALLCONV -#endif - -// define new macros for function names -// http://stackoverflow.com/questions/195975/how-to-make-a-char-string-from-a-c-macros-value -#include -#define STR_VALUE(arg) #arg -#define FUNCTION_NAME(name) STR_VALUE(name) -#define STRINGIFY(name) STR_VALUE(name) - -// I'll try to follow this example from: -// http://www.gershnik.com/tips/cpp.asp -// function type: typedef void [compiler stuff] func_t(int, float); -// function declaration: func_t func; -// pointer type: typedef func_t * func_ptr; -#ifdef __cplusplus -extern "C" { -#endif - - // For C calling conventions, replaced all "double &" with "double *", and "long &" with "long *" - typedef void (CALLCONV RPVersion_TYPE)( char* ); - typedef void (CALLCONV SETPATHdll_TYPE)( const char* ); - typedef void (CALLCONV ABFL1dll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV ABFL2dll_TYPE)(double *,double *,double *,long *,long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV ACTVYdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV AGdll_TYPE)(double *,double *,double *,double *,double *); - typedef void (CALLCONV CCRITdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV CP0dll_TYPE)(double *,double *,double *); - typedef void (CALLCONV CRITPdll_TYPE)(double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV CSATKdll_TYPE)(long *,double *,long *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV CV2PKdll_TYPE)(long *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV CVCPKdll_TYPE)(long *,double *,double *,double *,double *); - typedef void (CALLCONV CVCPdll_TYPE)(double *,double *,double *,double *,double *); - typedef void (CALLCONV DBDTdll_TYPE)(double *,double *,double *); - typedef void (CALLCONV DBFL1dll_TYPE)(double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DBFL2dll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DDDPdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV DDDTdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV DEFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DHD1dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV DHFL1dll_TYPE)(double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DHFL2dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DHFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DIELECdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV DOTFILLdll_TYPE)(long *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DPDD2dll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV DPDDKdll_TYPE)(long *,double *,double *,double *); - typedef void (CALLCONV DPDDdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV DPDTKdll_TYPE)(long *,double *,double *,double *); - typedef void (CALLCONV DPDTdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV DPTSATKdll_TYPE)(long *,double *,long *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DSFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DSFL1dll_TYPE)(double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV DSFL2dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV ENTHALdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV ENTROdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV ESFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV FGCTYdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV FPVdll_TYPE)(double *,double *,double *,double *,double *); - typedef void (CALLCONV FUGCOFdll_TYPE)(double *,double *,double *,double*, long *,char*,long ); - typedef void (CALLCONV GERG04dll_TYPE)(long *,long *,long *,char*,long ); - typedef void (CALLCONV GETFIJdll_TYPE)(char*,double *,char*,char*,long ,long ,long ); - typedef void (CALLCONV GETKTVdll_TYPE)(long *,long *,char*,double *,char*,char*,char*,char*,long ,long ,long ,long ,long ); - typedef void (CALLCONV GIBBSdll_TYPE)(double *,double *,double *,double *,double *); - typedef void (CALLCONV HSFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV INFOdll_TYPE)(long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV LIMITKdll_TYPE)(char*,long *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ,long ); - typedef void (CALLCONV LIMITSdll_TYPE)(char*,double *,double *,double *,double *,double *,long ); - typedef void (CALLCONV LIMITXdll_TYPE)(char*,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ,long ); - typedef void (CALLCONV MELTPdll_TYPE)(double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV MELTTdll_TYPE)(double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV MLTH2Odll_TYPE)(double *,double *,double *); - typedef void (CALLCONV NAMEdll_TYPE)(long *,char*,char*,char*,long ,long ,long ); - typedef void (CALLCONV PASSCMNdll_TYPE)(char *,long *,long *,long *,char *,long*,double *, double *, long*, char*, long, long, long); - typedef void (CALLCONV PDFL1dll_TYPE)(double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PDFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PEFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PHFL1dll_TYPE)(double *,double *,double *,long *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PHFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PHIXdll_TYPE)(long *,long *,double *,double *,double *, double *); - typedef void (CALLCONV PHI0dll_TYPE)(long *,long *,double *,double *,double *, double *); - typedef void (CALLCONV PQFLSHdll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PREOSdll_TYPE)(long *); - typedef void (CALLCONV PRESSdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV PSFL1dll_TYPE)(double *,double *,double *,long *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PSFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV PUREFLDdll_TYPE)(long *); - typedef void (CALLCONV QMASSdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV QMOLEdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV RESIDUALdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV REDXdll_TYPE)(double *,double *,double *); - typedef void (CALLCONV RMIX2dll_TYPE)(double *,double *); - typedef void (CALLCONV SATDdll_TYPE)(double *,double *,long *,long *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SATEdll_TYPE)(double *,double *,long *,long *,long *,double *,double *,double *,long *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SATHdll_TYPE)(double *,double *,long *,long *,long *,double *,double *,double *,long *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SATPdll_TYPE)(double *,double *,long *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SATSdll_TYPE)(double *,double *,long *,long *,long *,double *,double *,double *,long *,double *,double *,double *,long *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SATTdll_TYPE)(double *,double *,long *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SATSPLNdll_TYPE)(double *,long *,char*,long ); - typedef void (CALLCONV SETAGAdll_TYPE)(long *,char*,long ); - typedef void (CALLCONV SETKTVdll_TYPE)(long *,long *,char*,double *,char*,long *,char*,long ,long ,long ); - typedef void (CALLCONV SETMIXdll_TYPE)(char*,char*,char*,long *,char*,double *,long *,char*,long ,long ,long ,long ,long ); - typedef void (CALLCONV SETMODdll_TYPE)(long *,char*,char*,char*,long *,char*,long ,long ,long ,long ); - typedef void (CALLCONV SETREFdll_TYPE)(char*,long *,double *,double *,double *,double *,double *,long *,char*,long ,long ); - typedef void (CALLCONV SETUPdll_TYPE)(long *,char*,char*,char*,long *,char*,long ,long ,long ,long ); - typedef void (CALLCONV SPECGRdll_TYPE)(double *,double *,double *,double *); - typedef void (CALLCONV SUBLPdll_TYPE)(double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SUBLTdll_TYPE)(double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SURFTdll_TYPE)(double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV SURTENdll_TYPE)(double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TDFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TEFLSHdll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV THERM0dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV THERM2dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV THERM3dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV THERMdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *); - typedef void (CALLCONV THFLSHdll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TPFLSHdll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TPFL2dll_TYPE)(double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TPRHOdll_TYPE)(double *,double *,double *,long *,long *,double *,long *,char*,long ); - typedef void (CALLCONV TQFLSHdll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TRNPRPdll_TYPE)(double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV TSFLSHdll_TYPE)(double *,double *,double *,long *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,double *,long *,char*,long ); - typedef void (CALLCONV VIRBdll_TYPE)(double *,double *,double *); - typedef void (CALLCONV VIRCdll_TYPE)(double *,double *,double *); - typedef void (CALLCONV WMOLdll_TYPE)(double *,double *); - typedef void (CALLCONV XMASSdll_TYPE)(double *,double *,double *); - typedef void (CALLCONV XMOLEdll_TYPE)(double *,double *,double *); - - /* Define explicit function pointers - * Each will look something like: typedef RPVersion_TYPE * RPVersion_POINTER; - * - * The ## are needed to escape the _ character in the variable names - * - * ***MAGIC WARNING**!! X Macros in use - * See http://stackoverflow.com/a/148610 - * See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511 - */ - #define X(name) typedef name ## _TYPE * name ## _POINTER; - LIST_OF_REFPROP_FUNCTION_NAMES - #undef X - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif // REFPROP_LIB_H \ No newline at end of file From fd7a5a7bf0952b054b59a182c4d81d5c1843a84f Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Thu, 18 Dec 2014 11:35:42 +0100 Subject: [PATCH 2/4] Updated the external submodules --- externals/Catch | 2 +- externals/Eigen | 2 +- externals/REFPROP-headers | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/externals/Catch b/externals/Catch index 08dc8458..694c4d7a 160000 --- a/externals/Catch +++ b/externals/Catch @@ -1 +1 @@ -Subproject commit 08dc8458c0210217575a0cf332a641290cd6056d +Subproject commit 694c4d7a593a49140841273fdf0b3f767679f46a diff --git a/externals/Eigen b/externals/Eigen index 58dc47ff..4ff82ebc 160000 --- a/externals/Eigen +++ b/externals/Eigen @@ -1 +1 @@ -Subproject commit 58dc47ff34ae6ff7c8c85ce15769c9d58b1b55af +Subproject commit 4ff82ebc037a9bc9958ff76c6cb167a4bdf09c12 diff --git a/externals/REFPROP-headers b/externals/REFPROP-headers index e001c2fb..8e0cc189 160000 --- a/externals/REFPROP-headers +++ b/externals/REFPROP-headers @@ -1 +1 @@ -Subproject commit e001c2fbd1d9b93bd31b938e7bcbdee57b809170 +Subproject commit 8e0cc1899fa7f9a4db87071d02a2d795239c785f From 3392c7a40c27d3a0e91d5a5e56f7d310141e105e Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Thu, 18 Dec 2014 11:45:13 +0100 Subject: [PATCH 3/4] Added new header file to CMake --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ede42dc7..34c8d724 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ list(REMOVE_ITEM APP_SOURCES "${CMAKE_SOURCE_DIR}/src/CoolPropLib.cpp") set (APP_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/externals/Eigen") +list (APPEND APP_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/externals/REFPROP-headers") foreach (_headerFile ${APP_HEADERS}) get_filename_component(_dir ${_headerFile} PATH) list (APPEND APP_INCLUDE_DIRS ${_dir}) From ae36828ea1dbf6e31cf3ac75f74214cf92fc77c4 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Fri, 19 Dec 2014 11:31:21 +0100 Subject: [PATCH 4/4] Fixed the header handling, closes #362 and partly covers the issues named in #354. --- dev/generate_headers.py | 3 +- dev/scripts/release.bsh | 15 +++++++++- .../REFPROP/REFPROPMixtureBackend.cpp | 30 +++++++++---------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/dev/generate_headers.py b/dev/generate_headers.py index 9c4f2c9d..44678e8c 100644 --- a/dev/generate_headers.py +++ b/dev/generate_headers.py @@ -86,7 +86,7 @@ def TO_CPP(root_dir, hashes): hex_string = ',\n'.join([', '.join(chunk) for chunk in chunks]) # Check if hash is up to date based on using variable as key - if variable not in hashes or (variable in hashes and hashes[variable] != get_hash(hex_string.encode('ascii'))): + if not os.path.isfile(os.path.join(root_dir,'include',outfile)) or variable not in hashes or (variable in hashes and hashes[variable] != get_hash(hex_string.encode('ascii'))): # Generate the output string output = '// File generated by the script dev/generate_headers.py on '+ str(datetime.now()) + '\n\n' @@ -276,6 +276,7 @@ def generate(): import shutil shutil.copy2(os.path.join(repo_root_path, 'externals','Catch','single_include','catch.hpp'),os.path.join(repo_root_path,'include','catch.hpp')) + #shutil.copy2(os.path.join(repo_root_path, 'externals','REFPROP-headers','REFPROP_lib.h'),os.path.join(repo_root_path,'include','REFPROP_lib.h')) version_to_file(root_dir = repo_root_path) gitrev_to_file(root_dir = repo_root_path) diff --git a/dev/scripts/release.bsh b/dev/scripts/release.bsh index 81537fdc..a54dd8c4 100755 --- a/dev/scripts/release.bsh +++ b/dev/scripts/release.bsh @@ -12,6 +12,7 @@ fi CPVERSION="$1" BASEDIR="$HOME/buildbot/server-master/public_html" REPODIR="$HOME/src/CoolPropFull.git" +TMPSDIR="$HOME/src/CoolProp.sources" BINFOLDER="binaries" DOCFOLDER="sphinx" SRCFOLDER="$BASEDIR/$BINFOLDER/source" @@ -54,9 +55,21 @@ if [ "$DRYRUN" != "false" ]; then echo "Dry run; skipping folder date" RSYNC_DRY_RUN=--dry-run else + printMessage "Updating sources" pushd "$REPODIR" git pull - python dev/scripts/git-archive-all $SRCFOLDER/CoolProp_sources.zip + #python dev/scripts/git-archive-all $SRCFOLDER/CoolProp_sources.zip + popd + printMessage "Generating headers" + rsync -a --delete "$REPODIR/" "$TMPSDIR" + pushd "$TMPSDIR" + git reset --hard HEAD + python "dev/generate_headers.py" + rm -rf .git* + cd .. + rm $SRCFOLDER/CoolProp_sources.zip + zip -r $SRCFOLDER/CoolProp_sources.zip $(basename $TMPSDIR) + cd $(basename $TMPSDIR) popd rm -f "$BINFOLDER/README.rst.txt" if [ "$CPVERSION" = "nightly" ]; then diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp index 0529f781..0c220c04 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.cpp +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.cpp @@ -46,7 +46,7 @@ surface tension N/m #endif enum DLLNameManglingStyle{ NO_NAME_MANGLING = 0, LOWERCASE_NAME_MANGLING, LOWERCASE_AND_UNDERSCORE_NAME_MANGLING }; - + #include "REFPROP_lib.h" #include "REFPROPMixtureBackend.h" #include "Exceptions.h" @@ -98,9 +98,9 @@ static char default_reference_state[] = "DEF"; /* Define functions as pointers and initialise them to NULL * Declare the functions for direct access -* +* * Example: SETPATHdll_POINTER SETPATHdll; -* +* * ***MAGIC WARNING**!! X Macros in use * See http://stackoverflow.com/a/148610 * See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511 @@ -113,11 +113,11 @@ void *getFunctionPointer(const char * name, DLLNameManglingStyle mangling_style { std::string function_name; switch(mangling_style){ - case NO_NAME_MANGLING: + case NO_NAME_MANGLING: function_name = name; break; - case LOWERCASE_NAME_MANGLING: + case LOWERCASE_NAME_MANGLING: function_name = lower(name); break; - case LOWERCASE_AND_UNDERSCORE_NAME_MANGLING: + case LOWERCASE_AND_UNDERSCORE_NAME_MANGLING: function_name = lower(name) + "_"; break; } #if defined(__ISWINDOWS__) @@ -147,7 +147,7 @@ double setFunctionPointers() * C) RPVersion -> rpversion_ */ DLLNameManglingStyle mangling_style = NO_NAME_MANGLING; // defaults to no mangling - + SETUPdll = (SETUPdll_POINTER) getFunctionPointer("SETUPdll"); if (SETUPdll == NULL){ // some mangling in use SETUPdll = (SETUPdll_POINTER) getFunctionPointer("setupdll"); @@ -164,11 +164,11 @@ double setFunctionPointers() } } } - + /* Set the pointers, platform independent - * + * * Example: RPVersion = (RPVersion_POINTER) getFunctionPointer(STRINGIFY(RPVersion)); - * + * * ***MAGIC WARNING**!! X Macros in use * See http://stackoverflow.com/a/148610 * See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511 @@ -176,7 +176,7 @@ double setFunctionPointers() #define X(name) name = (name ## _POINTER) getFunctionPointer(STRINGIFY(name), mangling_style); LIST_OF_REFPROP_FUNCTION_NAMES #undef X - + return COOLPROP_OK; } @@ -202,7 +202,7 @@ bool load_REFPROP() // If REFPROP is not loaded if (RefpropdllInstance==NULL) { - + // Load it #if defined(__ISWINDOWS__) /* We need this logic on windows because if you use the bitness @@ -266,14 +266,14 @@ bool load_REFPROP() } #endif #endif - + if (setFunctionPointers()!=COOLPROP_OK) { printf("There was an error setting the REFPROP function pointers, check types and names in header file.\n"); throw CoolProp::AttributeError("There was an error setting the REFPROP function pointers, check types and names in header file."); return false; } - char rpv[255]; + char rpv[1000]; RPVersion(rpv); RPVersion_loaded = rpv; return true; @@ -1207,7 +1207,7 @@ void REFPROPMixtureBackend::update(CoolProp::input_pairs input_pair, double valu } long double REFPROPMixtureBackend::call_phixdll(long itau, long idel) { - double val = 0, tau = _tau, delta = _delta; + double val = 0, tau = _tau, delta = _delta; if (PHIXdll == NULL){throw ValueError("PHIXdll function is not available in your version of REFPROP. Please upgrade");} PHIXdll(&itau, &idel, &tau, &delta, &(mole_fractions[0]), &val); return static_cast(val)/pow(static_cast(_delta),idel)/pow(static_cast(_tau),itau);