Skip to content
Aalto-CFDPublic

About

DLBFoam: An open-source dynamic load balancing model for fast reacting flow simulations in OpenFOAM. https://doi.org/10.1016/j.cpc.2021.108073, https://doi.org/10.1063/5.0077437

Resources

Stars

104 stars

Watchers

10 watching

Forks

Latest commit

 

History

562 Commits

Folders and files

Repository files navigation

DLBFoam: Dynamic load balancing for fast reactive simulations

OpenFOAM dev

What is DLBFoam?

DLBFoam is an open-source library for OpenFOAM that accelerates chemistry calculations in parallel simulations through dynamic load balancing and a zonal reference mapping model.

DLBFoam also provides a fully analytical chemistry Jacobian via pyJac and optimized ODE solution routines via LAPACK. Combined with the load balancing features, these optimizations provide speed-ups of up to 250× compared to the standard OpenFOAM chemistry model.

The library can also be used solely for dynamic load balancing without the third-party pyJac and LAPACK dependencies.

Why do I need this?

Load imbalance in parallel reactive simulations is an issue that causes very long simulation times in OpenFOAM simulations utilizing finite-rate chemistry.

DLBFoam introduces runtime load balancing through MPI routines to minimize the load imbalance between ranks and achieve speed-up. The implementation details can be found in our paper [1]. In addition, the cellwise chemistry problem is significantly improved by the analytical Jacobian formulation and optimized matrix operations in the ODE solver class. The details for those implementations can be found in our follow-up paper [2].

crab pet

Prerequisites

  • OpenFOAM installation. dev and three latest official releases are maintained in corresponding branches. You can find older versions under tags and releases.
  • LAPACK (Intel MKL, OpenBLAS or standalone)
  • CMake
  • ct2foam (Optional)

Compilation

DLBFoam can be compiled by typing the following command after sourcing appropriate OpenFOAM version and making sure a valid LAPACK installation exists:

./Allwmake --clean --platform <LAPACK_INSTALLATION_TYPE>

<LAPACK_INSTALLATION_TYPE> can be MKL, OPENBLAS or STANDALONE.

DLBFoam requires LAPACK packages for improved ODE routines (LAPACKE C interface for OPENBLAS and standalone installation). There are three different ways to provide LAPACK for DLBFoam:

  • Intel-MKL: We recommend Intel-MKL libraries to be used together with DLBFoam whenever you are working on machines with Intel-based architecture. See further information and installation guidelines for Intel-MKL. Note that DLBFoam assumes, that the MKLROOT environment variable is set to represent the installation path according to the standard library installation scripts.

  • OpenBLAS: Another option is to utilise OpenBLAS library, which includes LAPACK routines. In this case, DLBFoam assumes that the OPENBLAS_INSTALL_ROOT environment variable is set to represent the OpenBLAS installation path successfully.

  • Standalone: A standalone installation may be a good idea if you are on your personal workstation and not on a cluster. You can see if you have the necessary lapacke dependency by e.g. executing ldconfig -p | grep "liblapacke". In case not, on debian systems you could e.g. install the requirements (including header files) by:

    (sudo) apt-get install liblapacke-dev
    

The default installation location is $FOAM_USER_LIBBIN. To install to $WM_PROJECT_SITE use:

WM_BUILD=site ./Allwmake --platform <LAPACK_INSTALLATION_TYPE>

To attempt to install to the core OpenFOAM installation ($FOAM_LIBBIN) (Use with caution as it overwrites dynamic code dictionaries!), use:

WM_BUILD=core ./Allwmake --platform <LAPACK_INSTALLATION_TYPE>

Mechanism generation

After the successful compilation, mechanism files for tutorials are compiled automatically, so you can run tutorials right away. If you want to use another mechanism, the C subroutines generated by the pyJac for the analytical Jacobian should be compiled and linked to the OpenFOAM case folder.

In this repository, we provide the input files and C subroutines generated by pyJac for GRI-3.0, Yao, and DRM-19 mechanisms. If you want to use one of these mechanisms, no other dependency is required (except a CMake installation).

  • Go to the utilities/ folder, and execute Allrun as:
./Allrun -m <mechName>

where <mechName> is gri30, yao, or drm19. This command will generate a compiled mechanism library <mechName>/lib/build/libc_pyjac.so. You need to put this mechanism library along with properties file located in <mechName>/foam/ to e.g. constant/foam/ folder and link them in controlDict, as explained in the next section.

If you want to use a different chemical mechanism, you need to create the thermo input files in a format required by OpenFOAM, as well as analytical Jacobian C subroutines generated by pyJac. This process requires many dependencies, most notably Cantera and pyJac.

We have developed a tool called ct2foam that makes this process a lot easier. Please check ct2foam (and pyjac2foam utility in it) if you are interested in using a different mechanism.

Usage

Once the compilation is successful, any case running with standard OpenFOAM can be easily converted to use DLBFOAM, by following these steps:

  • DLBFoam should be linked to the solver. Add the following to your system/controlDict file:
libs
(
    "libchemistryModel_DLB.so"
    "libODE_DLB.so"
    "$FOAM_CASE/constant/foam/libc_pyjac.so"
);

