From 68aa5da406e198bd1ae3fde5bced548e6db55281 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 29 May 2013 00:12:07 +0000 Subject: [PATCH] [Cython] Translated an example showing how to make a reaction path diagram --- .../cython/cantera/examples/reaction_path.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 interfaces/cython/cantera/examples/reaction_path.py diff --git a/interfaces/cython/cantera/examples/reaction_path.py b/interfaces/cython/cantera/examples/reaction_path.py new file mode 100644 index 000000000..65e55b2ac --- /dev/null +++ b/interfaces/cython/cantera/examples/reaction_path.py @@ -0,0 +1,46 @@ +""" +Viewing a reaction path diagram. + +This script uses Graphviz to generate an image. You must have Graphviz installed +and the program 'dot' must be on your path for this example to work. +Graphviz can be obtained from http://www.graphviz.org/ or (possibly) installed +using your operating system's package manager. +""" + +import os +import sys + +import cantera as ct + +# these lines can be replaced by any commands that generate +# an object of a class derived from class Kinetics in some state. +gas = ct.Solution('gri30.xml') +gas.TPX = 1300.0, ct.one_atm, 'CH4:0.4, O2:1, N2:3.76' +r = ct.Reactor(gas) +net = ct.ReactorNet([r]) +T = r.T +while T < 1900: + net.step(1.0) + T = r.T + +element = 'N' + +diagram = ct.ReactionPathDiagram(gas, element) +diagram.title = 'Reaction path diagram following {0}'.format(element) +diagram.label_threshold = 0.01 + +dot_file = 'rxnpath.dot' +img_file = 'rxnpath.png' +img_path = os.path.join(os.getcwd(), img_file) + +diagram.write_dot(dot_file) +print diagram.get_data() + +print("Wrote graphviz input file to '{0}'.".format(os.path.join(os.getcwd(), dot_file))) + +os.system('dot {0} -Tpng -o{1} -Gdpi=200'.format(dot_file, img_file)) +print("Wrote graphviz output file to '{0}'.".format(img_path)) + +if "-view" in sys.argv: + import webbrowser + webbrowser.open('file:///' + img_path)