diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c04eb877..baff78c36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ straightforward as possible. ### Fixed - ENH: Parachute trigger doesn't work if "Apogee" is used instead of "apogee" [#489](https://github.com/RocketPy-Team/RocketPy/pull/489) +- BUG: fin_flutter_analysis doesn't find any fin set [#510](https://github.com/RocketPy-Team/RocketPy/pull/510) - FIX: EmptyMotor is breaking the Rocket.draw() method [#516](https://github.com/RocketPy-Team/RocketPy/pull/516) ## [v1.1.4] - 2023-12-07 diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index a1dfadaf5..bcdf2f658 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -217,7 +217,7 @@ def fin_flutter_analysis( The fin thickness, in meters shear_modulus : float Shear Modulus of fins' material, must be given in Pascal - flight : rocketpy.Flight + flight : Flight Flight object containing the rocket's flight data see_prints : boolean, optional True if you want to see the prints, False otherwise. @@ -229,52 +229,52 @@ def fin_flutter_analysis( ------ None """ + found_fin = False - # First, we need identify if there is at least a fin set in the rocket - for aero_surface in flight.rocket.aerodynamic_surfaces: + # First, we need identify if there is at least one fin set in the rocket + for aero_surface in flight.rocket.fins: if isinstance(aero_surface, TrapezoidalFins): # s: surface area; ar: aspect ratio; la: lambda root_chord = aero_surface.root_chord s = (aero_surface.tip_chord + root_chord) * aero_surface.span / 2 ar = aero_surface.span * aero_surface.span / s la = aero_surface.tip_chord / root_chord + if not found_fin: + found_fin = True + else: + warnings.warn("More than one fin set found. The last one will be used.") + if not found_fin: + raise AttributeError( + "There is no TrapezoidalFins in the rocket, can't run Flutter Analysis." + ) - # This ensures that a fin set was found in the rocket, if not, break - try: - s = s - except NameError: - print("There is no fin set in the rocket, can't run a Flutter Analysis.") - return None - - # Calculate the Fin Flutter Mach Number - flutter_mach = ( - (shear_modulus * 2 * (ar + 2) * (fin_thickness / root_chord) ** 3) - / (1.337 * (ar**3) * (la + 1) * flight.pressure) - ) ** 0.5 - + # Calculate variables + flutter_mach = _flutter_mach_number( + fin_thickness, shear_modulus, flight, root_chord, ar, la + ) safety_factor = _flutter_safety_factor(flight, flutter_mach) - # Prints everything + # Prints and plots if see_prints: _flutter_prints( - fin_thickness, - shear_modulus, - s, - ar, - la, - flutter_mach, - safety_factor, - flight, + fin_thickness, shear_modulus, s, ar, la, flutter_mach, safety_factor, flight ) - - # Plots everything if see_graphs: _flutter_plots(flight, flutter_mach, safety_factor) - return None else: return flutter_mach, safety_factor +def _flutter_mach_number(fin_thickness, shear_modulus, flight, root_chord, ar, la): + flutter_mach = ( + (shear_modulus * 2 * (ar + 2) * (fin_thickness / root_chord) ** 3) + / (1.337 * (ar**3) * (la + 1) * flight.pressure) + ) ** 0.5 + flutter_mach.set_title("Fin Flutter Mach Number") + flutter_mach.set_outputs("Mach") + return flutter_mach + + def _flutter_safety_factor(flight, flutter_mach): """Calculates the safety factor for the fin flutter analysis. @@ -291,25 +291,9 @@ def _flutter_safety_factor(flight, flutter_mach): rocketpy.Function The safety factor for the fin flutter analysis. """ - safety_factor = [[t, 0] for t in flutter_mach[:, 0]] - for i in range(len(flutter_mach)): - try: - safety_factor[i][1] = flutter_mach[i][1] / flight.mach_number[i][1] - except ZeroDivisionError: - safety_factor[i][1] = np.nan - - # Function needs to remove NaN and Inf values from the source - safety_factor = np.array(safety_factor) - safety_factor = safety_factor[~np.isnan(safety_factor).any(axis=1)] - safety_factor = safety_factor[~np.isinf(safety_factor).any(axis=1)] - - safety_factor = Function( - source=safety_factor, - inputs="Time (s)", - outputs="Fin Flutter Safety Factor", - interpolation="linear", - ) - + safety_factor = flutter_mach / flight.mach_number + safety_factor.set_title("Fin Flutter Safety Factor") + safety_factor.set_outputs("Safety Factor") return safety_factor @@ -331,7 +315,8 @@ def _flutter_plots(flight, flutter_mach, safety_factor): ------- None """ - fig = plt.figure(figsize=(6, 6)) + # TODO: move to rocketpy.plots submodule + _ = plt.figure(figsize=(6, 6)) ax1 = plt.subplot(211) ax1.plot( flutter_mach[:, 0], @@ -362,8 +347,6 @@ def _flutter_plots(flight, flutter_mach, safety_factor): plt.subplots_adjust(hspace=0.5) plt.show() - return None - def _flutter_prints( fin_thickness, @@ -404,6 +387,7 @@ def _flutter_prints( ------- None """ + # TODO: move to rocketpy.prints submodule time_index = np.argmin(flutter_mach[:, 1]) time_min_mach = flutter_mach[time_index, 0] min_mach = flutter_mach[time_index, 1] @@ -427,8 +411,6 @@ def _flutter_prints( print(f"Minimum Safety Factor: {min_sf:.3f} at {time_min_sf:.2f} s") print(f"Altitude of minimum Safety Factor: {altitude_min_sf:.3f} m (AGL)\n") - return None - def create_dispersion_dictionary(filename): """Creates a dictionary with the rocket data provided by a .csv file. diff --git a/tests/fixtures/utilities/flutter_mach.txt b/tests/fixtures/utilities/flutter_mach.txt new file mode 100644 index 000000000..675072670 --- /dev/null +++ b/tests/fixtures/utilities/flutter_mach.txt @@ -0,0 +1,544 @@ +0.00000,1.00482 +0.00141,1.00482 +0.00282,1.00482 +0.00564,1.00482 +0.00846,1.00482 +0.01128,1.00482 +0.03947,1.00482 +0.04086,1.00482 +0.04224,1.00482 +0.04502,1.00482 +0.04779,1.00482 +0.05057,1.00482 +0.05154,1.00482 +0.05250,1.00482 +0.05443,1.00482 +0.05637,1.00482 +0.05830,1.00482 +0.06067,1.00482 +0.06304,1.00482 +0.06541,1.00482 +0.08910,1.00482 +0.09281,1.00482 +0.09576,1.00482 +0.09871,1.00482 +0.10100,1.00482 +0.10329,1.00482 +0.10558,1.00482 +0.11016,1.00482 +0.11474,1.00482 +0.11932,1.00482 +0.13124,1.00483 +0.14316,1.00483 +0.14995,1.00483 +0.15419,1.00484 +0.15844,1.00484 +0.16268,1.00484 +0.17117,1.00484 +0.17966,1.00485 +0.18815,1.00485 +0.19448,1.00486 +0.20082,1.00486 +0.20568,1.00487 +0.21055,1.00487 +0.21542,1.00487 +0.22515,1.00488 +0.23488,1.00489 +0.24461,1.00490 +0.25434,1.00491 +0.35166,1.00503 +0.36325,1.00505 +0.36690,1.00505 +0.37055,1.00506 +0.37785,1.00507 +0.38516,1.00508 +0.39246,1.00510 +0.43464,1.00518 +0.47682,1.00526 +0.51901,1.00536 +0.56119,1.00547 +0.60478,1.00559 +0.64836,1.00573 +0.69195,1.00587 +0.73553,1.00603 +0.79677,1.00627 +0.85800,1.00653 +0.91924,1.00682 +0.98047,1.00713 +1.04171,1.00746 +1.05229,1.00752 +1.06287,1.00758 +1.07345,1.00764 +1.08402,1.00770 +1.12937,1.00797 +1.17471,1.00826 +1.22005,1.00855 +1.26539,1.00886 +1.27509,1.00893 +1.28478,1.00900 +1.29448,1.00907 +1.32865,1.00932 +1.36282,1.00957 +1.39699,1.00984 +1.43116,1.01011 +1.46533,1.01038 +1.49950,1.01067 +1.53368,1.01096 +1.56785,1.01126 +1.60202,1.01157 +1.63619,1.01188 +1.67927,1.01229 +1.72235,1.01270 +1.76544,1.01313 +1.80852,1.01357 +1.85160,1.01403 +1.89468,1.01449 +1.93777,1.01496 +1.98085,1.01545 +2.02393,1.01595 +2.06115,1.01639 +2.08798,1.01671 +2.11482,1.01703 +2.14165,1.01736 +2.16848,1.01770 +2.19531,1.01804 +2.22783,1.01845 +2.26036,1.01887 +2.29288,1.01930 +2.31902,1.01965 +2.34517,1.02000 +2.37131,1.02036 +2.39746,1.02072 +2.42360,1.02109 +2.44975,1.02146 +2.47589,1.02183 +2.50204,1.02221 +2.52818,1.02259 +2.55433,1.02297 +2.58047,1.02336 +2.60661,1.02375 +2.63276,1.02415 +2.65890,1.02455 +2.68505,1.02495 +2.71119,1.02536 +2.73734,1.02577 +2.76348,1.02619 +2.79375,1.02667 +2.82401,1.02716 +2.85427,1.02766 +2.88454,1.02816 +2.90971,1.02858 +2.93489,1.02901 +2.96007,1.02943 +2.98525,1.02987 +2.98903,1.02993 +2.99282,1.03000 +2.99660,1.03006 +3.00038,1.03013 +3.00795,1.03026 +3.01552,1.03039 +3.02308,1.03052 +3.03065,1.03065 +3.03980,1.03081 +3.04895,1.03097 +3.05810,1.03113 +3.06725,1.03129 +3.08355,1.03158 +3.09985,1.03187 +3.11615,1.03216 +3.13245,1.03245 +3.14875,1.03274 +3.16969,1.03312 +3.19063,1.03350 +3.21157,1.03388 +3.23251,1.03425 +3.25345,1.03464 +3.28027,1.03512 +3.30176,1.03552 +3.30506,1.03558 +3.30836,1.03564 +3.31166,1.03570 +3.31496,1.03576 +3.31825,1.03582 +3.32485,1.03594 +3.33145,1.03606 +3.33804,1.03618 +3.34464,1.03630 +3.35947,1.03657 +3.37429,1.03684 +3.38912,1.03712 +3.40394,1.03739 +3.41877,1.03766 +3.43360,1.03793 +3.44842,1.03820 +3.46573,1.03852 +3.48304,1.03884 +3.50035,1.03916 +3.51766,1.03947 +3.53497,1.03979 +3.56092,1.04027 +3.58688,1.04074 +3.61283,1.04122 +3.63879,1.04170 +3.66474,1.04217 +3.68617,1.04257 +3.70759,1.04296 +3.72902,1.04335 +3.75044,1.04374 +3.77187,1.04414 +3.79928,1.04464 +3.82669,1.04514 +3.85410,1.04564 +3.88151,1.04614 +3.90892,1.04664 +3.93633,1.04714 +3.95590,1.04749 +3.97548,1.04785 +3.99505,1.04820 +4.01463,1.04855 +4.03420,1.04891 +4.06760,1.04951 +4.10099,1.05011 +4.12663,1.05057 +4.15226,1.05104 +4.17789,1.05150 +4.20352,1.05196 +4.22916,1.05241 +4.25840,1.05294 +4.28764,1.05346 +4.31688,1.05398 +4.34613,1.05450 +4.37537,1.05502 +4.40461,1.05554 +4.43385,1.05606 +4.46310,1.05657 +4.49234,1.05709 +4.52158,1.05761 +4.55082,1.05812 +4.58451,1.05871 +4.61820,1.05930 +4.65189,1.05989 +4.68558,1.06048 +4.71927,1.06107 +4.75296,1.06166 +4.78665,1.06225 +4.82034,1.06283 +4.85403,1.06341 +4.88772,1.06400 +4.92141,1.06458 +4.96628,1.06535 +5.01115,1.06612 +5.04557,1.06672 +5.07999,1.06731 +5.11442,1.06789 +5.14884,1.06848 +5.18327,1.06907 +5.21769,1.06965 +5.26816,1.07051 +5.31863,1.07137 +5.35914,1.07205 +5.39965,1.07273 +5.44016,1.07341 +5.48067,1.07409 +5.52118,1.07477 +5.56168,1.07545 +5.61536,1.07634 +5.65989,1.07708 +5.70441,1.07782 +5.74893,1.07856 +5.79345,1.07930 +5.83798,1.08003 +5.88250,1.08076 +5.92702,1.08149 +5.97154,1.08222 +6.01607,1.08295 +6.06059,1.08367 +6.10511,1.08439 +6.14964,1.08511 +6.19416,1.08583 +6.23868,1.08655 +6.28320,1.08727 +6.32773,1.08798 +6.37225,1.08870 +6.42126,1.08948 +6.47027,1.09026 +6.51928,1.09104 +6.56829,1.09182 +6.61730,1.09259 +6.66631,1.09336 +6.72280,1.09425 +6.77929,1.09514 +6.83577,1.09602 +6.89226,1.09690 +6.94875,1.09778 +7.00523,1.09865 +7.07604,1.09975 +7.14685,1.10084 +7.21766,1.10192 +7.28846,1.10300 +7.35927,1.10408 +7.43008,1.10515 +7.50088,1.10622 +7.57169,1.10728 +7.64250,1.10834 +7.74261,1.10984 +7.81742,1.11094 +7.89222,1.11205 +7.96702,1.11315 +8.04182,1.11425 +8.11662,1.11534 +8.19143,1.11643 +8.26623,1.11751 +8.34103,1.11859 +8.41583,1.11966 +8.50693,1.12096 +8.59802,1.12226 +8.68911,1.12354 +8.78020,1.12483 +8.87130,1.12610 +8.97337,1.12752 +9.07544,1.12893 +9.17751,1.13034 +9.27958,1.13174 +9.39730,1.13334 +9.51501,1.13492 +9.63272,1.13650 +9.75043,1.13807 +9.88568,1.13986 +10.02093,1.14163 +10.15618,1.14339 +10.29143,1.14513 +10.42668,1.14686 +10.56193,1.14858 +10.69717,1.15028 +10.85200,1.15221 +11.00683,1.15413 +11.16166,1.15602 +11.31649,1.15789 +11.45719,1.15958 +11.59788,1.16125 +11.73857,1.16291 +11.87927,1.16455 +12.03717,1.16638 +12.19507,1.16818 +12.35298,1.16996 +12.51088,1.17173 +12.53835,1.17204 +12.56582,1.17234 +12.59329,1.17264 +12.64822,1.17325 +12.70316,1.17385 +12.75810,1.17446 +12.91464,1.17616 +13.07118,1.17784 +13.22773,1.17950 +13.38427,1.18115 +13.54081,1.18277 +13.69736,1.18438 +13.85390,1.18597 +14.01044,1.18753 +14.16699,1.18908 +14.32353,1.19061 +14.49866,1.19230 +14.67379,1.19396 +14.84892,1.19561 +15.02405,1.19722 +15.19258,1.19876 +15.36112,1.20027 +15.52965,1.20175 +15.69818,1.20322 +15.89510,1.20491 +16.09201,1.20656 +16.28892,1.20818 +16.48584,1.20978 +16.71249,1.21157 +16.88934,1.21295 +17.06620,1.21430 +17.24305,1.21562 +17.41990,1.21692 +17.66279,1.21866 +17.84823,1.21996 +18.03368,1.22124 +18.21912,1.22248 +18.40457,1.22370 +18.63691,1.22519 +18.81772,1.22632 +18.99853,1.22742 +19.17934,1.22849 +19.36014,1.22954 +19.57740,1.23077 +19.79465,1.23196 +20.01191,1.23311 +20.22916,1.23422 +20.44642,1.23530 +20.66367,1.23634 +20.88093,1.23734 +21.09818,1.23830 +21.31544,1.23922 +21.53269,1.24011 +21.79548,1.24113 +22.05827,1.24209 +22.32106,1.24300 +22.58385,1.24385 +22.84664,1.24465 +23.17773,1.24558 +23.50882,1.24641 +23.83991,1.24716 +24.17100,1.24782 +24.44426,1.24830 +24.71751,1.24872 +24.99077,1.24908 +25.26402,1.24937 +25.48785,1.24957 +25.71168,1.24973 +25.93551,1.24985 +26.15934,1.24993 +26.38317,1.24997 +26.48571,1.24997 +26.49203,1.24997 +26.49834,1.24997 +26.51097,1.24997 +26.52359,1.24997 +26.53622,1.24997 +26.66249,1.24996 +26.78876,1.24993 +26.91502,1.24990 +27.04129,1.24985 +27.22094,1.24975 +27.40059,1.24963 +27.58024,1.24949 +27.75989,1.24932 +27.93954,1.24913 +27.98571,1.24907 +28.00326,1.24905 +28.02081,1.24903 +28.05590,1.24899 +28.09099,1.24895 +28.12608,1.24890 +28.31218,1.24868 +28.49828,1.24845 +28.68439,1.24822 +28.87049,1.24799 +29.15129,1.24763 +29.43209,1.24726 +29.71289,1.24688 +29.99369,1.24650 +30.27450,1.24610 +30.75950,1.24541 +31.24450,1.24469 +31.72951,1.24396 +32.21451,1.24321 +32.69952,1.24244 +33.18452,1.24166 +33.82542,1.24062 +34.46632,1.23957 +35.10722,1.23851 +35.74812,1.23744 +36.38902,1.23637 +37.10961,1.23516 +37.83020,1.23395 +38.55080,1.23274 +39.27139,1.23152 +40.20139,1.22996 +41.13139,1.22841 +42.06139,1.22685 +42.99139,1.22530 +44.27285,1.22317 +45.55431,1.22105 +46.83578,1.21894 +48.11724,1.21684 +49.39870,1.21475 +50.35181,1.21319 +51.30492,1.21165 +52.25803,1.21010 +53.21115,1.20856 +54.20806,1.20696 +55.20498,1.20536 +56.20190,1.20377 +58.19080,1.20060 +60.17970,1.19746 +62.16861,1.19433 +64.15407,1.19123 +66.13953,1.18815 +68.12499,1.18509 +70.10805,1.18204 +72.09112,1.17902 +74.07418,1.17602 +76.05617,1.17303 +78.03817,1.17007 +80.02016,1.16712 +90.39343,1.15197 +92.98675,1.14826 +95.58007,1.14457 +98.17339,1.14092 +103.36002,1.13368 +108.54666,1.12656 +113.73329,1.11954 +118.91993,1.11262 +130.27132,1.09784 +141.62271,1.08351 +152.97409,1.06961 +164.32548,1.05614 +164.55238,1.05587 +164.67454,1.05573 +164.79671,1.05559 +166.05238,1.05412 +166.05481,1.05412 +166.05723,1.05412 +166.06209,1.05411 +166.06694,1.05411 +166.07179,1.05410 +166.09452,1.05408 +166.11724,1.05405 +166.13997,1.05403 +166.16269,1.05401 +166.19698,1.05398 +166.23126,1.05395 +166.26554,1.05393 +166.29982,1.05390 +166.33411,1.05388 +166.39386,1.05384 +166.45362,1.05380 +166.51338,1.05376 +166.57313,1.05373 +166.63289,1.05370 +166.69265,1.05367 +166.78997,1.05362 +166.88728,1.05357 +166.98460,1.05353 +167.08192,1.05349 +167.17924,1.05345 +167.27656,1.05341 +167.43378,1.05334 +167.59101,1.05328 +167.74824,1.05322 +167.90546,1.05316 +168.06269,1.05310 +168.28621,1.05302 +168.50974,1.05293 +168.73327,1.05285 +168.95679,1.05277 +169.18032,1.05269 +169.47144,1.05258 +169.76256,1.05247 +170.05368,1.05237 +170.34480,1.05226 +170.65364,1.05215 +170.96247,1.05203 +171.27130,1.05192 +171.58063,1.05181 +171.88996,1.05170 +172.19930,1.05158 +172.50867,1.05147 +174.11482,1.05088 +175.72096,1.05030 +177.32711,1.04971 +182.05305,1.04800 +186.77899,1.04629 +191.50492,1.04458 +206.83749,1.03910 +222.17005,1.03369 +237.50262,1.02835 +261.57709,1.02008 +285.65156,1.01198 +307.29931,1.00482 diff --git a/tests/fixtures/utilities/flutter_safety_factor.txt b/tests/fixtures/utilities/flutter_safety_factor.txt new file mode 100644 index 000000000..d16f406a6 --- /dev/null +++ b/tests/fixtures/utilities/flutter_safety_factor.txt @@ -0,0 +1,544 @@ +0.00000,64.78797 +0.00141,64.78797 +0.00282,64.78797 +0.00564,64.78797 +0.00846,64.78797 +0.01128,64.78797 +0.03947,64.78797 +0.04086,64.78797 +0.04224,64.78797 +0.04502,64.78797 +0.04779,64.78797 +0.05057,64.78797 +0.05154,64.78797 +0.05250,64.78797 +0.05443,64.78797 +0.05637,64.78797 +0.05830,64.78870 +0.06067,64.79250 +0.06304,64.79970 +0.06541,64.80872 +0.08910,64.07620 +0.09281,63.57463 +0.09576,63.02247 +0.09871,62.29744 +0.10100,61.61289 +0.10329,60.84649 +0.10558,60.01939 +0.11016,58.21319 +0.11474,56.25412 +0.11932,54.19828 +0.13124,48.72230 +0.14316,43.50321 +0.14995,40.76230 +0.15419,39.16578 +0.15844,37.68120 +0.16268,36.30211 +0.17117,33.83169 +0.17966,31.69778 +0.18815,29.84870 +0.19448,28.62739 +0.20082,27.52171 +0.20568,26.73258 +0.21055,25.98188 +0.21542,25.26726 +0.22515,23.93750 +0.23488,22.72719 +0.24461,21.62231 +0.25434,20.61072 +0.35166,13.86414 +0.36325,13.32773 +0.36690,13.16685 +0.37055,13.00954 +0.37785,12.70534 +0.38516,12.41405 +0.39246,12.13490 +0.43464,10.72612 +0.47682,9.59273 +0.51901,8.66353 +0.56119,7.89146 +0.60478,7.22183 +0.64836,6.65328 +0.69195,6.16468 +0.73553,5.74038 +0.79677,5.23076 +0.85800,4.80096 +0.91924,4.43372 +0.98047,4.11643 +1.04171,3.84018 +1.05229,3.79617 +1.06287,3.75316 +1.07345,3.71112 +1.08402,3.67003 +1.12937,3.50382 +1.17471,3.35218 +1.22005,3.21328 +1.26539,3.08560 +1.27509,3.05962 +1.28478,3.03409 +1.29448,3.00899 +1.32865,2.92379 +1.36282,2.84337 +1.39699,2.76734 +1.43116,2.69535 +1.46533,2.62708 +1.49950,2.56226 +1.53368,2.50069 +1.56785,2.44224 +1.60202,2.38667 +1.63619,2.33379 +1.67927,2.27065 +1.72235,2.21115 +1.76544,2.15501 +1.80852,2.10194 +1.85160,2.05172 +1.89468,2.00413 +1.93777,1.95896 +1.98085,1.91605 +2.02393,1.87524 +2.06115,1.84161 +2.08798,1.81827 +2.11482,1.79563 +2.14165,1.77368 +2.16848,1.75238 +2.19531,1.73170 +2.22783,1.70745 +2.26036,1.68404 +2.29288,1.66143 +2.31902,1.64381 +2.34517,1.62666 +2.37131,1.60997 +2.39746,1.59372 +2.42360,1.57790 +2.44975,1.56248 +2.47589,1.54747 +2.50204,1.53283 +2.52818,1.51856 +2.55433,1.50461 +2.58047,1.49097 +2.60661,1.47763 +2.63276,1.46459 +2.65890,1.45184 +2.68505,1.43937 +2.71119,1.42715 +2.73734,1.41520 +2.76348,1.40350 +2.79375,1.39025 +2.82401,1.37733 +2.85427,1.36470 +2.88454,1.35238 +2.90971,1.34235 +2.93489,1.33256 +2.96007,1.32302 +2.98525,1.31373 +2.98903,1.31235 +2.99282,1.31098 +2.99660,1.30962 +3.00038,1.30826 +3.00795,1.30559 +3.01552,1.30299 +3.02308,1.30046 +3.03065,1.29800 +3.03980,1.29513 +3.04895,1.29236 +3.05810,1.28969 +3.06725,1.28713 +3.08355,1.28281 +3.09985,1.27880 +3.11615,1.27510 +3.13245,1.27170 +3.14875,1.26860 +3.16969,1.26505 +3.19063,1.26197 +3.21157,1.25936 +3.23251,1.25721 +3.25345,1.25551 +3.28027,1.25400 +3.30176,1.25330 +3.30506,1.25323 +3.30836,1.25316 +3.31166,1.25310 +3.31496,1.25305 +3.31825,1.25300 +3.32485,1.25291 +3.33145,1.25285 +3.33804,1.25281 +3.34464,1.25279 +3.35947,1.25282 +3.37429,1.25296 +3.38912,1.25321 +3.40394,1.25355 +3.41877,1.25395 +3.43360,1.25440 +3.44842,1.25489 +3.46573,1.25551 +3.48304,1.25618 +3.50035,1.25691 +3.51766,1.25770 +3.53497,1.25854 +3.56092,1.25991 +3.58688,1.26140 +3.61283,1.26301 +3.63879,1.26476 +3.66474,1.26662 +3.68617,1.26826 +3.70759,1.26999 +3.72902,1.27180 +3.75044,1.27370 +3.77187,1.27568 +3.79928,1.27835 +3.82669,1.28117 +3.85410,1.28413 +3.88151,1.28724 +3.90892,1.29047 +3.93633,1.29377 +3.95590,1.29612 +3.97548,1.29847 +3.99505,1.30081 +4.01463,1.30317 +4.03420,1.30552 +4.06760,1.30954 +4.10099,1.31356 +4.12663,1.31665 +4.15226,1.31974 +4.17789,1.32284 +4.20352,1.32595 +4.22916,1.32906 +4.25840,1.33261 +4.28764,1.33617 +4.31688,1.33974 +4.34613,1.34331 +4.37537,1.34690 +4.40461,1.35048 +4.43385,1.35408 +4.46310,1.35768 +4.49234,1.36129 +4.52158,1.36490 +4.55082,1.36853 +4.58451,1.37271 +4.61820,1.37690 +4.65189,1.38110 +4.68558,1.38531 +4.71927,1.38953 +4.75296,1.39376 +4.78665,1.39800 +4.82034,1.40224 +4.85403,1.40650 +4.88772,1.41077 +4.92141,1.41505 +4.96628,1.42076 +5.01115,1.42649 +5.04557,1.43089 +5.07999,1.43531 +5.11442,1.43974 +5.14884,1.44418 +5.18327,1.44862 +5.21769,1.45308 +5.26816,1.45964 +5.31863,1.46622 +5.35914,1.47152 +5.39965,1.47683 +5.44016,1.48216 +5.48067,1.48751 +5.52118,1.49286 +5.56168,1.49824 +5.61536,1.50538 +5.65989,1.51133 +5.70441,1.51730 +5.74893,1.52328 +5.79345,1.52929 +5.83798,1.53531 +5.88250,1.54135 +5.92702,1.54742 +5.97154,1.55349 +6.01607,1.55959 +6.06059,1.56570 +6.10511,1.57183 +6.14964,1.57798 +6.19416,1.58414 +6.23868,1.59032 +6.28320,1.59652 +6.32773,1.60274 +6.37225,1.60897 +6.42126,1.61586 +6.47027,1.62276 +6.51928,1.62969 +6.56829,1.63664 +6.61730,1.64362 +6.66631,1.65061 +6.72280,1.65871 +6.77929,1.66683 +6.83577,1.67499 +6.89226,1.68318 +6.94875,1.69140 +7.00523,1.69965 +7.07604,1.71005 +7.14685,1.72049 +7.21766,1.73099 +7.28846,1.74155 +7.35927,1.75215 +7.43008,1.76282 +7.50088,1.77354 +7.57169,1.78432 +7.64250,1.79516 +7.74261,1.81058 +7.81742,1.82218 +7.89222,1.83385 +7.96702,1.84558 +8.04182,1.85739 +8.11662,1.86927 +8.19143,1.88122 +8.26623,1.89324 +8.34103,1.90534 +8.41583,1.91751 +8.50693,1.93243 +8.59802,1.94747 +8.68911,1.96263 +8.78020,1.97790 +8.87130,1.99329 +8.97337,2.01069 +9.07544,2.02824 +9.17751,2.04595 +9.27958,2.06382 +9.39730,2.08464 +9.51501,2.10568 +9.63272,2.12695 +9.75043,2.14846 +9.88568,2.17347 +10.02093,2.19881 +10.15618,2.22448 +10.29143,2.25050 +10.42668,2.27687 +10.56193,2.30361 +10.69717,2.33071 +10.85200,2.36221 +11.00683,2.39423 +11.16166,2.42677 +11.31649,2.45986 +11.45719,2.49042 +11.59788,2.52145 +11.73857,2.55297 +11.87927,2.58500 +12.03717,2.62156 +12.19507,2.65880 +12.35298,2.69674 +12.51088,2.73539 +12.53835,2.74219 +12.56582,2.74901 +12.59329,2.75586 +12.64822,2.76961 +12.70316,2.78346 +12.75810,2.79741 +12.91464,2.83767 +13.07118,2.87872 +13.22773,2.92059 +13.38427,2.96331 +13.54081,3.00690 +13.69736,3.05141 +13.85390,3.09686 +14.01044,3.14328 +14.16699,3.19071 +14.32353,3.23918 +14.49866,3.29470 +14.67379,3.35163 +14.84892,3.41003 +15.02405,3.46996 +15.19258,3.52914 +15.36112,3.58987 +15.52965,3.65221 +15.69818,3.71622 +15.89510,3.79324 +16.09201,3.87276 +16.28892,3.95494 +16.48584,4.03989 +16.71249,4.14133 +16.88934,4.22333 +17.06620,4.30797 +17.24305,4.39539 +17.41990,4.48573 +17.66279,4.61484 +17.84823,4.71757 +18.03368,4.82413 +18.21912,4.93474 +18.40457,5.04964 +18.63691,5.20002 +18.81772,5.32232 +18.99853,5.44954 +19.17934,5.58197 +19.36014,5.71993 +19.57740,5.89350 +19.79465,6.07620 +20.01191,6.26874 +20.22916,6.47189 +20.44642,6.68648 +20.66367,6.91345 +20.88093,7.15380 +21.09818,7.40864 +21.31544,7.67916 +21.53269,7.96667 +21.79548,8.33915 +22.05827,8.74124 +22.32106,9.17584 +22.58385,9.64600 +22.84664,10.15485 +23.17773,10.85571 +23.50882,11.62791 +23.83991,12.47426 +24.17100,13.39282 +24.44426,14.19841 +24.71751,15.03405 +24.99077,15.87894 +25.26402,16.70184 +25.48785,17.33015 +25.71168,17.88741 +25.93551,18.34360 +26.15934,18.67019 +26.38317,18.84449 +26.48571,18.86954 +26.49203,18.86993 +26.49834,18.87019 +26.51097,18.87030 +26.52359,18.86989 +26.53622,18.86894 +26.66249,18.83017 +26.78876,18.73915 +26.91502,18.59816 +27.04129,18.41055 +27.22094,18.07178 +27.40059,17.66160 +27.58024,17.19538 +27.75989,16.68831 +27.93954,16.15447 +27.98571,16.01449 +28.00326,16.08442 +28.02081,16.15388 +28.05590,16.29229 +28.09099,16.42880 +28.12608,16.56338 +28.31218,17.24394 +28.49828,17.86823 +28.68439,18.43516 +28.87049,18.94468 +29.15129,19.60736 +29.43209,20.14822 +29.71289,20.57722 +29.99369,20.90697 +30.27450,21.15100 +30.75950,21.41023 +31.24450,21.51849 +31.72951,21.52921 +32.21451,21.48144 +32.69952,21.40267 +33.18452,21.31111 +33.82542,21.18884 +34.46632,21.07718 +35.10722,20.98154 +35.74812,20.90286 +36.38902,20.83991 +37.10961,20.78525 +37.83020,20.74438 +38.55080,20.71422 +39.27139,20.69224 +40.20139,20.67270 +41.13139,20.65995 +42.06139,20.65178 +42.99139,20.64664 +44.27285,20.64247 +45.55431,20.64042 +46.83578,20.63965 +48.11724,20.63915 +49.39870,20.63880 +50.35181,20.63880 +51.30492,20.63883 +52.25803,20.63886 +53.21115,20.63892 +54.20806,20.63901 +55.20498,20.63910 +56.20190,20.63919 +58.19080,20.63938 +60.17970,20.63958 +62.16861,20.63977 +64.15407,20.63996 +66.13953,20.64015 +68.12499,20.64033 +70.10805,20.64052 +72.09112,20.64070 +74.07418,20.64089 +76.05617,20.64107 +78.03817,20.64124 +80.02016,20.64142 +90.39343,20.64228 +92.98675,20.64249 +95.58007,20.64275 +98.17339,20.64303 +103.36002,20.64346 +108.54666,20.64383 +113.73329,20.64421 +118.91993,20.64460 +130.27132,20.64544 +141.62271,20.64624 +152.97409,20.64699 +164.32548,20.64772 +164.55238,20.64773 +164.67454,20.64774 +164.79671,20.64775 +166.05238,20.64783 +166.05481,20.77952 +166.05723,20.91102 +166.06209,21.17535 +166.06694,21.43890 +166.07179,21.70167 +166.09452,22.92118 +166.11724,24.12309 +166.13997,25.30649 +166.16269,26.47073 +166.19698,28.19017 +166.23126,29.86309 +166.26554,31.48771 +166.29982,33.06332 +166.33411,34.58900 +166.39386,37.12730 +166.45362,39.50943 +166.51338,41.73827 +166.57313,43.81483 +166.63289,45.74249 +166.69265,47.52632 +166.78997,50.13799 +166.88728,52.41218 +166.98460,54.38019 +167.08192,56.07366 +167.17924,57.52416 +167.27656,58.76154 +167.43378,60.37953 +167.59101,61.61653 +167.74824,62.55565 +167.90546,63.26560 +168.06269,63.80099 +168.28621,64.34231 +168.50974,64.70115 +168.73327,64.93912 +168.95679,65.09707 +169.18032,65.20148 +169.47144,65.28605 +169.76256,65.33552 +170.05368,65.36491 +170.34480,65.38195 +170.65364,65.39233 +170.96247,65.39784 +171.27130,65.40086 +171.58063,65.40263 +171.88996,65.40368 +172.19930,65.40428 +172.50867,65.40463 +174.11482,65.40537 +175.72096,65.40528 +177.32711,65.40516 +182.05305,65.40514 +186.77899,65.40517 +191.50492,65.40520 +206.83749,65.40529 +222.17005,65.40538 +237.50262,65.40547 +261.57709,65.40563 +285.65156,65.40568 +307.29931,65.40589 diff --git a/tests/unit/test_utilities.py b/tests/unit/test_utilities.py index aeb374db6..68dbc3d7f 100644 --- a/tests/unit/test_utilities.py +++ b/tests/unit/test_utilities.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from rocketpy import utilities +from rocketpy import Function, utilities @pytest.mark.parametrize( @@ -132,35 +132,77 @@ def test_liftoff_by_mass(mock_show, flight): assert f.plot() == None -@pytest.mark.skip(reason="legacy tests") -@patch("matplotlib.pyplot.show") -def test_fin_flutter_analysis(mock_show, flight): +def test_fin_flutter_analysis(flight_calisto_custom_wind): """Tests the fin_flutter_analysis function. It tests the both options of the see_graphs parameter. Parameters ---------- - flight : rocketpy.Flight + flight_calisto_custom_wind : Flight A Flight object with a rocket with fins. This flight object was created in the conftest.py file. """ flutter_mach, safety_factor = utilities.fin_flutter_analysis( fin_thickness=2 / 1000, shear_modulus=10e9, - flight=flight, + flight=flight_calisto_custom_wind, + see_prints=False, see_graphs=False, ) + assert np.isclose(flutter_mach(0), 1.00482, atol=5e-3) + assert np.isclose(flutter_mach(10), 1.1413572089696549, atol=5e-3) + assert np.isclose(flutter_mach(np.inf), 1.0048188594647927, atol=5e-3) + assert np.isclose(safety_factor(0), 64.78797, atol=5e-3) + assert np.isclose(safety_factor(10), 2.1948620401502072, atol=5e-3) + assert np.isclose(safety_factor(np.inf), 65.40588722032527, atol=5e-3) - assert abs(flutter_mach(15) - 1.085461074199555) < 1e-3 - assert abs(safety_factor(15) - 3.364511241274865) < 1e-3 + +def test_flutter_prints(flight_calisto_custom_wind): + """Tests the _flutter_prints function. + + Parameters + ---------- + flight_calisto_custom_wind : Flight + A Flight object with a rocket with fins. This flight object was created + in the conftest.py file. + """ + flutter_mach = Function("tests/fixtures/utilities/flutter_mach.txt") + safety_factor = Function("tests/fixtures/utilities/flutter_safety_factor.txt") assert ( - utilities.fin_flutter_analysis( + utilities._flutter_prints( # pylint: disable=protected-access fin_thickness=2 / 1000, shear_modulus=10e9, - flight=flight, - see_graphs=True, + s=0.009899999999999999, + ar=1.2222222222222223, + la=0.5, + flutter_mach=flutter_mach, + safety_factor=safety_factor, + flight=flight_calisto_custom_wind, ) - == None - ) + is None + ), "An error occurred while running the utilities._flutter_prints function." + + +@patch("matplotlib.pyplot.show") +def test_flutter_plots(mock_show, flight_calisto_custom_wind): + """Tests the _flutter_plots function. + + Parameters + ---------- + mock_show : mock + Mock of the matplotlib.pyplot.show function. This is here so the plots + are not shown during the tests. + flight_calisto_custom_wind : Flight + A Flight object with a rocket with fins. This flight object was created + in the conftest.py file. + """ + flutter_mach = Function("tests/fixtures/utilities/flutter_mach.txt") + safety_factor = Function("tests/fixtures/utilities/flutter_safety_factor.txt") + assert ( + utilities._flutter_plots( # pylint: disable=protected-access + flight_calisto_custom_wind, flutter_mach, safety_factor + ) + is None + ), "An error occurred while running the utilities._flutter_plots function." def test_get_instance_attributes(flight_calisto_robust):