OpenFOAM + Cantera

Overview

reactingCanteraFoam

OpenFOAM version Cantera version

This solver calls Cantera to update T psi mu alpha D in OpenFOAM

I have run test cases in Cantera-2.4 Cantera 2.5.1 with OpenFOAM. And the flame structures are better than that from reactingFoam. Since I have no time to test the performance thoroughly, I hope someone can do this if interested.

The tool to convert Cantera results to OpenFOAM fields is from JSqueo299 in GitHub.

The correct of transport equation is copied from ZSHtju in GitHub.

How to compile

You can compile Cantera source code, to generate c++ library and headers, which is used in this OpenFOAM solver.

Or using libcantera installed by conda:

conda install -c cantera libcantera-devel

in this way, you should change Make/options to :

-I/path_to_anaconda3/envs/yourEnvName/include

/path_to_anaconda3/envs/yourEnvName/lib/libcantera_shared.so

PS: if you want to use Cantera Python module, you have to install it individually:

conda install -c cantera cantera

If you just want to run this solver for a try, you can use my pre-compiled Cantera-2.5.2 library and headers in cantera_build:

cd cantera_build/lib
tar -zxvf libcantera_shared2.5.2.so.tar.gz
ln -s libcantera_shared2.5.2.so libcantera_shared.so.2
cd ../..
wmake

How to use

You can run the testCase:

cd testCase
export LD_LIBRARY_PATH=../cantera_build/lib:$LD_LIBRARY_PATH
export CANTERA_DATA=../cantera_build/data
reactingCanteraFoam

Or you can build your flame in OpenFOAM by these steps:

  • python adiabatic_flame.py, to generate a premixed flame, you will get adiabatic_flame.csv
  • matlab Ctr2OF.m, which will convert adiabatic_flame.csv to OpenFOAM 0 folder
  • rebuild mesh according to the output of MATLAB (domain length and grid number, uniform mesh)
  • run reactingCanteraFoam with following settup in constant/thermophysicalProperties
Sct 0.7;// ignore it if laminar
mechanismFile "h2_konnov_2008.xml"; // put the cantera mech file (*.cti or *.xml) in $FOAM_CASE or $CANTERA_DATA
transportModel "Mix"; // you can also try other transport models from Cantera: Multi, UnityLewis, Ion, water, HighP
Issues
  • Some minor issues with the installation

    Some minor issues with the installation

    1. If you don't use the pre-compiled Cantera 2.5.2 library and installed your own Cantera instead. During compilation, you might meet errors like missing or couldn't find 'newTransportMgr' and 'newSolution'. It is all about how Cantera is installed. Try the following installation after git clone Cantera:

    git checkout tags/v2.5.1 git submodule update

    python3 /usr/bin/scons build prefix= system_fmt=n system_eigen=n system_sundials=n python3 /usr/bin/scons test python3 /usr/bin/scons install #sudo might required

    1. The warning of missing header during compilation can be ignored. If anyone wants to avoid this, in the Make/options, we need many -I options for EXE_INC = (e.g.): -I$(LIB_SRC)/../../../DNS/solver/reactingCanteraFoam/cantera/include/cantera/transport \

    2. The solver is for OF7 at the time of this post. These are what I did to port it to OF6: createFieldRefs.H

    a. scalar nSpecies= composition.species().size(); //new line 17 b. if (gas->nSpecies() != nSpecies) //line 19 -> use nSpecies to avoid warning c const word Yname = "diff_" + Y[i].name(); //new line 44 d. dimensionedScalar(Yname, dimDensitydimVelocitydimLength, 0.0) // line 59: Yname is used here e. dimensionedScalar("diffsh", dimEnergy/dimTime/dimVolume, 0.0) //line 102: add "diffsh" f. dimensionedVector("vk", dimensionSet(1,0,-3,0,0,0,0), Foam::vector(0,0,0)) //line 115: add "vk" g. dimensionedScalar("Hsi", dimEnergy/dimMass, 0.0 //line 128: add "Hsi"

    YEqn.H //line 1, 2, and 3 initialize with dimensionedVector, replace zero h. vk = dimensionedVector("vk", dimensionSet(1,0,-3,0,0,0,0), Foam::vector(0,0,0)); i. diffsh = dimensionedScalar("diffsh", dimEnergy/dimTime/dimVolume, 0.0); j. DiffError = dimensionedVector("DiffError", dimDynamicViscosity/dimLength, Foam::vector(0,0,0)); k. X[i][cellI] = Y[i][cellI]*MW[cellI]/composition.W(i); // replace composition.Wi(i) l. YiEqn.solve(mesh.solver("Yi")); // replace "Yi" in () (make sure units are consistent by yourself....and check new commits...)

    opened by WWIIWWIIWW 0
Owner
Yan Zhang
OpenFOAM, Combustion modeling, Spray combustion
Yan Zhang
In-situ data analyses and machine learning with OpenFOAM and Python

PythonFOAM: In-situ data analyses with OpenFOAM and Python Using Python modules for in-situ data analytics with OpenFOAM 8. NOTE that this is NOT PyFO

Argonne Leadership Computing Facility - ALCF 99 May 11, 2022
OpenFOAM is a free, open source computational fluid dynamics (CFD) software package

acousticStreamingFoam About OpenFOAM OpenFOAM is a free, open source computational fluid dynamics (CFD) software package released by the OpenFOAM Foun

Bruno 1 Nov 2, 2021