Skip to content

Commit

Permalink
Now testing legacy code.
Browse files Browse the repository at this point in the history
  • Loading branch information
1ozturkbe committed Sep 11, 2019
1 parent 2a0d6e3 commit ede335a
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 108 deletions.
Empty file removed robust/simple_wing/__init__.py
Empty file.
107 changes: 0 additions & 107 deletions robust/simple_wing/models.py

This file was deleted.

53 changes: 52 additions & 1 deletion robust/testing/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
import numpy as np
from gpkit import Variable, Model, SignomialsEnabled

def simple_wing():
# Uncertain parameters
k = Variable("k", 1.17, "-", "form factor", pr=31.111111)
e = Variable("e", 0.92, "-", "Oswald efficiency factor", pr=7.6086956)
mu = Variable("\\mu", 1.775e-5, "kg/m/s", "viscosity of air", pr=4.225352)
rho = Variable("\\rho", 1.23, "kg/m^3", "density of air", pr=10)
tau = Variable("\\tau", 0.12, "-", "airfoil thickness to chord ratio", pr=33.333333)
N_ult = Variable("N_{ult}", 3.3, "-", "ultimate load factor", pr=33.333333)
V_min = Variable("V_{min}", 25, "m/s", "takeoff speed", pr=20)
C_Lmax = Variable("C_{L,max}", 1.6, "-", "max CL with flaps down", pr=25)
S_wetratio = Variable("(\\frac{S}{S_{wet}})", 2.075, "-", "wetted area ratio", pr=3.6144578)
W_W_coeff1 = Variable("W_{W_{coeff1}}", 12e-5, "1/m", "Wing Weight Coefficent 1", pr=60)
W_W_coeff2 = Variable("W_{W_{coeff2}}", 60, "Pa", "Wing Weight Coefficent 2", pr=66)
CDA0 = Variable("(CDA0)", 0.035, "m^2", "fuselage drag area", pr=42.857142)
W_0 = Variable("W_0", 6250, "N", "aircraft weight excluding wing", pr=60)

# Free Variables
D = Variable("D", "N", "total drag force")
A = Variable("A", "-", "aspect ratio", fix=True)
S = Variable("S", "m^2", "total wing area", fix=True)
V = Variable("V", "m/s", "cruising speed")
W = Variable("W", "N", "total aircraft weight")
Re = Variable("Re", "-", "Reynold's number")
C_D = Variable("C_D", "-", "Drag coefficient of wing")
C_L = Variable("C_L", "-", "Lift coefficient of wing")
C_f = Variable("C_f", "-", "skin friction coefficient")
W_w = Variable("W_w", "N", "wing weight")
constraints = []

# Drag Model
C_D_fuse = CDA0 / S
C_D_wpar = k * C_f * S_wetratio
C_D_ind = C_L ** 2 / (np.pi * A * e)
constraints += [C_D >= C_D_ind + C_D_fuse + C_D_wpar]

# Wing Weight Model
W_w_strc = W_W_coeff1 * (N_ult * A ** 1.5 * (W_0 * W * S) ** 0.5) / tau
W_w_surf = W_W_coeff2 * S
constraints += [W_w >= W_w_surf + W_w_strc]

# and the rest of the models
constraints += [D >= 0.5 * rho * S * C_D * V ** 2,
Re <= (rho / mu) * V * (S / A) ** 0.5,
C_f >= 0.074 / Re ** 0.2,
W <= 0.5 * rho * S * C_L * V ** 2,
W <= 0.5 * rho * S * C_Lmax * V_min ** 2,
W >= W_0 + W_w]

m = Model(D, constraints)
return m

def gp_test_model():
x = Variable('x')
y = Variable('y')
Expand All @@ -11,7 +63,6 @@ def gp_test_model():
b * x / y + b * x * y + a*b**2 * x ** 2 <= 1]
return Model((x * y) ** -1, constraints)


def sp_test_model():
x = Variable('x')
y = Variable('y')
Expand Down
66 changes: 66 additions & 0 deletions robust/testing/t_legacy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Testing legacy code"""
import numpy as np
import os

import unittest
from gpkit.tests.helpers import run_tests

from robust.testing.models import simple_wing
from robust.simulations import simulate
from robust.simulations import read_simulation_data

class TestLegacy(unittest.TestCase):
def test_simple_wing(self):
model = simple_wing()
number_of_time_average_solves = 3
number_of_iterations = 10
nominal_solution, nominal_solve_time, nominal_number_of_constraints, directly_uncertain_vars_subs = \
simulate.generate_model_properties(model, number_of_time_average_solves, number_of_iterations)
model_name = 'Simple Wing'
gammas = np.linspace(0, 1, 3)
min_num_of_linear_sections = 3
max_num_of_linear_sections = 99
linearization_tolerance = 1e-4
verbosity = 0

methods = [{'name': 'Best Pairs', 'twoTerm': True, 'boyd': False, 'simpleModel': False},
{'name': 'Linear. Perts.', 'twoTerm': False, 'boyd': False, 'simpleModel': False},
{'name': 'Simple Cons.', 'twoTerm': False, 'boyd': False, 'simpleModel': True},
{'name': 'Two Term', 'twoTerm': False, 'boyd': True, 'simpleModel': False}]
uncertainty_sets = ['box', 'elliptical']

variable_gamma_file_name = os.path.dirname(__file__) + '/simulation_data_variable_gamma.txt'
simulate.print_variable_gamma_results(model, model_name, gammas, number_of_iterations,
min_num_of_linear_sections,
max_num_of_linear_sections, verbosity, linearization_tolerance,
variable_gamma_file_name, number_of_time_average_solves, methods,
uncertainty_sets, nominal_solution, nominal_solve_time,
nominal_number_of_constraints, directly_uncertain_vars_subs)

gamma = 1.
numbers_of_linear_sections = [12, 20, 30, 44, 60, 80]

methods = [{'name': 'Best Pairs', 'twoTerm': True, 'boyd': False, 'simpleModel': False},
{'name': 'Linear. Perts.', 'twoTerm': False, 'boyd': False, 'simpleModel': False},
{'name': 'Two Term', 'twoTerm': False, 'boyd': True, 'simpleModel': False}]
uncertainty_sets = ['box', 'elliptical']

variable_pwl_file_name = os.path.dirname(__file__) + '/simulation_data_variable_pwl.txt'
simulate.print_variable_pwlsections_results(model, model_name, gamma, number_of_iterations,
numbers_of_linear_sections, linearization_tolerance,
verbosity, variable_pwl_file_name,
number_of_time_average_solves, methods, uncertainty_sets,
nominal_solution, nominal_solve_time,
nominal_number_of_constraints, directly_uncertain_vars_subs)

file_path_gamma = os.path.dirname(__file__) + '/simulation_data_variable_gamma.txt'
file_path_pwl = os.path.dirname(__file__) + '/simulation_data_variable_pwl.txt'
read_simulation_data.generate_all_plots(file_path_gamma, file_path_pwl)

TESTS = [TestLegacy]

def test():
run_tests(TESTS)

if __name__ == "__main__":
test()
3 changes: 3 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def import_tests():
from robust.testing import t_simulation
tests += t_simulation.TESTS

from robust.testing import t_legacy
tests += t_legacy.TESTS

return tests


Expand Down

0 comments on commit ede335a

Please sign in to comment.