Swarm-NG  1.1
swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES > Class Template Reference

ensemble data structure containing nbody systems. More...

#include <ensemble.hpp>

Classes

struct  Body
 Concrete structure of Body This class is specifically designed to be used with CoalescedStruct array. More...
 
struct  range_t
 A simple data structure to calculate statistical measures on a range of values. More...
 
struct  Sys
 Structure for quantities stored per system. More...
 
class  SystemRef
 Reference to a system within an ensemble. More...
 
class  SystemRefConst
 Constant encapsulation of SystemRef If the ens is constant use: SystemRefConst s = ens[i];. More...
 

Public Types

typedef CoalescedStructArray
< Body, double, CHUNK_SIZE
BodyArray
 Type of array that we want to use for Body.
 
typedef CoalescedStructArray
< Sys, double, CHUNK_SIZE
SysArray
 Type of array that we want to use for Sys.
 

Public Member Functions

GENERIC const int & nbod () const
 Number of bodies per system.
 
GENERIC const int & nsys () const
 Number of systems.
 
BodyArraybodies ()
 Coalsed array of bodies. For INTERNAL use only.
 
SysArraysystems ()
 Coalsed array of systems. For INTERNAL use only.
 
GENERIC SystemRef operator[] (const int &i)
 Index into systems array to access a system. More...
 
GENERIC void get_barycenter (const int &sys, double &x, double &y, double &z, double &vx, double &vy, double &vz, const int &max_body_id=MAX_NBODIES) const
 Deprecated function: this function uses a very bad signature and too many arguments. More...
 
GENERIC double calc_total_energy (int sys) const
 Total energy (potential+kinetic) of a system.
 
GENERIC void calc_total_energy (double *E) const
 Calculate the total energy of a system and store it in E. More...
 
GENERIC range_t time_ranges () const
 Range of times of systems (average,min,max) Averages the time for all systems and finds min and max Useful to find the best value for destination time.
 

Static Public Member Functions

static GENERIC size_t body_element_count (const int &nbod, const int &nsys)
 Size of Body[] array required for an ensemble of size nbod,nsys.
 
static GENERIC size_t sys_element_count (const int &nsys)
 Size of Sys[] array required for an ensemble of size nsys.
 

Static Public Attributes

static const int CHUNK_SIZE = _CHUNK_SIZE
 CHUNK_SIZE for Coalesced access. c.f CoalescedStructArray.
 
static const int NUM_BODY_ATTRIBUTES = _NUM_BODY_ATTRIBUTES
 Number of extra attributes.
 
static const int NUM_SYS_ATTRIBUTES = _NUM_SYS_ATTRIBUTES
 Number of extra attributes per system.
 

Protected Member Functions

GENERIC EnsembleBase ()
 Trivial constructor, creates an invalid ensemble. More...
 
GENERIC EnsembleBase (const int &nbod, const int &nsys, PBody body_array, PSys sys_array)
 Create an ensemble from pre-allocated body_array and sys_array arrays.
 

Protected Attributes

int _nbod
 Number of bodies.
 
int _nsys
 Number of systems.
 
BodyArray _body
 Coalesced array of Body.
 
SysArray _sys
 Coalesced array of Sys.
 

Detailed Description

template<int _CHUNK_SIZE, int _NUM_BODY_ATTRIBUTES = NUM_PLANET_ATTRIBUTES, int _NUM_SYS_ATTRIBUTES = NUM_SYSTEM_ATTRIBUTES>
class swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >

ensemble data structure containing nbody systems.

Internal Usage: Contains an ensemble of nsys() systems each containing nbod() bodies. use operator [] to peek into the data structure:

  • Index into ensemble to access a specific system
  • Index into system to access a specific body
  • Index into body to access a specific coordinate component
  • Each coordinate component has pos (position) and vel (velocity)

Example:

ens[0][1].mass() = 1.0; // Set mass of body 1 in system #0
ens[2][1][0].pos() = 4; // Set x cooridante of position of body #1 in system #2
ens[3][2][1].vel() = 3; // Set y coordinate of velocity of body #2 in system #3
ens[1].time() = 3; // Set time of system #1

Public Usage: There are accessors:

  • ensemble: nsys(), nbod()
  • system : time(), state(), id(), number() (pass system id as argument)
  • body : get_body(), set_body(), mass(), attribute(), x(), y(), z(), vx(), vy(), vz() ... for each body (pass system id and body number as argument)

Two utility functions are provided for ease of use: calc_total_energy(sys) and get_barycenter(sys)

This class does not contain memory management routines and cannot be instantiated. It should be used as the ensemble typedef only for parameter definition in functions and should be passed as a reference. To create an ensemble use one of defaultEnsemble, deviceEnsemble or hostEnsemble

The bodies and systems can have extra attributes. The constants used here for number of attributes are set in the configuration file which is set by CMake. You can change these values using the CMake system.

Definition at line 110 of file ensemble.hpp.

Constructor & Destructor Documentation

template<int _CHUNK_SIZE, int _NUM_BODY_ATTRIBUTES = NUM_PLANET_ATTRIBUTES, int _NUM_SYS_ATTRIBUTES = NUM_SYSTEM_ATTRIBUTES>
GENERIC swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >::EnsembleBase ( )
inlineprotected

Trivial constructor, creates an invalid ensemble.

Todo:
This is not safe and should be removed. ensemble is almost an abstract class and should not have a constructor anyway.

Definition at line 477 of file ensemble.hpp.

Member Function Documentation

template<int _CHUNK_SIZE, int _NUM_BODY_ATTRIBUTES = NUM_PLANET_ATTRIBUTES, int _NUM_SYS_ATTRIBUTES = NUM_SYSTEM_ATTRIBUTES>
GENERIC void swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >::calc_total_energy ( double *  E) const
inline

Calculate the total energy of a system and store it in E.

Todo:
unsafe function

Definition at line 699 of file ensemble.hpp.

template<int _CHUNK_SIZE, int _NUM_BODY_ATTRIBUTES = NUM_PLANET_ATTRIBUTES, int _NUM_SYS_ATTRIBUTES = NUM_SYSTEM_ATTRIBUTES>
GENERIC void swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >::get_barycenter ( const int &  sys,
double &  x,
double &  y,
double &  z,
double &  vx,
double &  vy,
double &  vz,
const int &  max_body_id = MAX_NBODIES 
) const
inline

Deprecated function: this function uses a very bad signature and too many arguments.

It is used to find a barycenter for first max_body_id planets in the system. If max_body_id is not specified, then the result is the barycenter for the whole planetary system.

Definition at line 665 of file ensemble.hpp.

Referenced by calc_semimajor_axes(), generate_ensemble_with_initial_conditions_cartesian_from_file(), generate_ensemble_with_initial_conditions_keplerian_from_file(), and print_system().

template<int _CHUNK_SIZE, int _NUM_BODY_ATTRIBUTES = NUM_PLANET_ATTRIBUTES, int _NUM_SYS_ATTRIBUTES = NUM_SYSTEM_ATTRIBUTES>
GENERIC SystemRef swarm::EnsembleBase< _CHUNK_SIZE, _NUM_BODY_ATTRIBUTES, _NUM_SYS_ATTRIBUTES >::operator[] ( const int &  i)
inline

Index into systems array to access a system.

Use: ens[i]

Finds the first body of a system to set as Body* parameter The hierarchy is like this: Blocks ( nsys / CHUNK_SIZE ) Bodies ( nbod ) Warps ( nsys % CHUNK_SIZE )

body index should come in the middle to provide efficient dynamic addressing.

Definition at line 512 of file ensemble.hpp.

Referenced by swarm::EnsembleBase< ENSEMBLE_CHUNK_SIZE >::calc_total_energy().


The documentation for this class was generated from the following file: