Skip to main content

hpr/
lib.rs

1//! The hpr-sim library facade: a builder API for environments, motors, rockets and flights, and
2//! the workspace's crates re-exported.
3//!
4//! **Guide:** [Start here][guide-start] says what works and how far to trust it, [Getting
5//! started][guide-first] flies a first rocket, and [The builder][guide-builder] walks through
6//! this crate's API. The [`guide`] module is the same walk-through in this reference, in five
7//! short chapters.
8//!
9//! [guide-start]: https://nrdptel.github.io/hpr-sim/start-here.html
10//! [guide-first]: https://nrdptel.github.io/hpr-sim/getting-started.html
11//! [guide-builder]: https://nrdptel.github.io/hpr-sim/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, and a test flies a rocket built
22//! both ways to the same numbers, bit for bit. So its numbers are as good as those models are;
23//! the guide's [Accuracy][guide-accuracy] page says how good that is, with every comparison made.
24//!
25//! [guide-accuracy]: https://nrdptel.github.io/hpr-sim/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`], a flight's [`FlightBuilder::simulation`] an
62//! [`hpr_sim::Simulation`]. For what the builder doesn't offer, such as staging, clusters, pods
63//! or mass shifts, build those with the crates, which this one re-exports by name.
64//!
65//! The `net` feature adds `hpr-net` (as `hpr::hpr_net`): the cache, the offline mode, the HTTP
66//! transport, a launch site's weather from Open-Meteo (`hpr_net::open_meteo`), weather-balloon
67//! soundings from the University of Wyoming's archive (`hpr_net::wyoming`), NOAA's GFS and RAP
68//! forecasts (`hpr_net::nomads`), a site's height above sea level from Open-Meteo
69//! (`hpr_net::elevation`), motor stock and prices from motor.fusionspace.co
70//! (`hpr_net::motor_finder`), and motor records and thrust curves from ThrustCurve.org
71//! (`hpr_net::thrustcurve`). The `parquet`
72//! feature turns on `hpr-sim`'s Parquet export (`hpr_sim::export::parquet`). [`ork`] flies the
73//! stage separation an OpenRocket `.ork` file describes.
74
75pub mod environment;
76pub mod error;
77pub mod flight;
78pub mod guide;
79pub mod motor;
80pub mod ork;
81pub mod rocket;
82
83pub use environment::Environment;
84pub use error::{CatalogProblem, Error, Order};
85pub use flight::{Flight, FlightBuilder};
86pub use motor::Motor;
87pub use rocket::Rocket;
88
89pub use hpr_aero;
90pub use hpr_analysis;
91pub use hpr_atmos;
92pub use hpr_core;
93pub use hpr_design;
94pub use hpr_flightdata;
95pub use hpr_forensics;
96pub use hpr_format;
97pub use hpr_io;
98pub use hpr_motor;
99#[cfg(feature = "net")]
100pub use hpr_net;
101pub use hpr_sim;
102
103pub use hpr_design::{FinCrossSection, FinPlanform, NoseShape, Position};
104pub use hpr_sim::{CanopyType, Device, DeviceDrag, EnvelopeFlag, Separation, Trigger};
105
106#[cfg(test)]
107mod tests;