Repository navigation
Expand file tree
/
Copy pathmotor.py
More file actions
2123 lines (1879 loc) · 84.5 KB
/
Copy pathmotor.py
File metadata and controls
2123 lines (1879 loc) · 84.5 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import base64
import re
import tempfile
import warnings
import xml.etree.ElementTree as ET
from abc import ABC, abstractmethod
from functools import cached_property
from os import path, remove
from pathlib import Path
import numpy as np
import requests
from ..mathutils.function import Function, funcify_method
from ..plots.motor_plots import _MotorPlots
from ..prints.motor_prints import _MotorPrints
from ..tools import parallel_axis_theorem_from_com, tuple_handler
# pylint: disable=too-many-public-methods
# ThrustCurve API cache
CACHE_DIR = Path.home() / ".rocketpy_cache"
class Motor(ABC):
"""Abstract class to specify characteristics and useful operations for
motors. Cannot be instantiated.
Attributes
----------
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 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
Radius of motor nozzle outlet in meters.
Motor.nozzle_area : float
Area of motor nozzle outlet in square meters.
Motor.nozzle_position : float
Motor's nozzle outlet position in meters, specified in the motor's
coordinate system. See :ref:`positions` for more information.
Motor.dry_mass : float
The mass of the motor when devoid of any propellants, measured in
kilograms (kg). It encompasses the structural weight of the motor,
including the combustion chamber, nozzles, tanks, and fasteners.
Excluded from this measure are the propellants and any other elements
that are dynamically accounted for in the `mass` parameter of the rocket
class. Ensure that mass contributions from components shared with the
rocket structure are not recounted here. This parameter does not vary
with time.
Motor.propellant_initial_mass : float
Total propellant initial mass in kg, including solid, liquid and gas
phases.
Motor.total_mass : Function
Total motor mass in kg as a function of time, defined as the sum
of propellant mass and the motor's dry mass (i.e. structure mass).
Motor.propellant_mass : Function
Total propellant mass in kg as a function of time, including solid,
liquid and gas phases.
Motor.structural_mass_ratio: float
Initial ratio between the dry mass and the total mass.
Motor.total_mass_flow_rate : Function
Time derivative of propellant total mass in kg/s as a function
of time as obtained by the thrust source.
Motor.center_of_mass : Function
Position of the motor center of mass in
meters as a function of time.
See :doc:`Positions and Coordinate Systems </user/positions>`
for more information regarding the motor's coordinate system.
Motor.center_of_propellant_mass : Function
Position of the motor propellant center of mass in meters as a
function of time.
See :doc:`Positions and Coordinate Systems </user/positions>`
for more information regarding the motor's coordinate system.
Motor.I_11 : Function
Component of the motor's inertia tensor relative to the e_1 axis
in kg*m^2, as a function of time. The e_1 axis is the direction
perpendicular to the motor body axis of symmetry, centered at
the instantaneous motor center of mass.
Motor.I_22 : Function
Component of the motor's inertia tensor relative to the e_2 axis
in kg*m^2, as a function of time. The e_2 axis is the direction
perpendicular to the motor body axis of symmetry, centered at
the instantaneous motor center of mass.
Numerically equivalent to I_11 due to symmetry.
Motor.I_33 : Function
Component of the motor's inertia tensor relative to the e_3 axis
in kg*m^2, as a function of time. The e_3 axis is the direction of
the motor body axis of symmetry, centered at the instantaneous
motor center of mass.
Motor.I_12 : Function
Component of the motor's inertia tensor relative to the e_1 and
e_2 axes in kg*m^2, as a function of time. See Motor.I_11 and
Motor.I_22 for more information.
Motor.I_13 : Function
Component of the motor's inertia tensor relative to the e_1 and
e_3 axes in kg*m^2, as a function of time. See Motor.I_11 and
Motor.I_33 for more information.
Motor.I_23 : Function
Component of the motor's inertia tensor relative to the e_2 and
e_3 axes in kg*m^2, as a function of time. See Motor.I_22 and
Motor.I_33 for more information.
Motor.propellant_I_11 : Function
Component of the propellant inertia tensor relative to the e_1
axis in kg*m^2, as a function of time. The e_1 axis is the
direction perpendicular to the motor body axis of symmetry,
centered at the instantaneous propellant center of mass.
Motor.propellant_I_22 : Function
Component of the propellant inertia tensor relative to the e_2
axis in kg*m^2, as a function of time. The e_2 axis is the
direction perpendicular to the motor body axis of symmetry,
centered at the instantaneous propellant center of mass.
Numerically equivalent to propellant_I_11 due to symmetry.
Motor.propellant_I_33 : Function
Component of the propellant inertia tensor relative to the e_3
axis in kg*m^2, as a function of time. The e_3 axis is the
direction of the motor body axis of symmetry, centered at the
instantaneous propellant center of mass.
Motor.propellant_I_12 : Function
Component of the propellant inertia tensor relative to the e_1 and
e_2 axes in kg*m^2, as a function of time. See Motor.propellant_I_11
and Motor.propellant_I_22 for more information.
Motor.propellant_I_13 : Function
Component of the propellant inertia tensor relative to the e_1 and
e_3 axes in kg*m^2, as a function of time. See Motor.propellant_I_11
and Motor.propellant_I_33 for more information.
Motor.propellant_I_23 : Function
Component of the propellant inertia tensor relative to the e_2 and
e_3 axes in kg*m^2, as a function of time. See Motor.propellant_I_22
and Motor.propellant_I_33 for more information.
Motor.thrust : Function
Motor thrust force obtained from the thrust source, in Newtons, as a
function of time.
Motor.vacuum_thrust : Function
Motor thrust force when the rocket is in a vacuum. In Newtons, as a
function of time.
Motor.total_impulse : float
Total impulse of the thrust curve in N*s.
Motor.max_thrust : float
Maximum thrust value of the given thrust curve, in N.
Motor.max_thrust_time : float
Time, in seconds, in which the maximum thrust value is achieved.
Motor.average_thrust : float
Average thrust of the motor, given in N.
Motor.burn_time : tuple of float
Tuple containing the initial and final time of the motor's burn time
in seconds.
Motor.burn_start_time : float
Motor burn start time, in seconds.
Motor.burn_out_time : float
Motor burn out time, in seconds.
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 : Function
Effective exhaust velocity of the propulsion gases in m/s. Computed
as the thrust divided by the mass flow rate. This corresponds to the
actual exhaust velocity only when the nozzle exit pressure equals the
atmospheric pressure.
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'
'akima' and 'linear'. Default is "linear".
Motor.reference_pressure : int, float, None
Atmospheric pressure in Pa at which the thrust data was recorded.
It will allow to obtain the net thrust in the Flight class.
"""
# pylint: disable=too-many-statements
def __init__(
self,
thrust_source,
dry_inertia,
nozzle_radius,
center_of_dry_mass_position,
dry_mass=None,
nozzle_position=0,
burn_time=None,
reshape_thrust_curve=False,
interpolation_method="linear",
coordinate_system_orientation="nozzle_to_combustion_chamber",
reference_pressure=None,
):
"""Initialize Motor 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 can contain a single line header 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 </user/motors/thrust>`
dry_mass : int, float
Same as in Motor class. See the :class:`Motor <rocketpy.Motor>` docs
center_of_dry_mass_position : int, float
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.
See :doc:`Positions and Coordinate Systems </user/positions>`
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 </user/positions>`
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".
reference_pressure : int, float, optional
Atmospheric pressure in Pa at which the thrust data was recorded.
Returns
-------
None
"""
# Define coordinate system orientation
self.coordinate_system_orientation = coordinate_system_orientation
match coordinate_system_orientation:
case "nozzle_to_combustion_chamber":
self._csys = 1
case "combustion_chamber_to_nozzle":
self._csys = -1
case _: # pragma: no cover
raise ValueError(
"Invalid coordinate system orientation. Options are "
"'nozzle_to_combustion_chamber' and 'combustion_chamber_to_nozzle'."
)
# Motor parameters
self.interpolate = interpolation_method
self.nozzle_position = nozzle_position
self.nozzle_radius = nozzle_radius
self.nozzle_area = np.pi * nozzle_radius**2
self.center_of_dry_mass_position = center_of_dry_mass_position
self.reference_pressure = reference_pressure
# Inertia tensor setup
inertia = (*dry_inertia, 0, 0, 0) if len(dry_inertia) == 3 else dry_inertia
self.dry_I_11 = inertia[0]
self.dry_I_22 = inertia[1]
self.dry_I_33 = inertia[2]
self.dry_I_12 = inertia[3]
self.dry_I_13 = inertia[4]
self.dry_I_23 = inertia[5]
# Handle .eng or .rse file inputs
self.description_eng_file = None
self.rse_motor_data = None
if isinstance(thrust_source, str):
if (
path.exists(thrust_source)
and path.splitext(path.basename(thrust_source))[1] == ".eng"
):
_, self.description_eng_file, points = Motor.import_eng(thrust_source)
thrust_source = points
elif (
path.exists(thrust_source)
and path.splitext(path.basename(thrust_source))[1] == ".rse"
):
self.rse_motor_data, points = Motor.import_rse(thrust_source)
thrust_source = points
# Evaluate raw thrust source
self.thrust_source = thrust_source
self.thrust = Function(
thrust_source, "Time (s)", "Thrust (N)", self.interpolate, "zero"
)
# Handle dry_mass input
self.dry_mass = dry_mass
# Handle burn_time input
self.burn_time = burn_time
if not self.thrust.is_array_source():
self.thrust.set_discrete(*self.burn_time, 50, self.interpolate, "zero")
# Reshape thrust_source if needed
if reshape_thrust_curve:
# Overwrites burn_time and thrust
self.thrust = Motor.reshape_thrust_curve(self.thrust, *reshape_thrust_curve)
self.burn_time = (self.thrust.x_array[0], self.thrust.x_array[-1])
# Post process thrust
self.thrust = Motor.clip_thrust(self.thrust, self.burn_time)
# Auxiliary quantities
self.burn_start_time = self.burn_time[0]
self.burn_out_time = self.burn_time[1]
self.burn_duration = self.burn_time[1] - self.burn_time[0]
# Compute thrust metrics
self.max_thrust = np.amax(self.thrust.y_array)
max_thrust_index = np.argmax(self.thrust.y_array)
self.max_thrust_time = self.thrust.source[max_thrust_index, 0]
self.average_thrust = self.total_impulse / self.burn_duration
# Initialize plots and prints object
self.prints = _MotorPrints(self)
self.plots = _MotorPlots(self)
@property
def burn_time(self):
"""Burn time range in seconds.
Returns
-------
tuple
Burn time range in seconds.
"""
return self._burn_time
@burn_time.setter
def burn_time(self, burn_time):
"""Sets burn time range in seconds.
Parameters
----------
burn_time : float or two position array_like
Burn time range in seconds.
"""
if burn_time:
self._burn_time = tuple_handler(burn_time)
else:
if self.thrust.is_array_source():
self._burn_time = (self.thrust.x_array[0], self.thrust.x_array[-1])
else: # pragma: no cover
raise ValueError(
"When using a float or callable as thrust source, a burn_time"
" argument must be specified."
)
@property
def dry_mass(self):
"""Dry mass of the motor in kg.
Returns
-------
self.dry_mass : float
Motor dry mass in kg.
"""
return self._dry_mass
@dry_mass.setter
def dry_mass(self, dry_mass):
"""Sets dry mass of the motor in kg.
Parameters
----------
dry_mass : float
Motor dry mass in kg.
"""
if dry_mass is not None:
if isinstance(dry_mass, (int, float)):
self._dry_mass = dry_mass
else:
raise ValueError("Dry mass must be a number.")
elif self.description_eng_file:
self._dry_mass = float(self.description_eng_file[-2]) - float(
self.description_eng_file[-3]
)
elif self.rse_motor_data:
self._dry_mass = float(
self.rse_motor_data["description"]["total_mass"]
) - float(self.rse_motor_data["description"]["propellant_mass"])
else:
raise ValueError("Dry mass must be specified.")
@cached_property
def total_impulse(self):
"""Calculates and returns total impulse by numerical integration
of the thrust curve in SI units.
Returns
-------
self.total_impulse : float
Motor total impulse in Ns.
"""
return self.thrust.integral(*self.burn_time)
@property
@abstractmethod
def exhaust_velocity(self):
"""Effective exhaust velocity of the motor gases.
Returns
-------
self.exhaust_velocity : Function
Gas exhaust velocity of the motor.
Notes
-----
This method is implemented in the following manner by the child
Motor classes:
- The ``SolidMotor`` assumes a constant exhaust velocity and computes
it as the ratio of the total impulse and the propellant mass;
- The ``HybridMotor`` assumes a constant exhaust velocity and computes
it as the ratio of the total impulse and the propellant mass;
- The ``LiquidMotor`` class favors the more accurate data from the
Tanks's mass flow rates. Therefore the exhaust velocity is generally
variable, being the ratio of the motor thrust by the mass flow rate.
This corresponds to the actual exhaust velocity only when the nozzle
exit pressure equals the atmospheric pressure.
"""
@funcify_method("Time (s)", "Total mass (kg)")
def total_mass(self):
"""Total mass of the motor as a function of time. It is defined as the
propellant mass plus the dry mass.
Returns
-------
Function
Motor total mass as a function of time.
"""
return self.propellant_mass + self.dry_mass
@funcify_method("Time (s)", "Propellant mass (kg)")
def propellant_mass(self):
"""Total propellant mass as a Function of time.
Returns
-------
Function
Total propellant mass as a function of time.
"""
return (
self.total_mass_flow_rate.integral_function() + self.propellant_initial_mass
)
@funcify_method("Time (s)", "Mass flow rate (kg/s)", extrapolation="zero")
def total_mass_flow_rate(self):
"""Time derivative of the propellant mass as a function of time. The
formula used is the opposite of thrust divided by exhaust velocity.
Returns
-------
Function
Time derivative of total propellant mass a function of time.
See Also
--------
SolidMotor.mass_flow_rate :
Numerically equivalent to ``total_mass_flow_rate``.
HybridMotor.mass_flow_rate :
Numerically equivalent to ``total_mass_flow_rate``.
LiquidMotor.mass_flow_rate :
Independent of ``total_mass_flow_rate`` favoring more accurate \
sum of Tanks' mass flow rates.
Notes
-----
This function computes the total mass flow rate of the motor by
dividing the thrust data by the exhaust velocity. This is an
approximation, and it is used by the child Motor classes as follows:
- The ``SolidMotor`` class uses this approximation to compute the \
grain's mass flow rate;
- The ``HybridMotor`` class uses this approximation as a reference \
to the sum of the oxidizer and fuel (grains) mass flow rates;
- The ``LiquidMotor`` class favors the more accurate data from the \
Tanks's mass flow rates. Therefore this value is numerically \
independent of the ``LiquidMotor.mass_flow_rate``.
- The ``GenericMotor`` class considers the total_mass_flow_rate as the \
same as the mass_flow_rate.
It should also be noted that, for hybrid motors, the oxidizer mass flow
rate should not be greater than `total_mass_flow_rate`, otherwise the
grains mass flow rate will be negative, losing physical meaning.
"""
average_exhaust_velocity = self.total_impulse / self.propellant_initial_mass
return self.thrust / -average_exhaust_velocity
@property
@abstractmethod
def propellant_initial_mass(self):
"""Propellant initial mass in kg, including solid, liquid and gas phases
Returns
-------
float
Propellant initial mass in kg.
"""
@property
def structural_mass_ratio(self):
"""Calculates the structural mass ratio. The ratio is defined as
the dry mass divided by the initial total mass.
Returns
-------
float
Initial structural mass ratio.
"""
initial_total_mass = self.dry_mass + self.propellant_initial_mass
try:
return self.dry_mass / initial_total_mass
except ZeroDivisionError as e:
raise ValueError(
"Total motor mass (dry + propellant) cannot be zero"
) from e
@funcify_method("Time (s)", "Motor center of mass (m)")
def center_of_mass(self):
"""Position of the center of mass as a function of time. The position
is specified as a scalar, relative to the motor's coordinate system.
Returns
-------
Function
Position of the center of mass as a function of time.
"""
mass_balance = (
self.center_of_propellant_mass * self.propellant_mass
+ self.dry_mass * self.center_of_dry_mass_position
)
return mass_balance / self.total_mass
@property
@abstractmethod
def center_of_propellant_mass(self):
"""Position of the propellant center of mass as a function of time.
The position is specified as a scalar, relative to the origin of the
motor's coordinate system.
Returns
-------
Function
Position of the propellant center of mass as a function of time.
"""
@funcify_method("Time (s)", "Inertia I_11 (kg m²)")
def I_11(self):
"""Inertia tensor 11 component, which corresponds to the inertia
relative to the e_1 axis, centered at the instantaneous center of mass.
Returns
-------
Function
Propellant inertia tensor 11 component at time t.
Notes
-----
The e_1 direction is assumed to be the direction perpendicular to the
motor body axis. Also, due to symmetry, I_11 = I_22.
See Also
--------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
prop_I_11 = self.propellant_I_11
dry_I_11 = self.dry_I_11
prop_to_cm = self.center_of_propellant_mass - self.center_of_mass
dry_to_cm = self.center_of_dry_mass_position - self.center_of_mass
prop_I_11 = parallel_axis_theorem_from_com(
prop_I_11, self.propellant_mass, prop_to_cm
)
dry_I_11 = parallel_axis_theorem_from_com(dry_I_11, self.dry_mass, dry_to_cm)
return prop_I_11 + dry_I_11
@funcify_method("Time (s)", "Inertia I_22 (kg m²)")
def I_22(self):
"""Inertia tensor 22 component, which corresponds to the inertia
relative to the e_2 axis, centered at the instantaneous center of mass.
Returns
-------
Function
Propellant inertia tensor 22 component at time t.
Notes
-----
The e_2 direction is assumed to be the direction perpendicular to the
motor body axis, and perpendicular to e_1. Also, due to symmetry,
I_22 = I_11.
See Also
--------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
# Due to symmetry, I_22 = I_11
return self.I_11
@funcify_method("Time (s)", "Inertia I_33 (kg m²)")
def I_33(self):
"""Inertia tensor 33 component, which corresponds to the inertia
relative to the e_3 axis, centered at the instantaneous center of mass.
Returns
-------
Function
Propellant inertia tensor 33 component at time t.
Notes
-----
The e_3 direction is assumed to be the axial direction of the rocket
motor.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
# Propellant inertia tensor 33 component wrt propellant center of mass
propellant_I_33 = self.propellant_I_33
# Dry inertia tensor 33 component wrt dry center of mass
dry_I_33 = self.dry_I_33
# Both inertia components wrt the same axis, Steiner not needed
return propellant_I_33 + dry_I_33
@funcify_method("Time (s)", "Inertia I_12 (kg m²)")
def I_12(self):
"""Inertia tensor 12 component, which corresponds to the product of
inertia relative to axes e_1 and e_2, centered at the instantaneous
center of mass.
Returns
-------
Function
Propellant inertia tensor 12 component at time t.
Notes
-----
The e_1 direction is assumed to be the direction perpendicular to the
motor body axis.
The e_2 direction is assumed to be the direction perpendicular to the
motor body axis, and perpendicular to e_1.
RocketPy follows the definition of the inertia tensor as in [1], which
includes the minus sign for all products of inertia.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
# Propellant inertia tensor 12 component wrt propellant center of mass
propellant_I_12 = self.propellant_I_12
# Dry inertia tensor 12 component wrt dry center of mass
dry_I_12 = self.dry_I_12
# Steiner correction not needed since the centers only move in the e_3 axis
return propellant_I_12 + dry_I_12
@funcify_method("Time (s)", "Inertia I_13 (kg m²)")
def I_13(self):
"""Inertia tensor 13 component, which corresponds to the product of
inertia relative to the axes e_1 and e_3, centered at the instantaneous
center of mass.
Returns
-------
Function
Propellant inertia tensor 13 component at time t.
Notes
-----
The e_1 direction is assumed to be the direction perpendicular to the
motor body axis.
The e_3 direction is assumed to be the axial direction of the rocket
motor.
RocketPy follows the definition of the inertia tensor as in [1], which
includes the minus sign for all products of inertia.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia
"""
# Propellant inertia tensor 13 component wrt propellant center of mass
propellant_I_13 = self.propellant_I_13
# Dry inertia tensor 13 component wrt dry center of mass
dry_I_13 = self.dry_I_13
# Steiner correction not needed since the centers only move in the e_3 axis
return propellant_I_13 + dry_I_13
@funcify_method("Time (s)", "Inertia I_23 (kg m²)")
def I_23(self):
"""Inertia tensor 23 component, which corresponds to the product of
inertia relative the axes e_2 and e_3, centered at the instantaneous
center of mass.
Returns
-------
Function
Propellant inertia tensor 23 component at time t.
Notes
-----
The e_2 direction is assumed to be the direction perpendicular to the
motor body axis, and perpendicular to e_1.
The e_3 direction is assumed to be the axial direction of the rocket
motor.
RocketPy follows the definition of the inertia tensor as in [1], which
includes the minus sign for all products of inertia.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia
"""
# wrt = with respect to
# Propellant inertia tensor 23 component wrt propellant center of mass
propellant_I_23 = self.propellant_I_23
# Dry inertia tensor 23 component wrt dry center of mass
dry_I_23 = self.dry_I_23
# Steiner correction not needed since the centers only move in the e_3 axis
return propellant_I_23 + dry_I_23
@property
@abstractmethod
def propellant_I_11(self):
"""Inertia tensor 11 component of the propellant, the inertia is
relative to the e_1 axis, centered at the instantaneous propellant
center of mass.
Returns
-------
Function
Propellant inertia tensor 11 component at time t.
Notes
-----
The e_1 direction is assumed to be the direction perpendicular to the
motor body axis.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
@property
@abstractmethod
def propellant_I_22(self):
"""Inertia tensor 22 component of the propellant, the inertia is
relative to the e_2 axis, centered at the instantaneous propellant
center of mass.
Returns
-------
Function
Propellant inertia tensor 22 component at time t.
Notes
-----
The e_2 direction is assumed to be the direction perpendicular to the
motor body axis, and perpendicular to e_1.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
@property
@abstractmethod
def propellant_I_33(self):
"""Inertia tensor 33 component of the propellant, the inertia is
relative to the e_3 axis, centered at the instantaneous propellant
center of mass.
Returns
-------
Function
Propellant inertia tensor 33 component at time t.
Notes
-----
The e_3 direction is assumed to be the axial direction of the rocket
motor.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
@property
@abstractmethod
def propellant_I_12(self):
"""Inertia tensor 12 component of the propellant, the product of inertia
is relative to axes e_1 and e_2, centered at the instantaneous propellant
center of mass.
Returns
-------
Function
Propellant inertia tensor 12 component at time t.
Notes
-----
The e_1 direction is assumed to be the direction perpendicular to the
motor body axis.
The e_2 direction is assumed to be the direction perpendicular to the
motor body axis, and perpendicular to e_1.
RocketPy follows the definition of the inertia tensor as in [1], which
includes the minus sign for all products of inertia.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor
"""
@property
@abstractmethod
def propellant_I_13(self):
"""Inertia tensor 13 component of the propellant, the product of inertia
is relative to axes e_1 and e_3, centered at the instantaneous
propellant center of mass.
Returns
-------
Function
Propellant inertia tensor 13 component at time t.
Notes
-----
The e_1 direction is assumed to be the direction perpendicular to the
motor body axis.
The e_3 direction is assumed to be the axial direction of the rocket
motor.
RocketPy follows the definition of the inertia tensor as in [1], which
includes the minus sign for all products of inertia.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia
"""
@property
@abstractmethod
def propellant_I_23(self):
"""Inertia tensor 23 component of the propellant, the product of inertia
is relative to axes e_2 and e_3, centered at the instantaneous
propellant center of mass.
Returns
-------
Function
Propellant inertia tensor 23 component at time t.
Notes
-----
The e_2 direction is assumed to be the direction perpendicular to the
motor body axis, and perpendicular to e_1.
The e_3 direction is assumed to be the axial direction of the rocket
motor.
RocketPy follows the definition of the inertia tensor as in [1], which
includes the minus sign for all products of inertia.
References
----------
https://en.wikipedia.org/wiki/Moment_of_inertia
"""
@staticmethod
def reshape_thrust_curve(thrust, new_burn_time, total_impulse):
"""Transforms the thrust curve supplied by changing its total
burn time and/or its total impulse, without altering the
general shape of the curve. This method does not mutate the original
object, it only returns a new thrust curve.
Parameters
----------
thrust : Function
Thrust curve to be reshaped.
new_burn_time : float, tuple of float
New desired burn time in seconds.
total_impulse : float
New desired total impulse.
Returns
-------
Function
Reshaped thrust curve.
Tip
---
See the User Guide page for examples on how to use this method.
"""
# Retrieve current thrust curve data points
time_array, thrust_array = thrust.x_array, thrust.y_array
new_burn_time = tuple_handler(new_burn_time)
# Compute old thrust based on new time discretization
# Adjust scale
new_time_array = (
(new_burn_time[1] - new_burn_time[0]) / (time_array[-1] - time_array[0])
) * time_array
# Adjust origin
new_time_array = new_time_array - new_time_array[0] + new_burn_time[0]
source = np.column_stack((new_time_array, thrust_array))
thrust = Function(
source, "Time (s)", "Thrust (N)", thrust.__interpolation__, "zero"
)
# Get old total impulse
old_total_impulse = thrust.integral(*new_burn_time)
# Compute new thrust values
new_thrust_array = (total_impulse / old_total_impulse) * thrust_array
source = np.column_stack((new_time_array, new_thrust_array))
thrust = Function(
source, "Time (s)", "Thrust (N)", thrust.__interpolation__, "zero"
)
return thrust
@staticmethod
def clip_thrust(thrust, new_burn_time):
"""Clips the thrust curve data points according to the new_burn_time
parameter. If the burn_time range does not coincides with the thrust
dataset, their values are interpolated.
Parameters
----------
thrust : Function
Thrust curve to be clipped.
new_burn_time : float, tuple of float
New desired burn time in seconds for the thrust curve.
Must be within the thrust curve time range, otherwise
the thrust time range is used instead.
Returns
-------
Function
Clipped thrust curve.
"""
# Check if burn_time is within thrust_source range
changed_burn_time = False
burn_time = list(tuple_handler(new_burn_time))
if burn_time[1] > thrust.x_array[-1]:
burn_time[1] = thrust.x_array[-1]
changed_burn_time = True
if burn_time[0] < thrust.x_array[0]:
burn_time[0] = thrust.x_array[0]
changed_burn_time = True
if changed_burn_time:
warnings.warn(
f"burn_time argument {new_burn_time} is out of "
"thrust source time range. "