Skip to content

models.rocket

machwave.models.rocket

Fuselage

Deals primarily with aerodynamic parameters.

Source code in machwave/models/rocket/fuselage.py
class Fuselage:
    """Deals primarily with aerodynamic parameters."""

    def __init__(
        self,
        length: float,
        outer_diameter: float,
        drag_coefficient: np.ndarray | float | int,
        frontal_area: float | None = None,
    ) -> None:
        """Initialize the Fuselage object.

        Args:
            length: Fuselage length [m].
            outer_diameter: Fuselage outer diameter [m].
            drag_coefficient: Drag coefficient value(s). Can be single value,
                or 2D array with first column as velocity and second column
                as corresponding drag coefficient.
        """
        self.length = length
        self.outer_diameter = outer_diameter
        self._frontal_area = frontal_area
        self._drag_coefficient = drag_coefficient

    @property
    def frontal_area(self) -> float:
        """Frontal area of the fuselage [m^2]."""
        if self._frontal_area is not None:
            return self._frontal_area

        return get_circle_area(self.outer_diameter)

    def get_drag_coefficient(self, velocity: float = 0) -> float:
        """Get the drag coefficient of the fuselage.

        Args:
            velocity: Velocity at which to calculate drag coefficient.

        Returns:
            Drag coefficient value.

        Raises:
            DragCoefficientTypeError: If type of drag_coefficient is not
                recognized.
            ValueError: If velocity is None and drag_coefficient is a list.
        """
        if isinstance(self._drag_coefficient, np.ndarray):
            if velocity is None:
                raise ValueError(
                    "`velocity` must be provided when `drag_coefficient` is a list."
                )

            return np.interp(
                velocity,
                self._drag_coefficient[:, 0],
                self._drag_coefficient[:, 1],
            )

        elif isinstance(self._drag_coefficient, (float, int)):
            return self._drag_coefficient
        else:
            raise DragCoefficientTypeError(
                self._drag_coefficient,
                "Type not recognized in 'drag_coefficient'. "
                "Must be a float, int, or a numpy array",
            )

frontal_area property

Frontal area of the fuselage [m^2].

__init__(length, outer_diameter, drag_coefficient, frontal_area=None)

Initialize the Fuselage object.

Parameters:

Name Type Description Default
length float

Fuselage length [m].

required
outer_diameter float

Fuselage outer diameter [m].

required
drag_coefficient ndarray | float | int

Drag coefficient value(s). Can be single value, or 2D array with first column as velocity and second column as corresponding drag coefficient.

required
Source code in machwave/models/rocket/fuselage.py
def __init__(
    self,
    length: float,
    outer_diameter: float,
    drag_coefficient: np.ndarray | float | int,
    frontal_area: float | None = None,
) -> None:
    """Initialize the Fuselage object.

    Args:
        length: Fuselage length [m].
        outer_diameter: Fuselage outer diameter [m].
        drag_coefficient: Drag coefficient value(s). Can be single value,
            or 2D array with first column as velocity and second column
            as corresponding drag coefficient.
    """
    self.length = length
    self.outer_diameter = outer_diameter
    self._frontal_area = frontal_area
    self._drag_coefficient = drag_coefficient

get_drag_coefficient(velocity=0)

Get the drag coefficient of the fuselage.

Parameters:

Name Type Description Default
velocity float

Velocity at which to calculate drag coefficient.

0

Returns:

Type Description
float

Drag coefficient value.

Raises:

Type Description
DragCoefficientTypeError

If type of drag_coefficient is not recognized.

ValueError

If velocity is None and drag_coefficient is a list.

Source code in machwave/models/rocket/fuselage.py
def get_drag_coefficient(self, velocity: float = 0) -> float:
    """Get the drag coefficient of the fuselage.

    Args:
        velocity: Velocity at which to calculate drag coefficient.

    Returns:
        Drag coefficient value.

    Raises:
        DragCoefficientTypeError: If type of drag_coefficient is not
            recognized.
        ValueError: If velocity is None and drag_coefficient is a list.
    """
    if isinstance(self._drag_coefficient, np.ndarray):
        if velocity is None:
            raise ValueError(
                "`velocity` must be provided when `drag_coefficient` is a list."
            )

        return np.interp(
            velocity,
            self._drag_coefficient[:, 0],
            self._drag_coefficient[:, 1],
        )

    elif isinstance(self._drag_coefficient, (float, int)):
        return self._drag_coefficient
    else:
        raise DragCoefficientTypeError(
            self._drag_coefficient,
            "Type not recognized in 'drag_coefficient'. "
            "Must be a float, int, or a numpy array",
        )

Rocket

A Rocket with propulsion, recovery system, fuselage and a specified dry-structure mass (mass_without_motor).

Source code in machwave/models/rocket/base.py
class Rocket:
    """
    A Rocket with propulsion, recovery system, fuselage and
    a specified dry-structure mass (mass_without_motor).
    """

    def __init__(
        self,
        propulsion: Motor,
        recovery: Recovery,
        fuselage: Fuselage,
        mass_without_motor: float,
    ) -> None:
        """
        Args:
            propulsion: Rocket motor or propulsion system.
            recovery: Recovery system (parachute, etc.).
            fuselage: Rocket body.
            mass_without_motor: Structure + avionics + recovery + fuselage mass [kg].
        """
        self.propulsion = propulsion
        self.recovery = recovery
        self.fuselage = fuselage
        self.mass_without_motor = mass_without_motor

    def get_launch_mass(self) -> float:
        """
        Total mass at liftoff = dry-structure + propellant.
        """
        return self.mass_without_motor + self.propulsion.get_launch_mass()

    def get_dry_mass(self) -> float:
        """
        Total dry mass = structure + inert mass of the motor.
        """
        return self.mass_without_motor + self.propulsion.get_dry_mass()

__init__(propulsion, recovery, fuselage, mass_without_motor)

Parameters:

Name Type Description Default
propulsion Motor

Rocket motor or propulsion system.

required
recovery Recovery

Recovery system (parachute, etc.).

required
fuselage Fuselage

Rocket body.

required
mass_without_motor float

Structure + avionics + recovery + fuselage mass [kg].

required
Source code in machwave/models/rocket/base.py
def __init__(
    self,
    propulsion: Motor,
    recovery: Recovery,
    fuselage: Fuselage,
    mass_without_motor: float,
) -> None:
    """
    Args:
        propulsion: Rocket motor or propulsion system.
        recovery: Recovery system (parachute, etc.).
        fuselage: Rocket body.
        mass_without_motor: Structure + avionics + recovery + fuselage mass [kg].
    """
    self.propulsion = propulsion
    self.recovery = recovery
    self.fuselage = fuselage
    self.mass_without_motor = mass_without_motor

get_dry_mass()

Total dry mass = structure + inert mass of the motor.

Source code in machwave/models/rocket/base.py
def get_dry_mass(self) -> float:
    """
    Total dry mass = structure + inert mass of the motor.
    """
    return self.mass_without_motor + self.propulsion.get_dry_mass()

get_launch_mass()

Total mass at liftoff = dry-structure + propellant.

Source code in machwave/models/rocket/base.py
def get_launch_mass(self) -> float:
    """
    Total mass at liftoff = dry-structure + propellant.
    """
    return self.mass_without_motor + self.propulsion.get_launch_mass()