From 8483c2bee12cbea8995138583fdd11e066b0d839 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Thu, 7 Sep 2023 12:27:43 -0300 Subject: [PATCH 1/3] DOC: update motor docstrings regarding coordinate systems. --- rocketpy/Rocket.py | 6 +- rocketpy/motors/HybridMotor.py | 11 ++-- rocketpy/motors/LiquidMotor.py | 10 ++-- rocketpy/motors/Motor.py | 106 +++++++++++++++++++++++++++++++-- rocketpy/motors/SolidMotor.py | 20 ++----- 5 files changed, 120 insertions(+), 33 deletions(-) diff --git a/rocketpy/Rocket.py b/rocketpy/Rocket.py index 2599b92a6..e873f2c8b 100644 --- a/rocketpy/Rocket.py +++ b/rocketpy/Rocket.py @@ -619,11 +619,11 @@ def add_motor(self, motor, position): Parameters ---------- - motor : Motor, SolidMotor, HybridMotor, LiquidMotor + motor : Motor, SolidMotor, HybridMotor, LiquidMotor, GenericMotor Motor to be added to the rocket. position : int, float - Position, in m, of the motor's nozzle exit area relative to the user - defined rocket coordinate system. + Position, in meters, of the motor's coordinate system origin + relative to the user defined rocket coordinate system. See Also -------- diff --git a/rocketpy/motors/HybridMotor.py b/rocketpy/motors/HybridMotor.py index 81112dd75..a3e84867c 100644 --- a/rocketpy/motors/HybridMotor.py +++ b/rocketpy/motors/HybridMotor.py @@ -25,7 +25,7 @@ class HybridMotor(Motor): HybridMotor.coordinate_system_orientation : str Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". @@ -144,7 +144,7 @@ class HybridMotor(Motor): HybridMotor.burn_duration : float Total motor burn duration, in seconds. It is the difference between the ``burn_out_time`` and the ``burn_start_time``. - HybridMotor.exhaust_velocity : float + HybridMotor.exhaust_velocity : Function Propulsion gases exhaust velocity, assumed constant, in m/s. HybridMotor.burn_area : Function Total burn area considering all grains, made out of inner @@ -272,7 +272,7 @@ def __init__( coordinate_system_orientation : string, optional Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". Default is @@ -497,8 +497,9 @@ def add_tank(self, tank, position): tank : Tank Tank object to be added to the motor. position : float - Position of the tank relative to the nozzle exit. The - tank reference point is its tank_geometry zero point. + Position of the tank relative to the origin of the motor + coordinate system. The tank reference point is its + tank_geometry zero reference point. See Also -------- diff --git a/rocketpy/motors/LiquidMotor.py b/rocketpy/motors/LiquidMotor.py index 1792caf88..cfca55985 100644 --- a/rocketpy/motors/LiquidMotor.py +++ b/rocketpy/motors/LiquidMotor.py @@ -23,7 +23,7 @@ class LiquidMotor(Motor): LiquidMotor.coordinate_system_orientation : str Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". @@ -226,7 +226,7 @@ def __init__( coordinate_system_orientation : string, optional Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". Default is @@ -434,9 +434,9 @@ def add_tank(self, tank, position): tank : Tank Tank object to be added to the rocket motor. position : float - Position of the tank relative to the motor nozzle, in meters. - The position is measured from the nozzle tip to the tank - geometry reference zero point. + Position of the tank relative to the origin of the motor + coordinate system. The tank reference point is its + tank_geometry zero reference point. See Also -------- diff --git a/rocketpy/motors/Motor.py b/rocketpy/motors/Motor.py index 81e419b0f..b40887223 100644 --- a/rocketpy/motors/Motor.py +++ b/rocketpy/motors/Motor.py @@ -25,8 +25,8 @@ class Motor(ABC): Motor.coordinate_system_orientation : str Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as - at the nozzle area, and must be kept the same for all other + coordinate system may be placed anywhere along such axis, such as + at the nozzle exit area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". Motor.nozzle_radius : float @@ -135,8 +135,8 @@ class Motor(ABC): Motor.burn_duration : float Total motor burn duration, in seconds. It is the difference between the burn_out_time and the burn_start_time. - Motor.exhaust_velocity : float - Propulsion gases exhaust velocity, assumed constant, in m/s. + Motor.exhaust_velocity : rocketpy.Function + Propulsion gases exhaust velocity in m/s. Motor.interpolate : string Method of interpolation used in case thrust curve is given by data set in .csv or .eng, or as an array. Options are 'spline' @@ -226,7 +226,7 @@ def __init__( coordinate_system_orientation : string, optional Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". Default is @@ -361,7 +361,7 @@ def exhaust_velocity(self): Returns ------- - self.exhaust_velocity : float + self.exhaust_velocity : rocketpy.Function Gas exhaust velocity of the motor. Notes @@ -1074,6 +1074,100 @@ def __init__( interpolation_method="linear", coordinate_system_orientation="nozzle_to_combustion_chamber", ): + """Initialize GenericMotor class, process thrust curve and geometrical + parameters and store results. + + Parameters + ---------- + thrust_source : int, float, callable, string, array, Function + Motor's thrust curve. Can be given as an int or float, in which + case the thrust will be considered constant in time. It can + also be given as a callable function, whose argument is time in + seconds and returns the thrust supplied by the motor in the + instant. If a string is given, it must point to a .csv or .eng file. + The .csv file shall contain no headers and the first column must + specify time in seconds, while the second column specifies thrust. + Arrays may also be specified, following rules set by the class + Function. Thrust units are Newtons. + + .. seealso:: :doc:`Thrust Source Details ` + + chamber_radius : int, float + The radius of a overall cylindrical chamber of propellant in meters. + This is a rough estimate for the motor's propellant chamber or tanks. + chamber_height : int, float + The height of a overall cylindrical chamber of propellant in meters. + This is a rough estimate for the motor's propellant chamber or tanks. + chamber_position : int, float + The position, in meters, of the centroid (half height) of the motor's + overall cylindrical chamber of propellant with respect to the motor's + coordinate system. + See :doc:`Positions and Coordinate Systems ` + dry_mass : int, float + The total mass of the motor structure, including chambers + and tanks, when it is empty and does not contain any propellant. + propellant_initial_mass : int, float + The initial mass of the propellant in the motor. + center_of_dry_mass_position : int, float, optional + The position, in meters, of the motor's center of mass with respect + to the motor's coordinate system when it is devoid of propellant. + If not specified, automatically sourced as the chamber position. + See :doc:`Positions and Coordinate Systems ` + dry_inertia : tuple, list + Tuple or list containing the motor's dry mass inertia tensor + components, in kg*m^2. This inertia is defined with respect to the + the `center_of_dry_mass_position` position. + Assuming e_3 is the rocket's axis of symmetry, e_1 and e_2 are + orthogonal and form a plane perpendicular to e_3, the dry mass + inertia tensor components must be given in the following order: + (I_11, I_22, I_33, I_12, I_13, I_23), where I_ij is the + component of the inertia tensor in the direction of e_i x e_j. + Alternatively, the inertia tensor can be given as + (I_11, I_22, I_33), where I_12 = I_13 = I_23 = 0. + nozzle_radius : int, float, optional + Motor's nozzle outlet radius in meters. + burn_time: float, tuple of float, optional + Motor's burn time. + If a float is given, the burn time is assumed to be between 0 and + the given float, in seconds. + If a tuple of float is given, the burn time is assumed to be between + the first and second elements of the tuple, in seconds. + If not specified, automatically sourced as the range between the + first and last-time step of the motor's thrust curve. This can only + be used if the motor's thrust is defined by a list of points, such + as a .csv file, a .eng file or a Function instance whose source is a + list. + nozzle_position : int, float, optional + Motor's nozzle outlet position in meters, in the motor's coordinate + system. See :doc:`Positions and Coordinate Systems ` + for details. Default is 0, in which case the origin of the + coordinate system is placed at the motor's nozzle outlet. + reshape_thrust_curve : boolean, tuple, optional + If False, the original thrust curve supplied is not altered. If a + tuple is given, whose first parameter is a new burn out time and + whose second parameter is a new total impulse in Ns, the thrust + curve is reshaped to match the new specifications. May be useful + for motors whose thrust curve shape is expected to remain similar + in case the impulse and burn time varies slightly. Default is + False. Note that the Motor burn_time parameter must include the new + reshaped burn time. + interpolation_method : string, optional + Method of interpolation to be used in case thrust curve is given + by data set in .csv or .eng, or as an array. Options are 'spline' + 'akima' and 'linear'. Default is "linear". + coordinate_system_orientation : string, optional + Orientation of the motor's coordinate system. The coordinate system + is defined by the motor's axis of symmetry. The origin of the + coordinate system may be placed anywhere along such axis, such as + at the nozzle area, and must be kept the same for all other + positions specified. Options are "nozzle_to_combustion_chamber" and + "combustion_chamber_to_nozzle". Default is + "nozzle_to_combustion_chamber". + + Returns + ------- + None + """ super().__init__( thrust_source, dry_mass, diff --git a/rocketpy/motors/SolidMotor.py b/rocketpy/motors/SolidMotor.py index df0fc5487..606104fe4 100644 --- a/rocketpy/motors/SolidMotor.py +++ b/rocketpy/motors/SolidMotor.py @@ -28,7 +28,7 @@ class SolidMotor(Motor): SolidMotor.coordinate_system_orientation : str Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". @@ -170,7 +170,7 @@ class SolidMotor(Motor): SolidMotor.burn_duration : float Total motor burn duration, in seconds. It is the difference between the ``burn_out_time`` and the ``burn_start_time``. - SolidMotor.exhaust_velocity : float + SolidMotor.exhaust_velocity : rocketpy.Function Propulsion gases exhaust velocity, assumed constant, in m/s. SolidMotor.burn_area : Function Total burn area considering all grains, made out of inner @@ -298,7 +298,7 @@ def __init__( coordinate_system_orientation : string, optional Orientation of the motor's coordinate system. The coordinate system is defined by the motor's axis of symmetry. The origin of the - coordinate system may be placed anywhere along such axis, such as + coordinate system may be placed anywhere along such axis, such as at the nozzle area, and must be kept the same for all other positions specified. Options are "nozzle_to_combustion_chamber" and "combustion_chamber_to_nozzle". Default is @@ -456,19 +456,11 @@ def evaluate_geometry(self): """Calculates grain inner radius and grain height as a function of time by assuming that every propellant mass burnt is exhausted. In order to do that, a system of differential equations is solved using - scipy.integrate.odeint. Furthermore, the function calculates burn area, - burn rate and Kn as a function of time using the previous results. All - functions are stored as objects of the class Function in - ``self.grain_inner_radius``, ``self.grain_height``, ``self.burn_area``, - ``self.burn_rate`` and ``self.Kn``. - + scipy.integrate.solve_ivp. Returns ------- - geometry : list of rocketpy.Functions - First element is the Function representing the inner radius of a - grain as a function of time. Second argument is the Function - representing the height of a grain as a function of time. + None """ # Define initial conditions for integration y0 = [self.grain_initial_inner_radius, self.grain_initial_height] @@ -530,7 +522,7 @@ def terminate_burn(t, y): reset_funcified_methods(self) - return [self.grain_inner_radius, self.grain_height] + return None @funcify_method("Time (s)", "burn area (m²)") def burn_area(self): From 0f4e4deb5f14ed5d405c48f3c6ab9cd63b91e6ba Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Thu, 7 Sep 2023 16:02:04 -0300 Subject: [PATCH 2/3] DOC: minor fixes of Function referencing. --- rocketpy/motors/Motor.py | 24 ++++++++++++------------ rocketpy/motors/SolidMotor.py | 12 ++++++------ rocketpy/motors/TankGeometry.py | 22 +++++++++++----------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/rocketpy/motors/Motor.py b/rocketpy/motors/Motor.py index b40887223..6fb33686b 100644 --- a/rocketpy/motors/Motor.py +++ b/rocketpy/motors/Motor.py @@ -135,7 +135,7 @@ class Motor(ABC): Motor.burn_duration : float Total motor burn duration, in seconds. It is the difference between the burn_out_time and the burn_start_time. - Motor.exhaust_velocity : rocketpy.Function + Motor.exhaust_velocity : Function Propulsion gases exhaust velocity in m/s. Motor.interpolate : string Method of interpolation used in case thrust curve is given @@ -361,7 +361,7 @@ def exhaust_velocity(self): Returns ------- - self.exhaust_velocity : rocketpy.Function + self.exhaust_velocity : Function Gas exhaust velocity of the motor. Notes @@ -386,7 +386,7 @@ def total_mass(self): Returns ------- - rocketpy.Function + Function Total mass as a function of time. """ return self.propellant_mass + self.dry_mass @@ -397,7 +397,7 @@ def propellant_mass(self): Returns ------- - rocketpy.Function + Function Total propellant mass as a function of time. """ return ( @@ -412,7 +412,7 @@ def total_mass_flow_rate(self): Returns ------- - rocketpy.Function + Function Time derivative of total propellant mass a function of time. See Also @@ -466,7 +466,7 @@ def center_of_mass(self): Returns ------- - rocketpy.Function + Function Position of the center of mass as a function of time. """ mass_balance = ( @@ -484,7 +484,7 @@ def center_of_propellant_mass(self): Returns ------- - rocketpy.Function + Function Position of the propellant center of mass as a function of time. """ pass @@ -835,7 +835,7 @@ def reshape_thrust_curve(thrust, new_burn_time, total_impulse): Parameters ---------- - thrust : rocketpy.Function + thrust : Function Thrust curve to be reshaped. new_burn_time : float, tuple of float New desired burn time in seconds. @@ -844,7 +844,7 @@ def reshape_thrust_curve(thrust, new_burn_time, total_impulse): Returns ------- - rocketpy.Function + Function Reshaped thrust curve. """ # Retrieve current thrust curve data points @@ -892,7 +892,7 @@ def clip_thrust(thrust, new_burn_time): Returns ------- - rocketpy.Function + Function Clipped thrust curve. """ # Check if burn_time is within thrust_source range @@ -1215,7 +1215,7 @@ def exhaust_velocity(self): Returns ------- - self.exhaust_velocity : rocketpy.Function + self.exhaust_velocity : Function Gas exhaust velocity of the motor. """ return self.total_impulse / self.propellant_initial_mass @@ -1228,7 +1228,7 @@ def center_of_mass(self): Returns ------- - rocketpy.Function + Function Function representing the center of mass of the motor. """ return self.center_of_dry_mass_position diff --git a/rocketpy/motors/SolidMotor.py b/rocketpy/motors/SolidMotor.py index 606104fe4..6b5bb3afa 100644 --- a/rocketpy/motors/SolidMotor.py +++ b/rocketpy/motors/SolidMotor.py @@ -170,7 +170,7 @@ class SolidMotor(Motor): SolidMotor.burn_duration : float Total motor burn duration, in seconds. It is the difference between the ``burn_out_time`` and the ``burn_start_time``. - SolidMotor.exhaust_velocity : rocketpy.Function + SolidMotor.exhaust_velocity : Function Propulsion gases exhaust velocity, assumed constant, in m/s. SolidMotor.burn_area : Function Total burn area considering all grains, made out of inner @@ -382,7 +382,7 @@ def exhaust_velocity(self): Returns ------- - self.exhaust_velocity : rocketpy.Function + self.exhaust_velocity : Function Gas exhaust velocity of the motor. """ return self.total_impulse / self.propellant_initial_mass @@ -445,7 +445,7 @@ def center_of_propellant_mass(self): Returns ------- - rocketpy.Function + Function Position of the propellant center of mass as a function of time. """ time_source = self.grain_inner_radius.x_array @@ -531,7 +531,7 @@ def burn_area(self): Returns ------- - burn_area : rocketpy.Function + burn_area : Function Function representing the burn area progression with the time. """ burn_area = ( @@ -554,7 +554,7 @@ def burn_rate(self): Returns ------- - burn_rate : rocketpy.Function + burn_rate : Function Rate of progression of the inner radius during the combustion. """ return -1 * self.mass_flow_rate / (self.burn_area * self.grain_density) @@ -566,7 +566,7 @@ def Kn(self): Returns ------- - Kn : rocketpy.Function + Kn : Function Kn as a function of time. """ Kn_source = ( diff --git a/rocketpy/motors/TankGeometry.py b/rocketpy/motors/TankGeometry.py index a84576029..064b3eba5 100644 --- a/rocketpy/motors/TankGeometry.py +++ b/rocketpy/motors/TankGeometry.py @@ -34,7 +34,7 @@ class TankGeometry: corresponding radius. As an example, `{ (-1,1): Function(lambda h: (1 - h**2) ** (1/2)) }` defines an spherical tank of radius 1. - TankGeometry.radius : rocketpy.Function + TankGeometry.radius : Function Piecewise defined radius in meters as a rocketpy.Function based on the TankGeometry.geometry dict. TankGeometry.average_radius : float @@ -49,16 +49,16 @@ class TankGeometry: TankGeometry.total_height : float The total height of the tank, in meters. It is calculated as the difference between the top and bottom coordinates. - TankGeometry.area : rocketpy.Function + TankGeometry.area : Function Tank cross sectional area in meters squared as a function of height, defined as the area of a circle with radius TankGeometry.radius. - TankGeometry.volume : rocketpy.Function + TankGeometry.volume : Function Tank volume in in meters cubed as a function of height, defined as the Tank volume from the bottom to the given height. TankGeometry.total_volume : float Total volume of the tank, in meters cubed. It is calculated as the volume from the bottom to the top of the tank. - TankGeometry.inverse_volume : rocketpy.Function + TankGeometry.inverse_volume : Function Tank height as a function of volume, defined as the inverse of the TankGeometry.volume Function. """ @@ -115,7 +115,7 @@ def radius(self): Returns ------- - rocketpy.Function + Function Piecewise defined Function of tank radius. """ return self.radius @@ -213,7 +213,7 @@ def inverse_volume(self): Returns ------- - rocketpy.Function + Function Tank height as a function of volume. """ return self.volume.inverse_function( @@ -233,7 +233,7 @@ def volume_moment(self, lower, upper): Returns ------- - rocketpy.Function + Function Tank's first volume moment as a function of height. References @@ -271,7 +271,7 @@ def Ix_volume(self, lower, upper): Returns ------- - rocketpy.Function + Function Tank volume of inertia as a function of height. References @@ -307,7 +307,7 @@ def Iy_volume(self, lower, upper): Returns ------- - rocketpy.Function + Function Tank volume of inertia as a function of height. """ return self.Ix_volume(lower, upper) @@ -324,7 +324,7 @@ def Iz_volume(self, lower, upper): Returns ------- - rocketpy.Function + Function Tank volume of inertia as a function of height. """ # Tolerance of 1e-8 is used to avoid numerical errors @@ -344,7 +344,7 @@ def add_geometry(self, domain, radius_function): domain : tuple Tuple containing the lower and upper bounds of the domain where the radius is valid. - radius_function : rocketpy.Function, callable + radius_function : Function, callable Function that defines the radius of the tank as a function of height. """ self._geometry[domain] = Function(radius_function) From 3ab0ae48bce8d8f85935fb327b8a722ee23836e6 Mon Sep 17 00:00:00 2001 From: Pedro Bressan Date: Thu, 7 Sep 2023 19:10:14 -0300 Subject: [PATCH 3/3] DOC: fix tank geometry attribute referencing. --- rocketpy/motors/HybridMotor.py | 2 +- rocketpy/motors/LiquidMotor.py | 2 +- rocketpy/motors/TankGeometry.py | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/rocketpy/motors/HybridMotor.py b/rocketpy/motors/HybridMotor.py index a3e84867c..b1656a025 100644 --- a/rocketpy/motors/HybridMotor.py +++ b/rocketpy/motors/HybridMotor.py @@ -499,7 +499,7 @@ def add_tank(self, tank, position): position : float Position of the tank relative to the origin of the motor coordinate system. The tank reference point is its - tank_geometry zero reference point. + geometry zero reference point. See Also -------- diff --git a/rocketpy/motors/LiquidMotor.py b/rocketpy/motors/LiquidMotor.py index cfca55985..d913f5e06 100644 --- a/rocketpy/motors/LiquidMotor.py +++ b/rocketpy/motors/LiquidMotor.py @@ -436,7 +436,7 @@ def add_tank(self, tank, position): position : float Position of the tank relative to the origin of the motor coordinate system. The tank reference point is its - tank_geometry zero reference point. + geometry zero reference point. See Also -------- diff --git a/rocketpy/motors/TankGeometry.py b/rocketpy/motors/TankGeometry.py index 064b3eba5..553ce1a98 100644 --- a/rocketpy/motors/TankGeometry.py +++ b/rocketpy/motors/TankGeometry.py @@ -25,7 +25,6 @@ class TankGeometry: Attributes ---------- - Geometrical attributes: TankGeometry.geometry : dict Dictionary containing the geometry of the tank. The dictionary keys are disjoint domains of the corresponding coordinates in @@ -238,7 +237,7 @@ def volume_moment(self, lower, upper): References ---------- - https://en.wikipedia.org/wiki/Moment_(physics) + .. [1] ``_ """ height = self.area.identity_function() @@ -276,7 +275,7 @@ def Ix_volume(self, lower, upper): References ---------- - https://en.wikipedia.org/wiki/List_of_moments_of_inertia + .. [1] https://en.wikipedia.org/wiki/List_of_moments_of_inertia """ height2 = self.radius.identity_function() ** 2