Cantera/CTI Files
From charlesreid1
CTI = CanTera Input file
CTI files use a custom markup language to specify information about the kinetics.
(You may also be interested in reading the Chemkin page.)
A CTI file must specify information about three things:
- Phases - Cantera/CTI Files/Phases
- Species - Cantera/CTI Files/Species
- Reactions - Cantera/CTI Files/Reactions
Contents
Units Specification
The units are the first thing defined in the file:
units(length = "cm", time = "s", quantity = "mol", act_energy = "J/mol")
Phases
Information about specifying phases in Cantera input file here: Cantera/CTI Files/Phases
Species
Information about specifying species in Cantera input files here: Cantera/CTI Files/Species
Reactions
Information about specifying reactions in Cantera input files here: Cantera/CTI Files/Reactions
CTI-Related Code
Conversion of Chemkin Files to CTI
CTI files can be generated from the ck2cti2 app, contained in cantera/src/apps/ck2cti.cpp
, which is a command-line utility to turn Chemkin-II reaction mechanism files, as well as transport and thermodynamic database files, into a CTI file.
Here is the description of the utility:
ck2cti.py: Convert Chemkin-format mechanisms to Cantera input files (.cti) If the output file name is not given, an output file with the same name as the input file, with the extension changed to '.cti'. Usage: ck2cti --input=<filename> [--thermo=<filename>] [--transport=<filename>] [--id=<phase-id>] [--output=<filename>] [-d | --debug] Example: ck2cti --input=chem.inp --thermo=therm.dat --transport=tran.dat
So to use this, I could run the command:
ck2cti2 --input=input.file --thermo=thermo.file --transport=transport.file --id=phaseid --output=myfile.cti
where input is a Chemkin II reaction mechanism file (the meat of the CTI file), thermo is a file in which to look for thermodynamic data if there is no THERMO section of the Chemkin input file, transport is a file in which to look for transport data (no transport data is put into the final CTI file if this is left off), and phaseid is a string name to give to the phase created in the new CTI file.
Conversion of CTI to XML
Once you have a CTI file (generated by hand, from a modified example, or from a Chemkin input file), the CTI file is then turned into an XML file, which is ultimately the format used by Cantera. This conversion is performed by the ct2ctml app, which is in cantera/src/base/ct2ctml.cpp
. This code, in turn, creates a direct call from C++ to Python.
In ct2ctml.cpp
, the following code block illustrates the call to Python to convert a CTI file to an XML file:
try {
exec_stream_t python;
python.set_wait_timeout(exec_stream_t::s_all, 1800000); // 30 minutes
python.start(pypath(), "-i");
stringstream output_stream;
python.in() <<
"if True:\n" << // Use this so that the rest is a single block
" import sys\n" <<
" sys.stderr = sys.stdout\n" <<
" import ctml_writer\n" <<
" ctml_writer.convert(r'" << file << "')\n" <<
" sys.exit(0)\n\n"
"sys.exit(7)\n";
python.close_in();
std::string line;
while (python.out().good()) {
std::getline(python.out(), line);
output_stream << line << std::endl;;
}
python.close();
python_exit_code = python.exit_code();
python_output = stripws(output_stream.str());
} catch (std::exception& err) {
This C++ code is actually calling the Python code that will do the conversion, using routines defined in cantera/interfaces/python/ctml_writer.py
.
The two lines of Python code that it calls consist of one import statement, and one call to convert the file:
import ctml_writer
ctml_writer.convert( [file] )
The call to ctml_writer
references the Python routines located in cantera/interfaces/python/ctml_writer.py
, which interprets the CTI file and turns it into an XML file.
Looking through the ctml_writer.py
code, you can see that it starts at the convert()
method. The convert method then moves to the write()
method, where it builds each piece of information specified in the CTI into an XML data structure. Finally, that data structure is written to an XML file.
Flags
Cantera all pages on the wiki related to the Cantera combustion microkinetics and thermodynamics (a.k.a. "thermochemistry") software.
Cantera · Cantera Outline · Category:Cantera
Outline of Cantera topics: Cantera Outline · Cantera Outline/Brief Understanding Cantera's Structure: Cantera Structure Cantera from Matlab: Using_Cantera#Matlab Cantera from Python: Using_Cantera#Python Cantera from C++: Using_Cantera#C++ Cantera + Fipy (PDE Solver): Fipy and Cantera/Diffusion 1D Cantera Gas Objects: Cantera/Gases Cantera 1D Domains, Stacks: Cantera_One-D_Domains · Cantera_Stacks Cantera Gas Mixing: Cantera_Gas_Mixing
Topics in Combustion: Diffusion: Cantera/Diffusion · Cantera/Diffusion Coefficients Sensitivity Analysis: Cantera/Sensitivity Analysis Analysis of the Jacobian Matrix in Cantera: Jacobian_in_Cantera Chemical Equilibrium: Chemical_Equilibrium Kinetic Mechanisms: Cantera/Kinetic_Mechanisms Reactor Equations: Cantera/Reactor_Equations Differential vs. Integral Reactors: Cantera/Integral_and_Differential_Reactors Effect of Dilution on Adiabatic Flame Temperature: Cantera/Adiabatic_Flame_Temperature_Dilution
Topics in Catalysis: Cantera for Catalysis: Cantera_for_Catalysis Steps for Modeling 0D Multiphase Reactor: Cantera_Multiphase_Zero-D Reaction Rate Source Terms: Cantera/Reaction_Rate_Source_Terms Surface coverage: Cantera/Surface_Coverage Surface reactions: Cantera/Surface_Reactions
Cantera Input Files: Chemkin file format: Chemkin CTI files: Cantera/CTI_Files · Cantera/CTI_Files/Phases · Cantera/CTI_Files/Species · Cantera/CTI_Files/Reactions
Hacking Cantera: Pantera (monkey patches and convenience functions for Cantera): Pantera Extending Cantera's C API: Cantera/Extending_C_API Extending Cantera with Python Classes: Cantera/Adding Python Class Debugging Cantera: Cantera/Debugging_Cantera Debugging Cantera from Python: Cantera/Debugging_Cantera_from_Python Gas Mixing Functions: Cantera_Gas_Mixing Residence Time Reactor (new Cantera class): Cantera/ResidenceTimeReactor
Resources: Cantera Resources: Cantera Resources Cantera Lecture Notes: Cantera_Lecture
Category:Cantera · Category:Combustion Category:C++ · Category:Python Flags · Template:CanteraFlag · e |
Installing Cantera notes on the wiki related to installing the Cantera thermochemistry software library.
Cantera Installation: Mac OS X 10.5 (Leopard): Installing_Cantera#Leopard Mac OS X 10.6 (Snow Leopard): Installing_Cantera#Snow_Leopard · Cantera2 Config Mac OS X 10.7 (Lion): Installing_Cantera#Lion Mac OS X 10.8 (Mountain Lion): Installing_Cantera#Mountain_Lion Ubuntu 12.04 (Precise Pangolin): Installing_Cantera#Ubuntu Windows XP: Installing_Cantera#Windows_XP Windows 7: Installing_Cantera#Windows_7
Cantera Preconfig: In old versions of Cantera, a preconfig file was used to specify library locations and options. Mac OS X 10.5 (Leopard) preconfig: Cantera_Preconfig/Leopard_Preconfig Mac OS X 10.6 (Snow Leopard) preconfig: Cantera_Preconfig/Snow_Leopard_Preconfig Mac OS X 10.8 (Mountain Lion) preconfig: Cantera_Config/MountainLion_SconsConfig Ubuntu 12.04 (Precise Pangolin) preconfig: Cantera_Config/Ubuntu1204_SconsConfig Flags · Template:InstallingCanteraFlag · e |