the first two libraries link the DLBFoam and the optimized LAPACK solvers, while the last library links the C subroutines generated in the previous section for the analytical Jacobian.

  • Select type loadBalanced_pyJac in constant/chemistryProperties:
type    loadBalanced_pyJac;
  • Add the loadbalancing subdictionary to the same chemistryProperties file:
loadbalancing
{
    active true;
    log	   true;
}
  • Set the solver flag under ode to seulex_LAPACK in order to use the optimized ODE solvers:
ode
{
    solver          seulex_LAPACK;
    absTol          1e-08;
    relTol          1e-05;
}
  • (Optional) Set the refmapping as active in chemistryProperties file if you want to use the reference mapping method:
refmapping
{
    active  true;


refmapping
{
    active          true;
    field           Z;
    min             0;
    max             1e-4;
}
    tolerance	1e-4;  // field tolerance
    deltaT	2; // temperature tolerance
}

Reference mapping uses a given field and maps a reference solution to reference cells satisfying a condition. You can use mixture fraction (Z) field by setting up the mixture fraction function object with executeInterval set on every time step.

In the example above, for each CFD iteration DLBFoam finds a reference solution where min<Z<max and solves the chemistry. Subsequent cells following the same condition are mapped from this reference solution.

(Optional) When deltaT is explicitly set, the mapper also checks the temperature between reference solution and other reference cells and ensures: abs(Tcell-Tref)<deltaT.

  • (Optional) In-situ adaptive tabulation (ISAT) is compatible with DLBFoam since OpenFOAM 12. Check commented out section in chemistryProperties of shearlayer_DLB_pyJac tutorial for an example.

  • Mechanism reduction is supported by loadBalanced, but not by loadBalanced_pyJac.

  • Disable load balancing (loadbalancing { active false; }) for reaction rates that depend on local mesh fields, such as fluxLimitedLangmuirHinshelwood. Offloaded problems do not transfer those fields to the receiving rank.

  • Run the case normally with OpenFOAM's reactive solvers.

For a working example, check the tutorials given in tutorials folder.

FAQ

Undefined symbol: eval_h

/path/to/user/OpenFoam/linux64GccDPInt32Opt/lib/libchemistryModel_DLB.so: undefined symbol: eval_h

Compiled mechanism library (libc_pyjac.so) cannot be found. Please read Mechanism Generation section of the README. Check if a correct path is set in controlDict and the file exists.

Tutorial works in serial, but it hangs in parallel

The reason might be that both OpenBLAS and LAPACKE are installed in your system and interfering with each other. This mostly happens in personal computers rather than clusters where software are controlled by modules. On your personal system, please follow the instructions below to mitigate this issue:

  1. Find all the OpenBlas related packages installed on your machine with dpkg --get-selections | grep openblas and remove all of them.
  2. Remove liblapacke-dev and install it again as (sudo) apt-get install liblapacke-dev.
  3. Recompile the code with the compilation flag --clean for STANDALONE platform: ./Allwmake --clean --platform STANDALONE

Contributors

Getting help and reporting bugs

Please submit a GitHub issue if you find a bug in the program. If you need help with the software or have further questions, either open an issue or contact the contributors.

Citation

If you use our model, please cite publications describing its implementation, Refs. [1] and [2].

References

[1] B. Tekgül, P. Peltonen, H. Kahila, O. Kaario, V. Vuorinen, DLBFoam: An open-source dynamic load balancing model for fast reacting flow simulations in OpenFOAM, Computer Physics Communications, Volume 267, 10.1016/j.cpc.2021.108073 (2021).

BibTex

@article{tekgul2021dlbfoam,
  title={DLBFoam: An open-source dynamic load balancing model for fast reacting flow simulations in OpenFOAM},
  author={Tekg{\"u}l, Bulut and Peltonen, Petteri and Kahila, Heikki and Kaario, Ossi and Vuorinen, Ville},
  journal={Computer Physics Communications},
  pages={108073},
  year={2021},
  publisher={Elsevier}
}

[2] I. Morev, B. Tekgül, M. Gadalla, A. Shahanaghi, J. Kannan, S. Karimkashi, O. Kaario, V. Vuorinen, Fast reactive flow simulations using analytical Jacobian and dynamic load balancing in OpenFOAM, Physics of Fluids 34, 021801, 10.1063/5.0077437 (2022).

BibTex

@article{morev2022fast,
  author = {Morev,Ilya  and Tekg{\"u}l,Bulut  and Gadalla,Mahmoud  and Shahanaghi,Ali  and Kannan,Jeevananthan  and Karimkashi,Shervin  and Kaario,Ossi  and Vuorinen,Ville },
  title = {{Fast reactive flow simulations using analytical Jacobian and dynamic load balancing in OpenFOAM}},
  journal = {Physics of Fluids},
  volume = {34},
  number = {2},
  pages = {021801},
  year = {2022},
  doi = {10.1063/5.0077437},
}

About

DLBFoam: An open-source dynamic load balancing model for fast reacting flow simulations in OpenFOAM. https://doi.org/10.1016/j.cpc.2021.108073, https://doi.org/10.1063/5.0077437

Resources

Stars

104 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages