01 - Loading AMUSE

The AMUSE framework is divided over several python packages and modules. All these have one common root module: amuse. This root defines the namespace of all sub-packages and modules. You can load the amuse module with:

In[1]:

import amuse

However the amuse module is mostly empty, as you can see when you try ‘Tab’ completion on the amuse module or run dir(amuse)

In[2]:

dir(amuse)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

The main body of the AMUSE framework is divided over 4 packages, each subdivided into more packages and modules.

community

This packages contains all the communtity codes. All software integrated into AMUSE, (N-body, stellar evolution, hydrodynamics and radiative transfer codes) is called a community code in AMUSE. Each community code is defined in a separate sub-package and every sub-package contains at least one module called interface. You can load a community code with: from amuse.community.<codename>.interface import <codeclass>. In later tutorials we will learn more about the codes and how to interact with each.

In[3]:

from amuse.community.bhtree.interface import BHTree
print BHTree
<class 'amuse.community.bhtree.interface.BHTree'>

units

A package to work with quantities and units. All calculations in AMUSE are done with quantities having units. These quantities and their units are implemented as python classes and can be used almost everywere you would normaly use a number (or a numpy array). In the next tutorial we will come back to the units, for now we will show a simple example

In[4]:

from amuse.units import units
from amuse.units import constants

In[5]:

constants.G * ( 5.972e24 | units.kg) /  (6378.1 | units.km )**2
quantity<9.7980933561 m * s**-2>

datamodel

All astrophysical bodies (stars, clouds, planets etc) are modelled with sets of particles or on grids. These sets and grids are defined in the datamodel package. You will see these used everywhere in amuse and in several tutorials we will cover them in more detail.

In[6]:

from amuse.datamodel import Particles
solar_system_planets = Particles(7)
solar_system_planets.mass = [641.85, 4868.5, 5973.6, 102430, 86832, 568460, 1898600] | (1e21 * units.kg)
print solar_system_planets
                 key         mass
                   -   1e+21 * kg
====================  ===========
11759470220597295702    6.419e+02
 7680937547177477680    4.868e+03
14603854154785062813    5.974e+03
16121505676595775052    1.024e+05
11072938864231128317    8.683e+04
 9591854211029195670    5.685e+05
11947799990975573772    1.899e+06
====================  ===========

rfi

The AMUSE framework is written in Python, most codes are written in C or Fortran. In AMUSE the Remote Function Invocation or rfi package implements all classes and tools to call functions on the community codes. The rfi package implements support for communicating over MPI, raw sockets and Ibis. This code is mainly used internally to the framework and in most scripts you will not see it, but you will be using it!

In[7]:

from amuse.rfi.channel import is_mpd_running
print is_mpd_running()
True

couple

Eventually you will want to connect different codes to simulate a coupled problem. As AMUSE is written in Python, you can easily write your own coupling strategy but in most cases you do not need to do this. This package contains several predefined coupling strategies, two of which we will cover in a later tutorial.

In[8]:

from amuse.couple import bridge

io

Saving and loading models is an important feature in AMUSE. AMUSE defines it’s own format and supports a number of common file formats often used in astro-physical codes. All saving all loading is supported through two functions: (this example depends on the datamodel example earlier on this page, if you get a NameError please rerun that cell)

In[9]:

from amuse import io
io.write_set_to_file(solar_system_planets, "solar.hdf5")
print io.read_set_from_file("solar.hdf5")
                 key         mass
                   -   1e+21 * kg
====================  ===========
15971190610269553817    6.419e+02
  769616704393732824    4.868e+03
   93061822910076228    5.974e+03
17506344067243819066    1.024e+05
14608055696462349340    8.683e+04
11147579528564337851    5.685e+05
14042327815465030986    1.899e+06
====================  ===========

ic

The Initial Conditions ic package provides a small set of often used algorithms to create an initial particle set or grid. The current set of supported algorithms is small but provides good examples for further extension.

In[10]:

from amuse.ic import plummer
particles = plummer.new_plummer_model(25)
print particles.mass.sum()
1.0 mass

ext

During development of AMUSE we have created several general purpose algorithms that do not fall in any of the above categories. All these are implemented in the modules of the ext package. These algorithms are very diverse and deal with model conversions (from a grid model to particle sets), post-processing (graphing, creating blender models) to handling of special conditions in a model (sinks and sources). Some of these algorithms will evetually move to the ic or couple modules. We will encounter some ext modules in these tutorials and you will see more use in the examples.

In[11]:

from amuse.ext import grid_to_sph

all in one

Most amuse code can be loaded with importing one module, the lab module. AMUSE contains a lot of sub-packages and modules, it is hard too learn and remember all these. We provide one module that imports most code from the other modules, as an easy interface to the AMUSE framework.

In[12]:

from amuse.lab import *
print new_plummer_model(10)
                 key         mass       radius           vx           vy           vz            x            y            z
                   -         mass       length  length / time  length / time  length / time       length       length       length
====================  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========
 4879582166954988598    1.000e-01    0.000e+00   -2.427e-02   -2.549e-01    4.824e-01    1.601e-01   -5.276e-01    8.357e-02
 9447285575351537656    1.000e-01    0.000e+00   -1.077e-01    2.946e-01    4.000e-01   -1.462e+00    6.916e-01   -6.705e-01
11090324892853409999    1.000e-01    0.000e+00   -1.130e-01    2.910e-01    2.253e-01    3.219e+00    2.516e+00   -3.056e+00
 3494316266081976069    1.000e-01    0.000e+00   -8.016e-01    7.305e-01   -1.642e-01   -1.953e-01   -6.412e-01    1.648e-01
 9380189819509163656    1.000e-01    0.000e+00    1.055e-02    1.497e-01   -2.043e-01    8.621e-01    1.080e+00    6.552e-01
14722128275749923141    1.000e-01    0.000e+00    4.691e-01   -6.698e-02   -3.871e-01   -5.440e-01   -6.878e-01    8.178e-01
16688668889203197691    1.000e-01    0.000e+00    3.574e-02   -6.718e-01   -1.765e-01   -8.739e-03   -1.054e+00    5.346e-01
 7362142817187969096    1.000e-01    0.000e+00    7.815e-02   -8.017e-01    1.147e-01   -6.500e-01   -2.076e-01    1.470e-02
18286878583873907961    1.000e-01    0.000e+00    4.335e-01   -1.216e-01   -1.873e-01   -9.010e-02   -1.088e+00    1.260e+00
10868837862741847349    1.000e-01    0.000e+00    1.950e-02    4.512e-01   -1.029e-01   -1.292e+00   -8.110e-02    1.955e-01
====================  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========

In[ ]:

Table Of Contents

Previous topic

Interactive tutorial

Next topic

03 - Generic units

This Page