Skip to content

services.eng

Import/export utilities for interoperability with external rocket simulation tools. Provides .eng file generation — the standard thrust-curve format used by OpenRocket, RASAero, and other flight simulators. Supply time-thrust arrays from a Machwave simulation and get a ready-to-use .eng string.

machwave.services.eng

generate_eng_file_content(time, thrust, propellant_mass, burn_time, chamber_length, outer_diameter, motor_mass, manufacturer, name, eng_res=25)

Generate .eng file content for rocket simulation software.

Parameters:

Name Type Description Default
time ndarray

Time array [s].

required
thrust ndarray

Thrust array [N].

required
propellant_mass ndarray

Propellant mass array [kg].

required
burn_time float

Total burn time [s].

required
chamber_length float

Chamber length [m].

required
outer_diameter float

Motor outer diameter [m].

required
motor_mass float

Motor mass [kg].

required
manufacturer str

Manufacturer name.

required
name str

Motor name.

required
eng_res int

Number of time steps in output file. Default is 25.

25

Returns:

Type Description
str

Content of the .eng file as a string.

Source code in machwave/services/eng.py
def generate_eng_file_content(
    time: np.ndarray,
    thrust: np.ndarray,
    propellant_mass: np.ndarray,
    burn_time: float,
    chamber_length: float,
    outer_diameter: float,
    motor_mass: float,
    manufacturer: str,
    name: str,
    eng_res: int = 25,
) -> str:
    """
    Generate .eng file content for rocket simulation software.

    Args:
        time: Time array [s].
        thrust: Thrust array [N].
        propellant_mass: Propellant mass array [kg].
        burn_time: Total burn time [s].
        chamber_length: Chamber length [m].
        outer_diameter: Motor outer diameter [m].
        motor_mass: Motor mass [kg].
        manufacturer: Manufacturer name.
        name: Motor name.
        eng_res: Number of time steps in output file. Default is 25.

    Returns:
        Content of the .eng file as a string.
    """
    burn_index = np.where(time <= burn_time)[0]
    time = time[burn_index]
    thrust = thrust[burn_index]
    propellant_mass = propellant_mass[burn_index]

    t_out = np.linspace(0, time[-1], eng_res)

    thrust_out = np.interp(t_out, time, thrust, left=0, right=0)
    propellant_mass_out = np.interp(t_out, time, propellant_mass, right=0)

    eng_header = (
        f"{name} {outer_diameter * 1e3:.4f} {chamber_length * 1e3:.4f} P "
        f"{propellant_mass_out[0]:.4f} {propellant_mass_out[0] + motor_mass:.4f} "
        f"{manufacturer}\n"
    )

    eng_content = "; Generated by Machwave program\n" + eng_header
    for i in range(eng_res):
        eng_content += f"   {t_out[i]:.2f} {thrust_out[i]:.0f}\n"
    eng_content += ";"

    return eng_content