C++ Module: polyhedralGravityModel

Executive Summary

This module encodes the polyhedron gravity model as described in Werner and Scheeres 1996. It inherits from the abstract class gravityModel and computes the gravity acceleration and potential with the constant density polyhedron equations.

The gravity acceleration is evaluated as

(1)\[\mathbf{a}^{P}=\frac{\mu}{V}\left(-\sum_{e\in\text{edges}}\mathbf{E}_e\mathbf{r}_eL_e +\sum_{f\in\text{faces}}\mathbf{F}_f\mathbf{r}_fw_f\right)\]

and the positive gravitational potential of the Werner and Scheeres formulation as

(2)\[U=\frac{\mu}{2V}\left(\sum_{e\in\text{edges}}\mathbf{r}^T_e\mathbf{E}_e\mathbf{r}_e -\sum_{f\in\text{faces}}\mathbf{r}^T_f\mathbf{F}_f\mathbf{r}_f\right)\]

computePotentialEnergy() returns the specific potential energy \(\Phi=-U\), in \(\mathrm{m^2/s^2}\), with zero at infinity. Thus \(\Phi\rightarrow-\mu/r\) far from the body and \(\mathbf{a}=-\nabla\Phi\). Multiplying \(\Phi\) by spacecraft mass gives potential energy in joules. This sign agrees with the point-mass model and the potential term in Spacecraft.totOrbEnergy.

Module Assumptions and Limitations

The evaluation point is referred to geographical coordinates with respect to the polyhedron gravity body. In other words, the input position is expressed in the planet centred rotating frame. The output gravity acceleration is also expressed in the previous frame.

The module assumes the polyhedron body has constant density.

The polyhedron shape must be a closed surface defined by non-degenerate triangular faces with consistently outward-pointing normals. Each edge must belong to two faces with opposite traversal directions. Vertex positions are measured from the body’s center of mass, and orderFacet uses one-based vertex indices.

The body need not be convex or star-shaped about its center of mass. Individual tetrahedra formed by a face and the origin may have negative signed volumes.

The module requires the standard gravity parameter to be provided by the user. Then, the body volume is internally computed from the polyhedron data to ensure consistency with the shape.

Initialization rejects a non-finite, zero, or negative total signed volume. For a closed, consistently oriented surface, a negative total indicates inward-pointing normals. A positive total alone does not establish mesh validity: callers remain responsible for closure, non-degenerate faces, and consistent local winding.

Detailed Module Description

The polyhedralGravityModel module handles the following behavior:

  1. Vertexes positions and faces indexes (corresponding to vertexes) are loaded from a polyhedron shape file.

  2. The module initializes and stores all the variables that have no dependency with the evaluation point: edge-facet dyad matrices, facet normals, facet centers and length of edges.

  3. By looping over edges and faces at the same time, the gravity acceleration and potential can be computed for an evaluation point.

The volume used to normalize both acceleration and potential is

\[V = \frac{1}{6}\sum_{f\in\text{faces}} \mathbf{r}_{f,1}\cdot \left(\mathbf{r}_{f,2}\times\mathbf{r}_{f,3}\right)\]

where the three vertex positions follow the outward winding of each face. The contributions are summed with their signs so overlapping tetrahedra cancel. Taking the absolute value of each contribution overestimates the volume of bodies that are not star-shaped about the origin and weakens both acceleration and potential by the ratio of the true volume to that overestimate (issue 1681).

User Guide

To use the polyhedron gravity model, instantiate the simIncludeGravBody.gravBodyFactory() and use the corresponding method to create a custom gravity body (Eros in this example). Then, use the gravity body method to attach a polyhedron gravity model and set the path to the polyhedron shape file as input argument.

mu = 4.46275472004e5  # [m^3/s^2] Eros gravitational parameter
file_poly = 'eros007790.tab'  # Path to a shape file of Eros
gravFactory = simIncludeGravBody.gravBodyFactory() # Instantiate gravity factory
erosGravBody = gravFactory.createCustomGravObject('eros_poly', mu=mu) # Create Eros gravity body
erosGravBody.isCentralBody = True # (Optional) If the body is to be central
erosGravBody.usePolyhedralGravityModel(file_poly) # Declare the use of a polyhedron model for Eros and set the shape file

For orbital propagation, the list of gravity bodies have to be appended to a spacecraft as

scObject = spacecraft.Spacecraft() # Creates spacecraft instance
scObject.gravField.gravBodies = spacecraft.GravBodyVector(list(gravFactory.gravBodies.values())) # Attach list of created gravity bodies to spacecraft

For direct gravity evaluations, initialize the attached polyhedral model and check the returned error before evaluating it. In Python, initializeParameters() returns None on success or an error string on failure. Simulation initialization performs this check through GravBodyData and reports a Basilisk error on failure. After correcting a rejected mesh, initialize the same model again before evaluating gravity. Each attempt discards previous facet and edge dyads, so successful retries use only the corrected mesh data.

poly = erosGravBody.poly
poly.muBody = erosGravBody.mu
error = poly.initializeParameters()
if error is not None:
    raise ValueError(error)
pos = [40e3, 30e3, 10e3]  # [m] Evaluation point in the body-fixed frame
acc = poly.computeField(pos)  # [m/s^2]
potential = poly.computePotentialEnergy(pos)  # [m^2/s^2]

Both direct model calls require a position relative to the gravity body in its body-fixed frame. For an inertial relative position, use erosGravBody.computePotentialEnergyInertial(position, timeNanos) after initializing the body and loading its ephemeris. The gravity effector uses this conversion automatically, extrapolating the planet orientation to the energy evaluation time with the same rotation model used for acceleration.

