summaryrefslogtreecommitdiff
path: root/creator
diff options
context:
space:
mode:
authorblendoit <blendoit@gmail.com>2019-10-01 23:29:24 -0700
committerblendoit <blendoit@gmail.com>2019-10-01 23:29:24 -0700
commit93cc49e414766f2980e06cbe2b9b8be10ec4472d (patch)
tree93c2c9e44cab44f37f6dee6f7fdafbf53372464d /creator
parentfa38b61ff2bd193fad1f320d2d59b8cb34ecd288 (diff)
Proper package structure
Diffstat (limited to 'creator')
-rw-r--r--creator/__init__.py1
-rw-r--r--creator/base.py59
-rw-r--r--creator/wing.py59
3 files changed, 65 insertions, 54 deletions
diff --git a/creator/__init__.py b/creator/__init__.py
new file mode 100644
index 0000000..6fc3a2c
--- /dev/null
+++ b/creator/__init__.py
@@ -0,0 +1 @@
+__all__ = ['base', 'fuselage', 'propulsion', 'wing']
diff --git a/creator/base.py b/creator/base.py
new file mode 100644
index 0000000..91d4c70
--- /dev/null
+++ b/creator/base.py
@@ -0,0 +1,59 @@
+"""The base.py module contains parent classes for components."""
+import numpy as np
+import sys
+import os.path
+import logging
+
+logging.basicConfig(filename='log.txt',
+ level=logging.DEBUG,
+ format='%(asctime)s - %(levelname)s - %(message)s')
+
+
+class Component:
+ """Basic component providing coordinates and tools."""
+
+ # TODO: define defaults in separate module
+ def __init__(self):
+ self.x = np.array([])
+ self.z = np.array([])
+ self.material = str()
+ self.mass = float()
+
+ def set_material(self, material):
+ """Set the component bulk material."""
+ self.material = material
+
+ def info_print(self, round):
+ """Print all the component's coordinates to the terminal."""
+ name = f' CREATOR DATA FOR {str(self).upper()} '
+ 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)
+ 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 = f'{str(self).lower()}_{number}.txt'
+ full_path = os.path.join(save_path, file_name)
+ try:
+ with open(full_path, 'w') as sys.stdout:
+ self.info_print(6)
+ # This line required to reset behavior of sys.stdout
+ sys.stdout = sys.__stdout__
+ 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
+
+
+class Aircraft:
+ """This class tracks all sub-components and is fed to the evaluator."""
+ pass
diff --git a/creator/wing.py b/creator/wing.py
index 4988cb5..be8e18a 100644
--- a/creator/wing.py
+++ b/creator/wing.py
@@ -11,65 +11,16 @@ Functions:
plot_geom(airfoil): generates a 2D plot of the airfoil & any components.
"""
-import sys
-import os.path
+import creator.base as base
+
import logging
import numpy as np
from math import sin, cos, atan
import bisect as bi
import matplotlib.pyplot as plt
-logging.basicConfig(filename='log.txt',
- level=logging.DEBUG,
- format='%(asctime)s - %(levelname)s - %(message)s')
-
-
-class Component:
- """Basic component providing coordinates and tools."""
-
- # TODO: define defaults in separate module
- def __init__(self):
- self.x = np.array([])
- self.z = np.array([])
- self.material = str()
- self.mass = float()
-
- def set_material(self, material):
- """Set the component bulk material."""
- self.material = material
-
- def info_print(self, round):
- """Print all the component's coordinates to the terminal."""
- name = f' CREATOR DATA FOR {str(self).upper()} '
- 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)
- 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 = f'{str(self).lower()}_{number}.txt'
- full_path = os.path.join(save_path, file_name)
- try:
- with open(full_path, 'w') as sys.stdout:
- self.info_print(6)
- # This line required to reset behavior of sys.stdout
- sys.stdout = sys.__stdout__
- 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
-
-class Airfoil(Component):
+class Airfoil(base.Component):
"""This class represents a single NACA airfoil.
The coordinates are saved as two lists
@@ -185,7 +136,7 @@ class Airfoil(Component):
return None
-class Spar(Component):
+class Spar(base.Component):
"""Contains a single spar's data."""
def __init__(self, airfoil, loc_percent, material):
"""Set spar location as percent of chord length."""
@@ -214,7 +165,7 @@ class Spar(Component):
return None
-class Stringer(Component):
+class Stringer(base.Component):
"""Contains the coordinates of all stringers."""
def __init__(self):
super().__init__()
Copyright 2019--2024 Marius PETER