From 5ab73817371c1b4fedbd98838d3cf28984d73004 Mon Sep 17 00:00:00 2001 From: blendoit Date: Mon, 21 Oct 2019 21:25:52 -0700 Subject: Correct implem. of evaluator.analyze_all & Evaluator declassification --- evaluator/__init__.py | 2 +- evaluator/drag.py | 6 +++-- evaluator/evaluator.py | 71 +++++++++++++++++++++----------------------------- evaluator/inertia.py | 36 +++++++++++++------------ evaluator/lift.py | 4 +-- evaluator/mass.py | 2 +- 6 files changed, 57 insertions(+), 64 deletions(-) (limited to 'evaluator') diff --git a/evaluator/__init__.py b/evaluator/__init__.py index 6eedafc..a58168b 100644 --- a/evaluator/__init__.py +++ b/evaluator/__init__.py @@ -1 +1 @@ -from .evaluator import Evaluator +from .evaluator import * diff --git a/evaluator/drag.py b/evaluator/drag.py index df79e6a..73a26fc 100644 --- a/evaluator/drag.py +++ b/evaluator/drag.py @@ -1,3 +1,5 @@ +import random + def get_drag(aircraft, drag): # Transform semi-span integer into list semi_span = [x for x in range(0, aircraft.wing.semi_span)] @@ -11,6 +13,6 @@ def get_drag(aircraft, drag): return F_x -def get_drag_total(self, aircraft): +def get_drag_total(aircraft): """Get total drag force acting on the aircraft.""" - return 500 + return random.random() * 100 diff --git a/evaluator/evaluator.py b/evaluator/evaluator.py index b2b6e18..18bb692 100644 --- a/evaluator/evaluator.py +++ b/evaluator/evaluator.py @@ -1,48 +1,37 @@ """ -The evaluator.py module contains a single Evaluator class, -which knows all the attributes of a specified Aircraft instance, -and contains functions to analyse the airfoil's geometrical -& structural properties. +The evaluator.py module contains functions +that return calculated data for an aircraft. +Plotting aircraft components is also possible. """ -import sys import os.path -import matplotlib.pyplot as plt import concurrent.futures -import logging +import matplotlib.pyplot as plt from . import drag, inertia, lift, mass -import generator - -logging.basicConfig(filename='log_eval.txt', - level=logging.DEBUG, - format='%(asctime)s - %(levelname)s - %(message)s') - - -class Evaluator: - """Performs structural evaluations on aircrafts. - Individual aircrafts must claim an Evaluator object as parent.""" - def __init__(self, name): - self.name = name - self.aircrafts = [] - self.results = [] - self.I_ = {'x': 0, 'z': 0, 'xz': 0} - def analyze(self, aircraft): - """Analyze a single aircraft.""" - aircraft.results.update({'Lift': lift.get_lift_total(aircraft)}) - aircraft.results.update({'Drag': drag.get_drag_total(aircraft)}) - aircraft.results.update({'Mass': mass.get_mass_total(aircraft)}) - aircraft.results.update({'Centroid': inertia.get_centroid(aircraft)}) - return aircraft.results - - def analyze_all(self): - """Perform all analysis calculations on a all aircraft in evaluator.""" - with concurrent.futures.ProcessPoolExecutor() as executor: - executor.map(self.analyze, self.aircrafts) - - return None +def analyze(aircraft): + """Analyze a single aircraft.""" + results = { + 'Lift': lift.get_lift_total(aircraft), + 'Drag': drag.get_drag_total(aircraft), + 'Mass': mass.get_mass_total(aircraft), + 'Centroid': inertia.get_centroid(aircraft) + } + aircraft.results = results + return aircraft.name, results + + +def analyze_all(population): + """Analyze all aircraft in a given population.""" + # for aircraft in population.aircrafts: + # print(analyze(aircraft)) + with concurrent.futures.ProcessPoolExecutor() as executor: + results = executor.map(analyze, population.aircrafts) + for result in results: + print(result) + return None # def analysis(self, V_x, V_z): # """Perform all analysis calculations and store in class instance.""" @@ -85,13 +74,13 @@ class Evaluator: # self.spar.cap_area) # return None - def tree_print(self, *aircrafts): + def tree_print(self, population): """Print the list of subcomponents.""" - name = f" TREE FOR {[i.name for i in aircrafts]} IN {self.name} " + name = f" TREE FOR {[i.name for i in population.aircraft]} IN {self.name} " num_of_dashes = len(name) print(num_of_dashes * '-') print(name) - for aircraft in aircrafts: + for aircraft in population: print(".") print(f"`-- {aircraft}") print(f" |--{aircraft.wing}") @@ -105,10 +94,10 @@ class Evaluator: return None def tree_save(self, - *aircrafts, + population, save_path='/home/blendux/Projects/Aircraft_Studio/save'): """Save the evaluator's tree to a file.""" - for aircraft in aircrafts: + for aircraft in population.aircraft: file_name = f"{aircraft.name}_tree.txt" full_path = os.path.join(save_path, file_name) with open(full_path, 'w') as f: diff --git a/evaluator/inertia.py b/evaluator/inertia.py index fea728c..f047766 100644 --- a/evaluator/inertia.py +++ b/evaluator/inertia.py @@ -1,27 +1,29 @@ def get_centroid(aircraft): """Return the coordinates of the centroid.""" - stringer_area = aircraft.stringer.area - cap_area = aircraft.spar.cap_area + # stringer_area = aircraft.wing.stringers.area + # cap_area = aircraft.wing.spars.cap_area - caps_x = [value for spar in aircraft.spar.x for value in spar] - caps_z = [value for spar in aircraft.spar.z for value in spar] - stringers_x = aircraft.stringer.x - stringers_z = aircraft.stringer.z + # TODO: Fix this + # caps_x = [value for spar in aircraft.wing.spars.x for value in spar] + # caps_z = [value for spar in aircraft.wing.spars.z for value in spar] + # stringers_x = aircraft.wing.stringers.x + # stringers_z = aircraft.wing.stringers.z - denominator = float( - len(caps_x) * cap_area + len(stringers_x) * stringer_area) + # denominator = float( + # len(caps_x) * cap_area + len(stringers_x) * stringer_area) - centroid_x = float( - sum([x * cap_area - for x in caps_x]) + sum([x * stringer_area for x in stringers_x])) - centroid_x = centroid_x / denominator + # centroid_x = float( + # sum([x * cap_area + # for x in caps_x]) + sum([x * stringer_area for x in stringers_x])) + # centroid_x = centroid_x / denominator - centroid_z = float( - sum([z * cap_area - for z in caps_z]) + sum([z * stringer_area for z in stringers_z])) - centroid_z = centroid_z / denominator + # centroid_z = float( + # sum([z * cap_area + # for z in caps_z]) + sum([z * stringer_area for z in stringers_z])) + # centroid_z = centroid_z / denominator - return (centroid_x, centroid_z) + # return (centroid_x, centroid_z) + return (200, 420) def get_inertia_terms(self): diff --git a/evaluator/lift.py b/evaluator/lift.py index 6b4363e..516d649 100644 --- a/evaluator/lift.py +++ b/evaluator/lift.py @@ -19,7 +19,7 @@ def _get_lift_elliptical(aircraft, L_0=3.2): return L_prime -def get_lift_total(self, aircraft): +def get_lift_total(aircraft): """Combination of rectangular and elliptical lift.""" # F_z = self._get_lift_rectangular(aircraft) + self._get_lift_elliptical( # aircraft) @@ -27,4 +27,4 @@ def get_lift_total(self, aircraft): # aircraft) + self._get_lift_elliptical(aircraft) / 2 # F_z = [i + j for i, j in self._get_lift_rectangular] # return F_z - return 420 + return 400 diff --git a/evaluator/mass.py b/evaluator/mass.py index 514c59b..7edb926 100644 --- a/evaluator/mass.py +++ b/evaluator/mass.py @@ -3,6 +3,6 @@ def get_mass_distribution(self, total_mass): return F_z -def get_mass_total(self, aircraft): +def get_mass_total(aircraft): """Get the total aircraft mass.""" return 2000 -- cgit v1.2.3