Before the fix for issue 1689, computePotentialEnergy() returned \(+U\), and spacecraft energy calculations used the inertial position without rotating it into the body frame. Callers that previously negated the returned potential to obtain specific potential energy should remove that extra negation.

Supported polyhedron shape files

Polyhedron shape files contain vertexes coordinates and the vertexes indexes that form each triangular face. The vertexes coordinates are assumed to be expressed in kilometers. The following file formats .tab, .obj and .txt are supported as inputs:

The .tab files do not have a header and have 4 columns where the first one denotes if the row refers to a vertex (v) coordinates or the face (f) composed of three vertexes

../../../../_images/poly_tab_example.jpg

Figure 1: Example of .tab polyhedron shape file

The .obj files content is equivalent to the .tab extension but they admit comments (#) and separate the vertexes and faces content with an empty line

../../../../_images/poly_obj_example.jpg

Figure 2: Example of .obj polyhedron shape file

The .txt file has a first line as a header where the number of vertexes (first column) and faces (second column) are indicated. Then, it has 3 columns where vertexes coordinates and subsequently the faces correspondence with vertexes are provided

../../../../_images/poly_txt_example.jpg

Figure 3: Example of .txt polyhedron shape file

Additional file formats could be added to the function loadPolyFromFileToList(fileName: str) under gravCoeffOpps.py.


class PolyhedralGravityModel : public GravityModel
#include <polyhedralGravityModel.h>

Constant-density polyhedral gravity model.

In this class, a polyhedron is defined by its triangular facets. Each facet is defined by three vertices (they are triangles), and each vertex is defined by its position relative to the center of mass of the body. The mesh must be closed and consistently outward oriented. Signed tetrahedral volumes support bodies that are not star-shaped about their center of mass.

Public Functions

std::optional<std::string> initializeParameters() override

Initialize all parameters necessary for the computation of gravity.

The attribute muBody must be set separately. Previous facet and edge dyads are discarded on every call, including retries.

Note

A positive total volume does not validate mesh closure or local facet winding.

Returns:

An empty optional on success, or an error message if vertex or facet data is missing or the total signed volume is non-positive or non-finite.

std::optional<std::string> initializeParameters(const GravBodyData &body) override

Initialize all parameters using the body’s gravitational parameter.

The attribute muBody is read from the given GravBodyData. Previous facet and edge dyads are discarded on every call, including retries.

Note

A positive total volume does not validate mesh closure or local facet winding.

Parameters:

body – Body supplying the gravitational parameter.

Returns:

An empty optional on success, or an error message if vertex or facet data is missing or the total signed volume is non-positive or non-finite.

Eigen::Vector3d computeField(const Eigen::Vector3d &pos_BP_P) const override

Returns the gravity acceleration at a position around this body.

The position is given in the gravity body-centred rotating reference frame. Likewise, the resulting acceleration is obtained in the gravity body-centred rotating reference frame

double computePotentialEnergy(const Eigen::Vector3d &pos_BP_P) const override

Compute polyhedral specific gravitational potential energy.

Note

This is the negative of the positive potential in the Werner and Scheeres formulation.

Parameters:

pos_BP_P – Position relative to the body in its body-fixed frame [m].

Returns:

Specific potential energy, approaching -muBody/r at infinity [m^2/s^2].

inline bool dependsOnOrientation() const override

Always returns true: the field is evaluated from the body’s facet geometry in the body-centred rotating frame, so it depends on the body orientation.

A polyhedral model represents an irregular (generally non-axisymmetric) shape, so the body orientation must be known to evaluate the field correctly. Without a planet-orientation message the body is treated as non-rotating, which produces spurious results (issue #1352).

Public Members

double muBody = 0

[m^3/s^2] Gravitation parameter for the planet

Eigen::MatrixX3d xyzVertex

This matrix contains the position of every vertex of this polyhedron, in meters. Each row corresponds to a different vertex, while each column corresponds to x, y, z respectively.

Eigen::MatrixX3i orderFacet

One-based vertex indices of the triangular facets.

Each row contains three numbers, each corresponding to the index of a vertex, as defined in xyzVertex. These three vertices define a single facet of the polyhedron.

Note that the order of the vertex index is important: the facets must all be outward pointing and form a closed surface. Individual signed tetrahedral volumes may be negative, but their total must be positive.

Private Functions

void initializeFacets()
void initializeEdges()
bool addEdge(Eigen::Vector2i edge, Eigen::Index idx_edge, int idx_facet)

Private Members

double volPoly = 0

[m^3] Volume of the polyhedral

Eigen::MatrixX3d normalFacet

This matrix contains the outward normal of each facet [-].

Eigen::MatrixX3d xyzFacet

This matrix contains the center of each facet [m].

Eigen::MatrixXi edgeVertex

This matrix contains the vertex initial and final indexes for each edge [-].

Eigen::MatrixXi edgeFacet

This matrix contains the shared facet indexes for each edge [-]

Eigen::VectorXd edgeLength

This vector contains the length of each edge [m]

std::vector<Eigen::Matrix3d> FfDyad

The entries of this vector correspond to the facet normal dyad product nf nf’ [-]

std::vector<Eigen::Matrix3d> EeDyad

The entries of this vector correspond to the edge dyad product as nFA n12’ + nFB n21’ (Figure 7 Werner&Scheeres 1996) [-]