The Python Driver
This page describes the Python interactive driver for MESA++.
What is the Python driver?
Importing the MESA++ Star module
into
a Python program
What is the Python driver?
The Python driver, star++,
is
an
interactive
application that uses the MESA++ C++ interface to
create, load, save, evolve, and examine stellar models. It is built
during the MESA++ install if the utils/makefile_headers
file contains the line USE_PYTHON=YES.
You
will
also
need to supply the correct values of PYTHON_INC_DIR, PYTHON_LIB_DIR, and PYTHON_LIB, which are,
respectively, the path to the Python headers, the path to the Python
libraries, and the linker flag (e.g. -lpython2.5) that is needed to
link the Python library into the executable.
If you go to the mesapp/star/test
directory and execute star++,
you
will
fire
up a Python interactive session that has been preloaded
with a star module:
% ./star++
mesa_data_dir = "../../../mesa/data"
kappa_file_prefix = "gs98"
other_kappa_file_prefix = ""
eos_file_prefix = "mesa"
other_eos_file_prefix = ""
net_reaction_filename = "reactions.list"
rates_dir = "rates"
ppn_rate_numbers_fname = ""
Python 2.6.6 (r266:84292, Feb 9 2011,
17:23:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>>
By default, star++ initializes the various MESA physics libraries
with the displayed settings. These are found in the file init.tcl,
which is a Python script containing the initialization code.
You may now view the functions provided by the star module:
>>>
dir (star)
['__doc__',
'__name__', '__package__', 'create', 'delete', 'error',
'initialize', 'is_initialized', 'load', 'on', 'plot',
'plot_hr',
'restart', 'save', 'step']
>>>
This lists the functions provided by star. To get a brief description of each, look at its doc string:
>>>
star.create.__doc__
'Create a new
Star object'
>>>
The Python driver, like MESA itself, manipulates individual Star
objects via an integer handle. To create a new Star object from an
inlist file, use
>>>
id = star.create("inlist")
create
pre-main-sequence model
done
build_pre_ms_model
run for a
few steps to let new model converge with basic parameter settings
dt/dt_Courant
1.1849439168881228E+00
stop because
model_number >= max_model_number
10
10
done
create pre main-sequence model
net name
basic.net
v_flag = F
kappa_file_prefix gs98
eos_file_prefix mesa
>>>
print id
1
>>>
This creates a new Star with handle 1. You can also load a Star from
a restart file:
>>>
id = star.restart("inlist", "star.restart")
You can evolve the star one or more time steps:
>>>
star.step(id, 10)
This evolves the Star with handle id for 10 time steps. You can
explicitly save a snapshot:
>>>
star.save(id, "restart", "star.restart")
At the moment, we've only implemented a snapshot save ("restart")
but we will be implementing other save formats in the future.
You can produce various kinds of plots:
>>>
star.plot_hr(id)
Plots the HR diagram of the star.
>>>
star.plot(id, "M", "T")
Plots temperature versus mass. These plot options do not actually
open a plot window or anything like that; they simply dump the data in
a form easily readable by plotting tools such as my personal favorite,
xmgrace. I like to have an xmgrace window open when I'm running star++
so I can plot a variable over successive steps and more easily see how
it is changing. It's surprisinglu useful.
You can have the stepper routine execute an arbitrary script every
time it completes a time step:
>>> star.on("step", "star.plot_hr(id)")
Finally, you can hit ctrl-C (or the corresponding interrupt sequence
on whatever platform you are using) to cleanly stop in the middle of a
sequence of time steps. The code will finish the time step it's on,
then return to the command level.
Development of the star++ driver is still in its early stages, so
look for more goodies to come. In particular, at Bill Paxton's
suggestion, I mean to provide easy
ways to change the PGStar output on the fly.
Importing the MESA++ Star module into a Python program
This section is brief, because I don't actually know how to do this.
However, I know it can be done, assuming you have the patience. The
details will apparently vary considerably with platform. For some tips
on how to attempt this, look here.website
design
by
Andreas Viklund