/
test_v1_struct_opt.py
104 lines (78 loc) · 3.96 KB
/
test_v1_struct_opt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from __future__ import division, print_function
import unittest
import numpy as np
from openaerostruct.geometry.utils import generate_mesh
from openaerostruct.geometry.geometry_group import Geometry
from openaerostruct.transfer.displacement_transfer import DisplacementTransfer
from openaerostruct.structures.struct_groups import SpatialBeamAlone
from openmdao.api import IndepVarComp, Problem, Group, NewtonSolver, ScipyIterativeSolver, LinearBlockGS, NonlinearBlockGS, DirectSolver, LinearBlockGS, PetscKSP, ScipyOptimizeDriver
class Test(unittest.TestCase):
def test(self):
# Create a dictionary to store options about the surface
mesh_dict = {'num_y' : 5,
'num_x' : 3,
'wing_type' : 'rect',
'symmetry' : True,
'span_cos_spacing' : 1.,
'span' : 10,
'chord' : 1}
mesh = generate_mesh(mesh_dict)
surf_dict = {
# Wing definition
'name' : 'wing', # name of the surface
'type' : 'structural',
'symmetry' : True, # if true, model one half of wing
# reflected across the plane y = 0
'fem_model_type' : 'tube',
'mesh' : mesh,
'num_x' : mesh.shape[0],
'num_y' : mesh.shape[1],
# Structural values are based on aluminum 7075
'E' : 70.e9, # [Pa] Young's modulus of the spar
'G' : 30.e9, # [Pa] shear modulus of the spar
'yield' : 500.e6 / 2.5, # [Pa] yield stress divided by 2.5 for limiting case
'mrho' : 3.e3, # [kg/m^3] material density
'fem_origin' : 0.35, # normalized chordwise location of the spar
't_over_c' : 0.15, # maximum airfoil thickness
'thickness_cp' : np.ones((3)) * .0075,
'wing_weight_ratio' : 1.,
'exact_failure_constraint' : False,
}
# Create the problem and assign the model group
prob = Problem()
ny = surf_dict['num_y']
loads = np.zeros((ny, 6))
loads[0, 2] = 1e4
indep_var_comp = IndepVarComp()
indep_var_comp.add_output('loads', val=loads, units='N')
indep_var_comp.add_output('load_factor', val=1.)
struct_group = SpatialBeamAlone(surface=surf_dict)
# Add indep_vars to the structural group
struct_group.add_subsystem('indep_vars',
indep_var_comp,
promotes=['*'])
prob.model.add_subsystem(surf_dict['name'], struct_group)
try:
from openmdao.api import pyOptSparseDriver
prob.driver = pyOptSparseDriver()
prob.driver.options['optimizer'] = "SNOPT"
prob.driver.opt_settings = {'Major optimality tolerance': 1.0e-8,
'Major feasibility tolerance': 1.0e-8}
except:
from openmdao.api import ScipyOptimizeDriver
prob.driver = ScipyOptimizeDriver()
prob.driver.options['disp'] = True
# Setup problem and add design variables, constraint, and objective
prob.model.add_design_var('wing.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
prob.model.add_constraint('wing.failure', upper=0.)
prob.model.add_constraint('wing.thickness_intersects', upper=0.)
# Add design variables, constraisnt, and objective on the problem
prob.model.add_objective('wing.structural_weight', scaler=1e-5)
# Set up the problem
prob.setup()
# from openmdao.api import view_model
# view_model(prob)
prob.run_driver()
self.assertAlmostEqual(prob['wing.structural_weight'][0], 1144.8503583047038, places=1)
if __name__ == '__main__':
unittest.main()