Commit 0765dcb
Implement ClusterMotor class for motor aggregation
- The solver now calls `motor.get_total_thrust_vector(t)` and
`motor.get_total_moment(t, rocket_cm)` to get the full
3D forces and torques from the propulsion system.
- These vectors are used to solve the full rigid body equations
of motion (Euler's equations) for angular acceleration.
- This enables correct 6-DOF simulation of motor clusters,
vectored thrust, and thrust misalignments.
Update Rocket class for 3D inertia and ClusterMotor
Refactors the `Rocket` class to integrate the new `ClusterMotor`
and handle 3D centers of mass and dynamic inertia.
- `add_motor()` is updated to detect `ClusterMotor` objects.
- `add_cluster_motor()` helper method added.
- `evaluate_center_of_mass` and `evaluate_center_of_dry_mass`
now perform weighted 3D vector averaging for CoM.
- `evaluate_dry_inertias` and `evaluate_inertias` are updated
to use the new dynamic `parallel_axis_theorem` functions.
- Internal attributes like `center_of_dry_mass_position` are
now 3D `Vector`s instead of Z-axis scalars.
Update HybridMotor to new dynamic inertia contract
Refactors `HybridMotor.__init__` to comply with the new base
class inertia contract.
- The class now calculates the individual inertias of the liquid
(tanks) and solid (grain) components relative to their own CoMs.
- It then uses the new dynamic PAT functions to aggregate these
inertias relative to the *total propellant center of mass*.
- The result is stored in `self.propellant_I_xx_from_propellant_CM`
for the `Motor` base class to consume.
Update LiquidMotor to new dynamic inertia contract
Refactors `LiquidMotor` to comply with the new base class inertia
contract.
- The class now correctly calculates the aggregated inertia of all
tanks relative to the total propellant center of mass (logic
handled by base class and PAT tools).
- Corrects the `propellant_I_11`, `_I_22`, etc. methods to
return the pre-calculated `propellant_I_xx_from_propellant_CM`
attribute, preventing an incorrect double application of the
Parallel Axis Theorem.
SolidMotor inertia logic for dynamic contract
1. **`.eng`/`.rse` File Pre-parsing:**
* The logic to read `.eng` and `.rse` files (using `Motor.import_eng` and `Motor.import_rse`) has been moved from the base class into the `SolidMotor.__init__` method.
* This ensures that the `thrust_source` data array is loaded and available *before* `super().__init__` is called.
2. **Inertia Re-calculation:**
* The original `SolidMotor` relied on the `motor.py` base class to handle all inertia calculations within `super().__init__`.
* This was problematic because `evaluate_geometry()` (which defines the grain properties needed for inertia) was called *after* `super().__init__`.
* This commit fixes this by adding a new block of code at the **end** of `SolidMotor.__init__` (after `evaluate_geometry()` has run).
* This new block explicitly:
1. Assigns the now-valid propellant inertia methods (e.g., `self.propellant_I_11`) to the new "contract" attributes (e.g., `self.propellant_I_11_from_propellant_CM`).
2. Imports the dynamic `parallel_axis_theorem` tools.
3. **Re-calculates** the propellant inertia relative to the motor origin (using the PAT logic from `motor.py`).
4. **Re-calculates** the final total motor inertia (`self.I_11`, `self.I_33`, etc.) by summing the dry and (now correct) propellant inertias. This overwrites the incorrect values that were set during the initial `super().__init__` call.
Refactor base Motor class for dynamic 6-DOF inertia
1. **Dynamic Inertia Calculation (Major Change):**
* The `__init__` method now imports the new dynamic Parallel Axis Theorem (PAT) functions from `tools.py` (e.g., `parallel_axis_theorem_I11`, `_I12`, etc.).
* A new "Inertia Contract" is established: `__init__` defines new abstract attributes (e.g., `self.propellant_I_11_from_propellant_CM = Function(0)`).
* Subclasses (like `SolidMotor`, `HybridMotor`) are now *required* to provide their propellant inertia relative to their *own propellant CoM* by overriding these `_from_propellant_CM` attributes.
* `__init__` (lines 280-333) immediately uses the dynamic PAT functions to calculate the propellant inertia tensor (e.g., `self.propellant_I_11`) relative to the **motor's origin**, based on these "contract" attributes.
* `__init__` (lines 336-351) then calculates the **total motor inertia** (`self.I_11`, `self.I_33`, etc.) relative to the **motor's origin** by adding the (constant) dry inertia.
*Note: This differs completely from the GitHub version, where inertia was calculated *later* inside the `@funcify_method` definitions (`I_11`, `I_33`, etc.) and relative to the *instantaneous center of mass*.*
2. **`.eng` File Parsing Fix:**
* The `__init__` method now includes logic (lines 235-240) to detect if `thrust_source` is a `.eng` file.
* If true, it sets the `delimiter` to a space (" ") and `comments` to a semicolon (";"), correcting the parsing failure that occurs in the original `Function` constructor which defaults to commas.
3. **`reference_pressure` Added:**
* The `__init__` signature (line 229) now accepts `reference_pressure=None`.
* This value is stored as `self.reference_pressure` (line 257) to be used in vacuum thrust calculations.
4. **Modified Inertia Methods (`I_11`, `I_33`, etc.):**
* The instance methods (e.g., `@funcify_method def I_11(self)`) starting at line 641 have been modified.
* While the GitHub version used these methods to calculate inertia relative to the instantaneous CoM, this version's logic is updated, although it appears redundant given that the primary inertia calculation (relative to the origin) is now finalized in `__init__`.
Update Rocket.draw() to visualize ClusterMotor configurations
1. **Import `ClusterMotor`:**
* The file now imports `ClusterMotor` (Line 5) to check the motor type.
2. **Refactored `_draw_motor` Method (Line 234):**
* This method is completely refactored. It now acts as a dispatcher,
calling the new `_generate_motor_patches` helper function.
* It checks `isinstance(self.rocket.motor, ClusterMotor)`.
* If it's a cluster, it adds all patches generated by the helper.
* If it's a simple motor, it uses the original logic (drawing the
nozzle and chamber centered at y=0).
* It also correctly calls `_draw_nozzle_tube` to connect the
airframe to the start of the cluster or single motor.
3. **New `_generate_motor_patches` Method (Line 259):**
* This is an **entirely new** helper function.
* It contains the core logic for drawing clusters.
* It iterates through `cluster.motors` and `cluster.positions`.
* For each sub-motor, it correctly calculates the 2D plot offset
(using `sub_pos[0]` for the 'xz' plane or `sub_pos[1]` for 'yz')
and the longitudinal position (`sub_pos[2]`).
* It re-uses the plotting logic of the individual sub-motors
(e.g., `_generate_combustion_chamber`, `_generate_grains`) but
applies the correct `translate=(pos_z, offset)` transform.
* This allows multiple motors to be drawn side-by-side.
4. **Fix `_draw_center_of_mass_and_pressure` (Line 389):**
* This method is updated to handle the new 3D `Vector` object
returned by `self.rocket.center_of_mass(0)`.
* It now accesses the Z-coordinate correctly using
`cm_z = float(cm_vector.z.real)` instead of assuming the
return value is a simple float.
Update function.py
Clear comments and cleaned code
Updated ClusterMotor
Clean comments and cleared code
Hybrid Motor correction
Correction of the comments and cleared the code
Correction of LiquidMotor
Clean comments and cleared code
Correction of Motor
Clean comments and clear code
Correction of SolidMotor
Clean comments and cleared code
Correction of Rocketplots
Clean comments and cleared code from copilot
Correction of Rocket
Clean comments and cleared code with copilot review
Correction of Flight
Clean comments and clear code
Correction of tools
Clean comments and clear code
ClusterMotor initialization and add docstring
Addresses pull request feedback on the new ClusterMotor class.
The monolithic __init__ method was large and difficult to maintain. This commit refactors the constructor by breaking its logic into several smaller, private helper methods:
- `_validate_inputs`: Handles all input validation and normalization.
- `_initialize_basic_properties`: Calculates scalar values (mass, impulse, burn time).
- `_initialize_thrust_and_mass`: Sets up thrust, mass flow rate, and propellant mass Functions.
- `_initialize_center_of_mass`: Sets up CoM and CoPM Functions.
- `_initialize_inertia_properties`: Calculates dry inertia and sets up propellant inertia Functions.
This improves readability and separates concerns.
Additionally:
- Adds a NumPy-style docstring to the `__init__` method.
- Cleans up inline comments, retaining all essential docstrings.
Refactor imports in solid_motor.py for clarity
Simplify return statement for inertia tensor calculation
Removing the # .real generated comment
Removing the generated unuseful comment
Implement deprecation warning decorator
Added a deprecation decorator to warn users about obsolete functions and their alternatives.
make format
make lint
partially fix tests
few adjusts1 parent 793e5f6 commit 0765dcb
File tree
13 files changed
+1903
-1246
lines changed- rocketpy
- mathutils
- motors
- plots
- rocket
- simulation
13 files changed
+1903
-1246
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
198 | 217 | | |
199 | 218 | | |
200 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
0 commit comments