def fitness(params): try: traces = rocket_architectures.sim_3_boosters(**params) except Exception as ex: print(ex) return 0.0 time, position, velocity, acceleration = traces speed = sqrt(np.sum(velocity * velocity, axis=1)) accel = sqrt(np.sum(acceleration * acceleration, axis=1)) / 9.81 # in Gs max_speed = max(speed) max_acceleration = max(sqrt(np.sum(acceleration * acceleration, axis=1))) max_distance = np.max(position[:, 0]) # print(f"Distance and speed: max height:{np.max(position[:,1]):0.1f}m, distance:{max_distance:0.0f}m, " # + f"max speed:{max_speed:0.0f}m/s, {ms2kmh(max_speed):0.0f}km/h), acceleration:{max_acceleration/9.81:0.0f}g") return max_distance ga = GeneticAlgorithm(params, fitness, population_size=40, generations=30, temperature_factor=0.91) ga.run() best_params = ga.get_best_params() traces = rocket_architectures.sim_3_boosters(**best_params) rocket_architectures.plot_basic(traces)
fin_length = 0.110 traces = sim1( radius = radius, C_drag = 0.32, dry_mass = 0.330, volume = volume, water_l = volume/3, pressure = 10.0, # relative pressure nozzle_radius = 0.011, launch_tube_length = 1.0, # m theta = 45, # degrees rail_length = 1.0, # m extra_frontal_surface = num_fins * fin_length * fin_thickness, timestep = 0.001 ) time, position, velocity, acceleration = traces speed = sqrt(np.sum(velocity * velocity, axis=1)) accel = sqrt(np.sum(acceleration * acceleration, axis=1)) / 9.81 # in Gs max_speed = max(speed) max_acceleration = max(sqrt(np.sum(acceleration * acceleration, axis=1))) print(f"Rocket length:{length:0.01f}m, volume:{volume:0.01f}l") print(f"Distance and speed: max height:{np.max(position[:,1]):0.1f}m, distance:{np.max(position[:,0]):0.0f}m, " + f"max speed:{max_speed:0.0f}m/s, {ms2kmh(max_speed):0.0f}km/h), acceleration:{max_acceleration/9.81:0.0f}g") plot_basic(traces)