Skip to the content.

The ThermoPack C++ wrapper is a header-only wrapper designed to be compatible with stl containers like std::vector, and to support use of std::unique_ptr and cousins. In short, it is intended to make using ThermoPack together with modern C++ as painless as possible.

Installing ThermoPack

The ThermoPack C++ wrapper is a header-only wrapper, that simplifies linking to the libthermopack binary. A pre-built ThermoPack library can be downloaded from the GitHub release page.

Once you have downloaded and unzipped the appropriate zip file for your system, you should see a directory structure like

|-- thermopack-<system>/
  |-- thermopack-config.cmake
  |-- addon/
    |-- cppThermopack/
  |-- installed/

Make sure to set the environment variable THERMOPACK_DIR to the thermopack-<system> directory (where thermopack-config.cmake is located) with export THERMOPACK_DIR=path/to/thermopack-<system>. You can also add this to your .bash_profile or similar.

Building ThermoPack on macOS or Linux

If you prefer to build ThermoPack from source:

git clone https://github.com/thermotools/thermopack.git
cd thermopack
mkdir build
cd build
cmake ..
make install
cd ..
export THERMOPACK_DIR=${PWD}

This should generate the file thermopack/installed/libthermopack.[so/dylib/dll], which you will later be linking to.

If you have any issues, see the installation guide.

You may want to add export THERMOPACK_DIR=path/to/thermopack to your .bash_profile, or equivalent, as well.

Building ThermoPack on Windows

Building ThermoPack from source using command prompt:

git clone https://github.com/thermotools/thermopack.git
cd thermopack
git submodule update --init --remote --recursive
mkdir build
cd build
cmake ..
cmake --build . --config Release --target install
cd ..
set THERMOPACK_DIR=%cd%

ThermoPack headers

The header files you will need are found in thermopack/addon/cppThermoPack/cppThermoPack.

Including and linking ThermoPack

Note: Before including ThermoPack in your project, ensure that you have compiled and installed ThermoPack by following the instructions for building with cmake, and that the environment variable THERMOPACK_DIR is set to the directory where thermopack-config.cmake is located.

An example CMakeLists.txt is found in thermopack/addon/cppExamples. In essence, all that is required to include ThermoPack is to add the following to your CMakeLists.txt:

set(THERMOPACK_DIR "/path/to/thermopack") # Not nessecary if THERMOPACK_DIR is set as an environment variable
find_library(THERMOPACK REQUIRED)

add_executable(<my_program> <my_source.cpp>)
add_library(<my_lib> <my_lib_source.cpp>)
# etc.

target_link_libraries(<my_program> thermopack) # find_library ensures that the imported target "thermopack" is available
target_link_libraries(<my_lib> thermopack)
# etc.

When building on Linux You should add the line

set_target_properties(<my_target> PROPERTIES 
                            INSTALL_RPATH ${THERMOPACK_INSTALL_DIR}
                            INSTALL_RPATH_USE_LINK_PATH TRUE)

to your CMakeLists.txt. This will add the THERMOPACK_INSTALL_DIR to your library/programs runtime search path (@rpath) and ensure that your binary will find the thermopack dynamic library at runtime if it is moved or installed to some other location than where it is built.

After the find_library(THERMOPACK REQUIRED) command has been run, several convenience variables will have been defined:

Library structure

The ThermoPack C++ wrapper defines a class structure that is almost identical to the structure in the python wrapper. All equations of state inherit from the Thermo class (defined in thermo.h), and only implement initialization and possibly some utility methods.

In addition, several utility structures are defined in utils.h. These include the Property and VectorProperty classes, which are used to hold computed values and derivatives. The structures support implicit conversion to respectively double and std::vector<double>, such that their existence can be ignored unless you are interested in computing derivatives.

The result of phase equilibrium calculations, such as flash- and saturation point calculations, are returned as a FlashResult object, which holds the attributes

Examples

Note: Before compiling the examples, you must have installed ThermoPack. ThermoPack will not be built as part of the build procedure for the examples.

Some sample programs using ThermoPack in C++ are found in the directory thermopack/addon/cppExamples. To build them, navigate to that directory, and

mkdir build
cd build
cmake ..
cmake --build . --config Release

This will build the examples as executables in the build directory.

Currently implemented examples are

Make sure libthermopack.[so/dylib/dll] is avaialble for the dynamic loader when running the examples by linking/copying the file to the build directory.