From charlesreid1

(Created page with "CTI = CanTera Input file CTI files use a custom markup language to specify information about the kinetics. =Division of the File= The file can be divided into multiple parts: ...")
 
No edit summary
 
(36 intermediate revisions by the same user not shown)
Line 3: Line 3:
CTI files use a custom markup language to specify information about the kinetics.
CTI files use a custom markup language to specify information about the kinetics.


=Division of the File=
(You may also be interested in reading the [[Chemkin]] page.)


The file can be divided into multiple parts:
* Phase specification
* Species
** Gas species
** Surface species
* Reactions
** Gas reactions
** Surface reactions


=Phase Specification=


=Species Specification=
A CTI file must specify information about three things:
* Phases - [[Cantera/CTI Files/Phases]]
* Species - [[Cantera/CTI Files/Species]]
* Reactions - [[Cantera/CTI Files/Reactions]]


=Reaction Specification=


==Surface Reactions==


Any surface reaction can be specified in the cti file using the <code>surface_reaction</code> function. The usage depends on the surface reaction form.
=Units Specification=


There are a variety of forms of surface reactions, each with a different specification method.
The units are the first thing defined in the file:


===Arrhenius Kinetics===
<pre>
units(length = "cm", time = "s", quantity = "mol", act_energy = "J/mol")
</pre>


The plain/default way, which uses Arrhenius kinetics:
=Phases=


<pre>
Information about specifying phases in Cantera input file here: [[Cantera/CTI Files/Phases]]
surface_reaction( "A(s) => B(s) + C",  [A, b, E])
</pre>


where:
=Species=
* A(s), B(s), C - species whose properties are defined in the species section (see above)
* A - Arrhenius parameter, pre-exponential factor (specified in units of...)
* b - Arrhenius parameter, degree of temperature influence on kinetic rate constant
* E - Arrhenius parameter, activation energy of reaction


The Arrhenius expression is:
Information about specifying species in Cantera input files here: [[Cantera/CTI Files/Species]]


<math>
=Reactions=
k = A T^b \exp \left( \frac{E}{RT} \right)
</math>


So, for example, a catalytic reaction where H2O (adsorbed onto a platinum surface) desorbs would look like this:
Information about specifying reactions in Cantera input files here: [[Cantera/CTI Files/Reactions]]


<pre>
=CTI-Related Code=
surface_reaction( "H2O(S) => H2O + PT(S)",  [1.00000E+13, 0, 40300])
</pre>


===Coverage-Dependent Surface Rates===
==Conversion of Chemkin Files to CTI==


The reaction rate may have some kind of... I dunno... coverage dependency, I guess?
CTI files can be generated from the ck2cti2 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.


I'm still working through this. This uses some kind of expression containing a, m, and e:
Here is the description of the utility:  


<pre>
<pre>
surface_reaction( "A(s) => B(s) + C", Arrhenius(A, b, E, coverage=['A(s)', surface_a, surface_m, surface_e])
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
</pre>
</pre>


Attempting to uncover how this is dealt with:
So to use this, I could run the command:


<pre>
<pre>
importKinetics::getCoverageDependence()
ck2cti2 --input=input.file --thermo=thermo.file --transport=transport.file --id=phaseid --output=myfile.cti
rdata.cov vector contains coverage-related parameters/information
rdata.cov.push_back(species_index)
rdata.cov.push_back(a)
rdata.cov.push_back(m)
rdata.cov.push_back(e)
</pre>
</pre>


and then
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.


<pre>
==Conversion of CTI to XML==
InterfaceKinetics::addElementaryReaction
 
if r.cov.size > 3:
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 <code>cantera/src/base/ct2ctml.cpp</code>. This code, in turn, creates a direct call from C++ to Python.
     this rxn is dependent on coverage
 
register rxn
In <code>ct2ctml.cpp</code>, the following code block illustrates the call to Python to convert a CTI file to an XML file:
</pre>
 
<source lang="cpp">
    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) {
</source>
 
This C++ code is actually calling the Python code that will do the conversion, using routines defined in <code>cantera/interfaces/python/ctml_writer.py</code>.


===Sticking Equations===
The two lines of Python code that it calls consist of one import statement, and one call to convert the file:


No idea how this works.
<source lang="python">
import ctml_writer
ctml_writer.convert( [file] )
</source>


<pre>
The call to <code>ctml_writer</code> references the Python routines located in <code>cantera/interfaces/python/ctml_writer.py</code>, which interprets the CTI file and turns it into an XML file.
surface_reaction( "OH + PT(S) => OH(S)",  stick(1.00000E+00, 0, 0))
</pre>


===Duplicate Reactions===
Looking through the <code>ctml_writer.py</code> code, you can see that it starts at the <code>convert()</code> method. The convert method then moves to the <code>write()</code> 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.


<pre>
surface_reaction( "O2 + 2 PT(S) => 2 O(S)",  Arrhenius(1.80000E+21, -0.5, 0),
                  options = 'duplicate')
</pre>


=Flags=


[[Category:Cantera]]
{{CanteraFlag}}

Latest revision as of 08:43, 17 April 2017

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:


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