summaryrefslogtreecommitdiff
path: root/evaluator/evaluator.py
diff options
context:
space:
mode:
authorblendoit <blendoit@gmail.com>2019-10-07 21:14:10 -0700
committerblendoit <blendoit@gmail.com>2019-10-07 21:14:10 -0700
commit1e8f2782753d70da35c2122f6d4441f94ee94ed6 (patch)
treeeac0cf710854250b4a4b5d129908eb18c774032a /evaluator/evaluator.py
parent76f3f92a300121f30998d60bd12b10f8c6fd0e2a (diff)
Subcomponent tree and Evaluator analysis
Made very good progress on component tree representation, and Evaluator analysis method.
Diffstat (limited to 'evaluator/evaluator.py')
-rw-r--r--evaluator/evaluator.py168
1 files changed, 102 insertions, 66 deletions
diff --git a/evaluator/evaluator.py b/evaluator/evaluator.py
index 680f2d7..1920c63 100644
--- a/evaluator/evaluator.py
+++ b/evaluator/evaluator.py
@@ -10,6 +10,11 @@ import os.path
import numpy as np
from math import sqrt
import matplotlib.pyplot as plt
+import logging
+
+logging.basicConfig(filename='log_eval.txt',
+ level=logging.DEBUG,
+ format='%(asctime)s - %(levelname)s - %(message)s')
class Evaluator:
@@ -22,35 +27,37 @@ class Evaluator:
self.I_ = {'x': 0, 'z': 0, 'xz': 0}
- def get_lift_rectangular(aircraft, lift):
- L_prime = [
- lift / (aircraft.semi_span * 2) for x in range(aircraft.semi_span)
- ]
- return L_prime
-
- def get_lift_elliptical(aircraft, L_0):
- L_prime = [
- L_0 / (aircraft.semi_span * 2) * sqrt(1 -
- (y / aircraft.semi_span)**2)
- for y in range(aircraft.semi_span)
- ]
- return L_prime
-
- def get_lift_total(aircraft):
- F_z = [(aircraft.lift_rectangular[_] + aircraft.lift_elliptical[_]) / 2
- for _ in range(len(aircraft.lift_rectangular))]
+ def get_lift_rectangular(aircraft, lift=50):
+ # L_prime = [
+ # lift / (aircraft.wing.semi_span * 2)
+ # for x in range(aircraft.wing.semi_span)
+ # ]
+ return lift
+
+ def get_lift_elliptical(aircraft, L_0=3.2):
+ # L_prime = [
+ # L_0 / (aircraft.wing.semi_span * 2) *
+ # sqrt(1 - (y / aircraft.wing.semi_span)**2)
+ # for y in range(aircraft.wing.semi_span)
+ # ]
+ return L_0
+
+ def get_lift_total(self, aircraft):
+ F_z = 100
+ # F_z = [(self.get_lift_rectangular() + self.get_lift_elliptical() / 2
+ # for _ in range(len(aircraft.lift_rectangular))]
return F_z
def get_mass_distribution(self, total_mass):
F_z = [total_mass / self.semi_span for x in range(0, self.semi_span)]
return F_z
- def get_drag(self, drag):
+ def get_drag(aircraft, drag):
# Transform semi-span integer into list
- semi_span = [x for x in range(0, self.semi_span)]
+ semi_span = [x for x in range(0, aircraft.wing.semi_span)]
# Drag increases after 80% of the semi_span
- cutoff = round(0.8 * self.semi_span)
+ cutoff = round(0.8 * aircraft.wing.span)
# Drag increases by 25% after 80% of the semi_span
F_x = [drag for x in semi_span[0:cutoff]]
@@ -140,6 +147,18 @@ class Evaluator:
area * zDist[_] * (I_z * V_z - I_xz * V_x) / denom)
return z
+ def analysis(self):
+ """Perform all analysis calculations and store in self.results."""
+ for aircraft in self.aircrafts:
+ results = {"Lift": 400, "Drag": 20, "Centroid": [0.2, 4.5]}
+ self.results.append(results)
+ # results = {
+ # "Lift": self.get_lift_total(aircraft),
+ # "Drag": self.get_drag(aircraft.wing),
+ # "Centroid": self.get_centroid(aircraft.wing)
+ # }
+ return results
+
# def analysis(self, V_x, V_z):
# """Perform all analysis calculations and store in class instance."""
@@ -161,56 +180,73 @@ class Evaluator:
# print("yayyyyy")
# return None
- def update_tree(self):
- """Refresh evaluator aircraft tree."""
- # print(self.name, "tree is:")
- # print(self.tree)
-
- # self.results.append(self.analysis(aircraft))
-
- def analysis(self, aircraft):
- """Perform all analysis calculations and store in class instance."""
-
- results = {
- "Lift": self.get_lift_total,
- "Drag": self.get_drag,
- "Centroid": self.get_centroid
- }
-
- # print(f"Analysis results for {aircraft.name}:\n", results)
- return (results)
- # self.results = self.get_lift_total(aircraft)
-
- # self.drag = self.get_drag(10)
- # self.lift_rectangular = self.get_lift_rectangular(13.7)
- # self.lift_elliptical = self.get_lift_elliptical(15)
- # self.lift_total = self.get_lift_total()
- # self.mass_dist = self.get_mass_distribution(self.mass_total)
- # self.centroid = self.get_centroid()
- # self.I_['x'] = self.get_inertia_terms()[0]
- # self.I_['z'] = self.get_inertia_terms()[1]
- # self.I_['xz'] = self.get_inertia_terms()[2]
- # spar_dx = self.get_dx(self.spar)
- # spar_dz = self.get_dz(self.spar)
- # self.spar.dP_x = self.get_dP(spar_dx, spar_dz, V_x, 0,
- # self.spar.cap_area)
- # self.spar.dP_z = self.get_dP(spar_dx, spar_dz, 0, V_z,
- # self.spar.cap_area)
- return None
-
- def info_print(self, round):
- """Print all the component's evaluated data to the terminal."""
- name = f' {print(self)} DATA FOR {str(self).upper()} '
+ # print(f"Analysis results for {aircraft.name}:\n", results)
+ # self.results = self.get_lift_total(aircraft)
+
+ # self.drag = self.get_drag(10)
+ # self.lift_rectangular = self.get_lift_rectangular(13.7)
+ # self.lift_elliptical = self.get_lift_elliptical(15)
+ # self.lift_total = self.get_lift_total()
+ # self.mass_dist = self.get_mass_distribution(self.mass_total)
+ # self.centroid = self.get_centroid()
+ # self.I_['x'] = self.get_inertia_terms()[0]
+ # self.I_['z'] = self.get_inertia_terms()[1]
+ # self.I_['xz'] = self.get_inertia_terms()[2]
+ # spar_dx = self.get_dx(self.spar)
+ # spar_dz = self.get_dz(self.spar)
+ # self.spar.dP_x = self.get_dP(spar_dx, spar_dz, V_x, 0,
+ # self.spar.cap_area)
+ # self.spar.dP_z = self.get_dP(spar_dx, spar_dz, 0, V_z,
+ # self.spar.cap_area)
+ # return None
+
+ def tree_print(self):
+ """Print a list of subcomponents."""
+ name = f" COMPONENT TREE FOR {[_.name for _ in self.aircrafts]} "
num_of_dashes = len(name)
print(num_of_dashes * '-')
print(name)
- for k, v in self.__dict__.items():
- if type(v) != list:
- print('{}:\n'.format(k), v)
+ for aircraft in self.aircrafts:
+ print(".")
+ print(f"`-- {aircraft}")
+ print(f" |--{aircraft.wing}")
+ for spar in aircraft.wing.spars[:-1]:
+ print(f" | |-- {spar}")
+ print(f" | `-- {aircraft.wing.spars[-1]}")
+ print(f" |-- {aircraft.fuselage}")
+ print(f" `-- {aircraft.propulsion}")
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 tree_save(self,
+ save_path='/home/blendux/Projects/Aircraft_Studio/save'):
+ """Save the evaluator's tree to a file."""
+ file_name = f"{self.name}_tree.txt"
+ full_path = os.path.join(save_path, file_name)
+ with open(full_path, 'w') as f:
+ try:
+ for aircraft in self.aircrafts:
+ f.write(".\n")
+ f.write(f"`-- {aircraft}\n")
+ f.write(f" |--{aircraft.wing}\n")
+ for spar in aircraft.wing.spars[:-1]:
+ f.write(f" | |-- {spar}\n")
+ f.write(f" | `-- {aircraft.wing.spars[-1]}\n")
+ f.write(f" |-- {aircraft.fuselage}\n")
+ f.write(f" `-- {aircraft.propulsion}\n")
+ logging.debug(f'Successfully wrote to file {full_path}')
+
+ except IOError:
+ print(f'Unable to write {file_name} to specified directory.\n',
+ 'Was the full path passed to the function?')
+ return None
+ try:
+ with open(full_path, 'w') as sys.stdout:
+ print('Successfully wrote to file {}'.format(full_path))
+ except IOError:
+ print(
+ 'Unable to write {} to specified directory.\n'.format(
+ file_name), 'Was the full path passed to the function?')
return None
def info_save(self, save_path, number):
Copyright 2019--2024 Marius PETER