From 21678d4029eab07ed831b7a55289dc1b750bb3f9 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 30 Jun 2019 15:52:03 -0700 Subject: square plots + shorter info_print() + enforce minimum chord length --- creator.py | 34 +++++++++++++++++++--------------- evaluator.py | 49 +++++++++++++++---------------------------------- gui.py | 6 +++--- main.py | 12 ++++++------ 4 files changed, 43 insertions(+), 58 deletions(-) diff --git a/creator.py b/creator.py index 8277b10..22449bd 100644 --- a/creator.py +++ b/creator.py @@ -64,7 +64,11 @@ class Airfoil: @classmethod def from_dimensions(cls, chord, semi_span): - cls.chord = chord + if chord > 20: + cls.chord = chord + else: + cls.chord = 20 + print('Chord too small, using minimum value of 20.') cls.semi_span = semi_span return Airfoil() @@ -163,24 +167,20 @@ class Airfoil: self.mass = mass def info_print(self, round): - """ - Print all the component's coordinates to the terminal. - - This function's output is piped to the 'save_coord' function below. - """ + # TODO: implement this info getting method! + """Print all the component's coordinates to the terminal.""" - name = ' CREATOR DATA ' + name = ' CREATOR DATA FOR {} '.format(str(self).upper()) num_of_dashes = len(name) - print(num_of_dashes * '-') print(name) - print('Component:', str(self)) - print('Chord length:', self.chord) - print('Semi-span:', self.semi_span) - print('Mass:', self.mass) + for k, v in self.__dict__.items(): + if type(v) != list: + print('{}:\n'.format(k), v) print(num_of_dashes * '-') - print('x-coordinates:\n', np.around(self.x, round)) - print('z-coordinates:\n', np.around(self.z, round)) + for k, v in self.__dict__.items(): + if type(v) == list: + print('{}:\n'.format(k), np.around(v, round)) return None def info_save(self, save_path, number): @@ -398,9 +398,13 @@ def plot_geom(airfoil, view: False): print('No stringers to plot.') # Graph formatting + plot_bound = max(airfoil.x) ax.set(title='NACA ' + str(airfoil.naca_num) + ' airfoil', xlabel='X axis', - ylabel='Z axis', ylim=[-50, 50]) + xlim=[- 0.10 * plot_bound, 1.10 * plot_bound], + ylabel='Z axis', + ylim=[- (1.10 * plot_bound / 2), (1.10 * plot_bound / 2)]) + plt.grid(axis='both', linestyle=':', linewidth=1) plt.gca().set_aspect('equal', adjustable='box') plt.gca().legend(bbox_to_anchor=(1, 1), diff --git a/evaluator.py b/evaluator.py index cab2e9b..d41716c 100644 --- a/evaluator.py +++ b/evaluator.py @@ -53,46 +53,27 @@ class Evaluator: # Inertia terms: self.I_ = {'x': 0, 'z': 0, 'xz': 0} - def info_print(self, round): - """ - Print all the component's evaluated data to the terminal. + def __str__(self): + return type(self).__name__ - This function's output is piped to the 'save_data' function below. - """ - name = ' EVALUATOR DATA ' + def info_print(self, round): + """Print all the component's evaluated data to the terminal.""" + name = ' EVALUATOR DATA FOR {} '.format(str(self).upper()) num_of_dashes = len(name) - - try: - print(num_of_dashes * '-') - print(name) - print('Evaluating:', self.airfoil) - print('Chord length:', self.chord) - print('Semi-span:', self.semi_span) - print('Total airfoil mass:', self.mass_total) - print('Centroid location:\n', np.around(self.centroid, 3)) - print('Inertia terms:') - print('I_x:\n', np.around(self.I_['x'], 3)) - print('I_z:\n', np.around(self.I_['z'], 3)) - print('I_xz:\n', np.around(self.I_['xz'], 3)) - print('Spar dP_x:\n', self.spar.dP_x) - print('Spar dP_z:\n', self.spar.dP_z) - print(num_of_dashes * '-') - print('Rectangular lift along semi-span:\n', - np.around(self.lift_rectangular, round)) - print('Elliptical lift along semi-span:\n', - np.around(self.lift_elliptical, round)) - print('Combined lift along semi-span:\n', - np.around(self.lift_total, round)) - print('Distribution of mass along semi-span:\n', - np.around(self.mass_dist, round)) - print('Drag along semi-span:\n', np.around(self.drag, round)) - except AttributeError: - print(num_of_dashes * '-') - print('Cannot print full evaluation. Was the airfoil analyzed?') + print(num_of_dashes * '-') + print(name) + for k, v in self.__dict__.items(): + if type(v) != list: + print('{}:\n'.format(k), v) + print(num_of_dashes * '-') + for k, v in self.__dict__.items(): + if type(v) == list: + print('{}:\n'.format(k), np.around(v, round)) return None def info_save(self, save_path, number): """Save all the object's coordinates (must be full path).""" + file_name = 'airfoil_{}_eval.txt'.format(number) full_path = os.path.join(save_path, file_name) try: diff --git a/gui.py b/gui.py index 05afc38..51e6aee 100644 --- a/gui.py +++ b/gui.py @@ -41,9 +41,9 @@ def main(): frame_2 = ttk.Frame(root) fig, ax = creator.plot_geom(af, False) plot = FigureCanvasTkAgg(fig, frame_2) - plot.draw() + # plot.draw() toolbar = NavigationToolbar2Tk(plot, frame_2) - toolbar.update() + # toolbar.update() # Layout # User input @@ -53,7 +53,7 @@ def main(): e_chord.grid(row=1, column=1, padx=4) frame_1.pack(side=tk.LEFT) # Graph window - plot.get_tk_widget().pack(fill=tk.BOTH) + plot.get_tk_widget().pack(expand=1, fill=tk.BOTH) toolbar.pack() frame_2.pack(side=tk.LEFT) diff --git a/main.py b/main.py index 624d31e..c0d90ae 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ start_time = time.time() # Airfoil dimensions NACA_NUM = 2412 -CHORD_LENGTH = 68 # inches +CHORD_LENGTH = 2 # inches SEMI_SPAN = 150 # inches # Thicknesses @@ -67,7 +67,7 @@ def main(): af.add_naca(NACA_NUM) af.add_mass(AIRFOIL_MASS) # af.info_print(2) - # af.info_save(SAVE_PATH, _) + af.info_save(SAVE_PATH, _) # Create spar instance af.spar = creator.Spar() @@ -79,7 +79,7 @@ def main(): af.spar.add_mass(SPAR_MASS) af.spar.add_webs(SPAR_THICKNESS) # af.spar.info_print(2) - # af.spar.info_save(SAVE_PATH, _) + af.spar.info_save(SAVE_PATH, _) # Create stringer instance af.stringer = creator.Stringer() @@ -93,17 +93,17 @@ def main(): af.stringer.add_mass(STRINGER_MASS) af.stringer.add_webs(SKIN_THICKNESS) # af.stringer.info_print(2) - # af.stringer.info_save(SAVE_PATH, _) + af.stringer.info_save(SAVE_PATH, _) # Plot components with matplotlib - creator.plot_geom(af, True) + # creator.plot_geom(af, True) # Evaluator object contains airfoil analysis results. eval = evaluator.Evaluator(af) # The analysis is performed in the evaluator.py module. eval.analysis(1, 1) # eval.info_print(2) - # eval.info_save(SAVE_PATH, _) + eval.info_save(SAVE_PATH, _) # evaluator.plot_geom(eval) # evaluator.plot_lift(eval) -- cgit v1.2.3