Coverage for /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/hypervehicle/hangar/falcon9.py: 93%

57 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-29 02:51 +0000

1import numpy as np 

2from hypervehicle import Vehicle 

3from hypervehicle.generator import Generator 

4from hypervehicle.components import RevolvedComponent 

5from hypervehicle.geometry import Vector3, Line, Polyline, Arc 

6 

7 

8class ParametricFalcon9(Generator): 

9 """Parametric generator for mock-up of the SpaceX Falcon 9. 

10 

11 References 

12 ---------- 

13 https://www.spacex.com/vehicles/falcon-9/ 

14 """ 

15 

16 def __init__(self, **kwargs) -> None: 

17 # Vehicle parameters 

18 self.D = 3.75 

19 self.L_b = 60 

20 self.h = 5 / 2 

21 self.r_n = 0.75 

22 self.r_o = 7 

23 self.f_L = 6 

24 

25 # Complete instantiation 

26 super().__init__(**kwargs) 

27 

28 def create_instance(self) -> Vehicle: 

29 # Initialise 

30 falcon9 = Vehicle() 

31 falcon9.configure( 

32 name="SpaceX Falcon 9", 

33 verbosity=1, 

34 ) 

35 

36 # Dependencies 

37 x_o = -np.sqrt((self.r_o - self.r_n) ** 2 - (self.r_o - self.h) ** 2) 

38 y_t = self.r_n * (self.r_o - self.h) / (self.r_o - self.r_n) 

39 x_t = x_o - np.sqrt(self.r_n**2 - y_t**2) 

40 x_a = x_o - self.r_n 

41 

42 # Ogive arc 

43 a_o = Vector3(-x_t, y_t) 

44 b_o = Vector3(0, self.h) 

45 c_o = Vector3(0, -self.r_o + self.h) 

46 ogive_arc = Arc(a_o, b_o, c_o) 

47 

48 # Nose arc 

49 a_n = Vector3(-x_a, 0) 

50 b_n = a_o 

51 c_n = Vector3(-x_o, 0) 

52 nose_arc = Arc(a_n, b_n, c_n) 

53 

54 # Fairing 

55 f0 = b_o 

56 f1 = f0 - Vector3(self.f_L, 0) 

57 fairing_line = Line(f0, f1) 

58 

59 # Body radius 

60 r_b = self.D / 2 

61 

62 # Fairing to body 

63 fb0 = f1 

64 fb1 = Vector3(f1.x - 0.1 * self.f_L, r_b) 

65 fb2 = Vector3(f1.x - 0.3 * self.f_L, 0) 

66 fb_line = Polyline([Line(fb0, fb1), Line(fb1, fb2)]) 

67 

68 # Fairing component 

69 fairing_line = Polyline([nose_arc, ogive_arc, fairing_line, fb_line]) 

70 fairing = RevolvedComponent(revolve_line=fairing_line, stl_resolution=100) 

71 falcon9.add_component(fairing) 

72 

73 # Body 

74 b00 = Vector3(f1.x, 0) 

75 b0 = Vector3(f1.x, r_b) 

76 b1 = b0 - Vector3(self.L_b, 0) 

77 body_cap_line = Line(b00, b0) 

78 body_line = Line(b0, b1) 

79 

80 # Base 

81 bb0 = b1 

82 bb1 = Vector3(bb0.x, 0) 

83 base_line = Line(bb0, bb1) 

84 

85 # Join 

86 line = Polyline([body_cap_line, body_line, base_line]) 

87 

88 fuselage = RevolvedComponent(revolve_line=line, stl_resolution=50) 

89 falcon9.add_component(fuselage) 

90 

91 return falcon9 

92 

93 

94if __name__ == "__main__": 

95 # To create the nominal geometry 

96 parametric_generator = ParametricFalcon9() 

97 falcon9 = parametric_generator.create_instance() 

98 falcon9.generate() 

99 falcon9.to_stl("falcon9")