diff --git a/examples/crm9/fun3d_tacs_meld/mphys_analysis.py b/examples/crm9/fun3d_tacs_meld/mphys_analysis.py index 9f2d5c15..600ba538 100644 --- a/examples/crm9/fun3d_tacs_meld/mphys_analysis.py +++ b/examples/crm9/fun3d_tacs_meld/mphys_analysis.py @@ -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) diff --git a/examples/mach_tutorials/CRM_aerostruct/as_opt_FUN3D.py b/examples/mach_tutorials/CRM_aerostruct/as_opt_FUN3D.py index 2db93257..8ae32259 100644 --- a/examples/mach_tutorials/CRM_aerostruct/as_opt_FUN3D.py +++ b/examples/mach_tutorials/CRM_aerostruct/as_opt_FUN3D.py @@ -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 } @@ -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', @@ -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 diff --git a/examples/mach_tutorials/CRM_aerostruct/as_opt_VLM.py b/examples/mach_tutorials/CRM_aerostruct/as_opt_VLM.py index 95adf008..120a57e7 100644 --- a/examples/mach_tutorials/CRM_aerostruct/as_opt_VLM.py +++ b/examples/mach_tutorials/CRM_aerostruct/as_opt_VLM.py @@ -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 } @@ -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', @@ -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 diff --git a/examples/mach_tutorials/CRM_aerostruct/sum_loads.py b/examples/mach_tutorials/CRM_aerostruct/sum_loads.py index b2e14a9a..e6ee1df7 100644 --- a/examples/mach_tutorials/CRM_aerostruct/sum_loads.py +++ b/examples/mach_tutorials/CRM_aerostruct/sum_loads.py @@ -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'] - - diff --git a/examples/mach_tutorials/aero/mphys_aero.py b/examples/mach_tutorials/aero/mphys_aero.py index 43cab081..f1d25c5d 100644 --- a/examples/mach_tutorials/aero/mphys_aero.py +++ b/examples/mach_tutorials/aero/mphys_aero.py @@ -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, diff --git a/examples/mach_tutorials/aero_opt/mphys_aero.py b/examples/mach_tutorials/aero_opt/mphys_aero.py index 399d17a3..7409c6dc 100644 --- a/examples/mach_tutorials/aero_opt/mphys_aero.py +++ b/examples/mach_tutorials/aero_opt/mphys_aero.py @@ -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, diff --git a/examples/mach_tutorials/aero_opt/mphys_aero_2pt.py b/examples/mach_tutorials/aero_opt/mphys_aero_2pt.py index ab59722a..8829f4d7 100644 --- a/examples/mach_tutorials/aero_opt/mphys_aero_2pt.py +++ b/examples/mach_tutorials/aero_opt/mphys_aero_2pt.py @@ -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', @@ -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, diff --git a/examples/mach_tutorials/aerostruct/mphys_as.py b/examples/mach_tutorials/aerostruct/mphys_as.py index 1d3abd90..23c94602 100644 --- a/examples/mach_tutorials/aerostruct/mphys_as.py +++ b/examples/mach_tutorials/aerostruct/mphys_as.py @@ -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, diff --git a/examples/mach_tutorials/aerostruct/mphys_as_2scenario.py b/examples/mach_tutorials/aerostruct/mphys_as_2scenario.py index 1a14bd3e..2c3009bb 100644 --- a/examples/mach_tutorials/aerostruct/mphys_as_2scenario.py +++ b/examples/mach_tutorials/aerostruct/mphys_as_2scenario.py @@ -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( @@ -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, diff --git a/examples/mach_tutorials/aerostruct_with_VLM/as_opt.py b/examples/mach_tutorials/aerostruct_with_VLM/as_opt.py index 987a832e..9dc5ea83 100644 --- a/examples/mach_tutorials/aerostruct_with_VLM/as_opt.py +++ b/examples/mach_tutorials/aerostruct_with_VLM/as_opt.py @@ -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) @@ -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) diff --git a/examples/mach_tutorials/aerostruct_with_VLM/mphys_as_vlm.py b/examples/mach_tutorials/aerostruct_with_VLM/mphys_as_vlm.py index 5eb2952c..c908d12f 100644 --- a/examples/mach_tutorials/aerostruct_with_VLM/mphys_as_vlm.py +++ b/examples/mach_tutorials/aerostruct_with_VLM/mphys_as_vlm.py @@ -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']) diff --git a/examples/tacs_only/mphys_crm_example.py b/examples/tacs_only/mphys_crm_example.py index 82ff9b83..28a9a8c5 100644 --- a/examples/tacs_only/mphys_crm_example.py +++ b/examples/tacs_only/mphys_crm_example.py @@ -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) @@ -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' diff --git a/mphys/geo_disp.py b/mphys/geo_disp.py index b21c0181..81dfd67b 100644 --- a/mphys/geo_disp.py +++ b/mphys/geo_disp.py @@ -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') diff --git a/mphys/integrated_forces.py b/mphys/integrated_forces.py index ae36421c..a1760a32 100644 --- a/mphys/integrated_forces.py +++ b/mphys/integrated_forces.py @@ -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') diff --git a/mphys/mphys_adflow.py b/mphys/mphys_adflow.py index 62818e10..090c0a3d 100644 --- a/mphys/mphys_adflow.py +++ b/mphys/mphys_adflow.py @@ -32,14 +32,7 @@ def setup(self): def mphys_add_coordinate_input(self): - local_size = self.x_a0.size - 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_points',shape=local_size,src_indices=np.arange(n1,n2,dtype=int),desc='aerodynamic surface with geom changes') + self.add_input('x_aero0_points', shape_by_conn=True, desc='aerodynamic surface with geom changes') # return the promoted name and coordinates return 'x_aero0_points', self.x_a0 @@ -140,14 +133,9 @@ def initialize(self): def setup(self): aero_nnodes = self.options['nnodes'] local_size = aero_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') @@ -185,22 +173,14 @@ def setup(self): #self.set_check_partial_options(wrt='*',directional=True) self.solver = self.options['aero_solver'] - # self.add_output('foo', val=1.0) solver = self.solver # self.ap_vars,_ = get_dvs_and_cons(ap=ap) # state inputs and outputs - local_coord_size = solver.getSurfaceCoordinates(includeZipper=False).size local_volume_coord_size = solver.mesh.getSolverGrid().size - n_list = self.comm.allgather(local_coord_size) - irank = self.comm.rank - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - - self.add_input('x_aero', src_indices=np.arange(n1,n2,dtype=int),shape=local_coord_size) - + self.add_input('x_aero', shape_by_conn=True) self.add_output('x_g', shape=local_volume_coord_size) #self.declare_partials(of='x_g', wrt='x_aero') @@ -271,15 +251,8 @@ def setup(self): # state inputs and outputs local_state_size = solver.getStateSize() - local_coord_size = solver.mesh.getSolverGrid().size - - n_list = self.comm.allgather(local_coord_size) - irank = self.comm.rank - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - - self.add_input('x_g', src_indices=np.arange(n1,n2,dtype=int),shape=local_coord_size) + self.add_input('x_g', shape_by_conn=True) self.add_output('q', shape=local_state_size) #self.declare_partials(of='q', wrt='*') @@ -507,19 +480,8 @@ def setup(self): self.solver = self.options['aero_solver'] solver = self.solver - local_state_size = solver.getStateSize() - local_coord_size = solver.mesh.getSolverGrid().size - s_list = self.comm.allgather(local_state_size) - n_list = self.comm.allgather(local_coord_size) - irank = self.comm.rank - - s1 = np.sum(s_list[:irank]) - s2 = np.sum(s_list[:irank+1]) - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - - self.add_input('x_g', src_indices=np.arange(n1,n2,dtype=int), shape=local_coord_size) - self.add_input('q', src_indices=np.arange(s1,s2,dtype=int), shape=local_state_size) + self.add_input('x_g', shape_by_conn=True) + self.add_input('q', shape_by_conn=True) local_surface_coord_size = solver.mesh.getSurfaceCoordinates().size self.add_output('f_aero', shape=local_surface_coord_size) @@ -629,27 +591,10 @@ def setup(self): self.solver = self.options['aero_solver'] solver = self.solver + local_nodes, _ = solver._getSurfaceSize(solver.allIsothermalWallsGroup) - local_state_size = solver.getStateSize() - local_coord_size = solver.mesh.getSolverGrid().size - s_list = self.comm.allgather(local_state_size) - n_list = self.comm.allgather(local_coord_size) - irank = self.comm.rank - - s1 = np.sum(s_list[:irank]) - s2 = np.sum(s_list[:irank+1]) - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - - local_nodes, nCells = solver._getSurfaceSize(solver.allIsothermalWallsGroup) - t_list = self.comm.allgather(local_nodes) - - t1 = np.sum(t_list[:irank]) - t2 = np.sum(t_list[:irank+1]) - - self.add_input('x_g', src_indices=np.arange(n1,n2,dtype=int), shape=local_coord_size) - self.add_input('q', src_indices=np.arange(s1,s2,dtype=int), shape=local_state_size) - + self.add_input('x_g', shape_by_conn=True) + self.add_input('q', shape_by_conn=True) self.add_output('q_convect', val=np.ones(local_nodes)*-499, shape=local_nodes, units='W/m**2') @@ -800,23 +745,11 @@ def setup(self): self.solver = self.options['aero_solver'] self.ap_funcs = self.options['ap_funcs'] self.write_solution = self.options['write_solution'] - solver = self.solver #self.set_check_partial_options(wrt='*',directional=True) self.solution_counter = 0 - local_state_size = solver.getStateSize() - local_coord_size = solver.mesh.getSolverGrid().size - s_list = self.comm.allgather(local_state_size) - n_list = self.comm.allgather(local_coord_size) - irank = self.comm.rank - - s1 = np.sum(s_list[:irank]) - s2 = np.sum(s_list[:irank+1]) - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - - self.add_input('x_g', src_indices=np.arange(n1,n2,dtype=int), shape=local_coord_size) - self.add_input('q', src_indices=np.arange(s1,s2,dtype=int), shape=local_state_size) + self.add_input('x_g', shape_by_conn=True) + self.add_input('q', shape_by_conn=True) #self.declare_partials(of=f_name, wrt='*') diff --git a/mphys/mphys_dvgeo.py b/mphys/mphys_dvgeo.py index b115890c..281fc31a 100644 --- a/mphys/mphys_dvgeo.py +++ b/mphys/mphys_dvgeo.py @@ -69,25 +69,15 @@ def nom_add_point_dict(self, point_dict): self.nom_addPointSet(v, k) def nom_addGeoDVGlobal(self, dvName, value, func): - - # to get the correct source indices - ind1 = self.comm.rank * value.size - ind2 = (self.comm.rank + 1) * value.size - # define the input - self.add_input(dvName, shape=value.shape, src_indices=np.arange(ind1, ind2,dtype=int)) + self.add_input(dvName, shape=len(value)) # call the dvgeo object and add this dv self.DVGeo.addGeoDVGlobal(dvName, value, func) def nom_addGeoDVLocal(self, dvName, axis='y'): nVal = self.DVGeo.addGeoDVLocal(dvName, axis=axis) - - # to get the correct source indices - ind1 = self.comm.rank * nVal - ind2 = (self.comm.rank + 1) * nVal - - self.add_input(dvName, shape=nVal, src_indices=np.arange(ind1, ind2, dtype=int)) + self.add_input(dvName, shape=nVal) return nVal def nom_addVSPVariable(self, component, group, parm, **kwargs): @@ -102,7 +92,7 @@ def nom_addVSPVariable(self, component, group, parm, **kwargs): val = self.DVGeo.DVs[dvName].value.copy() # add the input with the correct value, VSP DVs always have a size of 1 - self.add_input(dvName, val=val, src_indices=(self.comm.rank)) + self.add_input(dvName, shape=1, val=val) def nom_addThicknessConstraints2D(self, name, leList, teList, nSpan=10, nChord=10): self.DVCon.addThicknessConstraints2D(leList, teList, nSpan, nChord, lower=1.0, name=name) diff --git a/mphys/mphys_fun3d.py b/mphys/mphys_fun3d.py index 4688232b..1591ad5d 100644 --- a/mphys/mphys_fun3d.py +++ b/mphys/mphys_fun3d.py @@ -31,14 +31,7 @@ def _flatten_vectors(self, x, y, z): return matrix.flatten(order="C") def mphys_add_coordinate_input(self): - local_size = self.x_a0.size - 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_points',shape=local_size,src_indices=np.arange(n1,n2,dtype=int),desc='aerodynamic surface with geom changes') + self.add_input('x_aero0_points',shape_by_conn=True, desc='aerodynamic surface with geom changes') return 'x_aero0_points', self.x_a0 diff --git a/mphys/mphys_meld.py b/mphys/mphys_meld.py index ec03c903..ee5bda00 100644 --- a/mphys/mphys_meld.py +++ b/mphys/mphys_meld.py @@ -33,39 +33,18 @@ def setup(self): #self.set_check_partial_options(wrt='*',method='cs',directional=True) - struct_ndof = self.struct_ndof - struct_nnodes = self.struct_nnodes - aero_nnodes = self.aero_nnodes - - irank = self.comm.rank - - ax_list = self.comm.allgather(aero_nnodes*3) - ax1 = np.sum(ax_list[:irank]) - ax2 = np.sum(ax_list[:irank+1]) - - sx_list = self.comm.allgather(struct_nnodes*3) - sx1 = np.sum(sx_list[:irank]) - sx2 = np.sum(sx_list[:irank+1]) - - su_list = self.comm.allgather(struct_nnodes*struct_ndof) - su1 = np.sum(su_list[:irank]) - su2 = np.sum(su_list[:irank+1]) - # inputs - self.add_input('x_struct0', shape = struct_nnodes*3, - src_indices = np.arange(sx1, sx2, dtype=int), - desc='initial structural node coordinates') - self.add_input('x_aero0', shape = aero_nnodes*3, - src_indices = np.arange(ax1, ax2, dtype=int), - desc='initial aero surface node coordinates') - self.add_input('u_struct', shape = struct_nnodes*struct_ndof, - src_indices = np.arange(su1, su2, dtype=int), - desc='structural node displacements') + self.add_input('x_struct0', shape_by_conn=True, + desc='initial structural node coordinates') + self.add_input('x_aero0', shape_by_conn=True, + desc='initial aero surface node coordinates') + self.add_input('u_struct', shape_by_conn=True, + desc='structural node displacements') # outputs - self.add_output('u_aero', shape = aero_nnodes*3, - val=np.zeros(aero_nnodes*3), - desc='aerodynamic surface displacements') + self.add_output('u_aero', shape = self.aero_nnodes*3, + val=np.zeros(self.aero_nnodes*3), + desc='aerodynamic surface displacements') # partials #self.declare_partials('u_aero',['x_struct0','x_aero0','u_struct']) @@ -186,34 +165,15 @@ def setup(self): struct_ndof = self.struct_ndof struct_nnodes = self.struct_nnodes - aero_nnodes = self.aero_nnodes - - irank = self.comm.rank - - ax_list = self.comm.allgather(aero_nnodes*3) - ax1 = np.sum(ax_list[:irank]) - ax2 = np.sum(ax_list[:irank+1]) - - sx_list = self.comm.allgather(struct_nnodes*3) - sx1 = np.sum(sx_list[:irank]) - sx2 = np.sum(sx_list[:irank+1]) - - su_list = self.comm.allgather(struct_nnodes*struct_ndof) - su1 = np.sum(su_list[:irank]) - su2 = np.sum(su_list[:irank+1]) # inputs - self.add_input('x_struct0', shape = struct_nnodes*3, - src_indices = np.arange(sx1, sx2, dtype=int), + self.add_input('x_struct0', shape_by_conn=True, desc='initial structural node coordinates') - self.add_input('x_aero0', shape = aero_nnodes*3, - src_indices = np.arange(ax1, ax2, dtype=int), + self.add_input('x_aero0', shape_by_conn=True, desc='initial aero surface node coordinates') - self.add_input('u_struct', shape = struct_nnodes*struct_ndof, - src_indices = np.arange(su1, su2, dtype=int), + self.add_input('u_struct', shape_by_conn=True, desc='structural node displacements') - self.add_input('f_aero', shape = aero_nnodes*3, - src_indices = np.arange(ax1, ax2, dtype=int), + self.add_input('f_aero', shape_by_conn=True, desc='aerodynamic force vector') # outputs diff --git a/mphys/mphys_meldthermal.py b/mphys/mphys_meldthermal.py index 69d1c091..440d9314 100644 --- a/mphys/mphys_meldthermal.py +++ b/mphys/mphys_meldthermal.py @@ -37,46 +37,19 @@ def setup(self): self.cond_nnodes = self.options['cond_nnodes'] self.conv_nnodes = self.options['conv_nnodes'] self.check_partials= self.options['check_partials'] - cond_ndof = self.cond_ndof - cond_nnodes = self.cond_nnodes conv_nnodes = self.conv_nnodes - irank = self.comm.rank - - - - ax_list = self.comm.allgather(conv_nnodes*3) - ax1 = np.sum(ax_list[:irank]) - ax2 = np.sum(ax_list[:irank+1]) - - sx_list = self.comm.allgather(cond_nnodes*3) - sx1 = np.sum(sx_list[:irank]) - sx2 = np.sum(sx_list[:irank+1]) - - - cond_temp_list = self.comm.allgather(self.cond_nnodes*cond_ndof) - cond_temp_n1 = np.sum(cond_temp_list[:irank]) - cond_temp_n2 = np.sum(cond_temp_list[:irank+1]) - - print('cond_ndof', cond_ndof) # inputs - print('x_struct0',sx1, sx2, cond_nnodes*3) - - - self.add_input('x_struct0', shape = cond_nnodes*3, src_indices = np.arange(sx1, sx2, dtype=int), desc='initial structural node coordinates') - print('x_aero0',ax1, ax2, conv_nnodes*3) - self.add_input('x_aero0', shape = conv_nnodes*3, src_indices = np.arange(ax1, ax2, dtype=int), desc='initial aerodynamic surface node coordinates') - - - print('T_conduct',cond_temp_n1, cond_temp_n2, self.cond_nnodes*cond_ndof) - - self.add_input('T_conduct', shape = self.cond_nnodes*cond_ndof, src_indices = np.arange(cond_temp_n1, cond_temp_n2, dtype=int), - desc='conductive node displacements') + self.add_input('x_struct0', shape_by_conn=True, desc='initial structural node coordinates') + self.add_input('x_aero0', shape_by_conn=True, desc='initial aerodynamic surface node coordinates') + self.add_input('T_conduct', shape_by_conn=True, desc='conductive node displacements') # outputs print('T_convect', conv_nnodes) - self.add_output('T_convect', shape = conv_nnodes, val=np.ones(conv_nnodes)*301, desc='conv surface temperatures') + self.add_output('T_convect', shape = conv_nnodes, + val=np.ones(conv_nnodes)*301, + desc='conv surface temperatures') def compute(self, inputs, outputs): @@ -144,46 +117,10 @@ def setup(self): self.conv_nnodes = self.options['conv_nnodes'] self.check_partials= self.options['check_partials'] - cond_ndof = self.cond_ndof - cond_nnodes = self.cond_nnodes - conv_nnodes = self.conv_nnodes - - irank = self.comm.rank - - - - ax_list = self.comm.allgather(conv_nnodes*3) - ax1 = np.sum(ax_list[:irank]) - ax2 = np.sum(ax_list[:irank+1]) - - sx_list = self.comm.allgather(cond_nnodes*3) - sx1 = np.sum(sx_list[:irank]) - sx2 = np.sum(sx_list[:irank+1]) - - conv_node_list = self.comm.allgather(conv_nnodes) - conv_heat_n1 = np.sum(conv_node_list[:irank]) - conv_heat_n2 = np.sum(conv_node_list[:irank+1]) - - - stemp_list = self.comm.allgather(cond_nnodes*cond_ndof) - su1 = np.sum(stemp_list[:irank]) - cond_temp_n2 = np.sum(stemp_list[:irank+1]) - - # inputs - - # inputs - print('x_struct0',sx1, sx2, cond_nnodes*3) - self.add_input('x_struct0', shape = cond_nnodes*3, src_indices = np.arange(sx1, sx2, dtype=int), desc='initial structural node coordinates') - - print('x_aero0',ax1, ax2, conv_nnodes*3) - - self.add_input('x_aero0', shape = conv_nnodes*3, src_indices = np.arange(ax1, ax2, dtype=int), desc='initial aerodynamic surface node coordinates') - - - print('q_convect',conv_heat_n1, conv_heat_n2, conv_nnodes) - - self.add_input('q_convect', shape = conv_nnodes, src_indices = np.arange(conv_heat_n1, conv_heat_n2, dtype=int), desc='initial conv heat transfer rate') + self.add_input('x_struct0', shape_by_conn=True, desc='initial structural node coordinates') + self.add_input('x_aero0', shape_by_conn=True, desc='initial aerodynamic surface node coordinates') + self.add_input('q_convect', shape_by_conn=True, desc='initial conv heat transfer rate') print('q_conduct', self.cond_nnodes) diff --git a/mphys/mphys_rlt.py b/mphys/mphys_rlt.py index ed6ff12d..fedbca97 100644 --- a/mphys/mphys_rlt.py +++ b/mphys/mphys_rlt.py @@ -47,7 +47,6 @@ def setup(self): self.nn_s = nn_s self.ndof_a = ndof_a self.nn_a = nn_a - total_dof_struct = self.nn_s * self.ndof_s total_dof_aero = self.nn_a * self.ndof_a if self.isStruct: @@ -60,30 +59,12 @@ def setup(self): else: self.ustruct = None - # Get the source indices for each of the distributed inputs. - irank = self.comm.rank - - ax_list = self.comm.allgather(total_dof_aero) - ax1 = np.sum(ax_list[:irank]) - ax2 = np.sum(ax_list[:irank+1]) - - sx_list = self.comm.allgather(nn_s * 3) - sx1 = np.sum(sx_list[:irank]) - sx2 = np.sum(sx_list[:irank+1]) - - su_list = self.comm.allgather(total_dof_struct) - su1 = np.sum(su_list[:irank]) - su2 = np.sum(su_list[:irank+1]) - # Inputs - self.add_input('x_aero0', shape=total_dof_aero, - src_indices=np.arange(ax1, ax2, dtype=int), + self.add_input('x_aero0', shape_by_conn=True, desc='Initial aerodynamic surface node coordinates') - self.add_input('x_struct0', shape = nn_s * 3, - src_indices = np.arange(sx1, sx2, dtype=int), + self.add_input('x_struct0', shape_by_conn=True, desc='initial structural node coordinates') - self.add_input('u_struct', shape=total_dof_struct, - src_indices=np.arange(su1, su2, dtype=int), + self.add_input('u_struct', shape_by_conn=True, desc='Structural node displacements') # Outputs @@ -206,7 +187,6 @@ def setup(self): self.nn_s = nn_s self.nn_a = nn_a total_dof_struct = self.nn_s * self.ndof_s - total_dof_aero = self.nn_a * self.ndof_a if self.isStruct: # RLT depends on TACS vector types. @@ -218,34 +198,14 @@ def setup(self): else: self.fstruct = None - # Get the source indices for each of the distributed inputs. - irank = self.comm.rank - - ax_list = self.comm.allgather(total_dof_aero) - ax1 = np.sum(ax_list[:irank]) - ax2 = np.sum(ax_list[:irank+1]) - - sx_list = self.comm.allgather(nn_s * 3) - sx1 = np.sum(sx_list[:irank]) - sx2 = np.sum(sx_list[:irank+1]) - - su_list = self.comm.allgather(total_dof_struct) - su1 = np.sum(su_list[:irank]) - su2 = np.sum(su_list[:irank+1]) - # Inputs - self.add_input('x_aero0', shape=total_dof_aero, - src_indices=np.arange(ax1, ax2, dtype=int), + self.add_input('x_aero0', shape_by_conn=True, desc='Initial aerodynamic surface node coordinates') - self.add_input('x_struct0', shape = nn_s * 3, - src_indices = np.arange(sx1, sx2, dtype=int), + self.add_input('x_struct0', shape_by_conn=True, desc='initial structural node coordinates') - self.add_input('u_struct', shape=total_dof_struct, - src_indices=np.arange(su1, su2, dtype=int), + self.add_input('u_struct', shape_by_conn=True, desc='Structural node displacements') - - self.add_input('f_aero', shape=total_dof_aero, - src_indices=np.arange(ax1, ax2, dtype=int), + self.add_input('f_aero', shape_by_conn=True, desc='Aerodynamic force vector') # Outputs diff --git a/mphys/mphys_tacs.py b/mphys/mphys_tacs.py index 64909bff..aebf00f4 100644 --- a/mphys/mphys_tacs.py +++ b/mphys/mphys_tacs.py @@ -34,14 +34,7 @@ def setup(self): # self.add_output('x_struct0_surface', shape= self.surface_nodes.size, desc='structural node coordinates') def mphys_add_coordinate_input(self): - local_size = self.xpts.getArray().size - 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_struct0_points', shape=local_size, src_indices=np.arange(n1, n2, dtype=int), desc='structural node coordinates') + self.add_input('x_struct0_points', shape_by_conn=True, desc='structural node coordinates') # return the promoted name and coordinates return 'x_struct0_points', self.xpts.getArray() @@ -126,13 +119,10 @@ def setup(self): node_size = self.xpt_sens.getArray().size self.ndof = int(state_size/(node_size/3)) - state_indices = self._create_global_index_list_for_rank(state_size) - node_indices = self._create_global_index_list_for_rank(node_size) - # inputs - self.add_input('dv_struct', shape=ndv, desc='tacs design variables') - self.add_input('x_struct0', shape=node_size , src_indices=node_indices, desc='structural node coordinates') - self.add_input('f_struct', shape=state_size, src_indices=state_indices, desc='structural load vector') + self.add_input('dv_struct', shape_by_conn=True, desc='tacs design variables') + self.add_input('x_struct0', shape_by_conn=True, desc='structural node coordinates') + self.add_input('f_struct', shape_by_conn=True, desc='structural load vector') # outputs # its important that we set this to zero since this displacement value is used for the first iteration of the aero @@ -141,13 +131,6 @@ def setup(self): # partials #self.declare_partials('u_struct',['dv_struct','x_struct0','f_struct']) - def _create_global_index_list_for_rank(self,local_size): - size_on_each_rank = self.comm.allgather(local_size) - start = np.sum(size_on_each_rank[:self.comm.rank]) - end = np.sum(size_on_each_rank[:self.comm.rank+1]) - indices = np.arange(start, end, dtype=int) - return indices - def get_ndof(self): return self.solver_dict['ndof'] @@ -438,30 +421,15 @@ def setup(self): self.mapping = self.solver_dict['mapping'] - node_size = self.xpt_sens.getArray().size # self.ndof = int(state_size/(node_size/3)) - s_list = self.comm.allgather(surface_nodes.size//3) - n_list = self.comm.allgather(node_size) - irank = self.comm.rank - - s1 = np.sum(s_list[:irank]) - s2 = np.sum(s_list[:irank+1]) - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - - # inputs # self.add_input('dv_struct', shape=ndv , desc='tacs design variables') - print('conduction x_struct0', node_size) - self.add_input('x_struct0', shape=node_size , src_indices=np.arange(n1, n2, dtype=int), desc='structural node coordinates') - - print('conduction heat_xfer', surface_nodes.size/3) - self.add_input('q_conduct', shape=surface_nodes.size//3, src_indices=np.arange(s1, s2, dtype=int), desc='structural load vector') + self.add_input('x_struct0', shape_by_conn=True, desc='structural node coordinates') + self.add_input('q_conduct', shape_by_conn=True, desc='structural load vector') # outputs - print('conduction temp_cond', surface_nodes.size/3) self.add_output('T_conduct', shape=surface_nodes.size//3, val = np.ones(surface_nodes.size//3)*300,desc='temperature vector') # partials @@ -573,25 +541,14 @@ def setup(self): self.func_list = func_list self.ans = tacs_assembler.createVec() - state_size = self.ans.getArray().size self.xpt_sens = tacs_assembler.createNodeVec() - node_size = self.xpt_sens.getArray().size - - s_list = self.comm.allgather(state_size) - n_list = self.comm.allgather(node_size) - irank = self.comm.rank - - s1 = np.sum(s_list[:irank]) - s2 = np.sum(s_list[:irank+1]) - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) # OpenMDAO part of setup # TODO move the dv_struct to an external call where we add the DVs - self.add_input('dv_struct', shape=ndv, src_indices=np.arange(ndv), desc='tacs design variables') - self.add_input('x_struct0', shape=node_size, src_indices=np.arange(n1, n2, dtype=int), desc='structural node coordinates') - self.add_input('u_struct', shape=state_size, src_indices=np.arange(s1, s2, dtype=int), desc='structural state vector') + self.add_input('dv_struct', shape_by_conn=True, desc='tacs design variables') + self.add_input('x_struct0', shape_by_conn=True, desc='structural node coordinates') + self.add_input('u_struct', shape_by_conn=True, desc='structural state vector') # Remove the mass function from the func list if it is there # since it is not dependent on the structural state @@ -602,7 +559,7 @@ def setup(self): self.func_list = func_no_mass if len(self.func_list) > 0: - self.add_output('f_struct', shape=len(self.func_list), desc='structural function values') + self.add_output('func_struct', shape=len(self.func_list), desc='structural function values') # declare the partials #self.declare_partials('f_struct',['dv_struct','x_struct0','u_struct']) @@ -640,9 +597,9 @@ def compute(self,inputs,outputs): if self.check_partials: self._update_internal(inputs) - if 'f_struct' in outputs: - outputs['f_struct'] = self.tacs_assembler.evalFunctions(self.func_list) - print('f_struct',outputs['f_struct']) + if 'func_struct' in outputs: + outputs['func_struct'] = self.tacs_assembler.evalFunctions(self.func_list) + print('func_struct',outputs['func_struct']) if self.f5_writer is not None: self.f5_writer(self.tacs_assembler) @@ -657,28 +614,28 @@ def compute_jacvec_product(self,inputs, d_inputs, d_outputs, mode): if self.check_partials: self._update_internal(inputs) - if 'f_struct' in d_outputs: + if 'func_struct' in d_outputs: for ifunc, func in enumerate(self.func_list): self.tacs_assembler.evalFunctions([func]) if 'dv_struct' in d_inputs: dvsens = np.zeros(d_inputs['dv_struct'].size,dtype=TACS.dtype) self.tacs_assembler.evalDVSens(func, dvsens) - d_inputs['dv_struct'][:] += np.array(dvsens,dtype=float) * d_outputs['f_struct'][ifunc] + d_inputs['dv_struct'][:] += np.array(dvsens,dtype=float) * d_outputs['func_struct'][ifunc] if 'x_struct0' in d_inputs: xpt_sens = self.xpt_sens xpt_sens_array = xpt_sens.getArray() self.tacs_assembler.evalXptSens(func, xpt_sens) - d_inputs['x_struct0'][:] += np.array(xpt_sens_array,dtype=float) * d_outputs['f_struct'][ifunc] + d_inputs['x_struct0'][:] += np.array(xpt_sens_array,dtype=float) * d_outputs['func_struct'][ifunc] if 'u_struct' in d_inputs: prod = self.tacs_assembler.createVec() self.tacs_assembler.evalSVSens(func,prod) prod_array = prod.getArray() - d_inputs['u_struct'][:] += np.array(prod_array,dtype=float) * d_outputs['f_struct'][ifunc] + d_inputs['u_struct'][:] += np.array(prod_array,dtype=float) * d_outputs['func_struct'][ifunc] class TacsMass(om.ExplicitComponent): """ @@ -702,7 +659,7 @@ def setup(self): self.struct_objects = self.options['struct_objects'] self.check_partials = self.options['check_partials'] - self.set_check_partial_options(wrt='*',directional=True) + #self.set_check_partial_options(wrt='*',directional=True) tacs_assembler = self.tacs_assembler @@ -711,17 +668,10 @@ def setup(self): ndv = self.struct_objects[3]['ndv'] self.xpt_sens = tacs_assembler.createNodeVec() - node_size = self.xpt_sens.getArray().size - - n_list = self.comm.allgather(node_size) - irank = self.comm.rank - - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) # OpenMDAO part of setup - self.add_input('dv_struct', shape=ndv, desc='tacs design variables') - self.add_input('x_struct0', shape=node_size, src_indices=np.arange(n1, n2, dtype=int), desc='structural node coordinates') + self.add_input('dv_struct', shape=ndv, desc='tacs design variables') + self.add_input('x_struct0', shape_by_conn=True, desc='structural node coordinates') self.add_output('mass', 0.0, desc = 'structural mass') #self.declare_partials('mass',['dv_struct','x_struct0']) @@ -796,15 +746,9 @@ def setup(self): state_size = tmp.getArray().size self.ndof = int(state_size / ( node_size / 3 )) - irank = self.comm.rank - - n_list = self.comm.allgather(node_size) - n1 = np.sum(n_list[:irank]) - n2 = np.sum(n_list[:irank+1]) - # OpenMDAO setup - self.add_input('x_struct0', shape=node_size, src_indices=np.arange(n1, n2, dtype=int), desc='structural node coordinates') - self.add_output('f_struct', shape=state_size, desc='structural load') + self.add_input('x_struct0', shape_by_conn=True, desc='structural node coordinates') + self.add_output('f_struct', shape=state_size, desc='structural load') #self.declare_partials('f_struct','x_struct0') diff --git a/mphys/mphys_vlm.py b/mphys/mphys_vlm.py index 10792aef..e9f39d54 100644 --- a/mphys/mphys_vlm.py +++ b/mphys/mphys_vlm.py @@ -50,14 +50,9 @@ def initialize(self): def setup(self): aero_nnodes = self.options['nnodes'] local_size = aero_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') diff --git a/tests/input_files/get-input-files.sh b/tests/input_files/get-input-files.sh old mode 100644 new mode 100755 diff --git a/tests/unit_tests/meld_check_partials.py b/tests/integration_tests/meld_check_partials.py similarity index 100% rename from tests/unit_tests/meld_check_partials.py rename to tests/integration_tests/meld_check_partials.py diff --git a/tests/unit_tests/tacs_check_partials.py b/tests/integration_tests/tacs_check_partials.py similarity index 92% rename from tests/unit_tests/tacs_check_partials.py rename to tests/integration_tests/tacs_check_partials.py index cec230dc..814b685b 100644 --- a/tests/unit_tests/tacs_check_partials.py +++ b/tests/integration_tests/tacs_check_partials.py @@ -45,10 +45,10 @@ def forcer(x_s0,ndof): tacs_options = {'add_elements': add_elements, 'get_funcs' : get_funcs, - 'mesh_file' : 'debug.bdf', - 'forcer_func' : forcer} + 'mesh_file' : '../input_files/debug.bdf', + 'load_function' : forcer} - tacs_builder = TacsBuilder(tacs_options) + tacs_builder = TacsBuilder(tacs_options, check_partials=True) ################################################################################ # MPHY setup @@ -75,6 +75,6 @@ def configure(self): prob = om.Problem() prob.model = Top() -prob.setup(force_alloc_complex=True) +prob.setup(mode='rev',force_alloc_complex=True) prob.run_model() prob.check_partials(method='cs',compact_print=True) diff --git a/tests/unit_tests/test_aero_derivs.py b/tests/integration_tests/test_adflow_derivs.py similarity index 97% rename from tests/unit_tests/test_aero_derivs.py rename to tests/integration_tests/test_adflow_derivs.py index e002c5b7..f7f9dee0 100644 --- a/tests/unit_tests/test_aero_derivs.py +++ b/tests/integration_tests/test_adflow_derivs.py @@ -85,7 +85,7 @@ def setup(self): CFDSolver = ADFLOW(options=aero_options) - x_a = CFDSolver.getSurfaceCoordinates(groupName="allWalls") + x_a = CFDSolver.getSurfaceCoordinates(groupName="allWalls").flatten() dvs.add_output("x_aero", val=x_a) # create the multiphysics multipoint group. @@ -106,12 +106,12 @@ def configure(self): chordRef=3.25, evalFuncs=["lift", "drag", "cl", "cd"], ) - ap0.addDV("alpha", value=2.0, name="aoa") + ap0.addDV("alpha", value=2.0, name="aoa", units="deg") self.mp.s0.solver_group.aero.mphys_set_ap(ap0) # self.mp.s0.solver_group.aero_funcs.mphys_set_ap(ap0) self.mp.s0.aero_funcs.mphys_set_ap(ap0) - self.dvs.add_output("aoa", val=alpha0, units='deg') + self.dvs.add_output("aoa", val=alpha0, units="deg") self.connect("x_aero", ["mp.aero_mesh.x_aero0_points"]) # self.connect("aoa", ["mp.s0.solver_group.aero.aoa", "mp.s0.aero_funcs.aoa"]) diff --git a/tests/unit_tests/test_con_derivs.py b/tests/integration_tests/test_con_derivs.py similarity index 100% rename from tests/unit_tests/test_con_derivs.py rename to tests/integration_tests/test_con_derivs.py diff --git a/tests/unit_tests/test_geom_derivs.py b/tests/integration_tests/test_geom_derivs.py similarity index 100% rename from tests/unit_tests/test_geom_derivs.py rename to tests/integration_tests/test_geom_derivs.py diff --git a/tests/unit_tests/test_meld.py b/tests/integration_tests/test_meld_derivs.py similarity index 100% rename from tests/unit_tests/test_meld.py rename to tests/integration_tests/test_meld_derivs.py diff --git a/tests/unit_tests/test_struct_derivs.py b/tests/integration_tests/test_tacs_derivs.py similarity index 86% rename from tests/unit_tests/test_struct_derivs.py rename to tests/integration_tests/test_tacs_derivs.py index cd1d304c..cd552635 100644 --- a/tests/unit_tests/test_struct_derivs.py +++ b/tests/integration_tests/test_tacs_derivs.py @@ -85,7 +85,7 @@ def f5_writer(tacs): struct_options = { 'add_elements': add_elements, 'get_funcs': get_funcs, - 'mesh_file': os.path.join(baseDir, '../input_files/wingbox.bdf'), + 'mesh_file': os.path.join(baseDir, '../input_files/debug.bdf'), # 'f5_writer' : f5_writer, } @@ -138,13 +138,13 @@ def setUp(self): # objectives and nonlinear constraints prob.model.add_objective('mp.s0.struct_funcs.mass', ref=100.0) - prob.model.add_constraint('mp.s0.struct_funcs.funcs.f_struct', ref=1.0, upper=1.0) + prob.model.add_constraint('mp.s0.struct_funcs.funcs.func_struct', ref=1.0, upper=1.0) - prob.model.add_design_var('dv_struct', indices=[0, 3, 5], lower=-5, upper=10, ref=10.0) - prob.model.add_design_var('f_struct', indices=[0, 12, 34, 100], lower=-5, upper=10, ref=10.0) + prob.model.add_design_var('dv_struct', indices=[0], lower=-5, upper=10, ref=10.0) + prob.model.add_design_var('f_struct', indices=[0, 12, 34, 40], lower=-5, upper=10, ref=10.0) prob.model.add_design_var('xpts', indices=[0, 2, 5, 10], lower=-5, upper=10, ref=10.0) - prob.setup(mode='rev') + prob.setup(mode='rev',force_alloc_complex=True) # om.n2( # prob, # show_browser=False, @@ -159,23 +159,22 @@ def test_run_model(self): def test_derivatives(self): self.prob.run_model() print('----------------strating check totals--------------') - # data = self.prob.check_totals(step=1e-7, form='forward') - data = self.prob.check_totals(wrt='xpts', step=1e-7, step_calc='rel') # out_stream=None + data = self.prob.check_totals(wrt='xpts', method='cs', step=1e-30, step_calc='rel') # out_stream=None for var, err in data.items(): rel_err = err['rel error'] # , 'rel error'] - assert_near_equal(rel_err.forward, 0.0, 1e-2) - data = self.prob.check_totals(of=['mp.s0.struct_funcs.funcs.f_struct'], wrt='f_struct', step=3e-5, step_calc='rel') # out_stream=None + assert_near_equal(rel_err.forward, 0.0, 1e-8) + data = self.prob.check_totals(of=['mp.s0.struct_funcs.funcs.func_struct'], wrt='f_struct', method='cs', step=1e-30, step_calc='rel') # out_stream=None for var, err in data.items(): rel_err = err['rel error'] # , 'rel error'] - assert_near_equal(rel_err.forward, 0.0, 1e-2) - data = self.prob.check_totals(wrt='dv_struct', step=5e-6, step_calc='rel') # out_stream=None + assert_near_equal(rel_err.forward, 0.0, 1e-8) + data = self.prob.check_totals(wrt='dv_struct', method='cs', step=1e-30, step_calc='rel') # out_stream=None for var, err in data.items(): rel_err = err['rel error'] # , 'rel error'] - assert_near_equal(rel_err.forward, 0.0, 1e-2) + assert_near_equal(rel_err.forward, 0.0, 5e-8) if __name__ == '__main__': diff --git a/tests/unit_tests/vlm_check_partials.py b/tests/integration_tests/vlm_check_partials.py similarity index 90% rename from tests/unit_tests/vlm_check_partials.py rename to tests/integration_tests/vlm_check_partials.py index 4d5bcd16..b32b6da1 100644 --- a/tests/unit_tests/vlm_check_partials.py +++ b/tests/integration_tests/vlm_check_partials.py @@ -12,7 +12,7 @@ def setup(self): # VLM options aero_options = { - 'mesh_file':'debug_VLM.dat', + 'mesh_file':'../input_files/debug_VLM.dat', 'mach':0.85, 'aoa':1*np.pi/180., 'q_inf':25000., @@ -58,7 +58,9 @@ def read_VLM_mesh(mesh): def configure(self): self.dvs.add_output('aoa', self.aero_options['aoa'], units='rad') + self.dvs.add_output('u_aero', np.zeros_like(self.aero_options['x_aero0'])) self.connect('aoa',['mp_group.s0.solver_group.aero.aoa']) + self.connect('u_aero','mp_group.s0.solver_group.aero.u_aero') ## openmdao setup diff --git a/tests/unit_tests/vlm_tacs_meld_check_partials.py b/tests/integration_tests/vlm_tacs_meld_check_partials.py similarity index 86% rename from tests/unit_tests/vlm_tacs_meld_check_partials.py rename to tests/integration_tests/vlm_tacs_meld_check_partials.py index c6c2c525..0030c879 100644 --- a/tests/unit_tests/vlm_tacs_meld_check_partials.py +++ b/tests/integration_tests/vlm_tacs_meld_check_partials.py @@ -18,7 +18,7 @@ class Top(om.Group): def setup(self): # VLM options aero_options = { - 'mesh_file':'debug_VLM.dat', + 'mesh_file':'../input_files/debug_VLM.dat', 'mach':0.85, 'aoa':1*np.pi/180., 'q_inf':25000., @@ -52,7 +52,7 @@ def read_VLM_mesh(mesh): aero_options['N_nodes'], aero_options['N_elements'], aero_options['x_aero0'], aero_options['quad'] = read_VLM_mesh(aero_options['mesh_file']) self.aero_options = aero_options - # VLM assembler + # VLM builder aero_builder = VlmBuilder(aero_options) # TACS setup @@ -97,7 +97,7 @@ def f5_writer(tacs): # common setup options tacs_setup = {'add_elements': add_elements, 'get_funcs' : get_funcs, - 'mesh_file' : 'debug.bdf', + 'mesh_file' : '../input_files/debug.bdf', 'f5_writer' : f5_writer } # TACS assembler @@ -106,7 +106,7 @@ def f5_writer(tacs): tacs_setup['nmodes'] = 15 #struct_assembler = ModalStructAssembler(tacs_setup) else: - struct_builder = TacsBuilder(tacs_setup,check_partials=True) + struct_builder = TacsBuilder(tacs_setup, check_partials=True) # MELD setup @@ -128,11 +128,16 @@ def f5_writer(tacs): s0 = mp.mphys_add_scenario('s0') def configure(self): - self.dvs.add_output('aoa', self.aero_options['aoa'], units='rad') - #self.connect('aoa',['mp_group.s0.aero.aoa']) + for dv_name in ['aoa','q_inf','vel','mu','mach']: + if dv_name == 'aoa': + self.dvs.add_output(dv_name, val=self.aero_options[dv_name], units='rad') + else: + self.dvs.add_output(dv_name, val=self.aero_options[dv_name]) + self.connect(dv_name, 'mp_group.s0.solver_group.aero.%s' % dv_name) self.dvs.add_output('dv_struct',np.array([0.03])) - #self.connect('dv_struct',['mp_group.so.struct.dv_struct']) + self.connect('dv_struct',['mp_group.s0.solver_group.struct.dv_struct', + 'mp_group.s0.struct_funcs.dv_struct' ]) # OpenMDAO setup diff --git a/tests/unit_tests/vlm_tacs_meld_check_totals.py b/tests/integration_tests/vlm_tacs_meld_check_totals.py similarity index 84% rename from tests/unit_tests/vlm_tacs_meld_check_totals.py rename to tests/integration_tests/vlm_tacs_meld_check_totals.py index fd2a86ae..d69f34db 100644 --- a/tests/unit_tests/vlm_tacs_meld_check_totals.py +++ b/tests/integration_tests/vlm_tacs_meld_check_totals.py @@ -17,7 +17,7 @@ class Top(om.Group): def setup(self): # VLM options aero_options = { - 'mesh_file':'debug_VLM.dat', + 'mesh_file':'../input_files/debug_VLM.dat', 'mach':0.85, 'aoa':1*np.pi/180., 'q_inf':25000., @@ -96,7 +96,7 @@ def f5_writer(tacs): # common setup options tacs_setup = {'add_elements': add_elements, 'get_funcs' : get_funcs, - 'mesh_file' : 'debug.bdf', + 'mesh_file' : '../input_files/debug.bdf', 'f5_writer' : f5_writer } # TACS assembler @@ -105,7 +105,7 @@ def f5_writer(tacs): tacs_setup['nmodes'] = 15 #struct_assembler = ModalStructAssembler(tacs_setup) else: - struct_builder = TacsBuilder(tacs_setup,check_partials=True) + struct_builder = TacsBuilder(tacs_setup, check_partials=True) # MELD setup @@ -127,23 +127,28 @@ def f5_writer(tacs): s0 = mp.mphys_add_scenario('s0') def configure(self): - self.dvs.add_output('aoa', self.aero_options['aoa'], units='rad') - self.connect('aoa',['mp_group.s0.solver_group.aero.aoa']) + for dv_name in ['aoa','q_inf','vel','mu','mach']: + if dv_name == 'aoa': + self.dvs.add_output(dv_name, val=self.aero_options[dv_name], units='rad') + else: + self.dvs.add_output(dv_name, val=self.aero_options[dv_name]) + self.connect(dv_name, 'mp_group.s0.solver_group.aero.%s' % dv_name) self.dvs.add_output('dv_struct',np.array([0.03])) - self.connect('dv_struct',['mp_group.s0.solver_group.struct.dv_struct, mp_group.s0.struct_funcs.dv_struct']) + self.connect('dv_struct',['mp_group.s0.solver_group.struct.dv_struct', + 'mp_group.s0.struct_funcs.dv_struct' ]) # OpenMDAO setup prob = om.Problem() prob.model = Top() -prob.setup(force_alloc_complex=True) +prob.setup(force_alloc_complex=True, mode='rev') prob.model.mp_group.s0.nonlinear_solver = om.NonlinearBlockGS(maxiter=100, iprint=2, use_aitken=True, atol=1E-9) prob.model.mp_group.s0.linear_solver = om.LinearBlockGS(maxiter=10, iprint=2) -prob.setup(force_alloc_complex=True, mode='rev') +om.n2(prob, show_browser=False, outfile='check_totals.html') prob.run_model() -prob.check_totals(of=['mp_group.s0.struct.funcs.f_struct'], wrt=['aoa'], method='cs') +prob.check_totals(of=['mp_group.s0.struct_funcs.funcs.func_struct'], wrt=['aoa'], method='cs') diff --git a/tests/reg_tests/test_aerostruct.py b/tests/regression_tests/test_aerostruct.py similarity index 97% rename from tests/reg_tests/test_aerostruct.py rename to tests/regression_tests/test_aerostruct.py index f04123ff..5bcab893 100644 --- a/tests/reg_tests/test_aerostruct.py +++ b/tests/regression_tests/test_aerostruct.py @@ -208,7 +208,7 @@ def configure(self): "ref_vals": { "xa": 5.443441765975671, "cl": 0.33844664, - "f_struct": 0.24355979, + "func_struct": 0.24355979, "cd": 0.02988495, }, }, @@ -216,7 +216,7 @@ def configure(self): "name": "rlt", "xfer_builder_class": RltBuilder, "xfer_options": {"transfergaussorder": 2}, - "ref_vals": {"xa": 5.504999831790868, "f_struct": 0.31363742, "cl": 0.3047756, "cd": 0.0280476}, + "ref_vals": {"xa": 5.504999831790868, "func_struct": 0.31363742, "cl": 0.3047756, "cd": 0.0280476}, }, ] ) @@ -254,7 +254,7 @@ def test_run_model(self): print("xa =", np.mean(self.prob.get_val("mp_group.s0.solver_group.aero.geo_disp.x_aero", get_remote=True))) print("cl =", self.prob.get_val("mp_group.s0.aero_funcs.cl", get_remote=True)) print("cd =", self.prob.get_val("mp_group.s0.aero_funcs.cd", get_remote=True)) - print("cd =", self.prob.get_val("mp_group.s0.struct_funcs.funcs.f_struct", get_remote=True)) + print("cd =", self.prob.get_val("mp_group.s0.struct_funcs.funcs.func_struct", get_remote=True)) assert_near_equal( np.mean(self.prob.get_val("mp_group.s0.solver_group.aero.geo_disp.x_aero", get_remote=True)), @@ -268,7 +268,7 @@ def test_run_model(self): np.mean(self.prob.get_val("mp_group.s0.aero_funcs.cd", get_remote=True)), self.ref_vals["cd"], 1e-6 ) assert_near_equal( - np.mean(self.prob.get_val("mp_group.s0.struct_funcs.funcs.f_struct", get_remote=True)), - self.ref_vals["f_struct"], + np.mean(self.prob.get_val("mp_group.s0.struct_funcs.funcs.func_struct", get_remote=True)), + self.ref_vals["func_struct"], 1e-6, )