hpr/lib.rs
1//! The library facade of FusionSpace HPR ยท Sim: a builder API for environments, motors, rockets
2//! and flights, and the workspace's crates re-exported.
3//!
4//! The guide has three pages to start from. [Start here][guide-start] says what works and how far
5//! to trust it. [Getting started][guide-first] flies a first rocket. [The builder][guide-builder]
6//! walks through this crate's API. The [`guide`] module is the same walk-through in this
7//! reference, in five short chapters.
8//!
9//! [guide-start]: https://hpr.fusionspace.co/start-here.html
10//! [guide-first]: https://hpr.fusionspace.co/getting-started.html
11//! [guide-builder]: https://hpr.fusionspace.co/the-builder.html
12//!
13//! Four types make a flight, in the order a program needs them:
14//!
15//! - [`Environment`]: the launch site, the atmosphere and the wind.
16//! - [`Motor`]: a motor from the built-in catalog or a RASP `.eng` file.
17//! - [`Rocket`]: parts added from the nose back, the motor, and the recovery devices.
18//! - [`Flight`]: the rocket flown from a rail, with its apogee, speeds and landing.
19//!
20//! > **How far to trust it.** The builder adds no physics of its own. It makes the same design
21//! > tree and flies the same simulation as the crates below it. A test flies a rocket built both
22//! > ways to the same numbers, bit for bit. So its numbers are as good as those models are. The
23//! > guide's [Accuracy][guide-accuracy] page says how good that is, with every comparison made.
24//!
25//! [guide-accuracy]: https://hpr.fusionspace.co/accuracy.html
26//!
27//! ```
28//! use hpr::rocket::{Fins, Mass, MotorTube, Nose, Tube, material};
29//! use hpr::{
30//! CanopyType, Device, DeviceDrag, Environment, FinPlanform, Flight, Motor, NoseShape,
31//! Position, Rocket, Trigger,
32//! };
33//!
34//! let environment = Environment::new(32.99, -106.97, 1400.0)?;
35//! let ogive = NoseShape::Ogive { radius_ratio: 1.0 };
36//! let planform = FinPlanform::Trapezoidal {
37//! root_chord_m: 0.1,
38//! tip_chord_m: 0.04,
39//! span_m: 0.045,
40//! sweep_m: 0.05,
41//! };
42//! let mut rocket = Rocket::new("Small", 0.0563)?;
43//! rocket
44//! .add_nose(Nose::hollow(ogive, 0.22, 0.0015, material("abs")?))?
45//! .add_tube(Tube::new(0.9, 0.00115, material("kraft_phenolic")?))?
46//! .add_fins(Fins::new(3, planform, 0.003175, material("birch_plywood")?))?
47//! .add_motor_tube(MotorTube::new(0.2, 0.029, 0.001, material("kraft_phenolic")?))?
48//! .add_mass(Mass::new(0.2, Position::Top { aft_offset_m: 0.07 }))?
49//! .set_motor(Motor::from_catalog("H54")?.with_delay_s(10.0)?)?
50//! .add_parachute(Device::new(
51//! "parachute",
52//! DeviceDrag::canopy(CanopyType::FlatCircular, 0.9),
53//! Trigger::MotorDelay { motor: 0 },
54//! ));
55//! let flight = Flight::builder(&rocket, &environment, 1.8).fly()?;
56//! assert!(flight.apogee_m().is_some_and(|apogee_m| apogee_m > 1000.0));
57//! # Ok::<(), hpr::Error>(())
58//! ```
59//!
60//! The builder makes the same things the crates below it use, and hands them over. A rocket's
61//! [`Rocket::design`] is an [`hpr_design::Rocket`], and a flight's [`FlightBuilder::simulation`]
62//! is an [`hpr_sim::Simulation`]. For what the builder doesn't offer, such as staging, clusters,
63//! pods or mass shifts, build with the crates, which this one re-exports by name. Each covers
64//! one part of the work:
65//!
66//! - [`hpr_core`]: the math, units, frames, the Earth and gravity.
67//! - [`hpr_atmos`]: the atmosphere and the wind.
68//! - [`hpr_motor`]: solid motors, their thrust curves and motor files.
69//! - [`hpr_design`]: a rocket's parts, materials, mass and stages.
70//! - [`hpr_aero`]: the aerodynamics: normal force, center of pressure and drag.
71//! - [`hpr_sim`]: the flight itself, in six degrees of freedom, with recovery.
72//! - [`hpr_analysis`]: Monte Carlo runs, sensitivity analysis and optimization.
73//! - [`hpr_format`]: HPR's own design format.
74//! - [`hpr_io`]: other programs' files: OpenRocket designs and parts, weather and elevation.
75//! - [`hpr_flightdata`]: flight logs and the readings taken from them, with no simulator.
76//! - [`hpr_forensics`]: a flight log against a simulation of it, planned; today it holds only
77//! synthetic flights to test the readings on.
78//!
79//! The `net` feature adds `hpr-net` (as `hpr::hpr_net`). It holds the cache, the offline mode and
80//! the HTTP transport, and these sources:
81//!
82//! - `hpr_net::open_meteo`: a launch site's weather from Open-Meteo.
83//! - `hpr_net::wyoming`: weather-balloon soundings from the University of Wyoming's archive.
84//! - `hpr_net::nomads`: NOAA's GFS and RAP forecasts.
85//! - `hpr_net::elevation`: a site's height above sea level from Open-Meteo.
86//! - `hpr_net::motor_finder`: motor stock and prices from motor.fusionspace.co.
87//! - `hpr_net::thrustcurve`: motor records and thrust curves from ThrustCurve.org.
88//!
89//! The `parquet` feature turns on `hpr_sim`'s Parquet export (`hpr_sim::export::parquet`).
90//! [`ork`] flies the stage separation an OpenRocket `.ork` file describes.
91
92pub mod environment;
93pub mod error;
94pub mod flight;
95pub mod guide;
96pub mod motor;
97pub mod ork;
98pub mod rocket;
99
100pub use environment::Environment;
101pub use error::{CatalogProblem, Error, Order};
102pub use flight::{Flight, FlightBuilder};
103pub use motor::Motor;
104pub use rocket::Rocket;
105
106pub use hpr_aero;
107pub use hpr_analysis;
108pub use hpr_atmos;
109pub use hpr_core;
110pub use hpr_design;
111pub use hpr_flightdata;
112pub use hpr_forensics;
113pub use hpr_format;
114pub use hpr_io;
115pub use hpr_motor;
116#[cfg(feature = "net")]
117pub use hpr_net;
118pub use hpr_sim;
119
120pub use hpr_design::{FinCrossSection, FinPlanform, NoseShape, Position};
121pub use hpr_sim::{CanopyType, Device, DeviceDrag, EnvelopeFlag, Separation, Trigger};
122
123#[cfg(test)]
124mod tests;