Git Product home page Git Product logo

ct2foam's Introduction

ct2foam -- Convert Cantera based thermophysical data To OpenFoam format

ct2foam enables user to generate OpenFoam dictionary entries for NASA-polynomials, Sutherland and other transport models required in thermophysicalProperties file. This python package utilises Cantera to generate such entries for all species in a given chemical mechanism or for gaseous mixtures defined by the user. With the general functions provided in this package, it is also possible to create NASA-polynomial, Sutherland and other polynomial type fits for thermophysical data based on experiments.

Furthermore, this package supports the users of DLBFoam and pyJac by introducing an automated pyjac2foam script which builds a compilation environment for pyjac routines as well as utilises ct2foam to generate consistent thermodynamics dictionaries with pyJac. See pyjac2foam module instructions below for further information.

Installation

Package relies on Cantera installation, for which the recommended installation principle is via conda. Hence, the recommended and easiest installation path is via conda as well. In particular, we recommend using the Miniconda package manager for this.

For users interested to use the pyjac2foam module, python version must be set python<=3.6. Otherwise, the latest releases can be utilised (tested up to python 3.8.8).

  • To install in conda environment:
conda create --name ct2foam_env --channel cantera cantera python=3.6 numpy scipy matplotlib
cd my/installation/path
git clone [email protected]:kahilah/ct2foam.git
cd ct2foam
conda activate ct2foam_env
pip install .
  • To install on ubuntu without conda:

  • To install in other environments:

  • Dependencies are installed automatically:

    • cantera, numpy, scipy, cvxopt, matplotlib
    • Distribution is tested with Cantera 2.5.1
    • setup.py lists the dependencies.

Run tests:

cd ct2foam
python -m unittest discover
  • Note that ct2foam/test_data/OF_reference includes C++ code requiring OpenFoam based compilation. However, this is mainly included here for development / testing purposes and standard user is not required to compile anything here.

Running ct2foam:

  • Installation generates two global executables: ct2foam and ctmix2foam which can be run as follows:

  • ct2foam --input h2o2.cti --output test_output --Tmid 1000.0 --plot

    • outputs OpenFoam compatible thermodynamical and transport dictionary entries under output directory such that NASA-polynomials have a middle temperature of 1000 K. Thermodynamical fits with error larger than user given (or here default) tolerances, will be plotted under output/Figures directory. Supports input arguments --Tlow and --Thigh for low and high temperature limits of the NASA-polynomials, respectively.
  • ctmix2foam --input h2o2.cti --output test_output --name air --mixture "O2:1,AR:4" --Tmid 1000.0 --plot

    • outputs data for a mixture, defines similar to standard input format in Cantera.
  • See ct2foam -h for help.

  • Can be executed as a python modules:

    • python -m ct2foam.scripts.mech2foam
    • python -m ct2foam.scripts.mix2foam
  • Outputs log.txt including all the relevant information related to the particular execution.

  • Note that if you want plots for all species, you need to provide strict tolerance values for transport_fit_quality and nasa7_fit_quality

pyjac2foam

  • pyjac2foam module provides a consistent input of thermochemical data for users utilising DLBFoam and pyJac in OpenFoam environment. In particular, pyjac2foam.sh executable generates:

    • shared libray *.so, compiled with cmake.
    • consistent species ordering between OpenFOAM and pyjac inputs.
    • consistent thermophysicalProperties, chemistsryProperties and controlDict entries for an OpenFOAM case setup.
  • Note that pyJac is not set as a requirement for this python package. To install, ensure that you have python=3.6 installed. Then,

    • conda install -c slackha pyjac (or)
    • pip install pyjac
  • Furthermore, you need cmake to use the automatic library compilation.

  • For a simple test:

cd pyjac2foam/test_data
./run_test.sh
  • How-to:

    • Generate pyjac C-files (requires pyjac):
      • python -m pyjac --lang c --last_species N2 --input my_mechanism.cti
    • Compile + generate *.foam files under the same directory where pyjac output files are located.
      • pyjac2foam -m my_mechanism.cti -i pyjac/path -c
      • Example dictionary entries with correct absolute paths are printed after execution + written into file foam/include_example.txt
  • Notes:

    • note that compilation to a shared library is now with rather standard flags --> depending on the architecture, you may want to optimise CMakeLists
    • you can use pyjac2foam for library compilation with -c / --compile flag, or copy pyjac2foam/cmake_directives directory, modify them and run ./runCmake.sh

Notes

  • See TODO.txt for development to be considered in the future.

Acknowledgements

ct2foam's People

Contributors

arintanen avatar kahilah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ct2foam's Issues

A typing fix and a question

In ct2foam_utils.py, line 178 , "_transport" could possibly change to "_thermo".

Also is there any particular reason that T range is set to [280,3000]? since this range could be different for each specie or could be extended up to 6000K in thermo file.

pyjac still have the Temperature limit

Hi,

recently I used DLBfoam to study detonation problems. I noticed that the thermo.foam file generated with pyjac still has a temperature limit. Tlow = 280.0; Thigh = 3000.0; High temperatures are common in detonation problems, but this triggers a heat warning.

Whether the temperature limit of pyjac can also be lifted.

Regards

pyjac2foam can delete the whole file system if the run path contains spaces!

If pyjac2foam is ran in a location containing spaces, (e.g. /home/user1/some folder_with_space/folder1/folder2),
command " rm -rf $lib_path/" at line number 56 will get translated to "rm -rf /home/user1/ folder_with_space/folder1/folder2", which will remove the entire user's home directory (which already happened in our group today).

Minimum temperature limit

Hi,

I noticed the Minimum temperature of Tlow is 280.0K. Why designed it this way? Is there a way out of this? Because the lowest temperature in my mechanism file is 200K.

Regards

Different JANAF polynomials in chem_utils.c and thermo.foam

ct2foam utility refits JANAF polynomials to get rid of possible discontinuities at Tmid of a polynomial.
The fitted polynomial goes to thermo.foam file, used by thermophysicalProperties module of OpenFOAM.
However, pyJac uses the original .cti file with original JANAF polynomials to generate chem_utils.c, which is then used in the chemistry solver.
Thus, there is an inconsistency where different parts of the code use (probably slightly, but still) different thermal properties, which might lead to convergence/accuracy issues.

I would suggest using refitted polynomials everywhere.
The first thing that comes to my mind is the creation of another file (eg. mech_refitted.cti or use .yaml format as an intermediate step and cti2yaml+yaml2cti) with updated JANAF polynomials, which then can be used with by pyJac

Add a small comment on reactions{} entry

The reactions{} entry generated for the mechanism input files are supposed to be empty, since the reaction information is stored on libc_pyjac.so dynamic lib generated by pyJac.

I got some feedback from users that having no comments led them to think there was something wrong with ct2foam and that reaction information should be there.

So I propose putting a one-line comment explaining that the reaction information is stored in libc_pyjac.so file.

Install error

Hi,

when I build the latest version of ct2foam, some errors occured. Can you give me some suggestions.

