diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fe751f0..c2ca84cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,11 +192,37 @@ if (COOLPROP_EES_MODULE) set_target_properties (COOLPROP_EES PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DCOOLPROP_LIB -DCONVENTION=__cdecl") add_dependencies (COOLPROP_EES generate_headers) set_target_properties(COOLPROP_EES PROPERTIES SUFFIX ".dlf" PREFIX "") + # Put the version into the InnoInstaller setup file + CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/wrappers/EES/BuildInnoInstaller.iss.in" "${CMAKE_CURRENT_BINARY_DIR}/BuildInnoInstaller.iss") if (!MSVC) set_target_properties(COOLPROP_EES PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") endif() - add_dependencies (COOLPROP_EES generate_headers) - install (TARGETS COOLPROP_EES DESTINATION EES/${CMAKE_SYSTEM_NAME}) + add_dependencies (COOLPROP_EES generate_headers) + + if ( MSVC ) + set_target_properties( COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) + set_target_properties( COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}) + set_target_properties( COOLPROP_EES PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}) + # etc for the other available configuration types (MinSizeRel, RelWithDebInfo) + endif () + # copy required files + set(REQUIRED_FILES + CoolProp.htm + CoolProp.LIB + CoolProp_EES_Sample.EES + ) + foreach (_FILE ${REQUIRED_FILES}) + add_custom_command(TARGET COOLPROP_EES + PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/wrappers/EES/${_FILE} ${CMAKE_CURRENT_BINARY_DIR}/.) + endforeach() + + # Run InnoSetup to make the installer (must be on your path) + add_custom_command(TARGET COOLPROP_EES + POST_BUILD + COMMAND Compil32.exe /cc BuildInnoInstaller.iss + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + install (TARGETS ${CMAKE_CURRENT_BINARY_DIR}/Output/SetupCOOLPROP_EES.exe DESTINATION EES/${CMAKE_SYSTEM_NAME}) endif() if (COOLPROP_OCTAVE_MODULE) @@ -552,8 +578,9 @@ if (COOLPROP_SNIPPETS) set_target_properties( ${snippet_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/bin ) # etc for the other available configuration types (MinSizeRel, RelWithDebInfo) endif () - message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/bin/${snippet_name} > ${CMAKE_CURRENT_BINARY_DIR}/bin/${snippet_name}.output") # Run it and save the output to a file with .output appended + message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/bin/${snippet_name} > ${CMAKE_CURRENT_BINARY_DIR}/bin/${snippet_name}.output") + add_custom_command(TARGET ${snippet_name} POST_BUILD COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/${snippet_name} > ${CMAKE_CURRENT_BINARY_DIR}/bin/${snippet_name}.output) diff --git a/Readme.txt b/Readme.txt index 47b02ff4..8925e886 100644 --- a/Readme.txt +++ b/Readme.txt @@ -6,3 +6,30 @@ It was originally developed by Ian Bell, currently a post-doc at the University To see whats new, go to http://coolprop.sourceforge.net/changelog.html +Developers +========== + +Light debugging +--------------- +1. Install COOLPROP_EES +2. Append '$DEBUG' to the fluid name +3. Open the log.txt and log_stdout.txt files in c:\ees32\userlib\COOLPROP_EES + +Hardcore debugging +------------------ +To use a debug DLL, do (from root of repo) + +mkdir build/EES +cd build/EES +cmake ../.. -G "Visual Studio 10 2010" -DCOOLPROP_EES_MODULE=ON + +open the visual studio project, for the COOLPROP_EES project: + +1. Change the output directory to C:\ees32\userlib\COOLPROP_EES (this is where the DLF will go) +2. Under debugging, set the command to c:\ees32\ees +3. Set a breakpoint somewhere that it will get hit (in the COOLPROP_EES function for instance) +4. Run the project, it will build and start EES, open your code or call some inputs for EES +5. Debugger should stop at your breakpoint + + + diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index 2ec7bde8..8ed706dc 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -109,11 +109,7 @@ void FlashRoutines::PQ_flash(HelmholtzEOSMixtureBackend &HEOS) { if (HEOS.is_pure_or_pseudopure) { - double pc = HEOS.components[0]->pEOS->reduce.p; - double Tc = HEOS.components[0]->pEOS->reduce.T; - double Tt = HEOS.components[0]->pEOS->Ttriple; - double pt = HEOS.components[0]->pEOS->ptriple; - double Tsat_guess = 1/(1/Tc-(1/Tt-1/Tc)/log(pc/pt)*log(HEOS._p/pc)); + if (HEOS.components[0]->pEOS->pseudo_pure){ // It is a psedo-pure mixture @@ -156,6 +152,13 @@ void FlashRoutines::PQ_flash(HelmholtzEOSMixtureBackend &HEOS) } else { + + double pc = HEOS.components[0]->pEOS->reduce.p; + double Tc = HEOS.components[0]->pEOS->reduce.T; + double Tt = HEOS.components[0]->pEOS->Ttriple; + double pt = HEOS.components[0]->pEOS->ptriple; + double Tsat_guess = 1/(1/Tc-(1/Tt-1/Tc)/log(pc/pt)*log(HEOS._p/pc)); + // Set some imput options SaturationSolvers::mixture_VLE_IO io; io.sstype = SaturationSolvers::imposed_p; diff --git a/src/Backends/Helmholtz/Fluids/FluidLibrary.h b/src/Backends/Helmholtz/Fluids/FluidLibrary.h index 9552e478..a8abe468 100644 --- a/src/Backends/Helmholtz/Fluids/FluidLibrary.h +++ b/src/Backends/Helmholtz/Fluids/FluidLibrary.h @@ -1086,6 +1086,9 @@ public: for (std::size_t i = 0; i < fluid.aliases.size(); ++i) { string_to_index_map[fluid.aliases[i]] = index; + + // Add uppercase alias for EES compatibility + string_to_index_map[upper(fluid.aliases[i])] = index; } if (get_debug_level() > 5){ std::cout << format("Loaded.\n"); } diff --git a/src/main.cxx b/src/main.cxx index 2e75d8c3..f21c8d17 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -58,12 +58,13 @@ struct element int main() { - #if 1 - - double T = PropsSI("T","P",8.7257510472904255e+02,"Q",0.0000000000000000e+00,"Water"); + #if 0 + double T = PropsSI("P","T",5.9020000000000005e+02,"Q",0.0000000000000000e+00,"AceticAcid"); + std::cout << get_global_param_string("errstring"); + double Tc = Props1SI("Water","T_triple"); std::cout << get_global_param_string("errstring"); - double Tc = Props1SI("Water","Tcrit"); double rhoc = Props1SI("Water","rhocrit"); + double pc = Props1SI("Water","pcrit"); std::cout << Tc << rhoc << std::endl; #endif @@ -132,15 +133,22 @@ int main() // std::cout << s << std::endl; // int rr =0; // } - CoolProp::set_debug_level(1); + CoolProp::set_debug_level(11); - #if 0 - double rr0 = HumidAir::HAPropsSI("H","T",473.15,"W",0,"P",101325); - CoolProp::set_reference_stateS("Air","RESET"); - double rr1 = HumidAir::HAPropsSI("H","T",473.15,"W",0,"P",101325); + #if 1 + std::cout << get_global_param_string("incompressible_list_pure"); + std::cout << get_global_param_string("incompressible_list_solution"); + double rr2 = CoolProp::PropsSI("T","P",101325,"Q",0,"WATER"); + double rra = CoolProp::PropsSI("C","T",300,"D",1e-10,"HEOS::R1234ze(E)"); + double rrv = CoolProp::PropsSI("C","T",300,"D",1e-10,"REFPROP::R1234ze"); + + std::cout << get_global_param_string("errstring"); + double rr0 = HumidAir::HAPropsSI("B","T",473.15,"W",0.5,"P",101325); + //CoolProp::set_reference_stateS("Air","RESET"); + double rr1 = HumidAir::HAPropsSI("B","T",473.15,"W",0.5,"P",101325); int r = 1; #endif - #if 0 + #if 1 // First type (slowest, most string processing, exposed in DLL) double r0A = PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]"); // Default backend is HEOS double r0B = PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]"); @@ -200,7 +208,7 @@ int main() double rr = 0; return 0; #endif - #if 0 + #if 1 { std::string NBP_refs[] = {"D5","D6","MD2M","MDM","Benzene","Helium","Ethylene","Ethanol","n-Dodecane","Benzene","n-Undecane","Neon","Fluorine","Methanol","Acetone","Methane","Ethane","n-Pentane","n-Hexane","n-Heptane","n-Octane","CycloHexane","MD3M","MM","D4","MethylPalmitate","MethylStearate","MethylOleate","MethylLinoleate","MethylLinolenate","m-Xylene"}; std::string IIR_refs[] = {"SES36","R143a","CycloPropane","Propylene","R227EA","R365MFC","R161","HFE143m","SulfurHexafluoride","CarbonDioxide","R1234ze(E)","R22","R124","Propyne","R507A","R152A","R123","R11","n-Butane","IsoButane","RC318","R21","R114","R13","R12","R113","R1233zd(E)","R41"}; @@ -223,7 +231,7 @@ int main() for (std::size_t i = 0; i < sizeof(IIR_refs)/sizeof(IIR_refs[0]); ++i) { try{ - //set_reference_stateS(IIR_refs[i],"RESET"); + set_reference_stateS(IIR_refs[i],"RESET"); std::vector comps(1,IIR_refs[i]); HelmholtzEOSMixtureBackend HEOS(comps); HEOS.update(QT_INPUTS, 0, 273.15); @@ -373,7 +381,7 @@ int main() double rr = 4; } #endif - #if 0 + #if 1 { #if ENABLE_CATCH std::vector tags; diff --git a/wrappers/EES/BuildDLF.bat b/wrappers/EES/BuildDLF.bat deleted file mode 100644 index 4b5d2066..00000000 --- a/wrappers/EES/BuildDLF.bat +++ /dev/null @@ -1,12 +0,0 @@ -REM ******** set the variables ************ -call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" -call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" - -REM ******* compile all the sources *************** -cl /c /MP3 /I../../CoolProp /EHsc ../../CoolProp/*.cpp - -REM ******* compile the wrapper *************** -cl /c /EHsc /I../../CoolProp main.cpp -link /DLL *.obj /OUT:COOLPROP_EES.dlf - -erase *.obj \ No newline at end of file diff --git a/wrappers/EES/BuildDLFGCC.bat b/wrappers/EES/BuildDLFGCC.bat deleted file mode 100644 index ab09bf78..00000000 --- a/wrappers/EES/BuildDLFGCC.bat +++ /dev/null @@ -1,5 +0,0 @@ -REM ******* compile all the sources from CoolProp*************** -g++ -c -Wall -I../../CoolProp ../../CoolProp/*.cpp -g++ -c -Wall -I../../CoolProp main.cpp -g++ -shared -o COOLPROP_EES.dlf *.o -Wl -erase *.o \ No newline at end of file diff --git a/wrappers/EES/BuildDLL.bat b/wrappers/EES/BuildDLL.bat deleted file mode 100644 index 47003b1c..00000000 --- a/wrappers/EES/BuildDLL.bat +++ /dev/null @@ -1,13 +0,0 @@ -REM ******** set the variables ************ -call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" -call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" - -REM ******* compile all the sources *************** -cl /c /MP3 /I../../CoolProp /EHsc /DCOOLPROP_LIB /D"CONVENTION=__cdecl" ../../CoolProp/*.cpp - -mkdir dll -link /DLL *.obj /OUT:dll\CoolProp.dll -copy dll\CoolProp.dll . -dumpbin /EXPORTS CoolProp.dll > exports.txt -erase *.obj -erase *.exp \ No newline at end of file diff --git a/wrappers/EES/BuildInnoInstaller.iss.in b/wrappers/EES/BuildInnoInstaller.iss.in index 73c7a2cc..8a0694fb 100644 --- a/wrappers/EES/BuildInnoInstaller.iss.in +++ b/wrappers/EES/BuildInnoInstaller.iss.in @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "CoolProp" -#define MyAppVersion "${COOLPROP_VERSION}" +#define MyAppVersion "${CoolProp_VERSION}" #define MyAppPublisher "University of Liege" #define MyAppURL "www.coolprop.org" @@ -33,7 +33,6 @@ Source: "CoolProp.htm"; DestDir: "{app}"; Flags: ignoreversion Source: "CoolProp.LIB"; DestDir: "{app}"; Flags: ignoreversion Source: "COOLPROP_EES.dlf"; DestDir: "{app}"; Flags: ignoreversion Source: "CoolProp_EES_Sample.EES"; DestDir: "{app}"; Flags: ignoreversion -Source: "coolpropsi.LIB"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] diff --git a/wrappers/EES/CoolProp.LIB b/wrappers/EES/CoolProp.LIB index 6994d164..e96aee20 100644 Binary files a/wrappers/EES/CoolProp.LIB and b/wrappers/EES/CoolProp.LIB differ diff --git a/wrappers/EES/CopyDLF.bat b/wrappers/EES/CopyDLF.bat deleted file mode 100644 index cfbbe0a9..00000000 --- a/wrappers/EES/CopyDLF.bat +++ /dev/null @@ -1,2 +0,0 @@ -copy COOLPROP_EES.dlf c:\EES32\Userlib\COOLPROP_EES\ -copy CoolProp.dll c:\EES32\Userlib\COOLPROP_EES\ \ No newline at end of file diff --git a/wrappers/EES/build.json b/wrappers/EES/build.json deleted file mode 100644 index 6cc27c0a..00000000 --- a/wrappers/EES/build.json +++ /dev/null @@ -1,14 +0,0 @@ -[ -{ -"pre" : "", -"sources" : ["%PACKAGE_HOME%/main.cpp"], -"platform" : ["Windows"], -"compiler" : "VS+", -"bitness" : 32, -"c_flags" : "/MP3 /I../../include /EHsc", -"link_type" : "DLL", -"link_fname" : "COOLPROP_EES.dlf", -"link_flags" : "", -"post" : "" -} -] \ No newline at end of file diff --git a/wrappers/EES/exports.txt b/wrappers/EES/exports.txt deleted file mode 100644 index 7cc629db..00000000 --- a/wrappers/EES/exports.txt +++ /dev/null @@ -1,76 +0,0 @@ -Microsoft (R) COFF/PE Dumper Version 10.00.40219.01 -Copyright (C) Microsoft Corporation. All rights reserved. - - -Dump of file CoolProp.dll - -File Type: DLL - - Section contains the following exports for CoolProp.dll - - 00000000 characteristics - 535908FE time date stamp Thu Apr 24 14:52:14 2014 - 0.00 version - 1 ordinal base - 50 number of functions - 50 number of names - - ordinal hint RVA name - - 1 0 000A6950 DerivTerms - 2 1 000A6930 F2K - 3 2 001070D0 HAProps - 4 3 001088A0 HAProps_Aux - 5 4 0009EC70 IProps - 6 5 0009F650 IPropsSI - 7 6 0009C5F0 IsFluidType - 8 7 000A6910 K2F - 9 8 000A6CA0 Phase - 10 9 000A6D10 Phase_Tp - 11 A 000A6D80 Phase_Trho - 12 B 000A67A0 Props - 13 C 000A66E0 Props1 - 14 D 000A6720 Props1SI - 15 E 000A6760 PropsS - 16 F 000A68A0 PropsSI - 17 10 000CA9B0 conductivity_background - 18 11 000CA930 conductivity_critical - 19 12 000CA530 conformal_Trho - 20 13 000A6EA0 disable_TTSE_LUT - 21 14 000A6F60 disable_TTSE_LUT_writing - 22 15 000A6E20 enable_TTSE_LUT - 23 16 000A6EE0 enable_TTSE_LUT_writing - 24 17 000A69A0 fromSI - 25 18 000A6A40 get_Fluid_index - 26 19 000A7090 get_TTSESinglePhase_LUT_range - 27 1A 000A6A20 get_debug_level - 28 1B 000A6C30 get_fluid_param_string - 29 1C 000A6BD0 get_global_param_string - 30 1D 000A6BA0 get_param_index - 31 1E 000A7150 get_standard_unit_system - 32 1F 000A6E60 isenabled_TTSE_LUT - 33 20 000A6F20 isenabled_TTSE_LUT_writing - 34 21 000CAB90 psatL_anc - 35 22 000CAC40 psatV_anc - 36 23 000A6620 redirect_stdout - 37 24 000CAA10 rhosatL_anc - 38 25 000CAAD0 rhosatV_anc - 39 26 000A6FA0 set_TTSESat_LUT_size - 40 27 000A7030 set_TTSESinglePhase_LUT_range - 41 28 000A6FE0 set_TTSESinglePhase_LUT_size - 42 29 000A6A70 set_TTSE_mode - 43 2A 000A6A30 set_debug_level - 44 2B 000A6DF0 set_phase - 45 2C 000A6690 set_reference_stateD - 46 2D 000A6650 set_reference_stateS - 47 2E 000A7160 set_standard_unit_system - 48 2F 000A69E0 toSI - 49 30 000CA7E0 viscosity_dilute - 50 31 000CA860 viscosity_residual - - Summary - - 20000 .data - 9C000 .rdata - 25000 .reloc - 1FC000 .text diff --git a/wrappers/EES/main.cpp b/wrappers/EES/main.cpp index 0c5d0687..c204ab4f 100644 --- a/wrappers/EES/main.cpp +++ b/wrappers/EES/main.cpp @@ -29,13 +29,13 @@ // // // Ian Bell // // Thermodynamics Laboratory // -// University of Liège // +// University of Liège // // // // January 2013 // //============================================================================================// #define _CRT_SECURE_NO_WARNINGS -#include +#include #include #include #include @@ -43,7 +43,7 @@ #include "CoolProp.h" #include "CoolPropTools.h" -static const bool EES_DEBUG = false; +static bool EES_DEBUG = false; // Structure for handling ees calling syntax struct EesParamRec { @@ -54,8 +54,7 @@ struct EesParamRec { using namespace CoolProp; // Tell C++ to use the "C" style calling conventions rather than the C++ mangled names - -extern "C" +extern "C" { __declspec (dllexport) double COOLPROP_EES(char fluid[256], int mode, struct EesParamRec *input_rec) { @@ -66,19 +65,19 @@ extern "C" std::vector z; - std::string ErrorMsg, Outstr, In1str, In2str, Fluidstr; + std::string ErrorMsg, Outstr, In1str, In2str, Fluidstr, Units; std::vector fluid_split; if (mode==-1) { - strcpy(fluid,"T = coolprop('D','P',101.325,'Q',0,'R134a')"); + strcpy(fluid,"T = PropsSI('T','P',101325,'Q',0,'Water')"); return 0; } // Split the string that is passed in at the '~' delimiter that was used to join it fluid_split = strsplit(fluid_string,'~'); - if (fluid_split.size() != 4) + if (fluid_split.size() != 5) { - sprintf(err_str,"fluid[%s] length[%d] not 4 elements long",fluid_string.c_str(),fluid_split.size()); + sprintf(err_str,"fluid[%s] length[%d] not 5 elements long",fluid_string.c_str(),fluid_split.size()); strcpy(fluid,err_str); if (EES_DEBUG) { @@ -95,6 +94,15 @@ extern "C" Outstr = upper(fluid_split[1]); In1str = upper(fluid_split[2]); In2str = upper(fluid_split[3]); + Units = upper(fluid_split[4]); + } + + if (Fluidstr.find("$DEBUG") != std::string::npos){ + EES_DEBUG = true; + Fluidstr = Fluidstr.substr(0,Fluidstr.find("$DEBUG")); + } + else{ + EES_DEBUG = false; } // Check the number of inputs @@ -128,31 +136,47 @@ extern "C" { FILE *fp; fp = fopen("log.txt","a+"); - fprintf(fp,"%s %s %g %s %g %s\n",Outstr.c_str(),In1str.c_str(),In1,In2str.c_str(),In2,Fluidstr.c_str()); + fprintf(fp,"Inputs: %s %s %g %s %g %s %s\n",Outstr.c_str(),In1str.c_str(),In1,In2str.c_str(),In2,Fluidstr.c_str(), Units.c_str()); fclose(fp); } - //~ if (EES_DEBUG) - //~ { - //~ // This redirect standard output to file2.txt - //~ freopen("log_stdout.txt", "w", stdout); - //~ set_debug_level(10); // Maximum debugging - //~ } + if (EES_DEBUG) + { + // This redirects standard output to log_stdout.txt + freopen("log_stdout.txt", "w", stdout); + set_debug_level(100000); // Maximum debugging + } try { - if (z.size() > 0){ - // Mole fractions are given - out = PropsSI(Outstr, In1str, In1, In2str, In2, Fluidstr, z); - } - else{ - out = PropsSI(Outstr, In1str, In1, In2str, In2, Fluidstr); - } + if (!Units.compare("SI")){ + if (z.size() > 0){ + // Mole fractions are given + out = PropsSI(Outstr, In1str, In1, In2str, In2, Fluidstr, z); + } + else{ + // Mole fractions are not given + out = PropsSI(Outstr, In1str, In1, In2str, In2, Fluidstr); + } + } + else{ + // Mole fractions are not given + out = PropsSI(Outstr, In1str, In1, In2str, In2, Fluidstr); + } } catch(...) { std::string err_str = format("Uncaught error: \"%s\",\"%s\",%g,\"%s\",%g,\"%s\"\n",Outstr.c_str(),In1str.c_str(),In1,In2str.c_str(),In2,Fluidstr.c_str()); + // There was an error + if (EES_DEBUG) + { + FILE *fp; + fp = fopen("log.txt","a+"); + fprintf(fp,"Error: %s \n",err_str.c_str()); + fclose(fp); + } strcpy(fluid, err_str.c_str()); + return 0.0; } @@ -186,6 +210,13 @@ extern "C" // There was a warning, write it back strcpy(fluid, warn_string.c_str()); } + if (EES_DEBUG) + { + FILE *fp; + fp = fopen("log.txt", "a+"); + fprintf(fp,"Output: %g\n", out); + fclose(fp); + } return out; } }