Swarm-NG  1.1
swarmng Namespace Reference

Python interface to the Swarm-NG library. More...

Namespaces

 logdb
 Interface to the Log files generated by bdb_writer plugin.
 
 logrecord
 Contains the support functions for accessing the C++ logrecord data strcture.
 
 range_type
 Classes for defining arbitrary ranges easily in Python.
 

Classes

class  Config
 Specialization of std::map to hold all our configuration attributes. More...
 
class  System
 A planetary system within an ensemble. More...
 
class  Body
 A body object within a system. More...
 
class  Ensemble
 Abstract ensemble data structure. More...
 
class  DefaultEnsemble
 The default implementation of ensemble data structor that stores data in system memory. More...
 
class  Integrator
 An ODE integration algorithms. More...
 
class  GpuIntegrator
 GPU accelerated integrator. More...
 

Functions

def init
 Initialize the Swarm library, registering the GPU and Logging subsystem. More...
 
def generate_ensemble
 Generate an trivial ensemble with planets in circular orbits. More...
 
def sync
 Synchronize all CUDA kernels. More...
 
def calc_keplerian_for_cartesian
 Returns Keplerian coordinates (as a list) from position and velocity of a body in cartesian coordinates. More...
 
def calc_cartesian_for_keplerian
 Returns cartesian coordinates (position and velocity) of an object for the given Keplerian coordinates. More...
 
def find_max_energy_conservation_error
 Compare two ensembles and find the maximum of energy conservation error amongst systems. More...
 
def config
 Convert hashes and keyword arguments to a swarmng.Config object. More...
 
def keplerian_for_cartesian
 Caluclate Keplerian coordinates for a planet with respect to a predefined center. More...
 

Detailed Description

Python interface to the Swarm-NG library.

This package loads and verifies the libswarmng_ext.so and adds some API that is implemented in Python.

The extensive module for opening log files is also included in swarmng.logdb

Function Documentation

def swarmng.calc_cartesian_for_keplerian (   a,
  e,
  i,
  O,
  w,
  M 
)

Returns cartesian coordinates (position and velocity) of an object for the given Keplerian coordinates.

The return value is a list of following structure:

1 [ x, y, z, vx, vy, vz ]

Definition at line 72 of file __init__.doc.py.

def swarmng.calc_keplerian_for_cartesian (   x,
  y,
  z,
  vx,
  vy,
  vz,
  GM 
)

Returns Keplerian coordinates (as a list) from position and velocity of a body in cartesian coordinates.

The returned list has the following structure:

1 [ a, e, i, O, w, M ]

Definition at line 63 of file __init__.doc.py.

Referenced by keplerian_for_cartesian().

def swarmng.config (   l,
  kw 
)

Convert hashes and keyword arguments to a swarmng.Config object.

There are three ways to use this function: # Combining one or more hashes into a swarmng.Config object

1 >>> cc = { 'nsys' : 16, 'nbod' : 3 }
2 >>> c1 = { 'integrator' : 'hermite_cpu' , 'time_step' : 0.001, 'log_writer' : 'bdb' }
3 >>> swarmng.config(c1)
4 >>> swarmng.config(c1, c2)

# Create a config object for inline use using keyword arguments. Following snippet initializes Swarm with nogpu = 1

1 >>> c = swarmng.config(nogpu = 1)
2 >>> swarmng.init(c)

# Combine hashes and keyword arguments.

1 >>> c1 = { 'integrator' : 'hermite_cpu' , 'time_step' : 0.001, 'log_writer' : 'bdb' }
2 >>> swarmng.config(c1, { 'nsys' : 16, 'nbod' : 3 } , nogpu = 1)

Arguments and return type:

  • arbitrary number of Hash objects and keyword arguments

Returns: a swarmng.Config object that combines configuration options from the hashes and keyword arguments.

Definition at line 75 of file __init__.py.

References peyton::util.str().

Referenced by keplerian_for_cartesian(), and main().

def swarmng.find_max_energy_conservation_error (   ref,
  ens 
)

Compare two ensembles and find the maximum of energy conservation error amongst systems.

  • ref : Reference ensemble, possibly from the initial conditions, (should be of type swarmng.Ensemble)
  • ens : Ensemble to check (should be of type swarmng.Ensemble) Returns one number, that is the maximum of energy conservation error. Energy conservation error for a system is the difference in total energy compared to the reference system normalized by the amount of energy in the reference system.

Definition at line 324 of file __init__.doc.py.

def swarmng.generate_ensemble (   cfg)

Generate an trivial ensemble with planets in circular orbits.

  • cfg : a Config object with properties for creating the ensemble only nsys and nbod are mandatory.

Returns a DefaultEnsemble populated with generated systems.

This function is a wrapper for swarm::generate_ensemble. For more details refer to it.

Definition at line 44 of file __init__.doc.py.

def swarmng.init (   cfg)

Initialize the Swarm library, registering the GPU and Logging subsystem.

The initialization procedure must be run before any integration can be done. However, data structure manipulation and loading can be done before swarm.init

For more info on what configuration options are available for swarmng.init refer to Configuration Files page.

If you are trying to Swarm on a system without GPUs try setting nogpu = 1 in the configuration.

Definition at line 34 of file __init__.doc.py.

def swarmng.keplerian_for_cartesian (   planet,
  center 
)

Caluclate Keplerian coordinates for a planet with respect to a predefined center.

  • planet : a tuple of structure ((x,y,z),(vx,vy,vz),mass)
  • center : the supposed center of the orbit that planet is orbiting ( around of structure ((x,y,z),(vx,vy,vz),mass) )

Return type: a named tuple that has the following attributes

  • a : semi-major axis
  • e : eccentricity
  • i : inclination
  • O : Longitude of the ascending node
  • w : Argument of periapsis
  • M : mean anomaly.

Refer to Wikipedia:Orbital elements for meaning of these.

Definition at line 105 of file __init__.py.

References calc_keplerian_for_cartesian(), and config().

Referenced by swarmng.logrecord.LogRecord.bodies_in_keplerian(), and swarmng.logrecord.LogRecord.bodies_in_keplerian_jacobi().

def swarmng.sync ( )

Synchronize all CUDA kernels.

This function is rarely used after running an integration to make sure that the data structures have been updated.

Note: this is an wrapper for cudaThreadSynchronize from CUDA runtime.

Definition at line 53 of file __init__.doc.py.