Skip to content

Commit

Permalink
Merge pull request #51 from kejacobson/shape_by_conn
Browse files Browse the repository at this point in the history
Shape by connection
  • Loading branch information
anilyil authored Mar 21, 2021
2 parents 5f1fb47 + 4e00793 commit f0e5c69
Show file tree
Hide file tree
Showing 34 changed files with 165 additions and 452 deletions.
2 changes: 1 addition & 1 deletion examples/crm9/fun3d_tacs_meld/mphys_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def configure(self):
print("Scenario 0")
print('Lift =',prob['mp_group.s0.aero_funcs.Lift'])
print('CD =',prob['mp_group.s0.aero_funcs.C_D'])
print('KS =',prob['mp_group.s0.struct_funcs.funcs.f_struct'])
print('KS =',prob['mp_group.s0.struct_funcs.funcs.func_struct'])
output = prob.check_totals(of=['mp_group.s0.aero_funcs.Lift'], wrt=['thickness_lumped'],)
if MPI.COMM_WORLD.rank == 0:
print('check_totals output',output)
8 changes: 4 additions & 4 deletions examples/mach_tutorials/CRM_aerostruct/as_opt_FUN3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def setup(self):
'span_extend_bounds': [-.01, .01],#[-10., 10.], # plus-minus bounds on span-extension delta, m
'allowable_airfoil_thickness_fraction': 0.5, # fraction of baseline airfoil thickness allowable for plus-minus bounds, at each span station
'wing_twist_bounds': np.array([-10., 10.])*np.pi/180., # plus-minus bounds on wing twist at each span station, rad
'f_struct_bound': 2.0/3.0, # upper allowable bound on f_struct
'func_struct_bound': 2.0/3.0, # upper allowable bound on func_struct
'spar_depth_bound': 0.19, # lower allowable bound on spar depth, m
}

Expand Down Expand Up @@ -508,7 +508,7 @@ def configure(self):

prob.check_totals(
of=[
#'mp_group.s1.struct.funcs.f_struct',
#'mp_group.s1.struct.funcs.func_struct',
#'wing_area.area',
#'outputs.trim0.load_factor',
'outputs.trim1.load_factor',
Expand Down Expand Up @@ -581,11 +581,11 @@ def configure(self):
prob.model.add_constraint('struct_smoothness.le_spar_smoothness.diff', ref=model.opt_parameters['delta_thickness'], upper=0.0, linear=True)
prob.model.add_constraint('struct_smoothness.te_spar_smoothness.diff', ref=model.opt_parameters['delta_thickness'], upper=0.0, linear=True)

## add f_struct constraints, for every scenario except cruise
## add func_struct constraints, for every scenario except cruise

for i in range(0,model.misc_parameters['N_mp']):
if i != model.misc_parameters['cruise_case_ID']:
prob.model.add_constraint('mp_group.s'+str(i)+'.struct.funcs.f_struct', ref=1.0, upper=model.opt_parameters['f_struct_bound'])
prob.model.add_constraint('mp_group.s'+str(i)+'.struct.funcs.func_struct', ref=1.0, upper=model.opt_parameters['func_struct_bound'])

## add trim constraints

Expand Down
8 changes: 4 additions & 4 deletions examples/mach_tutorials/CRM_aerostruct/as_opt_VLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def setup(self):
'span_extend_bounds': [-.01, .01],#[-10., 10.], # plus-minus bounds on span-extension delta, m
'allowable_airfoil_thickness_fraction': 0.5, # fraction of baseline airfoil thickness allowable for plus-minus bounds, at each span station
'wing_twist_bounds': np.array([-10., 10.])*np.pi/180., # plus-minus bounds on wing twist at each span station, rad
'f_struct_bound': 2.0/3.0, # upper allowable bound on f_struct
'func_struct_bound': 2.0/3.0, # upper allowable bound on func_struct
'spar_depth_bound': 0.19, # lower allowable bound on spar depth, m
}

Expand Down Expand Up @@ -495,7 +495,7 @@ def configure(self):
#
#prob.check_totals(
# of=[
# 'mp_group.s1.struct.funcs.f_struct',
# 'mp_group.s1.struct.funcs.func_struct',
# 'outputs.wing_area.area',
# 'outputs.trim0.load_factor',
# 'outputs.trim1.load_factor',
Expand Down Expand Up @@ -566,11 +566,11 @@ def configure(self):
prob.model.add_constraint('struct_smoothness.le_spar_smoothness.diff', ref=model.opt_parameters['delta_thickness'], upper=0.0, linear=True)
prob.model.add_constraint('struct_smoothness.te_spar_smoothness.diff', ref=model.opt_parameters['delta_thickness'], upper=0.0, linear=True)

## add f_struct constraints, for every scenario except cruise
## add func_struct constraints, for every scenario except cruise

for i in range(0,model.misc_parameters['N_mp']):
if i != model.misc_parameters['cruise_case_ID']:
prob.model.add_constraint('mp_group.s'+str(i)+'.struct.funcs.f_struct', ref=1.0, upper=model.opt_parameters['f_struct_bound'])
prob.model.add_constraint('mp_group.s'+str(i)+'.struct.funcs.func_struct', ref=1.0, upper=model.opt_parameters['func_struct_bound'])

## add trim constraints

Expand Down
24 changes: 11 additions & 13 deletions examples/mach_tutorials/CRM_aerostruct/sum_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
import openmdao.api as om

class SumLoads(om.ExplicitComponent):

def initialize(self):

self.options.declare('load_size', types=int)
self.options.declare('load_list')

def setup(self):

for name in self.options['load_list']:
self.add_input(name,np.zeros(self.options['load_size']),src_indices=np.arange(0, self.options['load_size'], dtype=int))
self.add_input(name, shape_by_conn=True)

self.add_output('F_summed',np.zeros(self.options['load_size']))

def compute(self,inputs,outputs):

outputs['F_summed'] = np.zeros(self.options['load_size'])
for name in self.options['load_list']:
outputs['F_summed'] += inputs[name]
def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):

