def test_DLLM_valid_grad_TLift(self): OC, wing_param = self.__init_wing_param() x0 = wing_param.get_dv_array() DLLM = DLLMTargetLift('Simple', wing_param, OC) F_list_names = DLLM.get_DLLMPost().DEF_F_LIST_NAMES F_list_names.remove('Lift') def f2(x): wing_param.update_from_x_list(x) DLLM = DLLMTargetLift('Simple', wing_param, OC) DLLM.set_target_Lift(769200.) DLLM.set_F_list_names(F_list_names) DLLM.run_direct() DLLM.run_post() func = DLLM.get_F_list() return func def df2(x): wing_param.update_from_x_list(x) DLLM = DLLMTargetLift('Simple', wing_param, OC) DLLM.set_target_Lift(769200.) DLLM.set_F_list_names(F_list_names) DLLM.run_direct() DLLM.run_post() DLLM.run_adjoint() func_grad = array(DLLM.get_dF_list_dchi()) return func_grad val_grad2 = FDValidGrad(2, f2, df2, fd_step=1.e-8) ok2, df_fd2, df2 = val_grad2.compare(x0, treshold=1.e-6, split_out=True, return_all=True) assert (ok2)
def f2(x): wing_param.update_from_x_list(x) DLLM = DLLMTargetLift('Simple', wing_param, OC) DLLM.set_target_Lift(769200.) DLLM.set_F_list_names(F_list_names) DLLM.run_direct() DLLM.run_post() func = DLLM.get_F_list() return func
def df2(x): wing_param.update_from_x_list(x) DLLM = DLLMTargetLift('Simple', wing_param, OC) DLLM.set_target_Lift(769200.) DLLM.set_F_list_names(F_list_names) DLLM.run_direct() DLLM.run_post() DLLM.run_adjoint() func_grad = array(DLLM.get_dF_list_dchi()) return func_grad
def test_DLLM_valid_TLift(self): OC, wing_param = self.__init_wing_param() DLLM = DLLMTargetLift('Simple', wing_param, OC) DLLM.set_target_Lift(769200.) DLLM.run_direct() DLLM.run_post() F_list = DLLM.get_F_list() F_list_names = DLLM.get_F_list_names() lift_index = F_list_names.index('Lift') Lift = F_list[lift_index] assert (abs(Lift - 769200.) < 1.e-2)
def __config_DLLM(self): WARNING_MSG=self.WARNING_MSG+'__config_DLLM: ' input_keys=self.__config_dict.keys() type_key = self.__tag+'.DLLM.type' type = self.__config_dict[type_key] if type not in self.POS_SOLVER: print WARNING_MSG+'solver_type = '+str(solve_type)+' not in '+str(self.POS_SOLVER)+'. Set to default solver_type = Solver' type='Solver' if type == 'Solver': self.__DLLM_solver = DLLMSolver(self.__tag,self.__wing_param,self.__OC) elif type == 'TargetCl': self.__DLLM_solver = DLLMTargetCl(self.__tag,self.__wing_param,self.__OC) target_Cl_key = self.__tag+'.DLLM.target_Cl' target_Cl = self.__config_dict[target_Cl_key] self.__DLLM_solver.set_target_Cl(target_Cl) elif type == 'TargetLift': self.__DLLM_solver = DLLMTargetLift(self.__tag,self.__wing_param,self.__OC) target_Lift_key = self.__tag+'.DLLM.target_Lift' target_Lift = self.__config_dict[target_Lift_key] self.__DLLM_solver.set_target_Lift(target_Lift) method_key = self.__tag+'.DLLM.method' if method_key in input_keys: method = self.__config_dict[method_key] self.__DLLM_solver.set_method(method) relax_factor_key = self.__tag+'.DLLM.relax_factor' if relax_factor_key in input_keys: relax_factor = self.__config_dict[relax_factor_key] self.__DLLM_solver.set_relax_factor(relax_factor) stop_residual_key = self.__tag+'.DLLM.stop_residual' if stop_residual_key in input_keys: stop_residual = self.__config_dict[stop_residual_key] self.__DLLM_solver.set_stop_residual(stop_residual) max_iterations_key = self.__tag+'.DLLM.max_iterations' if max_iterations_key in input_keys: max_iterations = self.__config_dict[max_iterations_key] self.__DLLM_solver.set_max_iterations(max_iterations) gamma_file_name_key = self.__tag+'.DLLM.gamma_file_name' if gamma_file_name_key in input_keys: gamma_file_name = self.__config_dict[gamma_file_name_key] self.__DLLM_solver.set_gamma_file_name(gamma_file_name) F_list_names_key = self.__tag+'.DLLM.F_list_names' if F_list_names_key in input_keys: F_list_names = self.__config_dict[F_list_names_key] self.__DLLM_solver.set_F_list_names(F_list_names)
wing_param.set_value('tip_chord', 1.5) wing_param.set_value('root_height', 1.28) wing_param.set_value('break_height', 0.97) wing_param.set_value('tip_height', 0.33) wing_param.convert_to_design_variable('span', (10., 50.)) wing_param.convert_to_design_variable('sweep', (0., 40.)) wing_param.convert_to_design_variable('break_percent', (20., 40.)) wing_param.convert_to_design_variable('root_chord', (5., 7.)) wing_param.convert_to_design_variable('break_chord', (3., 5.)) wing_param.convert_to_design_variable('tip_chord', (1., 2.)) wing_param.convert_to_design_variable('root_height', (1., 1.5)) wing_param.convert_to_design_variable('break_height', (0.8, 1.2)) wing_param.convert_to_design_variable('tip_height', (0.2, 0.5)) wing_param.build_linear_airfoil(OC, AoA0=-2., Cm0=-0.1, set_as_ref=True) wing_param.build_airfoils_from_ref() wing_param.update() print wing_param DLLM = DLLMTargetLift('TLift', wing_param, OC) DLLM.set_target_Lift(769200.) #DLLM.set_method('scipy') DLLM.run_direct() DLLM.run_post() DLLM.run_adjoint() dF_list_dchi = DLLM.get_dF_list_dchi() # for i,name in enumerate(DLLM.get_F_list_names()): # print 'gradients for '+name+' = ',dF_list_dchi[i]