C++ Module: sphericalHarmonicsGravityModel

class SphericalHarmonicsGravityModel : public GravityModel
#include <sphericalHarmonicsGravityModel.h>

The Spherical Harmonics gravity model

Public Functions

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

Validate coefficients and initialize the recurrence tables.

The attributes muBody and radEquator must be set separately. Previous recurrence tables are discarded on every attempt.

Note

After failure, correct the configuration and initialize successfully before evaluating the field.

Returns:

An empty optional on success, or an error message if either coefficient table has fewer than maxDeg + 1 rows or a retained row l has fewer than l + 1 entries.

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

Initialize the gravity model from the body parameters.

The attribute radEquator is kept if it is positive, for example when it was loaded from the coefficient file, since the normalized coefficients are only valid with the reference radius of their model. Otherwise, it is read from the radEquator of the given GravBodyData.

The attribute muBody is replaced by body.mu, which must be finite and positive so the field and other gravity consumers use the same parameter. Previous recurrence tables are discarded on every attempt.

Note

After failure, correct the configuration and initialize successfully before evaluating the field.

Parameters:

body – Gravity body supplying the gravitational parameter and fallback reference radius.

Returns:

An empty optional on success, or an error message if body.mu is invalid or the coefficient tables do not contain all entries through maxDeg.

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

Compute gravity acceleration using the current maxDeg, including the point-mass term.

Parameters:

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

Throws:

BasiliskError – If initialization has not succeeded, maxDeg exceeds the initialized degree, or either coefficient table lacks an entry needed for the evaluation.

Returns:

Acceleration in the body-fixed frame [m/s^2].

Eigen::Vector3d computeField(const Eigen::Vector3d &position_planetFixed, size_t degree, bool include_zero_degree) const

Compute gravity acceleration through a requested degree.

Note

Coefficient values may be changed without reinitialization. Only rows and orders used by this evaluation are checked; higher degrees and extra columns are ignored.

Parameters:
  • position_planetFixed – Position relative to the body in the body-fixed frame [m].

  • degree – Maximum degree to evaluate; must not exceed maxDeg or the last initialized degree.

  • include_zero_degree – Whether to include the point-mass contribution.

Throws:

BasiliskError – If initialization has not succeeded, the requested degree exceeds a limit, or either coefficient table lacks an entry needed for the evaluation.

Returns:

Acceleration in the body-fixed frame [m/s^2].

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

Compute the point-mass approximation to specific potential energy.

Note

Spherical harmonics coefficients are currently ignored in the potential energy.

Note

The historical parameter name is retained for Python keyword compatibility. This radial potential is independent of the position frame’s orientation.

Parameters:

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

Returns:

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

bool dependsOnOrientation() const override

Returns true if any retained coefficient of order >= 1 (a tesseral or sectoral term) is non-zero. Such terms vary with the body’s longitude, so the body orientation must be known to evaluate them correctly. A purely zonal field (only order-0 terms, e.g. a J2-only model) returns false.

Public Members

double radEquator = 0

[m] Reference radius of the spherical harmonics coefficients

double muBody = 0

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

size_t maxDeg = 0

Maximum degree of spherical harmonics to use.

Initialization requires at least maxDeg + 1 rows in each coefficient table. Each retained row l must contain at least l + 1 entries. Higher degrees and extra columns are ignored. Reinitialize before evaluating degrees above the degree prepared by the last successful initialization.

std::vector<std::vector<double>> cBar

Normalized cosine coefficients indexed as cBar[degree][order] [-].

Note

See maxDeg for the required table dimensions.

std::vector<std::vector<double>> sBar

Normalized sine coefficients indexed as sBar[degree][order] [-].

Note

See maxDeg for the required table dimensions.

mutable BSKLogger bskLogger

BSK Logging.

Private Functions

void clearParameters()

Discard recurrence tables and invalidate the initialized degree.

std::optional<std::string> validateCoefficients(size_t degree) const

Check the coefficient entries needed through a given degree.

Parameters:

degree – Highest degree whose coefficients must be present.

Returns:

An empty optional on success, or an error identifying the missing row or entries.

Private Members

std::optional<size_t> initializedDegree

Degree prepared by the last successful initialization.

mutable std::vector<std::vector<double>> aBar

The following parameters are used internally to compute the gravity.

They are coefficients used in the method of Pines for the gravity due to SH. For their definition, see the ‘Basilisk-GravityEffector’ documentation. [-] Eq. 61

std::vector<std::vector<double>> n1

[-] Eq. 63

std::vector<std::vector<double>> n2

[-] Eq. 64

std::vector<std::vector<double>> nQuot1

[-] Eq. 79

std::vector<std::vector<double>> nQuot2

[-] Eq. 80