# Tools¶

group ToolsRebFunctions

Functions

double reb_random_uniform(double min, double max)

Return uniformly distributed random variable in a given range.

Return

A random variable

Parameters
• min: Minimum value.

• max: Maximum value.

double reb_random_powerlaw(double min, double max, double slope)

Returns a random variable drawn form a powerlaw distribution.

Return

A random variable

Parameters
• min: Minimum value.

• max: Maximum value.

• slope: Slope of powerlaw distribution.

double reb_random_normal(double variance)

Return a random number with normal distribution.

Algorithm by D.E. Knut, 1997, The Art of Computer Programmin, Addison-Wesley.

Return

A random variable

Parameters
• variance: Variance of normal distribution.

double reb_random_rayleigh(double sigma)

Return a random variable drawn form a Rayleigh distribution.

Return

A random variable

Parameters
• sigma: Scale parameter.

void reb_move_to_hel(struct reb_simulation *const r)

Move to the heliocentric frame.

This function moves all particles to the heliocentric frame. Note that the simulation will not stay in the heliocentric frame as it is not an inertial frame. Variational particles are not affected by the function.

Parameters
• r: The rebound simulation to be considered

void reb_move_to_com(struct reb_simulation *const r)

Move to center of momentum and center of mass frame.

This function moves all particles to the center of mass frame (sometimes also called center of momentum frame). In this frame the center of mass is at rest. It is recommended to call this function before you are doing a long term orbit integration. If the particles are slowly drifting away from the coordinate origin, numerical errors might build up.

Parameters
• r: The rebound simulation to be considered

struct reb_particle reb_get_com(struct reb_simulation *r)

Returns the center of mass.

Return

The center of mass as a particle (mass, position and velocity correspond to the center of mass)

Parameters
• r: The rebound simulation to be considered

struct reb_particle reb_get_com_of_pair(struct reb_particle p1, struct reb_particle p2)

Returns the center of mass of two particles.

Return

The center of mass as a particle (mass, position and velocity correspond to the center of mass)

Parameters
• p1: One of the two particles

• p2: One of the two particles

void reb_serialize_particle_data(struct reb_simulation *r, uint32_t *hash, double *m, double *radius, double (*xyz), double (*vxvyvz), double (*xyzvxvyvz))

Sets arrays to particle data.

This function can be used to quickly access particle data in a serialized form. NULL pointers will not be set.

Parameters
• r: The rebound simulation to be considered

• hash: 1D array to to hold particle hashes

• mass: 1D array to to hold particle masses

• radius: 1D array to to hold particle radii

• xyz: 3D array to to hold particle positions

• vxvyvz: 3D array to to hold particle velocities

• xyzvxvyvz: 3D array to to hold particle positions and velocities

void reb_set_serialized_particle_data(struct reb_simulation *r, uint32_t *hash, double *m, double *radius, double (*xyz), double (*vxvyvz), double (*xyzvxvyvz))

Sets particle data to data provided in arrays.

This function can be used to quickly set particle data in a serialized form. NULL pointers will not be accessed.

Parameters
• r: The rebound simulation to be considered

• hash: 1D array to to hold particle hashes

• mass: 1D array to to hold particle masses

• radius: 1D array to to hold particle radii

• xyz: 3D array to to hold particle positions

• vxvyvz: 3D array to to hold particle velocities

• xyzvxvyvz: 3D array to to hold particle positions and velocities

struct reb_particle reb_get_com_without_particle(struct reb_particle com, struct reb_particle p)

Takes the center of mass of a system of particles and returns the center of mass with one of the particles removed.

Return

The center of mass with particle p removed.

Parameters
• com: A particle structure that holds the center of mass state for a system of particles (mass, position, velocity).

• p: The particle to be removed from com.

int reb_get_particle_index(struct reb_particle *p)

Returns a particle pointer’s index in the simulation it’s in.

Return

The integer index of the particle in its simulation (will return -1 if not found in the simulation).

Parameters
• p: A pointer to the particle

struct reb_particle reb_get_com_range(struct reb_simulation *r, int first, int last)

Returns the center of mass for particles with indices between first (inclusive) and last (exclusive).

For example, reb_get_com_range(r, 6, 9) returns COM for particles 6, 7 and 8.

Return

A reb_particle structure for the center of mass of all particles in range [first, last). Returns particle filled with zeros if passed last <= first.

Parameters
• r: A pointer to the simulation structure.

• first: First index in range to consider.

• last: Will consider particles with indices < last (i.e., particle with index last not considered).

struct reb_particle reb_get_jacobi_com(struct reb_particle *p)

Returns the jacobi center of mass for a given particle.

Return

A reb_particle structure for the center of mass of all particles with lower index. Returns particles if passed the 0th particle.

Parameters
• p: A pointer to the particle