def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):

if mode == 'fwd':
pass

if mode == 'rev':

if 'F_summed' in d_outputs:
for name in self.options['load_list']:
if name in d_inputs:
d_inputs[name] += d_outputs['F_summed']


2 changes: 1 addition & 1 deletion examples/mach_tutorials/aero/mphys_aero.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def configure(self):
chordRef=3.25,
evalFuncs=['cl','cd']
)
ap0.addDV('alpha',value=aoa,name='aoa')
ap0.addDV('alpha', value=aoa, name='aoa', units='deg')

# here we set the aero problems for every cruise case we have.
# this can also be called set_flow_conditions, we don't need to create and pass an AP,
Expand Down
2 changes: 1 addition & 1 deletion examples/mach_tutorials/aero_opt/mphys_aero.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def configure(self):
chordRef=3.25,
evalFuncs=['cl', 'cd']
)
ap0.addDV('alpha',value=aoa,name='aoa')
ap0.addDV('alpha', value=aoa, name='aoa', units='deg')

# here we set the aero problems for every cruise case we have.
# this can also be called set_flow_conditions, we don't need to create and pass an AP,
Expand Down
4 changes: 2 additions & 2 deletions examples/mach_tutorials/aero_opt/mphys_aero_2pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def configure(self):
chordRef=3.25,
evalFuncs=['cl', 'cd']
)
ap0.addDV('alpha',value=aoa,name='aoa')
ap0.addDV('alpha', value=aoa, name='aoa', units='deg')

ap1 = AeroProblem(
name='ap1',
Expand All @@ -121,7 +121,7 @@ def configure(self):
chordRef=3.25,
evalFuncs=['cl', 'cd']
)
ap1.addDV('alpha',value=aoa,name='aoa')
ap1.addDV('alpha', value=aoa, name='aoa', units='deg')

# here we set the aero problems for every cruise case we have.
# this can also be called set_flow_conditions, we don't need to create and pass an AP,
Expand Down
4 changes: 2 additions & 2 deletions examples/mach_tutorials/aerostruct/mphys_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def configure(self):
chordRef=3.25,
evalFuncs=['lift','drag', 'cl', 'cd']
)
ap0.addDV('alpha',value=aoa,name='aoa')
ap0.addDV('mach',value=0.8,name='mach')
ap0.addDV('alpha', value=aoa, name='aoa', units='deg')
ap0.addDV('mach', value=0.8, name='mach')

# here we set the aero problems for every cruise case we have.
# this can also be called set_flow_conditions, we don't need to create and pass an AP,
Expand Down
8 changes: 4 additions & 4 deletions examples/mach_tutorials/aerostruct/mphys_as_2scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def configure(self):
chordRef=3.25,
evalFuncs=['lift','drag', 'cl', 'cd']
)
ap0.addDV('alpha',value=aoa,name='aoa')
ap0.addDV('mach',value=0.8,name='mach')
ap0.addDV('alpha', value=aoa, name='aoa', units='deg')
ap0.addDV('mach', value=0.8, name='mach')

# similarly, add the aero problem for the second analysis point
ap1 = AeroProblem(
Expand All @@ -201,8 +201,8 @@ def configure(self):
chordRef=3.25,
evalFuncs=['lift','drag', 'cl', 'cd']
)
ap1.addDV('alpha',value=aoa,name='aoa')
ap1.addDV('mach',value=0.7,name='mach')
ap1.addDV('alpha', value=aoa, name='aoa', units='deg')
ap1.addDV('mach', value=0.7, name='mach')

# here we set the aero problems for every cruise case we have.
# this can also be called set_flow_conditions, we don't need to create and pass an AP,
Expand Down
4 changes: 2 additions & 2 deletions examples/mach_tutorials/aerostruct_with_VLM/as_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def configure(self):

