gonzales.simulator.simulation

  • class gonzales.simulator.simulation.SimulationBase(space, output_filepath, G, eps)
    __init__(space, output_filepath, G, eps)

    Base class for all simulation types.

    Parameters
    • space – instance of Space

    • output_filepath – output filepath

    • G – gravitational constant

    • eps – gravitational softening

    add_result(res_name, res_frequency=1)

    Adds a result which shall be written to the hdf5 file during the simulation. The shape of the result needs to be provided, as does the frequency of the output. The default res_frequency 1 means the result will be written to the file at each simulation step.

    Parameters
    • res_name – string, name of result

    • res_frequency – int, result will be written every res_frequency steps. If 0, result will not be written at all.

    Returns

    create_datasets(hdf5_fobj, n_steps, step_size)

    Creates hdf5 datasets.

    run(n_steps, step_size)

    Runs the simulation.

    Parameters
    • n_steps – number of steps

    • step_size – step size

    set_kernel(kernel_func)

    Sets the kernel function which will be used to calculate accelerations for each simulation step.

    Parameters

    kernel_func – function used to calculate accelerations

    static set_metadata(hdf5_obj, **kwargs)

    Sets metadata attributes for hdf5 object (can be a group or a dataset)


  • class gonzales.simulator.simulation.PPSimulation(*args, **kwargs)

    Bases: gonzales.simulator.simulation.SimulationBase

    Simulation class for brute-force simulations.

    __init__(*args, **kwargs)
    Parameters
    • space – instance of Space

    • output_filepath – output filepath

    • G – gravitational constant

    • eps – gravitational softening

    calc_accs()

    Calculates the acceleration vector, using the kernel which was set.


  • class gonzales.simulator.simulation.BHSimulation(space, output_filepath, G, eps, root_width, root_center, theta)

    Bases: gonzales.simulator.simulation.SimulationBase

    Simulation class for Barnes-Hut simulations.

    __init__(space, output_filepath, G, eps, root_width, root_center, theta)
    Parameters
    • space – instance of Space

    • output_filepath – output filepath

    • G – gravitational constant

    • eps – gravitational softening

    • root_width – octree root node width

    • root_center – octree root node center

    • theta – threshold parameter

    calc_accs()

    Calculates the acceleration vector, using the kernel which was set.


  • class gonzales.simulator.simulation.ResultReader(hdf5_filepath)

    Reader for hdf5 results. Should be closed after using.

    __init__(hdf5_filepath)
    Parameters

    hdf5_filepath – path to hdf5 file

    close()

    Closes the hdf5 file. This should be called when the reader is not needed anymore.

    get_info()

    Returns simulation info, which is dict-like iterable.

    get_result(result_name, step_num)

    Get a specific result for a given step.

    Parameters
    • result_name – str, name of result, must be supported by simulation

    • step_num – step number

    get_result_frequency(result_name)

    Get result frequency.

    Parameters

    result_name – str, name of result, must be supported by simulation

    Returns result frequency

    get_result_num_steps(result_name)
    Parameters

    result_name – str, name of result, must be supported by simulation

    Returns number of steps for which result is calculated