Consolidated print_coord and save_coord methods into 'Coordinates'

Commit
a90f8e3e657311c7961d137892523a301c2dd219
Author
Marius Peter <blendoit@gmail.com>
Author date
Committer
Marius Peter <blendoit@gmail.com>
Committer date
Changed files
creator.py
index f401791a..9a0eaddc 100644..100644
@@ -38,34 +38,55 @@
38 38 def __init__(self, chord, semi_span):
39 39 # Global dimensions
40 40 self.chord = chord
41 Added: if chord < 10:
42 Added: self.chord = 10
41 43 self.semi_span = semi_span
44 Added: # Component material
45 Added: self.material = str()
42 46 # Upper coordinates
43 47 self.x_u = []
44 48 self.y_u = []
45 49 # Lower coordinates
46 50 self.x_l = []
47 51 self.y_l = []
48 Removed: # Upper coordinates
49 Removed: self.x_u = []
50 Removed: self.y_u = []
51 Removed: # Lower coordinates
52 Removed: self.x_l = []
53 Removed: self.y_l = []
54 52 # Coordinates x_u, y_u, x_l, y_l packed in single list
55 53 self.coordinates = []
56 54 global parent
57 55 parent = self
58 56
59 Removed: def create(self, chord, semi_span):
60 Removed: self.chord = chord
61 Removed: self.semi_span = semi_span
57 Added: def print_coord(self, round):
58 Added: """
59 Added: Print all the object's coordinates to the terminal.
62 60
63 Removed: chord = self.chord
64 Removed: semi_span = self.semi_span
61 Added: This function's output is piped to the 'save_coord' function below.
62 Added: """
63 Added: print('Chord length', self.chord, sep='\n')
64 Added: print('Semi-span')
65 Added: print('x_u the upper x-coordinates')
66 Added: print(np.around(self.x_u, round))
67 Added: print('y_u the upper y-coordinates')
68 Added: print(np.around(self.y_u, round))
69 Added: print('x_l the lower x-coordinates')
70 Added: print(np.around(self.x_l, round))
71 Added: print('y_l the lower y-coordinates')
72 Added: print(np.around(self.y_l, round))
73 Added: return None
65 74
75 Added: def save_coord(self, save_dir_path):
76 Added: """
77 Added: Save all the object's coordinates (must be full path).
78 Added: """
79 Added: object_name = str(self.__name__)
80 Added: file_name = 'airfoil_%s' % airfoil_number
81 Added: full_path = os.path.join(save_dir_path, file_name + '.txt')
82 Added: file = open(full_path, 'w')
83 Added: sys.stdout = file
84 Added: self.print_coord(4)
85 Added: return None
66 86
87 Added:
67 88 class Airfoil(Coordinates):
68 Removed: """This class enables the creation of a NACA airfoil."""
89 Added: """This class enables the creation of a single NACA airfoil."""
69 90
70 91 def __init__(self):
71 92 global parent
@@ -74,8 +95,8 @@
74 95 # NACA number
75 96 self.naca_num = int()
76 97 # Mean camber line
77 Removed: self.x_c = []
78 Removed: self.y_c = []
98 Added: self.x_c = [] # Contains only integers from 0 to self.chord
99 Added: self.y_c = [] # Contains floats
79 100 # Thickness
80 101 self.y_t = []
81 102 # dy_c / d_x
@@ -103,9 +124,6 @@
103 124 m = int(str(naca_num)[0]) / 100
104 125 p = int(str(naca_num)[1]) / 10
105 126 t = int(str(naca_num)[2:]) / 100
106 Removed: # Chord length. Should be higher than 10.
107 Removed: if self.chord < 10:
108 Removed: self.chord = 10
109 127 # x-coordinate of maximum camber
110 128 p_c = p * self.chord
111 129
@@ -196,57 +214,17 @@
196 214 self.coordinates.append(self.x_u)
197 215 self.coordinates.append(self.y_u)
198 216 self.coordinates.append(self.x_l)
199 Removed: self.coordinates.append(self.x_l)
217 Added: self.coordinates.append(self.y_l)
200 218
201 219 return None
202 220
203 Removed: def print_geometry(self, round):
204 Removed: """
205 Removed: Print all the declared geometry to the terminal.
206 Removed: """
207 Removed: # Print all our basic geometry, useful for debugging
208 Removed: print('Chord length')
209 Removed: print(self.chord)
210 Removed: print('x_c the x-coordinates of the mean camber line')
211 Removed: print(np.around(self.x_c, round))
212 Removed: print('y_c the y-coordinates of the mean camber line')
213 Removed: print(np.around(self.y_c, round))
214 Removed: print('y_t the y-coordinates of the airfoil thickness')
215 Removed: print(np.around(self.y_t, round))
216 Removed: print('dy_c the derivative of y_c with respect to dx')
217 Removed: print(np.around(self.dy_c, round))
218 Removed: print('theta is like an angle, idk')
219 Removed: print(np.around(self.theta, round))
220 Removed: print('x_u the x-coordinates of the upper airfoil surface')
221 Removed: print(np.around(self.x_u, round))
222 Removed: print('y_u the y-coordinates of the upper airfoil surface')
223 Removed: print(np.around(self.y_u, round))
224 Removed: print('x_l the x-coordinates of the lower airfoil surface')
225 Removed: print(np.around(self.x_l, round))
226 Removed: print('y_l the y-coordinates of lower airfoil surface')
227 Removed: print(np.around(self.y_l, round))
228 Removed: return None
229 221
230 Removed: def save_values(self, airfoil_number, save_dir_path):
231 Removed: """
232 Removed: Save all the declared geometry to save_dir_path (must be full path).
233 Removed: """
234 Removed: file_name = 'airfoil_%s' % airfoil_number
235 Removed: full_path = os.path.join(save_dir_path, file_name + '.txt')
236 Removed: file = open(full_path, 'w')
237 Removed: sys.stdout = file
238 Removed: self.print_geometry(4)
239 Removed: return None
240 Removed:
241 Removed:
242 222 class Spar(Coordinates):
243 223 """Contains a single spar's location and material."""
244 224 global parent
245 225
246 226 def __init__(self):
247 227 super().__init__(parent.chord, parent.semi_span)
248 Removed: # Spar material
249 Removed: self.spar_material = []
250 228
251 229 def add_spar(self, coordinates, material, spar_x):
252 230 """
@@ -358,7 +336,7 @@
358 336 plt.plot(x, y, '.-', color='b', label='spar')
359 337 plt.legend()
360 338 except:
361 Removed: print('Did plot spars. Were they added?')
339 Added: print('Did not plot spars. Were they added?')
362 340 # Plot stringers
363 341 # if len(self.spar_x) != 0:
364 342 # for _ in range(0, len(self.stringer_x)):
main.py
index dd6b179a..41070546 100644..100644
@@ -19,7 +19,7 @@
19 19 import time
20 20 start_time = time.time()
21 21
22 Removed: CHORD_LENGTH = 100
22 Added: CHORD_LENGTH = 40
23 23 SEMI_SPAN = 200
24 24
25 25 POP_SIZE = 1
@@ -32,11 +32,12 @@
32 32 for airfoil_number in range(1, POP_SIZE + 1):
33 33 foo = creator.Airfoil()
34 34 foo.naca(2412)
35 Removed: # foo.print_geometry(4)
35 Added: # foo.print_coord(4)
36 36 foo.spar = creator.Spar()
37 37 foo.spar.add_spar(foo.coordinates, 'aluminium', 0.15)
38 Added: foo.spar.print_coord(4)
38 39 creator.plot(foo, foo.spar)
39 Removed: # foo.save_values(airfoil_number, SAVE_PATH)
40 Added: foo.save_values(SAVE_PATH)
40 41
41 42 print("--- %s seconds ---" % (time.time() - start_time))
42 43