From 5bf57795fc63171767e8e729945c996208b551b9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 15 Apr 2016 13:00:08 -0400 Subject: [PATCH] [Doc] Add slicing and dict-based compositions to Python tutorial --- doc/sphinx/cython/tutorial.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/sphinx/cython/tutorial.rst b/doc/sphinx/cython/tutorial.rst index d679b67f8..97f1dec37 100644 --- a/doc/sphinx/cython/tutorial.rst +++ b/doc/sphinx/cython/tutorial.rst @@ -126,6 +126,12 @@ fractions (``Y``):: >>> gas1.X = 'CH4:1, O2:2, N2:7.52' +Mass and mole fractions can also be set using `dict` objects, for cases where +the composition is stored in a variable or being computed:: + + >>> phi = 0.8 + >>> gas1.X = {'CH4':1, 'O2':2/phi, 'N2':2*3.76/phi} + When the composition alone is changed, the temperature and density are held constant. This means that the pressure and other intensive properties will change. The composition can also be set in conjunction with the intensive @@ -185,6 +191,27 @@ Or to set the mass fractions while holding temperature and pressure constant:: >>> gas1.TPX = None, None, 'CH4:1.0, O2:0.5' +Working with a Subset of Species +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Many properties of a `Solution` provide values for each species present in the +phase. If you want to get values only for a subset of these species, you can use +Python's "slicing" syntax to select data for just the species of interest. To +get the mole fractions of just the major species in `gas1`, in the order +specified, you can write: + + >>> Xmajor = gas1['CH4','O2','CO2','H2O','N2'].X + +If you want to use the same set of species repeatedly, you can keep a reference +to the sliced phase object: + + >>> major = gas1['CH4','O2','CO2','H2O','N2'] + >>> cp_major = major.partial_molar_cp + >>> wdot_major = major.net_production_rates + +The slice object and the original object share the same internal state, so +modifications to one will affect the other. + Working With Mechanism Files ----------------------------