Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Implementing 3-dof-simulation #745

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,552 changes: 1,552 additions & 0 deletions docs/examples/test_bella_lui_flight_sim.ipynb

Large diffs are not rendered by default.

847 changes: 847 additions & 0 deletions docs/examples/test_camoes_flight_sim.ipynb

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions rocketpy/motors/PointMassMotor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from functools import cached_property
import numpy as np
from ..mathutils.function import Function, funcify_method
from .motor import Motor

class PointMassMotor(Motor):
"""Class representing a motor modeled as a point mass.
Inherits from the Motor class and simplifies the model to a thrust-producing
object without detailed structural components."""

def __init__(
self,
thrust_source,
dry_mass,
thrust_curve=None,
propellant_initial_mass=None,
propellant_final_mass=None,
burn_time=None,
center_of_dry_mass_position=0,
interpolation_method="linear",
):
"""Initialize the PointMassMotor class.

Parameters
----------
thrust_source : int, float, callable, string, array, Function
Thrust source similar to the Motor class.
dry_mass : float
Total dry mass of the motor in kg.
thrust_curve : Function, np.array, or str (csv file), optional
Required if thrust_source is a csv file, Function, or np.array.
propellant_initial_mass : float, optional
Required if thrust_source is a csv file, Function, or np.array.
propellant_final_mass : float, optional
Required if thrust_source is callable.
burn_time : float or tuple of float, optional
Required if thrust_source is callable or if a thrust value is given.
center_of_dry_mass_position : float, optional
Initial position of the motor, default is 0.
interpolation_method : string, optional
Interpolation method for thrust curve, default is 'linear'.
"""
if isinstance(thrust_source, (Function, np.ndarray, str)):
if thrust_curve is None or propellant_initial_mass is None:
raise ValueError("thrust_curve and propellant_initial_mass are required for csv, Function, or np.array inputs.")
elif callable(thrust_source):
if any(param is None for param in [thrust_curve, propellant_initial_mass, burn_time, propellant_final_mass]):
raise ValueError("thrust_curve, propellant_initial_mass, burn_time, and propellant_final_mass are required for callable inputs.")
elif isinstance(thrust_source, (int, float)):
if any(param is None for param in [thrust_curve, propellant_initial_mass, burn_time]):
raise ValueError("thrust_curve, propellant_initial_mass, and burn_time are required when a thrust value is given.")

Check warning on line 51 in rocketpy/motors/PointMassMotor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/PointMassMotor.py#L43-L51

Added lines #L43 - L51 were not covered by tests

super().__init__(

Check warning on line 53 in rocketpy/motors/PointMassMotor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/PointMassMotor.py#L53

Added line #L53 was not covered by tests
thrust_source=thrust_source,
dry_mass=dry_mass,
center_of_dry_mass_position=center_of_dry_mass_position,
burn_time=burn_time,
interpolation_method=interpolation_method,
)

@funcify_method("Time (s)", "Thrust (N)")
def thrust(self):
"""Returns the thrust of the motor as a function of time."""
return self.thrust_source

Check warning on line 64 in rocketpy/motors/PointMassMotor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/PointMassMotor.py#L64

Added line #L64 was not covered by tests

@cached_property
def total_mass(self):
"""Returns the constant total mass of the point mass motor."""
return self.dry_mass

Check warning on line 69 in rocketpy/motors/PointMassMotor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/PointMassMotor.py#L69

Added line #L69 was not covered by tests

@funcify_method("Time (s)", "Acceleration (m/s^2)")
def acceleration(self):
"""Computes the acceleration of the motor as thrust divided by mass."""
return self.thrust() / self.total_mass

Check warning on line 74 in rocketpy/motors/PointMassMotor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/PointMassMotor.py#L74

Added line #L74 was not covered by tests
18 changes: 17 additions & 1 deletion rocketpy/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@
from rocketpy.rocket.parachute import Parachute
from rocketpy.tools import parallel_axis_theorem_from_com


class BaseRocket:
"""Base class for a rocket model with minimal attributes and methods."""
def __init__(self, mass):
self.mass = mass
self.motor = None

Check warning on line 31 in rocketpy/rocket/rocket.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/rocket/rocket.py#L30-L31

Added lines #L30 - L31 were not covered by tests
def add_motor(self, motor):
self.motor = motor

Check warning on line 33 in rocketpy/rocket/rocket.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/rocket/rocket.py#L33

Added line #L33 was not covered by tests
def evaluate_total_mass(self):
if self.motor:
return self.mass + self.motor.total_mass
return self.mass

Check warning on line 37 in rocketpy/rocket/rocket.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/rocket/rocket.py#L35-L37

Added lines #L35 - L37 were not covered by tests

class PointMassRocket(BaseRocket):
"""Rocket modeled as a point mass for3-DOF simulations."""
def __init__(self, mass, drag_coefficient=0):
super().__init__(mass)
self.drag_coefficient = drag_coefficient

Check warning on line 43 in rocketpy/rocket/rocket.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/rocket/rocket.py#L42-L43

Added lines #L42 - L43 were not covered by tests
# pylint: disable=too-many-instance-attributes, too-many-public-methods, too-many-instance-attributes
class Rocket:
"""Keeps rocket information.
Expand Down
Loading
Loading