コード例 #1
0
 def __init__(self,
              vehicle_body: str,
              initial_time: float,
              parameter_vector: list):
     """
     Constructor of the ThrustGuidance class.
     Parameters
     ----------
     vehicle_body : str
         Name of the vehicle to apply the thrust guidance to.
     initial_time: float
         Initial time of the simulation [s].
     parameter_vector : list
         List of thrust parameters to retrieve the thrust guidance from.
     Returns
     -------
     none
     """
     print('Initializing guidance...')
     # Set arguments as attributes
     self.vehicle_body = vehicle_body
     self.initial_time = initial_time
     self.parameter_vector = parameter_vector
     self.thrust_magnitude = parameter_vector[0]
     self.time_interval = parameter_vector[1]
     # Prepare dictionary for thrust angles
     self.thrust_angle_dict = {} # this defines the in-plane angle
     self.thrust_angle_2_dict = {} # this defines the out-of-plane angle
     # Initialize time
     current_time = initial_time
     # Loop over nodes
     for i in range(4): #((len(parameter_vector) - 2)/2): # qui mi da non risolto perche e' ancora basato sulla lunghezza precedente
         # Store time as key, thrust angle as value
         self.thrust_angle_dict[current_time] = parameter_vector[i + 2]
         self.thrust_angle_2_dict[current_time] = parameter_vector[i + 2 + 5]#(len(parameter_vector) - 2)/2]
         # Increase time
         current_time += self.time_interval
     # Create interpolator settings
     interpolator_settings = interpolators.linear_interpolation(
         boundary_interpolation=interpolators.use_boundary_value)
     # Create the interpolator between nodes and set it as attribute
     self.thrust_angle_interpolator = interpolators.create_one_dimensional_interpolator(self.thrust_angle_dict,
                                                                                        interpolator_settings)
     self.thrust_angle_2_interpolator = interpolators.create_one_dimensional_interpolator(self.thrust_angle_2_dict,
                                                                                        interpolator_settings)
コード例 #2
0
def compare_benchmarks(first_benchmark: dict,
                       second_benchmark: dict,
                       output_path: str,
                       filename: str) -> dict:
    """
    It compares the results of two benchmark runs.

    It uses an 8th-order Lagrange interpolator to compare the state (or the dependent variable, depending on what is
    given as input) history. The difference is returned in form of a dictionary and, if desired, written to a file named
    filename and placed in the directory output_path.

    Parameters
    ----------
    first_benchmark : dict
        State (or dependent variable history) from the first benchmark.
    second_benchmark : dict
        State (or dependent variable history) from the second benchmark.
    output_path : str
        If and where to save the benchmark results (if None, results are NOT written).
    filename : str
        Name of the output file.

    Returns
    -------
    benchmark_difference : dict
        Interpolated difference between the two benchmarks' state (or dependent variable) history.
    """
    # Create 8th-order Lagrange interpolator for first benchmark
    benchmark_interpolator = interpolators.create_one_dimensional_interpolator(first_benchmark,
                                                                               interpolators.lagrange_interpolation(8))
    # Calculate the difference between the benchmarks
    print('Calculating benchmark differences...')
    # Initialize difference dictionaries
    benchmark_difference = dict()
    # Calculate the difference between the states and dependent variables in an iterative manner
    for second_epoch in second_benchmark.keys():
        benchmark_difference[second_epoch] = benchmark_interpolator.interpolate(second_epoch) - \
                                         second_benchmark[second_epoch]
    # Write results to files
    if output_path is not None:
        save2txt(benchmark_difference,
                 filename,
                 output_path)
    # Return the interpolator
    return benchmark_difference
コード例 #3
0
    # Set output path for the benchmarks
    if write_results_to_file:
        benchmark_output_path = current_dir + '/SimulationOutput/benchmarks/'
    else:
        benchmark_output_path = None
    # Generate benchmarks
    benchmark_step_size = 1.0
    benchmark_list = Util.generate_benchmarks(
        benchmark_step_size, simulation_start_epoch, constant_specific_impulse,
        bodies, benchmark_propagator_settings, thrust_parameters,
        are_dependent_variables_to_save, benchmark_output_path)
    # Extract benchmark states
    first_benchmark_state_history = benchmark_list[0]
    second_benchmark_state_history = benchmark_list[1]
    # Create state interpolator for first benchmark
    benchmark_state_interpolator = interpolators.create_one_dimensional_interpolator(
        first_benchmark_state_history, benchmark_interpolator_settings)

    # Compare benchmark states, returning interpolator of the first benchmark
    benchmark_state_difference = Util.compare_benchmarks(
        first_benchmark_state_history, second_benchmark_state_history,
        benchmark_output_path, 'benchmarks_state_difference.dat')

    # Extract benchmark dependent variables, if present
    if are_dependent_variables_to_save:
        first_benchmark_dependent_variable_history = benchmark_list[2]
        second_benchmark_dependent_variable_history = benchmark_list[3]
        # Create dependent variable interpolator for first benchmark
        benchmark_dependent_variable_interpolator = interpolators.create_one_dimensional_interpolator(
            first_benchmark_dependent_variable_history,
            benchmark_interpolator_settings)