Skip to content

[#1656] Add optional equinoctial formation averaging - #1668

Merged
schaubh merged 6 commits into
AVSLab:developfrom
zakariyaghazzol:feature/bsk-1656--formation-barycenter
Nov 6, 2026
Merged

schaubh merged 6 commits into
AVSLab:developfrom
zakariyaghazzol:feature/bsk-1656--formation-barycenter

Conversation

@zakariyaghazzol

@zakariyaghazzol zakariyaghazzol commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds optional prograde and retrograde equinoctial mass-averaged formation barycenter evaluation through orbitalElementType. The Cartesian and default classical-element modes still use the same calculations and output messages.

The new modes mass-average orbit size, shape and tilt, and circularly average mean longitude. They calculate the reference position and velocity from the averaged equinoctial elements. The scalar is named semiMajorAxis to distinguish it from the plane-direction vectors.

The supported domain is nonradial elliptic motion. Unsupported states, excluded poles and numerically undefined longitude means raise explicit Basilisk errors.

Verification

  • Clean Linux Release build, followed by a rebuild after the final variable rename.
  • Full run_all_test.py: 807 native tests passed; 13,874 Python tests passed, 459 skipped, zero failures.
  • 231 module cases cover the reported formations, both representations, weighting, orbital timing, numerical boundaries and repeated message updates. Both output forms are checked.
  • Reporter cases use a geometry-specific 1 cm regression budget. We haven't established a formal second-order error bound.
  • Twenty captured legacy states match the baseline exactly.
  • Applicable pre-commit checks and strict scoped documentation preview pass.

Skips require disabled optional features, Cargo or optional Orekit. Native Windows and enabled optional-feature configurations were not validated locally.

Documentation

Updates module usage, element definitions and limitations, and adds release-note and known-issue snippets.

@zakariyaghazzol
zakariyaghazzol requested a review from a team as a code owner November 5, 2026 04:03
@schaubh schaubh self-assigned this Nov 5, 2026
@schaubh
schaubh self-requested a review November 5, 2026 15:10
@schaubh schaubh added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 5, 2026
@schaubh schaubh added this to Basilisk Nov 5, 2026
…uters.

Before the tolerances were very tight and could fail on other platforms.
Extend formationBarycenter coverage beyond single-spacecraft singular
states with 18 formation cases spanning both equinoctial representations.

Add 12 exact and near-equatorial cases with circular, near-circular, and
eccentric members. Use unequal masses, semimajor axes, and orbital phases,
with widely separated ascending nodes and nearby periapsis longitudes.
Compute the independent reference from prescribed classical elements so
undefined angles need not be recovered from Cartesian input states.

Add six cases that cancel the averaged eccentricity components, inclination
components, or both. A 1:3 mass ratio balances opposing component vectors
with a 3:1 magnitude ratio. Their common mean longitude and analytically
known averaged orbit provide expected states independently of the general
weighted-reference helper.

Check position and velocity on both C and C++ output interfaces using
physical absolute tolerances. Include descriptive parameter IDs and
docstrings explaining each fixture. Production behavior is unchanged.

Validation:
- All 249 module tests pass on the local macOS build in 1.04 seconds.
- All 18 new cases pass under Python 3.14 and Python 3.15.
- A separate 70-digit classical-orbit reference agrees with all 18 expected
  states within 6.4 nm in position and 5.1e-12 m/s in velocity.
- Review probes confirm all 18 cases reject Cartesian fallback and equal
  weights; all six near-equatorial cases reject flattening onto the equator.
- Applicable pre-commit checks, docstring rendering, and git diff --check
  pass.
… tests

Protect the existing classical averaging behavior while PR 1668 adds
optional equinoctial representations. Add 12 regressions using four
three-spacecraft formations across three configuration paths:

- Omit orbitalElementType to exercise the default classical selection.
- Set CLASSICAL explicitly.
- Start in Cartesian mode with zero mu, then enable orbital averaging
  through the legacy useOrbitalElements and mu attributes after an update.

Cover unequal spacecraft masses and semimajor axes, angular wrapping,
eccentric retrograde motion, and low-eccentricity inclined formations.
Check position and velocity against fixed outputs captured from the
unmodified C++ module and header at PR 1668's base commit,
d0f9832. Document the reference provenance,
input element ordering, physical units, and configuration coverage.

Require finite, identical C and C++ output states. Compare against the
fixed references with zero relative tolerance and absolute tolerances of
2 micrometers in position and 2e-8 m/s in velocity. Use nonsingular inputs
to retain sensitivity without depending on ill-conditioned classical
angles or exact floating-point agreement across computers.

Validation:
- All 261 formationBarycenter tests pass under Python 3.15.
- All 12 added cases also pass under Python 3.14.
- Baseline outputs remain within tolerance with floating-point contraction
  disabled in the original module and orbital utilities.
- Separate review probes reject Cartesian/equinoctial substitution, equal
  weighting, arithmetic angle averaging, and mean-anomaly substitution.
- All 128 input-rounding probes, perturbing components by up to four ULPs,
  remain within tolerance.
- Pre-commit checks, diff checks, and RST docstring parsing pass.

Validation was performed on macOS ARM; Linux and Windows execution remains
for CI. This change adds tests only and preserves the production module
and public API.

schaubh commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Backward compatibility

The opt-in design follows the recommendation in issue #1656: preserve existing Cartesian and classical averaging while adding alternative representations. Added 12 classical compatibility regressions using fixed outputs captured from the pre-PR implementation. These cover default selection, explicit CLASSICAL, and the legacy runtime configuration pattern, checking both position and velocity.

schaubh commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Equinoctial option names

Renamed the choices to EQUINOCTIAL_PROGRADE and EQUINOCTIAL_RETROGRADE throughout the implementation, documentation, and tests. Keeping explicit selection is appropriate because the representation must be common to the formation, and averaging in different representations can produce different references. Automatic switching could therefore change the reference unexpectedly.

schaubh commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Portable numerical assertions

Corrected the Cartesian regression test’s dependence on bitwise agreement between NumPy and C++ arithmetic. The independent NumPy comparison now permits small floating-point rounding differences, including fused multiply-add differences. Exact comparisons between native outputs remain, preserving the check that the orbital selector does not affect Cartesian behavior.

schaubh commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Multi-spacecraft singularity coverage

Added 18 regressions covering nontrivial equatorial and near-equatorial formations, including circular and near-circular members. Additional cases exercise cancellation of averaged eccentricity components, inclination components, and both together. Both representations and output interfaces are checked against independent references, including analytical cancellation cases.

schaubh commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Observable runtime-selector transitions

Replaced the singleton runtime-selector test, which could pass even when the selector change was ignored. The replacement covers all six directed transitions among classical, prograde, and retrograde averaging using a formation with distinct expected outputs. It verifies changes after initialization and after a scheduled update. Deliberately ignored or swapped selections fail every applicable case.

schaubh commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Mathematical review, documentation, and validation

Independently checked the equinoctial conversion and reconstruction for both representations, including singular and cancellation cases; no algebraic defect was found. The documentation explains the supported elliptic domain, excluded poles, undefined longitude means, and the interpretation of output velocity for unequal semimajor axes.

All 266 module tests and both existing station-keeping integration cases pass locally. Captured legacy outputs remain identical, and header compilation, scoped documentation, and formatting checks pass. Validation of the combined branch on Linux and Windows remains for CI.

@schaubh schaubh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I posted some small comments and pushed commits to address them. @zakariyaghazzol , please take a look at my commits and let me know if you agree with them.

@zakariyaghazzol

Copy link
Copy Markdown
Contributor Author

Thanks, @schaubh. I went through your commits and agree with the changes. The test with multiple spacecraft makes it easier to tell if the mode switched. The barycenter and station-keeping tests passed in my Linux run too.

When you get a chance, could you approve the new CI run so we can check macOS?

@schaubh schaubh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing my changes @zakariyaghazzol. I'll merge this PR when all the tests are successfully completed.

@schaubh
schaubh merged commit 016955f into AVSLab:develop Nov 6, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this to ✅ Done in Basilisk Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

In formationBarycenter classical orbital-element averaging is singular near circular orbits

2 participants