Cantera Lecture: Difference between revisions
From charlesreid1
| Line 57: | Line 57: | ||
Any flow controllers needed? ''No'' | Any flow controllers needed? ''No'' | ||
What ''will'' we need? A reactor | |||
What are we going to fill the reactor with? We also need a fluid phase, and a mechanism to go along with it (if we want reactions), or thermodynamic data to go along with it (if we want thermodynamic state changes) | |||
[[Image:batch.jpg]] | [[Image:batch.jpg]] | ||
| Line 88: | Line 92: | ||
batch = Reactor(gas); | batch = Reactor(gas); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
We didn't specify the volume of the Reactor object - so how do we find it? | |||
How do we get information about the Reactor object? | |||
What information ''can'' we get about the Reactor object? | |||
<syntaxhighlight lang="matlab"> | |||
% We can use the volume() function to find the reactor's volume | |||
volume(batch) | |||
% We can find the Matlab object type like this: | |||
class(batch) | |||
% This returns "Reactor" type | |||
% Show the functions available for Reactor objects | |||
methods Reactor | |||
</syntaxhighlight> | |||
The method "setInitialVolume()" looks good, so we can use it to set the initial volume of the reactor: | |||
<syntaxhighlight lang="matlab"> | |||
setInitialVolume( batch, 10.0 ); | |||
</syntaxhighlight> | |||
Another interesting method is "massFractions()": | |||
<syntaxhighlight lang="matlab"> | |||
% Display the mass fractions in the reactor | |||
massFractions(batch) | |||
</syntaxhighlight> | |||
This returns a 9-element vector, but it isn't clear what mass fractions are for which species. | |||
How can we figure out what species are in the reactor? | |||
Is this a ''reactor'' property? | |||
Or is it a ''gas/fluid'' property? | |||
So use the same methodology: | |||
<syntaxhighlight lang="matlab"> | |||
% Find the class type of the gas phase object | |||
class(gas) | |||
% This returns type "Solution" | |||
% This shows the methods available to Solution types | |||
methods Solution | |||
% This list looks a little short - but we can show inherited methods like this: | |||
methods Solution -full | |||
</syntaxhighlight> | |||
The "speciesNames()" function looks like what we want: | |||
<syntaxhighlight lang="matlab"> | |||
speciesNames(gas) | |||
</syntaxhighlight> | |||
This returns a 9-element vector of strings - names of species in the mechanism file 'h2o2.cti'. | |||
{{Stub|plot of Cantera batch reactor results}} | |||
== Constant Pressure Reactor Example == | |||
Now for a more interesting (relevant) combustion problem: | |||
How might we use reactors, walls, reservoirs, etc. to create a batch reactor? | |||
We can create a piston-cylinder system - this would be a constant-pressure system | |||
[[Image:piston.jpg]] | |||
Revision as of 07:30, 25 October 2010
Cantera Overview
Cantera is a code written in C++ that can be used to perform chemical kinetic and thermodynamic calculations.
The way it does this is by providing the user with a set of building blocks, and allowing the user to piece these building blocks together to form complex kinetic/thermodynamic systems or networks
Users can interface with Cantera through C++, or through the other interfaces:
- Matlab toolbox
- Python
- Fortran
Visit the Cantera (software) page for a Cantera installation guide for either Mac, Linux, or Windows.
Cantera Objects
Reservoir - fixed state
- the state of the reservoir never changes
- used to impose fixed upstream/inlet conditions
- chemistry is frozen - so no reactions will take place
Reactor - canonical chemical reactor
- contains some mixture of species
- has a set of characteristics
- e.g. T, V, P, composition, enthalpy, density, MW, etc...
Fluids - gases or liquids
Chemical Mechanisms - external files "fed" to Cantera
- chemical mechanisms specify two things:
- species
- reactions
- all thermodynamic data for species is specified (e.g. heat capacity as a polynomial function - "NASA coefficients")
- all thermodynamic data for chemical reactions (pre-exponential factors, activation energies, etc.)
Walls - separate reactors
- can have heat transfer via the usual mechanisms - convection, conduction, radiation
- can have a set heating rate (a constant, or a function of time)
- can move - due to a pressure difference, a displacement rate expression, etc.)
Flow controllers - control flow... 3 types
- Mass flow controller - maintains a fixed mass flowrate
- Valves - the mass flowrate is a function of $ \Delta P $
- Pressure flow controller - maintains a fixed $ P $ in the reactor (think of this as a pressure relief valve)
Matlab Examples
Batch Reactor Example
How might we combine the above Cantera objects to make a batch reactor?
e.g. where would the reactor go? Where would the flow controllers go?
Any reservoirs needed? No
Any flow controllers needed? No
What will we need? A reactor
What are we going to fill the reactor with? We also need a fluid phase, and a mechanism to go along with it (if we want reactions), or thermodynamic data to go along with it (if we want thermodynamic state changes)
We want to know what happens when the reactor is changing from state 1 to state 2
For a constant volume reactor:
What is going into our reactor?
% Import a phase to fill the reactor with
% (The H2 combustion mechanism is contained in the file h2o2.cti, which comes with Cantera)
gas = importPhase('h2o2.cti');
What is the thermodynamic state of the material going into the reactor?
% Set the gas temperature at 1500 K
% Set the pressure at 1 atm
% Set the composition to be 2 parts hydrogen, 1 part oxygen, and 20 parts dilute, inert Argon
set(gas, 'T',1500, 'P',oneatm, 'X','H2:2, O2:1, AR:20')
How to create a batch reactor? Create a Cantera Reactor object
% We have already set the thermodynamic state of the "gas" object
% But if we wanted to, we could set it when we create the Reactor
batch = Reactor(gas);
We didn't specify the volume of the Reactor object - so how do we find it?
How do we get information about the Reactor object?
What information can we get about the Reactor object?
% We can use the volume() function to find the reactor's volume
volume(batch)
% We can find the Matlab object type like this:
class(batch)
% This returns "Reactor" type
% Show the functions available for Reactor objects
methods Reactor
The method "setInitialVolume()" looks good, so we can use it to set the initial volume of the reactor:
setInitialVolume( batch, 10.0 );
Another interesting method is "massFractions()":
% Display the mass fractions in the reactor
massFractions(batch)
This returns a 9-element vector, but it isn't clear what mass fractions are for which species.
How can we figure out what species are in the reactor?
Is this a reactor property?
Or is it a gas/fluid property?
So use the same methodology:
% Find the class type of the gas phase object
class(gas)
% This returns type "Solution"
% This shows the methods available to Solution types
methods Solution
% This list looks a little short - but we can show inherited methods like this:
methods Solution -full
The "speciesNames()" function looks like what we want:
speciesNames(gas)
This returns a 9-element vector of strings - names of species in the mechanism file 'h2o2.cti'.
Constant Pressure Reactor Example
Now for a more interesting (relevant) combustion problem:
How might we use reactors, walls, reservoirs, etc. to create a batch reactor?
We can create a piston-cylinder system - this would be a constant-pressure system
| |||||||||||||||||||||||

