From bc73117c0eb2e9beaaf370be2635201378ad6a5d Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 15 Mar 2024 00:29:09 -0400 Subject: [PATCH] TST: add tests for file setters and json parsing in the Monte Carlo class --- tests/fixtures/monte_carlo/example.inputs.txt | 10 +++++ .../fixtures/monte_carlo/example.outputs.txt | 10 +++++ .../monte_carlo/monte_carlo_fixtures.py | 21 ++++++++++ tests/test_monte_carlo.py | 42 +++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 tests/fixtures/monte_carlo/example.inputs.txt create mode 100644 tests/fixtures/monte_carlo/example.outputs.txt diff --git a/tests/fixtures/monte_carlo/example.inputs.txt b/tests/fixtures/monte_carlo/example.inputs.txt new file mode 100644 index 000000000..d82cae696 --- /dev/null +++ b/tests/fixtures/monte_carlo/example.inputs.txt @@ -0,0 +1,10 @@ +{"elevation": 1401.4956352929128, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.9450816780482028, "wind_velocity_y_factor": 0.9781441848266635, "datum": "WGS84", "timezone": "UTC", "radius": 0.0635062964327075, "mass": 15.908580991806707, "I_11_without_motor": 6.321, "I_22_without_motor": 6.322114874292384, "I_33_without_motor": 0.012957242330574877, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 10.116998067339784, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.6280833219672366, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 1.0177025917838693, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.0967003213742696, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "'Function from R1 to R1 : (Scalar) \u2192 (Scalar)'", "total_impulse": 8008.347921291322, "burn_start_time": 0, "burn_out_time": 3.906214754528265, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03293120513502925, "grain_number": 5, "grain_density": 1854.2340720665204, "grain_outer_radius": 0.032985640020247765, "grain_initial_inner_radius": 0.015310123275236702, "grain_initial_height": 0.11811825300572186, "grain_separation": 0.006711096958736968, "grains_center_of_mass_position": 0.39647964588403434, "center_of_dry_mass_position": 0.317, "nozzle_position": 0.0013349636505807958, "throat_radius": 0.010921423639193314, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3720479424144372}], "aerodynamic_surfaces": [{"length": 0.5578974370049176, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1358373309953151}, {"n": 4, "root_chord": 0.11974359643195065, "tip_chord": 0.03940879564813866, "span": 0.10000563733372181, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1674848464453782}, {"top_radius": 0.0629442823276734, "bottom_radius": 0.044000809597868056, "length": 0.060919598903432425, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6979653598166442, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6191976129185146, "upper_button_position": 0.0787677468981296}], "rail_length": 5.2, "inclination": 85.41806990321825, "heading": 54.18109302296489} +{"elevation": 1406.5350756913592, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.9516662861966597, "wind_velocity_y_factor": 1.0064048593297057, "datum": "WGS84", "timezone": "UTC", "radius": 0.06350349167738431, "mass": 15.768610173003173, "I_11_without_motor": 6.321, "I_22_without_motor": 6.315825792646666, "I_33_without_motor": 0.028629613565978755, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 9.89730766328184, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.4899191353962622, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.9607265553248231, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.4523711630490321, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "'Function from R1 to R1 : (Scalar) \u2192 (Scalar)'", "total_impulse": 6446.57135198394, "burn_start_time": 0, "burn_out_time": 3.9894949335022, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03320688298961293, "grain_number": 5, "grain_density": 1909.5604610821972, "grain_outer_radius": 0.0324705584521942, "grain_initial_inner_radius": 0.014811951142584205, "grain_initial_height": 0.11731380337585026, "grain_separation": 0.00491393364215582, "grains_center_of_mass_position": 0.39628551738684287, "center_of_dry_mass_position": 0.317, "nozzle_position": 0.0007868629707592146, "throat_radius": 0.01060574995942289, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3735008381135014}], "aerodynamic_surfaces": [{"length": 0.5585570098911449, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.132236295583569}, {"n": 4, "root_chord": 0.11988524950598159, "tip_chord": 0.039971120565612084, "span": 0.09991375118669615, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.168340642420532}, {"top_radius": 0.06366749282692026, "bottom_radius": 0.04247035278896944, "length": 0.05982474727356781, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6981342606544769, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6165145493073986, "upper_button_position": 0.08161971134707835}], "rail_length": 5.2, "inclination": 86.94780910509066, "heading": 53.98156443958248} +{"elevation": 1397.5103755289601, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.9963390772837555, "wind_velocity_y_factor": 0.9310545880995709, "datum": "WGS84", "timezone": "UTC", "radius": 0.06349982790733924, "mass": 16.113964741354632, "I_11_without_motor": 6.321, "I_22_without_motor": 6.332851244792044, "I_33_without_motor": 0.030021814198234187, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 9.779220764010605, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.4845247961789623, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.9682134611200442, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.585599474971143, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "data/motors/Cesaroni_M1670.eng", "total_impulse": 7487.827034238503, "burn_start_time": 0, "burn_out_time": 3.914765014376584, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.032744147927549344, "grain_number": 5, "grain_density": 1867.9086875282821, "grain_outer_radius": 0.03294126549026792, "grain_initial_inner_radius": 0.015080085662914838, "grain_initial_height": 0.11988311114017533, "grain_separation": 0.005305032186539184, "grains_center_of_mass_position": 0.3983717635734512, "center_of_dry_mass_position": 0.317, "nozzle_position": -0.00037263633999194966, "throat_radius": 0.011059633377750937, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3738508519821517}], "aerodynamic_surfaces": [{"length": 0.5578912976208477, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1350183318601563}, {"n": 4, "root_chord": 0.12017400986558589, "tip_chord": 0.03962943164232406, "span": 0.09981633200128909, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1688641229895451}, {"top_radius": 0.06373223012294663, "bottom_radius": 0.04232126759707431, "length": 0.060581689919426356, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.7008512596941494, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6171911772790206, "upper_button_position": 0.08366008241512879}], "rail_length": 5.2, "inclination": 84.38246649324918, "heading": 57.68102782665487} +{"elevation": 1391.4643973320065, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.994774900128261, "wind_velocity_y_factor": 1.0273174134096499, "datum": "WGS84", "timezone": "UTC", "radius": 0.06350873600135983, "mass": 15.916394040973515, "I_11_without_motor": 6.321, "I_22_without_motor": 6.308143425967061, "I_33_without_motor": 0.01802192268136874, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 9.962077401196566, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.4441736202776219, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.893598158549614, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.8260068764932076, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "'Function from R1 to R1 : (Scalar) \u2192 (Scalar)'", "total_impulse": 7665.613115626527, "burn_start_time": 0, "burn_out_time": 3.940913002019911, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.033695677239588384, "grain_number": 5, "grain_density": 1819.143680494988, "grain_outer_radius": 0.032291825881788055, "grain_initial_inner_radius": 0.015534286519013498, "grain_initial_height": 0.12111389087171241, "grain_separation": 0.00518858578159403, "grains_center_of_mass_position": 0.3958892234962095, "center_of_dry_mass_position": 0.317, "nozzle_position": 0.000841381739081922, "throat_radius": 0.010545258737885452, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.372609521542472}], "aerodynamic_surfaces": [{"length": 0.5582963193527628, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1340975925429957}, {"n": 4, "root_chord": 0.11995055756311049, "tip_chord": 0.03911287548791437, "span": 0.0999837256839886, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.168546806795111}, {"top_radius": 0.06238999721506463, "bottom_radius": 0.04232254608023388, "length": 0.06127586518492881, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6998568516921738, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6169186688752775, "upper_button_position": 0.08293818281689636}], "rail_length": 5.2, "inclination": 85.5600719639608, "heading": 54.55110563306921} +{"elevation": 1393.8209804460496, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 1.000560647640797, "wind_velocity_y_factor": 1.022342992550456, "datum": "WGS84", "timezone": "UTC", "radius": 0.06349155639173172, "mass": 15.738934754709508, "I_11_without_motor": 6.321, "I_22_without_motor": 6.319864104451785, "I_33_without_motor": 0.02545348425633203, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 10.028901279392143, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.6235052375811327, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.9507391354824055, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.771359370747443, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "data/motors/Cesaroni_M1670.eng", "total_impulse": 7177.104378492918, "burn_start_time": 0, "burn_out_time": 4.027061395012405, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03321825858808873, "grain_number": 5, "grain_density": 1928.250127701342, "grain_outer_radius": 0.0326772635525661, "grain_initial_inner_radius": 0.014434444632840328, "grain_initial_height": 0.11915759110557982, "grain_separation": 0.003435521791718822, "grains_center_of_mass_position": 0.3981852218515913, "center_of_dry_mass_position": 0.317, "nozzle_position": -0.0011190287234854237, "throat_radius": 0.01095718616985679, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3718019413845894}], "aerodynamic_surfaces": [{"length": 0.5577890154392657, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1338320467616545}, {"n": 4, "root_chord": 0.11997673771622025, "tip_chord": 0.03961950834152785, "span": 0.09987516565794868, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1677474523375928}, {"top_radius": 0.06268560633721164, "bottom_radius": 0.044510867340116785, "length": 0.06075235914452975, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6988166137446366, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6166577593632545, "upper_button_position": 0.08215885438138204}], "rail_length": 5.2, "inclination": 84.3544821309231, "heading": 50.72164249193685} +{"elevation": 1400.4245658042064, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.9934430357253621, "wind_velocity_y_factor": 0.9995090755329425, "datum": "WGS84", "timezone": "UTC", "radius": 0.06350584375449667, "mass": 16.296803998687906, "I_11_without_motor": 6.321, "I_22_without_motor": 6.319261987424873, "I_33_without_motor": 0.03630373525141324, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 10.002039291361488, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.521968760387734, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.9020101884044889, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.1765277521869204, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": [[0, 6000], [1, 6000], [2, 6000], [3, 6000], [4, 6000]], "total_impulse": 7217.188111138403, "burn_start_time": 0, "burn_out_time": 3.953528968797261, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03284513500057279, "grain_number": 5, "grain_density": 1800.639910024485, "grain_outer_radius": 0.03301656874049487, "grain_initial_inner_radius": 0.014555186055323372, "grain_initial_height": 0.1206707133239914, "grain_separation": 0.004454433148147433, "grains_center_of_mass_position": 0.39627775359288614, "center_of_dry_mass_position": 0.317, "nozzle_position": 0.0005563722488752347, "throat_radius": 0.010933800510542133, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3728443371458632}], "aerodynamic_surfaces": [{"length": 0.558850056530137, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1337806099233774}, {"n": 4, "root_chord": 0.12022514479101613, "tip_chord": 0.03977488143313973, "span": 0.0994325007551205, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1664648740494952}, {"top_radius": 0.06479268414162065, "bottom_radius": 0.04152271271281226, "length": 0.05909910459243895, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6986745614799809, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6200750499897003, "upper_button_position": 0.07859951149028055}], "rail_length": 5.2, "inclination": 85.05093618827794, "heading": 53.60886223539351} +{"elevation": 1415.056657477282, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 1.0312596248131305, "wind_velocity_y_factor": 0.9782064047459161, "datum": "WGS84", "timezone": "UTC", "radius": 0.06350611017605608, "mass": 16.022551859182254, "I_11_without_motor": 6.321, "I_22_without_motor": 6.327756636233426, "I_33_without_motor": 0.02557444953196947, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 9.980848801873547, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.508699434351987, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.9515739039961527, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.5321962395547486, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": [[0, 6000], [1, 6000], [2, 6000], [3, 6000], [4, 6000]], "total_impulse": 6812.795180685129, "burn_start_time": 0, "burn_out_time": 4.049618335869951, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03319383745172945, "grain_number": 5, "grain_density": 1906.7678709629558, "grain_outer_radius": 0.03340103180630861, "grain_initial_inner_radius": 0.014551079041229029, "grain_initial_height": 0.12005768142411836, "grain_separation": 0.00657049931137661, "grains_center_of_mass_position": 0.3981008886145341, "center_of_dry_mass_position": 0.317, "nozzle_position": -0.0006893392436535004, "throat_radius": 0.012024640120421601, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3712329054659291}], "aerodynamic_surfaces": [{"length": 0.5594118729079444, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1335349426174457}, {"n": 4, "root_chord": 0.12009642855415019, "tip_chord": 0.04001264775075921, "span": 0.10078751689454832, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1677588565290395}, {"top_radius": 0.06427069561590722, "bottom_radius": 0.04397816658676053, "length": 0.0593018307726965, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6994742704183982, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6179749167952617, "upper_button_position": 0.08149935362313643}], "rail_length": 5.2, "inclination": 85.27775446168337, "heading": 52.07473124199783} +{"elevation": 1407.8607034367462, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.9243120897907832, "wind_velocity_y_factor": 1.0025238660743678, "datum": "WGS84", "timezone": "UTC", "radius": 0.06349969087635444, "mass": 15.890306082322684, "I_11_without_motor": 6.321, "I_22_without_motor": 6.318894753828044, "I_33_without_motor": 0.022625913266197582, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 10.015807670191228, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.4770955482649448, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.909871981719692, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.2298197853504698, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": [[0, 6000], [1, 6000], [2, 6000], [3, 6000], [4, 6000]], "total_impulse": 6290.904709483322, "burn_start_time": 0, "burn_out_time": 4.0264151892663715, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.033694339637079185, "grain_number": 5, "grain_density": 1808.8899716051212, "grain_outer_radius": 0.03265337873317285, "grain_initial_inner_radius": 0.015369739745945339, "grain_initial_height": 0.12082242511279105, "grain_separation": 0.00581455836021638, "grains_center_of_mass_position": 0.397321775713535, "center_of_dry_mass_position": 0.317, "nozzle_position": 0.0008404742853902787, "throat_radius": 0.011003804698621191, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.372796006115578}], "aerodynamic_surfaces": [{"length": 0.5559534534598283, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.1353044227867581}, {"n": 4, "root_chord": 0.12003997954303475, "tip_chord": 0.040562591675552394, "span": 0.1001969641064779, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1671994512705786}, {"top_radius": 0.06535000693622554, "bottom_radius": 0.04350279638873781, "length": 0.058974725448361943, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.701347285230197, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6181432349663547, "upper_button_position": 0.08320405026384226}], "rail_length": 5.2, "inclination": 84.97776656660177, "heading": 52.580896737469814} +{"elevation": 1386.2658290054742, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 1.0118150053505988, "wind_velocity_y_factor": 0.9571284969912979, "datum": "WGS84", "timezone": "UTC", "radius": 0.06349006343504872, "mass": 15.42094541890885, "I_11_without_motor": 6.321, "I_22_without_motor": 6.3356695712837094, "I_33_without_motor": 0.006705760681207741, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 10.066449429645994, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.4779869817042537, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.8973690466734414, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.7041267766602894, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "'Function from R1 to R1 : (Scalar) \u2192 (Scalar)'", "total_impulse": 6381.219851440446, "burn_start_time": 0, "burn_out_time": 4.054255258168555, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03222852327072895, "grain_number": 5, "grain_density": 1815.8174750986202, "grain_outer_radius": 0.03275386125470833, "grain_initial_inner_radius": 0.015021358564266188, "grain_initial_height": 0.11894549555735523, "grain_separation": 0.005129849003987609, "grains_center_of_mass_position": 0.3963108881310866, "center_of_dry_mass_position": 0.317, "nozzle_position": -0.00015441772326065553, "throat_radius": 0.011378587756155079, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.3725029856828037}], "aerodynamic_surfaces": [{"length": 0.5577981332870249, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.134456731296994}, {"n": 4, "root_chord": 0.12000296575078867, "tip_chord": 0.03907415657688916, "span": 0.10001130751688864, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1678017879176694}, {"top_radius": 0.06376703301251549, "bottom_radius": 0.044211136643289226, "length": 0.06054053098519092, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.6997142332882197, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6196474863730008, "upper_button_position": 0.08006674691521887}], "rail_length": 5.2, "inclination": 85.88443199907574, "heading": 54.81131149740836} +{"elevation": 1403.7325602045448, "gravity": "'Function from R1 to R1 : (height (m)) \u2192 (gravity (m/s\u00b2))'", "latitude": 32.990254, "longitude": -106.974998, "wind_velocity_x_factor": 0.9804329129220021, "wind_velocity_y_factor": 0.988332671080639, "datum": "WGS84", "timezone": "UTC", "radius": 0.0634997822583417, "mass": 15.200469661823616, "I_11_without_motor": 6.321, "I_22_without_motor": 6.335914970817965, "I_33_without_motor": 0.045148017264811394, "I_12_without_motor": 0, "I_13_without_motor": 0, "I_23_without_motor": 0, "power_off_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power Off)'", "power_on_drag": "'Function from R1 to R1 : (Mach Number) \u2192 (Drag Coefficient with Power On)'", "power_off_drag_factor": 1.0, "power_on_drag_factor": 1.0, "center_of_mass_without_motor": 0.0, "coordinate_system_orientation": "tail_to_nose", "parachutes": [{"cd_s": 10.063947984376528, "trigger": ".main_trigger at 0x7814fd01cfe0>", "sampling_rate": 105, "lag": 1.4609886041307245, "noise": [0, 8.3, 0.5], "name": "calisto_main_chute"}, {"cd_s": 0.9010741447720559, "trigger": ".drogue_trigger at 0x7814fd01c540>", "sampling_rate": 105, "lag": 1.0441960102548469, "noise": [0, 8.3, 0.5], "name": "calisto_drogue_chute"}], "motors": [{"thrust_source": "'Function from R1 to R1 : (Scalar) \u2192 (Scalar)'", "total_impulse": 4377.734925575618, "burn_start_time": 0, "burn_out_time": 4.011186754001263, "dry_mass": 1.815, "dry_I_11": 0.125, "dry_I_22": 0.125, "dry_I_33": 0.002, "dry_I_12": 0, "dry_I_13": 0, "dry_I_23": 0, "nozzle_radius": 0.03305502881850419, "grain_number": 5, "grain_density": 1785.487368974391, "grain_outer_radius": 0.03206110002556264, "grain_initial_inner_radius": 0.015876272475096095, "grain_initial_height": 0.1200659797847355, "grain_separation": 0.006612189921193928, "grains_center_of_mass_position": 0.3977976410061983, "center_of_dry_mass_position": 0.317, "nozzle_position": -0.0011342800834796306, "throat_radius": 0.009963047423146689, "interpolate": "linear", "coordinate_system_orientation": "nozzle_to_combustion_chamber", "position": -1.372285899045296}], "aerodynamic_surfaces": [{"length": 0.5594889434620973, "kind": "vonkarman", "base_radius": 0.0635, "bluffness": null, "rocket_radius": 0.0635, "name": "calisto_nose_cone", "position": 1.135362678737609}, {"n": 4, "root_chord": 0.12045943903706133, "tip_chord": 0.040893613797167924, "span": 0.10022691137098828, "rocket_radius": 0.0635, "cant_angle": 0, "sweep_length": 0.07999999999999999, "sweep_angle": null, "airfoil": null, "name": "calisto_trapezoidal_fins", "position": -1.1681386229540538}, {"top_radius": 0.06395950267498926, "bottom_radius": 0.04495193258314121, "length": 0.060736166658098174, "rocket_radius": 0.0635, "name": "calisto_tail", "position": -1.313}], "rail_buttons": [{"buttons_distance": 0.7023822176360356, "angular_position": 45, "name": "Rail Buttons", "lower_button_position": -0.6166788769292593, "upper_button_position": 0.08570334070677632}], "rail_length": 5.2, "inclination": 85.49506843878025, "heading": 52.680314874463875} diff --git a/tests/fixtures/monte_carlo/example.outputs.txt b/tests/fixtures/monte_carlo/example.outputs.txt new file mode 100644 index 000000000..ffc0f5548 --- /dev/null +++ b/tests/fixtures/monte_carlo/example.outputs.txt @@ -0,0 +1,10 @@ +{"lateral_surface_wind": 0.0, "apogee_x": 418.0900192341263, "apogee_time": 29.227877417373804, "max_mach_number": 1.0597636981635778, "apogee": 5690.287437226489, "x_impact": 480.48559284729896, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.28886753090850337, "out_of_rail_velocity": 25.983654528478493, "y_impact": 346.7826493888511, "apogee_y": 301.74630214056145, "impact_velocity": -5.371608743357084, "t_final": 353.87686346458946} +{"lateral_surface_wind": 0.0, "apogee_x": 664.8205729246815, "apogee_time": 26.40800619077295, "max_mach_number": 0.8577562337266057, "apogee": 4715.816960792063, "x_impact": 774.0891149671631, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.3285641180798137, "out_of_rail_velocity": 22.82061718874699, "y_impact": 562.7937790273377, "apogee_y": 483.3484727242321, "impact_velocity": -5.408315380727355, "t_final": 299.60847406715055} +{"lateral_surface_wind": 0.0, "apogee_x": 766.3125531509313, "apogee_time": 27.926605808862806, "max_mach_number": 0.9775271452143771, "apogee": 5333.672919610753, "x_impact": 884.994696596615, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.3436250275216524, "out_of_rail_velocity": 27.626343866105426, "y_impact": 559.8829519991676, "apogee_y": 484.798733226189, "impact_velocity": -5.497690913213444, "t_final": 327.7157423960461} +{"lateral_surface_wind": 0.0, "apogee_x": 587.5317254837414, "apogee_time": 28.782471451734626, "max_mach_number": 1.0199401850539194, "apogee": 5506.343181861931, "x_impact": 686.5316364540121, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.29597291668803427, "out_of_rail_velocity": 25.323284778536475, "y_impact": 488.7776245777793, "apogee_y": 418.2923812342386, "impact_velocity": -5.411864875130086, "t_final": 333.08817486926347} +{"lateral_surface_wind": 0.0, "apogee_x": 574.3435227488437, "apogee_time": 27.657740448471746, "max_mach_number": 0.9499674698056779, "apogee": 5222.770164417492, "x_impact": 669.7873944157898, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.35454649267427035, "out_of_rail_velocity": 26.79571219168167, "y_impact": 547.7994529511036, "apogee_y": 469.7336805974083, "impact_velocity": -5.3642688614023, "t_final": 325.6947684429422} +{"lateral_surface_wind": 0.0, "apogee_x": 617.4055133432199, "apogee_time": 27.860776577624453, "max_mach_number": 0.9391624608249222, "apogee": 5165.427839134199, "x_impact": 715.9015528056536, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.31178728761821195, "out_of_rail_velocity": 24.067906801593168, "y_impact": 527.6424058896348, "apogee_y": 455.044172305862, "impact_velocity": -5.467639886548914, "t_final": 314.140756080289} +{"lateral_surface_wind": 0.0, "apogee_x": 463.7203499996117, "apogee_time": 27.173024195105338, "max_mach_number": 0.8879882772048172, "apogee": 4936.646625623801, "x_impact": 543.9667463996028, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.3262013366369224, "out_of_rail_velocity": 22.993879265630007, "y_impact": 423.8593982789621, "apogee_y": 361.32615557055516, "impact_velocity": -5.431124330631135, "t_final": 307.92373590017286} +{"lateral_surface_wind": 0.0, "apogee_x": 415.0946170176034, "apogee_time": 26.158939945211348, "max_mach_number": 0.8302455031820458, "apogee": 4621.646237220374, "x_impact": 489.5625692055425, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.3353263159726264, "out_of_rail_velocity": 22.35481535832323, "y_impact": 374.56318197644185, "apogee_y": 317.5838766916845, "impact_velocity": -5.3972844384921, "t_final": 291.01036623249445} +{"lateral_surface_wind": 0.0, "apogee_x": 466.8917957287704, "apogee_time": 26.612259607079338, "max_mach_number": 0.862939429135814, "apogee": 4750.199442755109, "x_impact": 552.5208903404148, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.3298597000284287, "out_of_rail_velocity": 22.740120701870772, "y_impact": 389.6042530941056, "apogee_y": 329.218827701524, "impact_velocity": -5.2978952420899, "t_final": 302.0154671206384} +{"lateral_surface_wind": 0.0, "apogee_x": 230.54329163654137, "apogee_time": 21.045450434487567, "max_mach_number": 0.5800585300053369, "apogee": 3303.1748009382363, "x_impact": 284.76193579684883, "frontal_surface_wind": 0.0, "out_of_rail_time": 0.4028036449544367, "out_of_rail_velocity": 18.60552705484144, "y_impact": 217.08948166662054, "apogee_y": 175.75266710831295, "impact_velocity": -5.2650912092579425, "t_final": 226.12896807596684} diff --git a/tests/fixtures/monte_carlo/monte_carlo_fixtures.py b/tests/fixtures/monte_carlo/monte_carlo_fixtures.py index 59f8bd2c2..c25a95188 100644 --- a/tests/fixtures/monte_carlo/monte_carlo_fixtures.py +++ b/tests/fixtures/monte_carlo/monte_carlo_fixtures.py @@ -1,3 +1,6 @@ +"""Defines the fixtures for the Monte Carlo tests. The fixtures should be +instances of the MonteCarlo class, ideally.""" + import pytest from rocketpy.simulation import MonteCarlo @@ -5,6 +8,24 @@ @pytest.fixture def monte_carlo_calisto(stochastic_environment, stochastic_calisto, stochastic_flight): + """Creates a MonteCarlo object with the stochastic environment, stochastic + calisto and stochastic flight. + + Parameters + ---------- + stochastic_environment : StochasticEnvironment + The stochastic environment object, this is a pytest fixture. + stochastic_calisto : StochasticRocket + The stochastic rocket object, this is a pytest fixture. + stochastic_flight : StochasticFlight + The stochastic flight object, this is a pytest fixture. + + Returns + ------- + MonteCarlo + The MonteCarlo object with the stochastic environment, stochastic + calisto and stochastic flight. + """ return MonteCarlo( filename="monte_carlo_test", environment=stochastic_environment, diff --git a/tests/test_monte_carlo.py b/tests/test_monte_carlo.py index debf7d6d3..8142f91dd 100644 --- a/tests/test_monte_carlo.py +++ b/tests/test_monte_carlo.py @@ -97,6 +97,48 @@ def test_monte_carlo_simulate(monte_carlo_calisto): os.remove("monte_carlo_test.inputs.txt") +def test_monte_carlo_set_inputs_log(monte_carlo_calisto): + """Tests the set_inputs_log method of the MonteCarlo class. + + Parameters + ---------- + monte_carlo_calisto : MonteCarlo + The MonteCarlo object, this is a pytest fixture. + """ + monte_carlo_calisto.input_file = "tests/fixtures/monte_carlo/example.inputs.txt" + monte_carlo_calisto.set_inputs_log() + assert len(monte_carlo_calisto.inputs_log) == 10 + assert all(isinstance(item, dict) for item in monte_carlo_calisto.inputs_log) + assert all( + "gravity" in item and "elevation" in item + for item in monte_carlo_calisto.inputs_log + ) + + +def test_monte_carlo_set_outputs_log(monte_carlo_calisto): + """Tests the set_outputs_log method of the MonteCarlo class. + + Parameters + ---------- + monte_carlo_calisto : MonteCarlo + The MonteCarlo object, this is a pytest fixture. + """ + monte_carlo_calisto.output_file = "tests/fixtures/monte_carlo/example.outputs.txt" + monte_carlo_calisto.set_outputs_log() + assert len(monte_carlo_calisto.outputs_log) == 10 + assert all(isinstance(item, dict) for item in monte_carlo_calisto.outputs_log) + assert all( + "apogee" in item and "impact_velocity" in item + for item in monte_carlo_calisto.outputs_log + ) + + +# def test_monte_carlo_set_errors_log(monte_carlo_calisto): +# monte_carlo_calisto.error_file = "tests/fixtures/monte_carlo/example.errors.txt" +# monte_carlo_calisto.set_errors_log() +# assert + + def test_monte_carlo_prints(monte_carlo_calisto): """Tests the prints methods of the MonteCarlo class.""" monte_carlo_calisto.info()