Skip to main content

rockets_engine/
lib.rs

1//! Powered, three-dimensional point-mass flight, using SI units and simulation time.
2//!
3//! Prescribed motors supply thrust and consume propellant in proportion to impulse;
4//! [`Stage`]s add serial or parallel staging with scheduled separations. [`Simulator`]
5//! integrates translation while [`ForceModel`] supplies environmental acceleration and
6//! [`Guidance`] supplies optional control commands. [`UniformGravity`] covers local
7//! flat-frame flight and [`CentralGravity`] covers planet-scale arcs; the default
8//! `ballistics` feature reuses ballistics-engine's atmosphere and drag kernel.
9//!
10//! Coordinates are right-handed; the conventional local frame is X/downrange, Y/up,
11//! Z/lateral, but [`CentralGravity`] works in an Earth-centered frame of the caller's
12//! choosing. No time compression occurs inside this crate. This is a point-mass model,
13//! not an attitude, actuator or aerodynamic-lift simulation.
14//!
15//! See the README and `examples/boost_coast.rs` for integration and model assumptions.
16
17// wasm-bindgen generates unsafe blocks, so the wasm build cannot keep the forbid.
18#![cfg_attr(not(feature = "wasm"), forbid(unsafe_code))]
19#![warn(missing_docs)]
20#![doc = include_str!("../README.md")]
21
22#[cfg(any(feature = "cli", feature = "wasm"))]
23mod analysis;
24#[cfg(feature = "ballistics")]
25pub mod ballistics;
26#[cfg(any(feature = "cli", feature = "wasm"))]
27pub mod command;
28#[cfg(feature = "ballistics")]
29mod dynamics;
30mod error;
31mod flight;
32mod guidance;
33mod motor;
34#[cfg(feature = "wasm")]
35pub mod wasm;
36
37#[cfg(feature = "ballistics")]
38pub use dynamics::{RollDynamics, Weathercock, WeathercockParams};
39pub use error::{Error, Result};
40pub use flight::{
41    AltitudeSwitch, BoxedForces, CentralGravity, FlightState, ForceModel, IntegratorSettings,
42    RailForces, Simulator, StepResult, UniformGravity, EARTH_MU_M3_S2,
43};
44pub use guidance::{
45    BoxedGuidance, ControlInput, FixedDirection, Guidance, GuidanceContext, ProgradeDirection,
46    SteeringLag, ThrustMisalignment,
47};
48pub use motor::{
49    Motor, MotorPhase, MotorSample, Rocket, RocketSample, Stage, ThrustCurve, ThrustPoint,
50};
51
52/// Three-dimensional SI vector in the fixed world frame.
53pub type Vec3 = nalgebra::Vector3<f64>;
54
55pub(crate) fn finite_vec(value: &Vec3) -> bool {
56    value.iter().all(|x| x.is_finite())
57}
58
59pub(crate) fn nonnegative(value: f64, field: &'static str) -> Result<()> {
60    if !value.is_finite() || value < 0.0 {
61        return Err(Error::invalid(field, "must be finite and nonnegative"));
62    }
63    Ok(())
64}
65
66pub(crate) fn positive(value: f64, field: &'static str) -> Result<()> {
67    if !value.is_finite() || value <= 0.0 {
68        return Err(Error::invalid(field, "must be finite and positive"));
69    }
70    Ok(())
71}