prob.model.add_objective('mp_group.s0.struct_funcs.mass',ref=1000.0)
prob.model.add_constraint('mp_group.s0.solver_group.aero.CL',ref=1.0,equals=0.5)
prob.model.add_constraint('mp_group.s0.struct_funcs.funcs.f_struct',ref=1.0, upper = 2.0/3.0)
prob.model.add_constraint('mp_group.s0.struct_funcs.funcs.func_struct',ref=1.0, upper = 2.0/3.0)

prob.model.add_constraint('le_spar_smoothness.diff', ref=1e-3, upper = 0.0, linear=True)
prob.model.add_constraint('te_spar_smoothness.diff', ref=1e-3, upper = 0.0, linear=True)
Expand Down Expand Up @@ -228,5 +228,5 @@ def configure(self):
case = cr.get_case(case_id)
matrix[i,1] = case.get_objectives()['mp_group.s0.struct_funcs.mass'][0]
matrix[i,2] = case.get_constraints()['mp_group.s0.solver_group.aero.forces.CL'][0]
matrix[i,3] = case.get_constraints()['mp_group.s0.struct_funcs.f_struct'][0]
matrix[i,3] = case.get_constraints()['mp_group.s0.struct_funcs.funcs.f_struct'][0]
np.savetxt('history.dat',matrix)
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ def configure(self):
if MPI.COMM_WORLD.rank == 0:
print('cl =',prob['mp_group.s0.solver_group.aero.forces.CL'])
if not args.modal:
print('f_struct =',prob['mp_group.s0.struct_funcs.funcs.f_struct'])
print('func_struct =',prob['mp_group.s0.struct_funcs.funcs.func_struct'])
print('mass =',prob['mp_group.s0.struct_funcs.mass.mass'])
10 changes: 5 additions & 5 deletions examples/tacs_only/mphys_crm_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def f5_writer(tacs):
f5.writeToFile('ucrm.f5')

tacs_setup = {'add_elements': add_elements,
'mesh_file' : 'CRM_box_2nd.bdf',
'get_funcs' : get_funcs,
'load_function': forcer_function,
'f5_writer' : f5_writer}
'mesh_file' : 'CRM_box_2nd.bdf',
'get_funcs' : get_funcs,
'load_function': forcer_function,
'f5_writer' : f5_writer}

# assembler = TacsOmfsiAssembler(tacs_setup,add_forcer=True)
tacs_builder = TacsBuilder(tacs_setup)
Expand Down Expand Up @@ -100,7 +100,7 @@ def configure(self):

model.add_design_var('dv_struct',lower=0.001,upper=0.075,scaler=1.0/1.0)
model.add_objective('mp_group.s0.struct_funcs.mass.mass',scaler=1.0/100000.0)
model.add_constraint('mp_group.s0.struct_funcs.funcs.f_struct',lower = 0.0, upper = 2.0/3.0,scaler=1000.0/1.0)
model.add_constraint('mp_group.s0.struct_funcs.funcs.func_struct',lower = 0.0, upper = 2.0/3.0,scaler=1000.0/1.0)

prob.driver = ScipyOptimizeDriver(debug_print=['objs','nl_cons'],maxiter=1500)
prob.driver.options['optimizer'] = 'SLSQP'
Expand Down
16 changes: 4 additions & 12 deletions mphys/geo_disp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ def initialize(self):
def setup(self):
nnodes = self.options['number_of_surface_nodes']
local_size = nnodes * 3
n_list = self.comm.allgather(local_size)
irank = self.comm.rank

n1 = np.sum(n_list[:irank])
n2 = np.sum(n_list[:irank+1])

self.add_input('x_aero0', shape=local_size,
src_indices=np.arange(n1,n2,dtype=int),
desc='aerodynamic surface with geom changes')
self.add_input('u_aero', shape=local_size,
val=np.zeros(local_size),
src_indices=np.arange(n1,n2,dtype=int),
desc='aerodynamic surface displacements')
self.add_input('x_aero0', shape_by_conn=True,
desc='aerodynamic surface with geom changes')
self.add_input('u_aero', shape_by_conn=True,
desc='aerodynamic surface displacements')

self.add_output('x_aero', shape=local_size, desc='deformed aerodynamic surface')

Expand Down
4 changes: 2 additions & 2 deletions mphys/integrated_forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def setup(self):
self.add_input('ref_length', val = 1.0)
self.add_input('q_inf', val = 1.0)

self.add_input('x_aero',shape=3*nnodes, desc = 'surface coordinates')
self.add_input('f_aero',shape=3*nnodes, desc = 'dimensional forces at nodes')
self.add_input('x_aero', shape_by_conn=True, desc = 'surface coordinates')
self.add_input('f_aero', shape_by_conn=True, desc = 'dimensional forces at nodes')

self.add_output('C_L', desc = 'Lift coefficient')
self.add_output('C_D', desc = 'Drag coefficient')
Expand Down
Loading

0 comments on commit f0e5c69

Please sign in to comment.