Module: NBodyGravity

struct GravitySource
#include <NBodyGravity.h>

Represents a gravity source in an N-body simulation.

A gravity source is a celestial body or point mass that generates a gravitational field.

Public Members

std::shared_ptr<GravityModel> model

The gravity model associated with the source.

ReadFunctor<SpicePlanetStateMsgPayload> stateInMsg

Input message providing the state of the source.

bool isCentralBody

Flag indicating whether this source is the central body.

struct GravityTarget
#include <NBodyGravity.h>

Represents a gravity target in an N-body simulation.

A gravity target is a body or site subject to gravitational forces.

Public Members

ReadFunctor<SCMassPropsMsgPayload> massPropertiesInMsg

Input message for the target’s mass properties.

ReadFunctor<SCStatesMsgPayload> centerOfMassStateInMsg

Input message for the target’s state.

Message<ForceAtSiteMsgPayload> massFixedForceOutMsg

Output message for the computed force.

class NBodyGravity : public SysModel
#include <NBodyGravity.h>

Simulates N-body gravitational interactions.

The NBodyGravity class manages gravitational forces between multiple sources and targets, computing the resultant forces on the targets due to the gravitational fields of the sources.

Public Functions

void Reset(uint64_t CurrentSimNanos)

Resets the N-body gravity simulation.

Ensures all sources and targets input messages are linked, that at most one central source is defined, and initializes the source gravity model parameters.

Parameters:

CurrentSimNanos – The current simulation time in nanoseconds.

Throws:

std::runtime_error – If there are configuration errors.

void UpdateState(uint64_t CurrentSimNanos)

Updates the gravitational force of all targets.

Parameters:

CurrentSimNanos – The current simulation time in nanoseconds.

GravitySource &addGravitySource(std::string name, std::shared_ptr<GravityModel> gravityModel, bool isCentralBody)

Adds a new gravity source to the simulation.

A gravity source is a celestial body or point mass that generates a gravitational field.

Remember to link the stateInMsg of the returned source.

Parameters:
  • name – The name of the gravity source.

  • gravityModel – The gravity model associated with the source.

  • isCentralBody – Indicates if this is the central body (only one per simulation).

Throws:

std::invalid_argument – If the source name is duplicated.

Returns:

A reference to the newly added GravitySource.

GravityTarget &addGravityTarget(std::string name)

Adds a new gravity target to the simulation.

A gravity target is a body or site subject to gravitational forces.

Remember to link the massPropertiesInMsg and centerOfMassStateInMsg messages of the returned target.

Parameters:

name – The name of the gravity target.

Throws:

std::invalid_argument – If the target name is duplicated.

Returns:

A reference to the newly added GravityTarget.

GravityTarget &addGravityTarget(std::string name, MJSite &site)

Adds a gravity target tied to a specific site.

The gravity field is computed at the site’s position/orientation, and the gravity force/torque is applied at a newly created actuator on this site.

Remember to tie the massPropertiesInMsg message of the returned target.

Parameters:
  • name – The name of the gravity target.

  • site – The site associated with the target.

Returns:

A reference to the newly added GravityTarget.

GravityTarget &addGravityTarget(std::string name, MJBody &body)

Adds a gravity target tied to a specific body.

The gravity field is computed at the body’s center mass, and the gravity force/torque is applied at a newly created actuator on this site.

Parameters:
  • name – The name of the gravity target.

  • body – The body associated with the target.

Returns:

A reference to the newly added GravityTarget.

inline GravitySource &getGravitySource(std::string name)

Retrieves a gravity source by name.

Parameters:

name – The name of the gravity source.

Throws:

std::out_of_range – If the source does not exist.

Returns:

A reference to the GravitySource.

inline GravityTarget &getGravityTarget(std::string name)

Retrieves a gravity target by name.

Parameters:

name – The name of the gravity target.

Throws:

std::out_of_range – If the target does not exist.

Returns:

A reference to the GravityTarget.

Eigen::Vector3d computeAccelerationFromSource(GravitySource &source, Eigen::Vector3d r_J2000)

Computes the gravitational acceleration from a source at a position.

Parameters:
  • source – The gravity source.

  • r_J2000 – The position vector in the J2000 frame.

Returns:

The gravitational acceleration vector.

Eigen::Vector3d computeAccelerationOnTarget(GravityTarget &target)

Computes the total gravitational acceleration acting on a target.

Parameters:

target – The gravity target.

Returns:

The gravitational acceleration vector.

Public Members

BSKLogger bskLogger

BSK Logging.

Protected Attributes

std::map<std::string, GravitySource> sources

Map of gravity sources by name.

std::map<std::string, GravityTarget> targets

Map of gravity targets by name.