Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch aoa1, aoa2 back to vector aoa in supersonic panel example #167

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions examples/aerostructural/supersonic_panel/as_opt_parallel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import openmdao.api as om
import os
from openmdao.core.constants import _DEFAULT_OUT_STREAM

from mphys import Multipoint, MultipointParallel
from mphys.scenario_aerostructural import ScenarioAeroStructural
Expand Down Expand Up @@ -67,9 +68,7 @@ def setup(self):
self.ivc.add_output('density', val=2800.)
self.ivc.add_output('mach', val=[5.,3.])
self.ivc.add_output('qdyn', val=[3E4,1E4])
#self.ivc.add_output('aoa', val=[3.,2.], units='deg') # derivatives are wrong when using vector aoa and coloring; see OpenMDAO issue 2919
self.ivc.add_output('aoa1', val=3., units='deg')
self.ivc.add_output('aoa2', val=2., units='deg')
self.ivc.add_output('aoa', val=[3.,2.], units='deg')
self.ivc.add_output('geometry_morph_param', val=1.)

# create dv_struct, which is the thickness of each structural element
Expand Down Expand Up @@ -113,20 +112,16 @@ def setup(self):
self.connect(var, 'multipoint.'+self.scenario_names[i]+'.'+var)

# connect vector inputs
for var in ['mach', 'qdyn']: #, 'aoa']:
for var in ['mach', 'qdyn', 'aoa']:
self.connect(var, 'multipoint.'+self.scenario_names[i]+'.'+var, src_indices=[i])

self.connect(f'aoa{i+1}', 'multipoint.'+self.scenario_names[i]+'.aoa')

# connect top-level geom parameter
self.connect('geometry_morph_param', 'multipoint.'+self.scenario_names[i]+'.geometry.geometry_morph_param')

# add design vars
self.add_design_var('geometry_morph_param', lower=0.1, upper=10.0)
self.add_design_var('dv_struct', lower=1.e-4, upper=1.e-2, ref=1.e-3)
#self.add_design_var('aoa', lower=-10., upper=10.)
self.add_design_var('aoa1', lower=-20., upper=20.)
self.add_design_var('aoa2', lower=-20., upper=20.)
self.add_design_var('aoa', lower=-20., upper=20.)

# add objective/constraints
self.add_objective(f'multipoint.{self.scenario_names[0]}.mass', ref=0.01)
Expand All @@ -151,7 +146,8 @@ def get_model(scenario_names):
prob.check_totals(step_calc='rel_avg',
compact_print=True,
directional=False,
show_progress=True)
show_progress=True,
out_stream=None if prob.model.comm.rank>0 else _DEFAULT_OUT_STREAM)

else:

Expand All @@ -176,33 +172,33 @@ def get_model(scenario_names):
prob.run_driver()
prob.cleanup()

# write out data
cr = om.CaseReader("optimization_history.sql")
driver_cases = cr.list_cases('driver')
if prob.model.comm.rank==0: # write out data
cr = om.CaseReader("optimization_history.sql")
driver_cases = cr.list_cases('driver')

case = cr.get_case(0)
cons = case.get_constraints()
dvs = case.get_design_vars()
objs = case.get_objectives()
case = cr.get_case(0)
cons = case.get_constraints()
dvs = case.get_design_vars()
objs = case.get_objectives()

f = open("optimization_history.dat","w+")
f = open("optimization_history.dat","w+")

for i, k in enumerate(objs.keys()):
f.write('objective: ' + k + '\n')
for j, case_id in enumerate(driver_cases):
f.write(str(j) + ' ' + str(cr.get_case(case_id).get_objectives(scaled=False)[k][0]) + '\n')
f.write(' ' + '\n')
for i, k in enumerate(objs.keys()):
f.write('objective: ' + k + '\n')
for j, case_id in enumerate(driver_cases):
f.write(str(j) + ' ' + str(cr.get_case(case_id).get_objectives(scaled=False)[k][0]) + '\n')
f.write(' ' + '\n')

for i, k in enumerate(cons.keys()):
f.write('constraint: ' + k + '\n')
for j, case_id in enumerate(driver_cases):
f.write(str(j) + ' ' + ' '.join(map(str,cr.get_case(case_id).get_constraints(scaled=False)[k])) + '\n')
f.write(' ' + '\n')
for i, k in enumerate(cons.keys()):
f.write('constraint: ' + k + '\n')
for j, case_id in enumerate(driver_cases):
f.write(str(j) + ' ' + ' '.join(map(str,cr.get_case(case_id).get_constraints(scaled=False)[k])) + '\n')
f.write(' ' + '\n')

for i, k in enumerate(dvs.keys()):
f.write('DV: ' + k + '\n')
for j, case_id in enumerate(driver_cases):
f.write(str(j) + ' ' + ' '.join(map(str,cr.get_case(case_id).get_design_vars(scaled=False)[k])) + '\n')
f.write(' ' + '\n')
for i, k in enumerate(dvs.keys()):
f.write('DV: ' + k + '\n')
for j, case_id in enumerate(driver_cases):
f.write(str(j) + ' ' + ' '.join(map(str,cr.get_case(case_id).get_design_vars(scaled=False)[k])) + '\n')
f.write(' ' + '\n')

f.close()
f.close()
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,18 @@ def setup(self):
# distributed IVCs
self.ivc.add_output('mach', [5., 3.])
self.ivc.add_output('qdyn', [3E4, 1E4])
#self.ivc.add_output('aoa', [3., 2.]) # derivatives are wrong when using vector aoa and coloring; see OpenMDAO issue 2919
self.ivc.add_output('aoa1', 3.)
self.ivc.add_output('aoa2', 2.)
self.ivc.add_output('aoa', [3., 2.])

# add distributed design vars
#self.add_design_var('aoa', lower=-20., upper=20.)
self.add_design_var('aoa1', lower=-20., upper=20.)
self.add_design_var('aoa2', lower=-20., upper=20.)
self.add_design_var('aoa', lower=-20., upper=20.)

# add the parallel servers
self.add_subsystem('multipoint', ParallelRemoteGroup(num_scenarios=2), promotes=['*'])

# connect distributed IVCs to servers, which are size (2,) and (1,) on client and server sides
for i in range(2):
for var in ['mach', 'qdyn']: #, 'aoa']:
for var in ['mach', 'qdyn', 'aoa']:
self.connect(var, f'remote_scenario{i}.{var}', src_indices=[i])
self.connect(f'aoa{i+1}', f'remote_scenario{i}.aoa')

# add CL and stress constraints
min_CL = [0.15, 0.45]
Expand Down
Loading