CoolProp low level tabular for Matlab

326 views
Skip to first unread message

Mark335

unread,
Aug 25, 2016, 3:15:27 PM8/25/16
to coolprop-users
Many of the users and examples are in Python or C.

Can anyone help to understand how to utilize the low level interface and Tabular Interpolation features of CoolProp?

The high level interface is working perfectly, but 99% of my computation time of 150 seconds is being spent in the CoolProp wrapper function in Matlab.

I would like to evaluate if using the low level interface or Tabular Interpolation could help to speed this up significantly.

Ian Bell

unread,
Aug 26, 2016, 1:30:30 AM8/26/16
to coolpro...@googlegroups.com
Here is an example of calling low-level interface through the DLL directly, implemented in MATLAB: http://www.coolprop.org/dev/coolprop/wrappers/MATLAB/index.html#calling-low-level-interface-through-dll  It is from our development docs, and yes, the speedup should be VERY significant.  MATLAB is a poor language for interfacing with low-level code, and results in unfortunately either a) a convenient and user friendly, but slow high-level interface (what you are using), or b) Very painful interfacing to the guts of CoolProp through the DLL directly.  It works, but it's quite verbose.  You might want to build your own MATLAB wrapper scripts to hide a lot of the messy stuff you need to do.

Best,
Ian

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.
Visit this group at https://groups.google.com/group/coolprop-users.
For more options, visit https://groups.google.com/d/optout.

Mark335

unread,
Aug 31, 2016, 1:46:42 AM8/31/16
to coolprop-users
Ian,

Can you provide some more detailed help on how to implement the low level interface and corresponding tabular interpolation?

I tried to use the code directly, but it failed almost immediately at the library step. I am not sure where to get or where to store any library files and the more details or step by step, the better.

Regards


On Thursday, August 25, 2016 at 10:30:30 PM UTC-7, Ian Bell wrote:
Here is an example of calling low-level interface through the DLL directly, implemented in MATLAB: http://www.coolprop.org/dev/coolprop/wrappers/MATLAB/index.html#calling-low-level-interface-through-dll  It is from our development docs, and yes, the speedup should be VERY significant.  MATLAB is a poor language for interfacing with low-level code, and results in unfortunately either a) a convenient and user friendly, but slow high-level interface (what you are using), or b) Very painful interfacing to the guts of CoolProp through the DLL directly.  It works, but it's quite verbose.  You might want to build your own MATLAB wrapper scripts to hide a lot of the messy stuff you need to do.

Best,
Ian
On Thu, Aug 25, 2016 at 1:15 PM, Mark335 <markh...@gmail.com> wrote:
Many of the users and examples are in Python or C.

Can anyone help to understand how to utilize the low level interface and Tabular Interpolation features of CoolProp?

The high level interface is working perfectly, but 99% of my computation time of 150 seconds is being spent in the CoolProp wrapper function in Matlab.

I would like to evaluate if using the low level interface or Tabular Interpolation could help to speed this up significantly.

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.

Ian Bell

unread,
Aug 31, 2016, 10:18:14 AM8/31/16
to coolpro...@googlegroups.com
Mark,

Step #1: Download the appropriate pre-compiled shared library of CoolProp for your computer: http://www.coolprop.org/coolprop/wrappers/SharedLibrary/index.html#pre-compiled-binaries.  If you have a 64-bit windows machine and you are running 64-bit MATLAB (I think you do), you will want the 64-bit windows one.  Place it in the directory with your MATLAB script file

Step #2: Run your script.

Generally, comments like "it failed almost immediately" are quite useless and make it unlikely that you will get useful help.  To be useful, comments like these should be accompanied by screenshots, error log and DETAILED descriptions of what you have already tried, what versions of OS and MATLAB you use, etc. 

Best,
Ian

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.

Mark335

unread,
Aug 31, 2016, 8:40:22 PM8/31/16
to coolprop-users
Ian,

Sorry for the ambiguity.

Thanks for pointing to the files I needed. That helped move me forward. I now get an error on the loadlibrary line 18.

The error is: 

Error using loadlibrary
The specified key is not present in this container.