(ct2foam_env) scramjetfoam@scramjetFoam:~/OpenFOAM/cantera/ct2foam$ pip install .
Processing /home/scramjetfoam/OpenFOAM/cantera/ct2foam
DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
pip 21.3 will remove support for this functionality. You can find discussion regarding this at pypa/pip#7555.
Collecting cvxopt>=1.2.0
Using cached cvxopt-1.3.2.tar.gz (4.1 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.19.2 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from ct2foam==0.0.1) (1.19.2)
Requirement already satisfied: scipy>=1.5.2 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from ct2foam==0.0.1) (1.5.2)
Requirement already satisfied: matplotlib>=3.3 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from ct2foam==0.0.1) (3.3.4)
Requirement already satisfied: cycler>=0.10 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from matplotlib>=3.3->ct2foam==0.0.1) (0.11.0)
Requirement already satisfied: pillow>=6.2.0 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from matplotlib>=3.3->ct2foam==0.0.1) (8.3.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from matplotlib>=3.3->ct2foam==0.0.1) (3.0.4)
Requirement already satisfied: python-dateutil>=2.1 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from matplotlib>=3.3->ct2foam==0.0.1) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from matplotlib>=3.3->ct2foam==0.0.1) (1.3.1)
Requirement already satisfied: six>=1.5 in /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages (from python-dateutil>=2.1->matplotlib>=3.3->ct2foam==0.0.1) (1.16.0)
Building wheels for collected packages: ct2foam, cvxopt
Building wheel for ct2foam (setup.py) ... done
Created wheel for ct2foam: filename=ct2foam-0.0.1-py3-none-any.whl size=29103 sha256=64b8ece321ec824daf141f55c148a321a6f215c38895b7d4815edcc4d00d906c
Stored in directory: /tmp/pip-ephem-wheel-cache-i541o16_/wheels/95/9f/03/d67af7d32a9a317e4e75ac5f9614162976ab191c62793bde76
Building wheel for cvxopt (PEP 517) ... error
ERROR: Command errored out with exit status 1:
command: /opt/miniconda3/envs/ct2foam_env/bin/python /opt/miniconda3/envs/ct2foam_env/lib/python3.6/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmptag8od85
cwd: /tmp/pip-install-suruxf6i/cvxopt_4264a0279f2444d0b1b152dd6fd98ebb
Complete output (36 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/cvxopt
copying src/python/_version.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/coneprog.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/modeling.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/cvxprog.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/solvers.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/init.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/msk.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/printing.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/misc.py -> build/lib.linux-x86_64-3.6/cvxopt
copying src/python/info.py -> build/lib.linux-x86_64-3.6/cvxopt
running build_ext
building 'base' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
creating build/temp.linux-x86_64-3.6/src/C
gcc -pthread -B /opt/miniconda3/envs/ct2foam_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/miniconda3/envs/ct2foam_env/include/python3.6m -c src/C/base.c -o build/temp.linux-x86_64-3.6/src/C/base.o
gcc -pthread -B /opt/miniconda3/envs/ct2foam_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/miniconda3/envs/ct2foam_env/include/python3.6m -c src/C/dense.c -o build/temp.linux-x86_64-3.6/src/C/dense.o
src/C/dense.c: In function ‘Matrix_NewFromPyBuffer’:
src/C/dense.c:277:28: warning: ‘n.d’ may be used uninitialized [-Wmaybe-uninitialized]
277 | MAT_BUFD(a)[cnt] = n.d;
| ^
src/C/dense.c:255:13: note: ‘n’ declared here
255 | number n;
| ^
gcc -pthread -B /opt/miniconda3/envs/ct2foam_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/miniconda3/envs/ct2foam_env/include/python3.6m -c src/C/sparse.c -o build/temp.linux-x86_64-3.6/src/C/sparse.o
gcc -pthread -shared -B /opt/miniconda3/envs/ct2foam_env/compiler_compat -L/opt/miniconda3/envs/ct2foam_env/lib -Wl,-rpath=/opt/miniconda3/envs/ct2foam_env/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/src/C/base.o build/temp.linux-x86_64-3.6/src/C/dense.o build/temp.linux-x86_64-3.6/src/C/sparse.o -L/usr/lib -lm -llapack -lblas -o build/lib.linux-x86_64-3.6/cvxopt/base.cpython-36m-x86_64-linux-gnu.so
/opt/miniconda3/envs/ct2foam_env/compiler_compat/ld: cannot find -llapack: No such file or directory
/opt/miniconda3/envs/ct2foam_env/compiler_compat/ld: cannot find -lblas: No such file or directory
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
ERROR: Failed building wheel for cvxopt
Successfully built ct2foam
Failed to build cvxopt
ERROR: Could not build wheels for cvxopt which use PEP 517 and cannot be installed directly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.