Installing Cantera
From charlesreid1
This page is primarily focused on explaining the Cantera installation procedure for Linux, Mac OS X, and Windows.
Also, this page is designed to be useful for anyone installing Cantera. If you don't think it's useful, or if you're having a problem not addressed by the page, please email me at root (at) charlesmartinreid.com with your problem and (if you found it) the solution, or with any comments or suggestions, and I will adjust the page accordingly.
Downloading
You can download Cantera from Google Code: http://code.google.com/p/cantera/downloads/list
(it used to be hosted at SourceForge, but the project has since moved to Google Code)
This guide will cover version 1.8.0.
Linux
You probably already know what to do. You can follow the Mac instructions - the main thing that will change is the procedure for installing Numpy (you can probably use aptitude or yum or whatever package manager your distro uses), and the corresponding path to Numpy include files.
Mac OS X
Dependencies
If you wish to use Cantera from Python, you have two options:
- Use version 1.8.0 and install Numpy
- Use version 1.7.x and install Numarray
I highly recommend using version 1.8.0 and Numpy, as Numarray is no longer supported. This guide will only cover this method.
Anther package that is not required by Cantera, but that is useful, is Sundials, a suite of nonlinear and differential equation solvers.
Leopard
If you're installing Cantera on a Mac, you have to build it from source.
Start by downloading the Cantera 1.7 or 1.8 source code, and unzip it. Go to this directory, and edit the preconfig file. This is a wrapper for configure (so when you are ready to configure, you don't run ./configure, you run ./preconfig). Preconfig contains many options that are laid out very clearly, so go through the file and set values appropriate to your system.
One of the problems with using Cantera with Numpy is that Cantera incorrectly parses the path to the Numpy home directory to get a Numpy include directory that doesn't exist. This causes the 'import_array' error (below). This can be resolved by pointing Cantera configure to the Numpy include directory, by removing the variable NUMPY_HOME and adding a variable NUMPY_INC_DIR.
Before (broken):
NUMPY_HOME=${NUMPY_HOME:="/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/numpy/core/include"}
After (fixed):
# NUMPY_HOME=${NUMPY_HOME:="/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/numpy/core/include"}
NUMPY_INC_DIR=${NUMPY_INC_DIR:="/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/numpy/core/include/numpy"}
export NUMPY_INC_DIR
Beware that including the "numpy" directory at the end may cause problems. If you are getting lots of Numpy-related (or Python-related) errors, try leaving off the last "numpy" directory. See Installing Cantera#Mac Installation Errors below for more info on errors and possible causes.
You can find my preconfig file for Leopard here: Cantera Preconfig/Leopard Preconfig
The next steps are the usual:
$ ./preconfig
$ make all
$ make install
Snow Leopard
Snow Leopard was a bit more of a challenge to get working, not sure why. So if you run into problems, consult the Installing Cantera#Mac Installation Errors section below, or try emailing myself or the Cantera user group.
Mac Installation Errors
(Many details forthcoming...)
Windows
The following instructions for installing a binary version of Cantera on Windows have been tested on both Windows XP and Windows 7.
Windows XP
See below... instructions work for both Windows XP and Windows 7.
Windows 7
- Install Python 2.5 (you will need the Python 2.5.4 installer from here: http://www.python.org/download/releases/2.5.4 ).
- It is strongly recommended that you install Python to the root path "C:\Python25"
- Install the Python Numarray package (you will need to download the installer for numarray from Sourceforge: http://sourceforge.net/projects/numpy/files/ . Be sure and scroll down to the section named “Old Numarray” and download the file numarray-1.5.2.win32-py2.5.exe)
- Download and run the Windows installer for Cantera 1.7 from Sourceforge: http://sourceforge.net/projects/cantera/
- It is strongly recommended that you install Cantera to the local path "C:\Cantera"
- Once Cantera has been installed, open C:\Cantera (or wherever you installed Cantera to) and double-click the executable, which should be named something like Cantera-1.7-python25.exe; this installs the bare minimum Python libraries required by Cantera for importing/converting Cantera input files.
- Set two environmental variables by right-clicking My Computer and clicking Properties, then selecting the "Advanced" tab (for Windows XP) or the "Advanced System Settings" link (for Windows 7), and click the "Environmental Variables" button.
- Create a new user variable by clicking “New...”
- Set the first variable:
- For variable name, type
PYTHONPATH - For variable value, type
C:\Python25
- For variable name, type
- Set the second variable:
- For variable name, type
PYTHON_CMD - For variable value, type
C:\Python25\python.exe
- For variable name, type
- Click “OK”several times until you've saved everything
- Download the Sundials Matlab Toolbox, which will not have anything to install; the Sundials toolbox provides Cantera with some important differential equation solvers. It can be downloaded here: https://computation.llnl.gov/casc/sundials/download/download.html
- The toolbox does not need to be “installed” - it's just a collection of files that needs to be put somewhere
- It is strongly recommended that you put the Sundials toolbox in the directory
C:\sundialsTB
- Point Matlab to the Cantera and Sundials toolboxes
- Open Matlab and click File > Set Path...
- Click “Add with subdirectories”
- Add
C:\Cantera\MATLAB - Add
C:\sundialsTB
- To test your installation of Cantera, execute the following command:
>> gas = GRI30;
This should create a gas using the GRI-Mech 3.0 chemical mechanism. If you see problems with a cti reader, or a ct2html reader not being built, check to make sure you set the PYTHON_CMD environmental variable properly.
Windows Installation Errors
Resources
On The Web
Cantera Google Groups Page - https://code.google.com/p/cantera/
- Download Cantera 1.8.0 (beta), source code ONLY
- Check out a copy of the subversion repository
Cantera (Google) Users Group Page - https://groups.google.com/group/cantera-users?pli=1
- Download Cantera documentation
- Use the discussion board
Cantera SourceForge Page - http://sourceforge.net/projects/cantera/files/
- Download Cantera 1.7.1, source code or (Windows) binaries
- Download (more) Cantera documentation
Lecture
As a TA for CHEN 6153 at the University of Utah, I gave a lecture on the installation and use of Cantera.
The lecture notes are here: Cantera Lecture
The video screencast of the lcture is here: http://files.charlesmartinreid.com/CanteraScreencast.mov
You can download the example Matlab scripts here as well:
- Constant volume batch reactor http://files.charlesmartinreid.com/CanteraLecture_Batch.m
- Constant pressure batch reactor http://files.charlesmartinreid.com/CanteraLecture_BatchConstP.m
- Continuously Stirred combustor http://files.charlesmartinreid.com/CanteraLecture_CSTR.m