CoolProp inside OpenFOAM library - error 'key [CO2] was not found........'

248 views
Skip to first unread message

Edo Macchi

unread,
Oct 1, 2015, 11:17:32 AM10/1/15
to coolprop-users

Hello,


I am trying to use CoolProp in OpenFOAM, a C++ library mainly used for CFD.


I successfully build a simple solver (for transient heat conduction) whose purpose was to check whether I could effectively use the C++ low-level interface of CoolProp inside OpenFOAM. This solver works just fine.


Next I wanted to build an OpenFOAM thermophysical model (in practice it's a shared library) that uses CoolProp to compute density,thermal conductivity, viscosity, etc.

I tried building the library (always using the C++ low-level interface of CoolProp) and after some problems I have succeeded building it without errors. However when I tried using the new library in a standard OpenFOAM CFD solver (linking also CoolProp using a static library, as done in the simple heat transfer solver) I got the following CoolProp error:


terminate called after throwing an instance of 'CoolProp::CoolPropError<(CoolProp::CoolPropBaseError::ErrCode)4>'

what(): key [CO2] was not found in string_to_index_map in JSONFluidLibrary

Abandon (core dumped)


The error clearly comes from this definition:


shared_ptr<CoolProp::AbstractState> CarbonDioxide(CoolProp::AbstractState::factory("HEOS","CO2"));


If I understand correctly it seems that the string CO2 is not recognized. This is quite strange since it's exactly the same definition I used in the simple solver that works. The only difference is that now the definition is inside a library while before it was in the main source code of the solver.

Any suggestions? Is there a way to solve or bypass this error?


Thank you.

Best regards,


Edoardo


csr...@unife.it

unread,
Jan 31, 2017, 3:15:31 AM1/31/17
to coolprop-users
Hello Edo,

I would like to implement the Coolprop libraries inside OpenFOAM, and I just started to look at the source file.

I was wondering if you succeeded in the implementation or if you drop this topic.

Thanks in advance for your suggestions!

Nicola

Edo Macchi

unread,
Feb 1, 2017, 9:12:15 AM2/1/17
to coolprop-users
Hello Nicola,

well, to be precise I succeeded in the implementation but then I dropped the topic since I had to focus on another problem where I could use CoolProp directly in C++/OpenFOAM without the need of a thermophysical library (modelling an unsteady flow network+conjugated heat transfer).

However a few months ago I restarted working on this. At the time I discarded the CoolProp model implemented in OpenFOAM and decided to use a tabulated library (one of the two you can find in the OpenFOAM forum on cfd-online). I had two main motives: 1) the implementation OpenFOAM+CoolProp still had some speed problems; 2) in any case even with CoolProp you need to use the "tabulated" backend since solving the full EOS is simply too slow for a CFD simulation.

Your question gave me the opportunity to invest a few hours on improving the implementation of CoolProp in OpenFOAM (through there are still some additional changes that can be done). Furthermore I made some speed tests discovering (unexpectedly) that the tabulated OpenFOAM library is much slower than the corresponding thermophysical model that uses CoolProp (tabulated backend BICUBIC&HEOS). The speed up is 7.7 times!!

Of course the CoolProp implementation works for my problem (sCO2 flow) but it's not general purpose (for sure there will be problems for reactive flows).

Some more general info concerning CFD simulations with variable properties (with large changes):
-if possible separate the temperature/pressure dependence (in particular the pressure could lead to crashes or instabilities);
-if possible use analytical interpolations (even if quite complex or with several ifs it's much faster than table interpolation, in my case, for example, speed up x40).

Starting from the source is the right approach. First it's better to understand how to use the low-level C++ interface of CoolProp (this is quite simple). Then I suggests to study very well the thermophysical library of OpenFOAM. Unfortunately it is quite complex (at least it was for me) but I could make changes to the library (for example adding low level calls for the properties (e.g., thermo.Cp(scalar,scalar)) only after understanding it's structure.

I can give you some help for the implementation and if you want I can probably share some of the code.

What kind of problem are you interested in?

Best regards,

Edoardo
Reply all
Reply to author
Forward
0 new messages