def fitness(self, shape_parameters): """ Propagates the trajectory with the shape parameters given as argument. This function uses the shape parameters to set a new aerodynamic coefficient interface, subsequently propagating the trajectory. The fitness, currently set to zero, can be computed here: it will be used during the optimization process. Parameters ---------- shape_parameters : list of floats List of shape parameters to be optimized. Returns ------- fitness : float Fitness value (for optimization, see assignment 3). """ # Delete existing capsule self.bodies.delete_body('Capsule') # Create new capsule with a new coefficient interface based on the current parameters, add it to the body system add_capsule_to_body_system(self.bodies, shape_parameters, self.capsule_density) # Update propagation model with new body shape self.propagator_settings.recreate_state_derivative_models(self.bodies) # Create new aerodynamic guidance guidance_object = CapsuleAerodynamicGuidance(self.bodies, shape_parameters[5]) # Set aerodynamic guidance (this line links the CapsuleAerodynamicGuidance settings with the propagation) environment_setup.set_aerodynamic_guidance( guidance_object, self.bodies.get_body('Capsule')) # Create simulation object and propagate dynamics self.dynamics_simulator = propagation_setup.SingleArcDynamicsSimulator( self.bodies, self.integrator_settings, self.propagator_settings, True) # For the first two assignments, no computation of fitness is needed fitness = 0.0 return fitness
def fitness(self, thrust_parameters: list) -> float: """ Propagate the trajectory with the thrust parameters given as argument. This function uses the thrust parameters to set a new acceleration model, subsequently propagating the trajectory. The fitness, currently set to zero, can be computed here: it will be used during the optimization process. Parameters ---------- thrust_parameters : list of floats List of thrust parameters. Returns ------- fitness : float Fitness value (for optimization, see assignment 3). """ # Retrieve the accelerations from the translational state propagator acceleration_settings = self.translational_state_propagator_settings.acceleration_settings # Clear the existing thrust acceleration acceleration_settings['Vehicle']['Vehicle'].clear() # Get the new thrust settings new_thrust_settings = get_thrust_acceleration_model_from_parameters( thrust_parameters, self.bodies, self.simulation_start_epoch, self.constant_specific_impulse) # Set new acceleration settings acceleration_settings['Vehicle']['Vehicle'].append(new_thrust_settings) # Update translational propagator settings self.translational_state_propagator_settings.reset_and_recreate_acceleration_models( acceleration_settings, self.bodies) # Update full propagator settings self.propagator_settings.recreate_state_derivative_models(self.bodies) # Create simulation object and propagate dynamics self.dynamics_simulator = propagation_setup.SingleArcDynamicsSimulator( self.bodies, self.integrator_settings, self.propagator_settings, True) # For the first two assignments, no computation of fitness is needed fitness = 0.0 return fitness
propagation_setup.acceleration.cannonball_radiation_pressure_type, SC_NAMES[i], "Sun")) acceleration_models = propagation_setup.create_acceleration_models( bodies, acceleration_settings, bodies_to_propagate, central_bodies) # Propagator settings propagator_settings = propagation_setup.propagator.translational( central_bodies, acceleration_models, bodies_to_propagate, initial_state, simulation_end_epoch, output_variables=dependent_variables_to_save) # Integrator settings fixed_step_size = 10.0 #seconds integrator_settings = propagation_setup.integrator.runge_kutta_4( simulation_start_epoch, fixed_step_size) # Create dynamics simulator dynamics_simulator = propagation_setup.SingleArcDynamicsSimulator( bodies, integrator_settings, propagator_settings) # Retrieve Results np.savetxt('AOP_Optimisation_Results.dat', result2array(dynamics_simulator.dependent_variable_history)) np.savetxt('AOP_Optimisation_AOPValues.dat', RAAN)
def fitness(self, trajectory_parameters) -> float: """ Propagate the trajectory using the hodographic method with the parameters given as argument. This function uses the trajectory parameters to create a new hodographic shaping object, from which a new thrust acceleration profile is extracted. Subsequently, the trajectory is propagated numerically, if desired. The fitness, currently set to zero, can be computed here: it will be used during the optimization process. Parameters ---------- trajectory_parameters : list of floats List of trajectory parameters to optimize. Returns ------- fitness : float Fitness value (for optimization, see assignment 3). """ # Create hodographic shaping object self.hodographic_shaping = create_hodographic_shaping_object( trajectory_parameters, self.bodies) # Propagate trajectory only if required if self.perform_propagation: initial_propagation_time = get_trajectory_initial_time( trajectory_parameters, self.time_buffer) # Reset initial time self.integrator_settings.initial_time = initial_propagation_time # Retrieve the accelerations from the translational state propagator acceleration_settings = self.translational_state_propagator_settings.acceleration_settings # Clear the existing thrust acceleration acceleration_settings['Vehicle']['Vehicle'].clear() # Create specific impulse lambda function specific_impulse_function = lambda t: self.specific_impulse # Compute offset, which is the time since J2000 (when t=0 for tudat) at which the simulation starts # N.B.: this is different from time_buffer, which is the delay between the start of the hodographic # trajectory and the beginning of the simulation time_offset = get_trajectory_initial_time(trajectory_parameters) # Retrieve new thrust settings new_thrust_settings = shape_based_thrust.get_low_thrust_acceleration_settings( self.hodographic_shaping, self.bodies, 'Vehicle', specific_impulse_function, time_offset) # Set new acceleration settings acceleration_settings['Vehicle']['Vehicle'].append( new_thrust_settings) # Update translational propagator settings: accelerations self.translational_state_propagator_settings.reset_and_recreate_acceleration_models( acceleration_settings, self.bodies) # Retrieve initial state new_initial_state = get_hodograph_state_at_epoch( trajectory_parameters, self.bodies, initial_propagation_time) # Update translational propagator settings: initial state self.translational_state_propagator_settings.reset_initial_states( new_initial_state) # Update full propagator settings self.propagator_settings.recreate_state_derivative_models( self.bodies) # Reset full initial state new_full_initial_state = propagation_setup.propagator.combine_initial_states( self.propagator_settings.propagator_settings_per_type) self.propagator_settings.reset_initial_states( new_full_initial_state) # Get the termination settings self.propagator_settings.termination_settings = Util.get_termination_settings( trajectory_parameters, self.minimum_mars_distance, self.time_buffer) # Create simulation object and propagate dynamics self.dynamics_simulator = propagation_setup.SingleArcDynamicsSimulator( self.bodies, self.integrator_settings, self.propagator_settings, True) # For the first two assignments, no computation of fitness is needed fitness = 0.0 return fitness
def fitness(self, orbit_parameters: List[float]) -> List[float]: """ Computes the fitness value for the problem. Parameters ---------- orbit_parameters : List[float] Vector of decision variables of size n (for this problem, n = 4). Returns ------- List[float] List of size p with the values for each objective (for this multi-objective optimization problem, p=2). """ # Retrieves system of bodies current_bodies = self.bodies_function() # Retrieves Itokawa gravitational parameter itokawa_gravitational_parameter = current_bodies.get_body("Itokawa").gravitational_parameter # Reset the initial state from the decision variable vector new_initial_state = conversion.keplerian_to_cartesian( gravitational_parameter=itokawa_gravitational_parameter, semi_major_axis=orbit_parameters[0], eccentricity=orbit_parameters[1], inclination=np.deg2rad(orbit_parameters[2]), argument_of_periapsis=np.deg2rad(235.7), longitude_of_ascending_node=np.deg2rad(orbit_parameters[3]), true_anomaly=np.deg2rad(139.87)) # Retrieves propagator settings object propagator_settings = self.propagator_settings_function() # Retrieves integrator settings object integrator_settings = self.integrator_settings_function() # Reset the initial state propagator_settings.reset_initial_states(new_initial_state) # Propagate orbit dynamics_simulator = propagation_setup.SingleArcDynamicsSimulator(current_bodies, integrator_settings, propagator_settings, print_dependent_variable_data=False) # Update dynamics simulator function self.dynamics_simulator_function = lambda: dynamics_simulator # Retrieve dependent variable history dependent_variables = dynamics_simulator.dependent_variable_history dependent_variables_list = np.vstack(list(dependent_variables.values())) # Retrieve distance distance = dependent_variables_list[:, 0] # Retrieve latitude latitudes = dependent_variables_list[:, 1] # Compute mean latitude mean_latitude = np.mean(np.absolute(latitudes)) # Computes fitness as mean latitude current_fitness = 1.0 / mean_latitude # Exaggerate fitness value if the spacecraft has broken out of the selected distance range current_penalty = 0.0 if (max(dynamics_simulator.dependent_variable_history.keys()) < self.mission_final_time): current_penalty += 1.0E4 return [current_fitness + current_penalty, np.mean(distance) + current_penalty * 1.0E3]
# Create propagation settings. propagator_settings = propagation_setup.TranslationalStatePropagatorSettings( central_bodies, acceleration_models, bodies_to_propagate, system_initial_state, simulation_end_epoch) # Create numerical integrator settings. integrator_settings = propagation_setup.IntegratorSettings( propagation_setup.AvailableIntegrators.rk4, simulation_start_epoch, fixed_step_size) ################################################################################ # PROPAGATE #################################################################### ################################################################################ # Instantiate the dynamics simulator. dynamics_simulator = propagation_setup.SingleArcDynamicsSimulator( body_system, integrator_settings, propagator_settings, True) # Propagate and store results to outer loop results dictionary. result = dynamics_simulator.get_equations_of_motion_numerical_solution() ################################################################################ # VISUALISATION / OUTPUT / PRELIMINARY ANALYSIS ################################ ################################################################################ import matplotlib.pyplot as plt from tudatpy.util import result2array array = result2array(result) print(array)