pub fn design_with(
file: &OrkFile,
supplied: &SuppliedCurves,
) -> Imported<Design>Expand description
Like design, but a motor can also take its thrust curve from supplied.
Each motor looks in three places, in order: a curve embedded in the file, then a supplied curve for the motor’s digest, then the bundled catalog. An embedded curve that does not read or build is passed over, with a warning, for the next place.
use hpr_io::ork::{CaseSize, Curve, SuppliedCurves};
use hpr_motor::{SolidMotor, ThrustCurve};
let xml = br#"<?xml version='1.0' encoding='utf-8'?>
<openrocket version="1.9" creator="example">
<rocket><subcomponents><stage><name>Sustainer</name><subcomponents>
<bodytube><id>body</id><length>0.4</length><thickness>0.001</thickness>
<radius>0.0125</radius>
<motormount><ignitionevent>automatic</ignitionevent><ignitiondelay>0.0</ignitiondelay>
<overhang>0.0</overhang>
<motor configid="c1"><type>single</type><manufacturer>Example</manufacturer>
<digest>0123abcd</digest><designation>E9</designation>
<diameter>0.024</diameter><length>0.07</length><delay>4.0</delay></motor>
</motormount></bodytube>
</subcomponents></stage></subcomponents></rocket>
</openrocket>"#;
let read = hpr_io::ork::read(xml)?;
// A made-up 19 N·s motor: 10 N for about two seconds, from 10 g of propellant in a 30 g motor.
let thrust = ThrustCurve::new(vec![0.0, 0.1, 1.9, 2.0], vec![0.0, 10.0, 10.0, 0.0])?;
let (diameter_m, length_m, propellant_kg, loaded_kg) = (0.024, 0.07, 0.01, 0.03);
let motor = SolidMotor::from_envelope(thrust, diameter_m, length_m, propellant_kg, loaded_kg)?;
let mut supplied = SuppliedCurves::new("a motor database");
supplied.insert("0123abcd", CaseSize { diameter_m, length_m }, motor)?;
let design = hpr_io::ork::design_with(&read.value, &supplied).value;
let flown = &design.motors.configurations[0].motors[0];
assert!(matches!(flown.curve, Curve::Supplied { .. }));
assert!(design.rocket.assemble("c1").is_ok());