Error in CoolProp_lowlevel (line 18)
    loadlibrary(libname,'CoolPropLib.h','includepath',path_to_include,'alias','CoolProp'); % loading library with alias coolprop
 
I have restructured the loadlibrary command many different ways. Redownloaded the CoolPropLib.h file and verified all file names and paths are copy and pasted direct.

I am running Windows 10 64bit and Matlab 2015b.

Any further help would be very appreciated to get this to run.

Regards,

Ian Bell

unread,
Sep 1, 2016, 12:43:16 AM9/1/16
to coolpro...@googlegroups.com
What code did you try to run?  

When you run "mex -setup" at the matlab shell (without the quotes), what do you get?  MATLAB needs access to a compiler, but I think the error message should be different in that case.

Where did you put the CoolPropLib.h?

Maybe it is a windows 10 problem, but I don't think it should be.

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Mark335

unread,
Sep 1, 2016, 11:21:44 AM9/1/16
to coolprop-users
I was trying to run the example you directed me towards for Matlab from http://www.coolprop.org/dev/coolprop/wrappers/MATLAB/index.html#calling-low-level-interface-through-dll.

The CoolPropLib.h file is located c:\users\username\documents\matlab\CoolProp\include

Running mex -setup in Matlab starts the default comiler setup. This was performed earlier with the mingw compiler and completing mex -setup the "Done" message appears after the options file is updated indicating it was completed without errors

Ian Bell

unread,
Sep 1, 2016, 8:34:45 PM9/1/16
to coolpro...@googlegroups.com
I've not tried to use mingw with MATLAB before, I don't think that is the problem, but I don't have any experience with this error either, so who knows...  Can you try on windows 7 somehow?  That's pretty much the architecture I have been using, and I haven't had serious problems.


Perhaps your MATLAB installation is corrupted?  That's what the google links suggest.

Ian


To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.

Mark335

unread,
Sep 2, 2016, 1:19:08 AM9/2/16
to coolprop-users
I have tried the same Matlab example on Mac OS X with Matlab 2015b and Xcode as the compiler.

The output and error is similar and is shown below.

libname =

libCoolProp

Error using loadlibrary
There was an error loading the library "libCoolProp"
dlopen(libCoolProp.dylib, 6): image not found

Error in CoolProp_lowlevel (line 18)
    loadlibrary(libname,'CoolPropLib.h','includepath',path_to_include,'alias','CoolProp');
    % loading library with alias coolprop


Caused by:
    Error using loaddefinedlibrary
    dlopen(libCoolProp.dylib, 6): image not found

Ian Bell

unread,
Sep 2, 2016, 10:26:17 AM9/2/16
to coolpro...@googlegroups.com
Weird.  I have MATLAB on OSX 10.9, I can try this evening

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Mark335

unread,
Sep 2, 2016, 8:17:13 PM9/2/16
to coolprop-users
Ian,

I have CoolProp and the low level interface working on Mac OS X 10.11. Haven't figured out the issue in the Windows environment yet, but will keep working on that.

One reason I want to go to this method was due to computation errors in the saturation region where the internal CoolProp solver was failing because it was iterating internally to a value below the saturation temperature causing an error to a temperature which was too low. The input temperature was at the saturation condition, but when solving, the internal routine was iterating to solve for enthalpy from and input of Q and T.

To ensure I benefit most from the low level tabular interpolation, I want to ensure I am properly using it. 
The Tabular Interpolation page says:

"It is critical that you try to only initialize one AbstractState instance and then call its methods. The overhead for generating an AbstractState instance when using TTSE or BICUBIC is not too punitive..."

For the Matlab example provided on CoolProp's website which you pointed me to earlier, the script loads the library if not loaded, initializes points, uses the AbstractState_factory to set the handle, and then calls the library function to calculate the values.

Is the AbstractState_factory the instance to call only once or is there some other aspect to this I am missing?

For instance, are you saying to avoid the scenario where I put that entire Matlab example code into a function and then call that function 10000 times thereby checking for library, setting AbstactState_factory, and calling the library function 10000?

Instead, the AbstractState_factory would be called outside of the function and only the library function is called in the function 10000 times? Does that method work when you have many functions and functions of functions calling the same Coolprop library function?

Regards,
Reply all
Reply to author
Forward
0 new messages