Skip to content

Add pytabprops support for the mixing model without Cantera

Mike Hansen requested to merge mahanse/py_mixmdl into master

Hi @james and @elizabeth! Pytabprops and conda-based toolchains have me excited about using Spitfire and TabProps together. Being able to use the PDFs and integrator in Python would be a nice addition. I'd like to take a reaction model built in Spitfire and, with pytabprops, entirely in Python without intermediate tables or input files, create and visualize a table for a turbulent flow.

This change grafts on a new CMake variable that lets me build the mixing model code without Cantera (only needed for the reaction preprocessors) and puts a simple interface (pybind is so cool!) around the Beta and Clipped Gaussian PDFs. I can call get_pdf and integrate(LagrangeInterpolant1D) from Python. I'll note that TabProps' integrator is about 200x faster than using scipy's quad_vec with a scipy interpolant and lambda x: scipyinterp(x) * mdl.get_pdf(x) as the integrand. There could be a number of reasons for the performance difference, but I really don't care since I can just use TabProps anyway ;).

There's also a little Python test setup in here, which could be expanded for the higher-dimensional interpolants, and which could include correctness testing on the PDFs, although I'm not sure that's totally warranted at this level. We could probably just verify that the Python API is working correctly - the mean/variance are correct, etc.

So the best part about this is skipping the cantera source build and using conda to get boost. I didn't install a single TPL myself. Here's the configure script I was running with the environment setup commented out. Note boost-cpp in there. CMake not being too smart with Python (it finds system Python even with the conda environment active) is annoying but could possibly be resolved with an environment variable prior to running cmake for automated builds.

# set up the tool chain
# conda create --name cppenv python=3.7
# conda activate cppenv
# conda install numpy scipy matplotlib
# conda install -c anaconda cmake
# conda install -c conda-forge boost-cpp
# conda install -c conda-forge pybind11

# set up a build dir
# mkdir build
# cd build

# and then run this script (../configure), build, and test
cmake .. \
     -DPYTHON_LIBRARY=/opt/anaconda3/envs/cppenv/lib/libpython3.7m.a \
     -DPYTHON_INCLUDE_DIR=/opt/anaconda3/envs/cppenv/bin/python3.7m \
     -DPYTHON_EXECUTABLE=/opt/anaconda3/envs/cppenv/bin/python3.7 \
     -DENABLE_PYTHON=ON \
     -DENABLE_MIXMDL=ON \
     -DTabProps_UTILS=ON \
     -DTabProps_PREPROCESSOR=OFF \
     -DTabProps_ENABLE_TESTING=ON \
     -DCMAKE_BUILD_TYPE=Release

# make -j4 install
# ctest
# or ctest -R "pytabprops"
Edited by James Sutherland

Merge request reports