# OpenLB Automatic Code Generation

Common subexpression elimination (CSE) is an established approach to reducing
the arithmetic complexity of computation kernels in LBM. OpenLB currently provides
CSE-optimized versions of common LBM library functions [1] as well as various
collision operators [2].

These CSE-optimized partial template specializations are generated automatically
using the `cse.py` utility implemented in the present folder. It is applied to
all changed `*.cse.template` files when calling `make cse` from the OpenLB root.

This functionality is possible by combining a lightweight wrapper around the
CSE algorithm provided by the SymPy CAS [3] and dynamic Python C++ bindings
generated by cppyy [4].

## Basic usage

- Install all dependencies (SymPy, cppyy, Mako)
  See `conda.env` for a full listing.
- Modify / extend the desired template (e.g. `src/dynamics/collisionLES.cse.template` for LES collisions)
- Call `make cse` (this takes quite a while, parallel make recommended)

All usage of CSE-optimized functions can be disabled by declaring

> #define DISABLE_CSE

prior to including the OpenLB header files.

[1]: `src/dynamics/lbm.h` resp. `src/dynamics/lbm.cse.h`
[2]: e.g. `src/dynamics/collision.h` resp. `src/dynamics/collision.cse.h`
[3]: https://www.sympy.org
[4]: https://cppyy.readthedocs.io/en/latest/
