From charlesreid1

(Created page with "Pantera is a Python library that implements several monkey patches and convenience functions for Cantera. Link to Github repo: https://github.com/charlesreid1/pantera {{C...")
 
No edit summary
Line 3: Line 3:
Link to Github repo: https://github.com/charlesreid1/pantera
Link to Github repo: https://github.com/charlesreid1/pantera


=The Pantera Library Layout=


This section describes the layout of the core source code of Pantera.


Pantera provides classes that interface with and extend Cantera classes.
Pantera also monkey-patches Cantera. Monkey patches are modifications to existing objects that add new features or bring back useful but deprecated features.
Pantera Sub-Modules:
* Cantera Monkey-Patches - patches existing Cantera classes (adds essential functionality ONLY!)
* Gases submodule - gas compositions, gas mixing, gas objects
* Configurations submodule - extends Cantera reactor networks to be more useful and flexible (plug flow reactors, packed bed reactors, ignition reactors, recycle reactors, etc.)
* Reactors submodule - extends Cantera reactors to be more useful (but most of the useful stuff is in the configurations)
* Engineering submodule - applied engineering problems solved with Cantera
==Cantera Monkey-Patches==
There are a couple of monkey patches applied to Cantera. The two classes affected are:
* Cantera.Reactor
* Cantera.Solution
===Solution class Monkey-Patches===
The Solution class is monkey-patched to more easily obtain mass and mole fractions for particular species.
If you have a Solution (bascially a gas phase object) using the Cantera library, you can obtain mass and mole fractions using the somewhat clunky notation:
<pre>
speciesName = ['CH4','O2']
Xs = my_solution[speciesName].X
Ys = my_solution[speciesName].Y
</pre>
This monkey-patch allows for the much more intuitive:
<pre>
speciesName = ['CH4','O2']
Xs = my_solution.mole_fraction( speciesName )
Ys = my_solution.mass_fraction( speciesName )
</pre>
This works when passing a single species names or a lists of species names as a parameter.
===Reactor class Monkey-Patches===
The Reactor class monkey-patches are actually provided in the PanteraReactors.py file in the pantera.reactors submodule. It is described here anyway, since it is still a monkey-patch.
In Cantera 2.0, you could access the state of a Cantera reactor like this:
<pre>
# Cantera 2.0
r = Reactor(my_solution)
print r.temperature()
print r.pressure()
print r.moleFractions()
</pre>
However, Cantera 2.1 created problems by doing away with this. Now, you can only access the temperature of the reactor.
What's worse, if you want to access the pressure and mole fractions of a reactor, you need to use the contents, but Cantera 2.1 also did away with ways of accessing the contents of the reactor. You used to be able to do this:
<pre>
# Cantera 2.0
r = Reactor(my_solution)
c = r._contents
T = c.temperature()
P = c.pressure()
X = c.moleFractions()
</pre>
Again, Cantera 2.1 created problems by doing away with this.
These monkey-patches fix this. Now you can do this:
<pre>
r = Reactor(my_solution)
print r.T
print r.P
print r.X
print r.Y
c = r._contents
print c.T
print c.P
print c.X
print c.Y
</pre>
Woo hoo!


{{CanteraFlag}}
{{CanteraFlag}}
[[Category:Github]]
[[Category:Github]]

Revision as of 07:21, 17 April 2017

Pantera is a Python library that implements several monkey patches and convenience functions for Cantera.

Link to Github repo: https://github.com/charlesreid1/pantera

The Pantera Library Layout

This section describes the layout of the core source code of Pantera.

Pantera provides classes that interface with and extend Cantera classes.

Pantera also monkey-patches Cantera. Monkey patches are modifications to existing objects that add new features or bring back useful but deprecated features.

Pantera Sub-Modules:

  • Cantera Monkey-Patches - patches existing Cantera classes (adds essential functionality ONLY!)
  • Gases submodule - gas compositions, gas mixing, gas objects
  • Configurations submodule - extends Cantera reactor networks to be more useful and flexible (plug flow reactors, packed bed reactors, ignition reactors, recycle reactors, etc.)
  • Reactors submodule - extends Cantera reactors to be more useful (but most of the useful stuff is in the configurations)
  • Engineering submodule - applied engineering problems solved with Cantera

Cantera Monkey-Patches

There are a couple of monkey patches applied to Cantera. The two classes affected are:

  • Cantera.Reactor
  • Cantera.Solution

Solution class Monkey-Patches

The Solution class is monkey-patched to more easily obtain mass and mole fractions for particular species.

If you have a Solution (bascially a gas phase object) using the Cantera library, you can obtain mass and mole fractions using the somewhat clunky notation:

speciesName = ['CH4','O2']
Xs = my_solution[speciesName].X
Ys = my_solution[speciesName].Y

This monkey-patch allows for the much more intuitive:

speciesName = ['CH4','O2']
Xs = my_solution.mole_fraction( speciesName )
Ys = my_solution.mass_fraction( speciesName )

This works when passing a single species names or a lists of species names as a parameter.

Reactor class Monkey-Patches

The Reactor class monkey-patches are actually provided in the PanteraReactors.py file in the pantera.reactors submodule. It is described here anyway, since it is still a monkey-patch.

In Cantera 2.0, you could access the state of a Cantera reactor like this:

# Cantera 2.0
r = Reactor(my_solution)
print r.temperature()
print r.pressure()
print r.moleFractions()

However, Cantera 2.1 created problems by doing away with this. Now, you can only access the temperature of the reactor.

What's worse, if you want to access the pressure and mole fractions of a reactor, you need to use the contents, but Cantera 2.1 also did away with ways of accessing the contents of the reactor. You used to be able to do this:

# Cantera 2.0
r = Reactor(my_solution)
c = r._contents
T = c.temperature()
P = c.pressure()
X = c.moleFractions()

Again, Cantera 2.1 created problems by doing away with this.

These monkey-patches fix this. Now you can do this:

r = Reactor(my_solution)
print r.T
print r.P
print r.X
print r.Y

c = r._contents
print c.T
print c.P
print c.X
print c.Y

Woo hoo!