def test_architecture(): """Test architecture construction routines """ test_archi_dict = generate_architecture_dict() for archi_name in list(test_archi_dict.keys()): architecture = test_archi_dict[archi_name] test_archi = archi.Architecture(architecture['parent_map']) assert test_archi.kite_nodes == architecture[ 'kite_nodes'], 'kite_nodes of ' + archi_name assert test_archi.layer_nodes == architecture[ 'layer_nodes'], 'layer nodes of ' + archi_name assert test_archi.layers == architecture[ 'layers'], 'layers of ' + archi_name assert test_archi.siblings_map == architecture[ 'siblings_map'], 'siblings_map of ' + archi_name assert test_archi.number_of_nodes == architecture[ 'number_of_nodes'], 'number_of_nodes of ' + archi_name assert test_archi.children_map == architecture[ 'children_map'], 'children map of ' + archi_name assert test_archi.kites_map == architecture[ 'kites_map'], 'kite-children map of ' + archi_name
def build(self, is_standalone_trial=True): if is_standalone_trial: print_op.log_license_info() if self.__options['user_options']['trajectory']['type'] == 'mpc': raise ValueError( 'Build method not supported for MPC trials. Use PMPC wrapper instead.' ) awelogger.logger.info('') awelogger.logger.info('Building trial (%s) ...', self.__name) awelogger.logger.info('') architecture = archi.Architecture( self.__options['user_options']['system_model']['architecture']) self.__options.build(architecture) self.__model.build(self.__options['model'], architecture) self.__formulation.build(self.__options['formulation'], self.__model) self.__nlp.build(self.__options['nlp'], self.__model, self.__formulation) self.__optimization.build(self.__options['solver'], self.__nlp, self.__model, self.__formulation, self.__name) self.__visualization.build(self.__model, self.__nlp, self.__name, self.__options) self.__quality.build(self.__options['quality'], self.__name) self.set_timings('construction') awelogger.logger.info('Trial (%s) built.', self.__name) awelogger.logger.info( 'Trial construction time: %s', print_op.print_single_timing(self.__timings['construction'])) awelogger.logger.info('')
def __build_trial(self): """ Build options, model, formulation and nlp of mpc trial. """ awelogger.logger.info("Building MPC trial...") # build import awebox.mdl.architecture as archi architecture = archi.Architecture(self.__trial.options['user_options']['system_model']['architecture']) self.__trial.options.build(architecture) self.__trial.model.build(self.__trial.options['model'], architecture) self.__trial.formulation.build(self.__trial.options['formulation'], self.__trial.model) self.__trial.nlp.build(self.__trial.options['nlp'], self.__trial.model, self.__trial.formulation) self.__trial.visualization.build(self.__trial.model, self.__trial.nlp, 'MPC control', self.__trial.options) return None
def build(self, is_standalone_trial=True): if is_standalone_trial: print_op.log_license_info() logging.info('') logging.info('Building trial (%s) ...', self.__name) logging.info('') architecture = archi.Architecture(self.__options['user_options']['system_model']['architecture']) self.__options.build(architecture) self.__model.build(self.__options['model'], architecture) self.__formulation.build(self.__options['formulation'], self.__model) self.__nlp.build(self.__options['nlp'], self.__model, self.__formulation) self.__optimization.build(self.__options['solver'], self.__nlp, self.__model, self.__formulation, self.__name) self.__visualization.build(self.__model, self.__nlp, self.__name, self.__options) self.__quality.build(self.__options['quality'], self.__name) self.set_timings('construction') logging.info('Trial (%s) built.', self.__name) logging.info('Trial construction time: %s',print_op.print_single_timing(self.__timings['construction'])) logging.info('')
def test(gamma_scale=1.): architecture = archi.Architecture({1: 0}) options = {} options['induction'] = {} options['induction']['vortex_gamma_scale'] = gamma_scale options['induction']['vortex_wake_nodes'] = 2 options['induction']['vortex_far_convection_time'] = 1. options['induction']['vortex_u_ref'] = 1. options['induction']['vortex_position_scale'] = 1. kite = architecture.kite_nodes[0] xd_struct = cas.struct([ cas.entry("wx_" + str(kite) + "_ext_0", shape=(3, 1)), cas.entry("wx_" + str(kite) + "_ext_1", shape=(3, 1)), cas.entry("wx_" + str(kite) + "_int_0", shape=(3, 1)), cas.entry("wx_" + str(kite) + "_int_1", shape=(3, 1)) ]) xl_struct = cas.struct([cas.entry("wg_" + str(kite) + "_0")]) var_struct = cas.struct_symSX( [cas.entry('xd', struct=xd_struct), cas.entry('xl', struct=xl_struct)]) variables = var_struct(0.) variables['xd', 'wx_' + str(kite) + '_ext_0'] = 0.5 * vect_op.yhat_np() variables['xd', 'wx_' + str(kite) + '_int_0'] = -0.5 * vect_op.yhat_np() variables['xd', 'wx_' + str(kite) + '_ext_1'] = variables['xd', 'wx_' + str(kite) + '_ext_0'] + vect_op.xhat_np() variables['xd', 'wx_' + str(kite) + '_int_1'] = variables['xd', 'wx_' + str(kite) + '_int_0'] + vect_op.xhat_np() variables['xl', 'wg_' + str(kite) + '_0'] = 1. / gamma_scale test_list = get_list(options, variables, architecture) filaments = test_list.shape[1] filament_count_test = filaments - 6 if not (filament_count_test == 0): message = 'filament list does not work as expected. difference in number of filaments in test_list = ' + str( filament_count_test) awelogger.logger.error(message) raise Exception(message) LE_expected = cas.DM(np.array([0., -0.5, 0., 0., 0.5, 0., 1.])) PE_expected = cas.DM(np.array([0., 0.5, 0., 1., 0.5, 0., 1.])) TE_expected = cas.DM(np.array([1., -0.5, 0., 0., -0.5, 0., 1.])) expected_filaments = { 'leading edge': LE_expected, 'positive edge': PE_expected, 'trailing edge': TE_expected } for type in expected_filaments.keys(): expected_filament = expected_filaments[type] expected_in_list = expected_filament_in_list(test_list, expected_filament) if not expected_in_list: message = 'filament list does not work as expected. ' + type + \ ' test filament not in test_list.' awelogger.logger.error(message) with np.printoptions(precision=3, suppress=True): print('test_list:') print(np.array(test_list)) raise Exception(message) NE_not_expected = cas.DM(np.array([1., -0.5, 0., 1., 0.5, 0., -1.])) not_expected_filaments = {'negative edge': NE_not_expected} for type in not_expected_filaments.keys(): not_expected_filament = not_expected_filaments[type] is_reasonable = not (expected_filament_in_list(test_list, not_expected_filament)) if not is_reasonable: message = 'filament list does not work as expected. ' + type + \ ' test filament in test_list.' awelogger.logger.error(message) with np.printoptions(precision=3, suppress=True): print('test_list:') print(np.array(test_list)) raise Exception(message) return test_list