Installing and Using Cantera 1 7 Through Python














- Slides: 14

Installing and Using Cantera 1. 7 Through Python 2. 5 Maria A. Puccio 5/3/07

Installation

5 Steps to Installing Cantera • 1. Install Python 2. 5 – (For Windows) Download and Run Python 2. 5 http: //www. python. org/ftp/python/2. 5/python 2. 5. msi • 2. Install numarray site-package for Python – Download and Run “old numarray” http: //sourceforge. net/projects/numpy/numarray 1. 5. 2. win 32 -py 2. 5. exe • 3. Install Cantera 1. 7 – http: //sourceforge. net/projects/cantera/

5 Steps to Installation Continued • 4. Run “Cantera-1. 7. 0. win 32 -py 2. 5. exe” – Located in “Cantera” folder – This creates the interface between Cantera and Python You may see an icon like this on your desktop, it is a shortcut to this folder

5 Steps to Installation Continued • 5. Add 2 new environment variables – Control Panel System Advanced – Variables to add… • 1) “PYTHON_CMD” “C: Python 25Python. exe” • 2) “CANTERA_DATA” “C: Program FilesCommon FilesCanteradata” • Restart your computer for variables to take affect

Using Cantera Through Python

Using Python • A few notes about Python. – “Python is a dynamic, object-oriented programming language that can be used for many kinds of software development” www. python. org • Python is run through an interpreter called IDLE. – Try running the first tutorial that comes with the Cantera package. It is in the Cantera folder, under tutorialsPython – You will need to right click on “tut 1. py” and select “Edit with IDLE”

Using Python Continued • Two windows will appear, the first is the program “tut 1. py”, and the second is the “Python Shell”. We will focus on the python shell for now.

Using Python Continued • Python works by typing commands into the command line (indicated by the >>>) and pressing enter to see the results. – Try typing in the command: print “hello world”

Using Python Continued • A few things to note… – Python is case sensitive, so make sure “print” is not capitalized! – Like other languages, Python highlights or changes the color of things it recognizes (the word “print” changes from black to orange because Python recognizes it as a command) • Now on to the tutorial. The first mini program they have you do looks like this from Cantera import * gas 1 = GRI 30() print gas 1

Saving/Running Programs in Python • So you don’t have to keep typing this in, let’s open a new window and save this program – Make sure you save it as a “. py” file! • Once you have saved, you can run the program by clicking “Run Module” under the “Run” menu

Tutorials 1 Through 4 • Okay, now you should be ready to go through the tutorials that come with the Cantera package. • Once you have done this, you may want to check out the next section of this tutorial. – It goes over a few things that the Cantera tutorials don’t cover. • I’ll expand on this once I’ve learned more about Cantera. – For now this section just goes over saving data to a “. csv” file and opening this using excel.

Additional Tips and Tricks

• IN PROGRESS