From charlesreid1

No edit summary
Line 40: Line 40:


=CTI Code=
=CTI Code=
==Conversion of CTI to XML==


CTI files can be generated from the ck2cti app, contained in <code>cantera/src/apps/ck2cti.cpp</code>, 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.
CTI files can be generated from the ck2cti app, contained in <code>cantera/src/apps/ck2cti.cpp</code>, 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.

Revision as of 22:57, 29 January 2014

CTI = CanTera Input file

CTI files use a custom markup language to specify information about the kinetics.

A CTI file must specify information about three things:

Division of CTI Files

The file can be divided into multiple parts:

  • Phase specification
  • Species
    • Gas species
    • Surface species
  • Reactions
    • Gas reactions
    • Surface reactions

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 Code

Conversion of CTI to XML

CTI files can be generated from the ck2cti 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.

CTI files are then turned into XML files, which is ultimately the format used by Cantera, 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) {

The code that deals with CTI files is actually in two lines of Python code:

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, then moves to the write() method, where it builds each piece of information specified in the CTI into an XML data structure, which is then written to a file.