examples/example_05_custom_parameter.py
def euler_scheme(traj, diff_func):
    """Simulation function for Euler integration.

    :param traj:

        Container for parameters and results

    :param diff_func:

        The differential equation we want to integrate

    """

    steps = traj.steps
    initial_conditions = traj.initial_conditions
    dimension = len(initial_conditions)

    # This array will collect the results
    result_array = np.zeros((steps,dimension))
    # Get the function parameters stored into `traj` as a dictionary
    # with the (short) names as keys :
    func_params_dict = traj.func_params.f_to_dict(short_names=True, fast_access=True)
    # Take initial conditions as first result
    result_array[0] = initial_conditions

    # Now we compute the Euler Scheme steps-1 times
    for idx in range(1,steps):
        result_array[idx] = diff_func(result_array[idx-1], **func_params_dict) * traj.dt + \
                            result_array[idx-1]
    # Note the **func_params_dict unzips the dictionary, it's the reverse of **kwargs in function
    # definitions!

    #Finally we want to keep the results
    traj.f_add_result('euler_evolution', data=result_array, comment='Our time series data!')
def euler_scheme(traj, diff_func):
    steps = traj.steps
    initial_conditions = traj.initial_conditions
    dimension = len(initial_conditions)

    # This array will collect the results
    result_array = np.zeros((steps,dimension))
    # Get the function parameters stored into `traj` as a dictionary
    # with the (short) names as keys :
    func_params_dict = traj.func_params.f_to_dict(short_names=True, fast_access=True)
    # Take initial conditions as first result
    result_array[0] = initial_conditions

    # Now we compute the Euler Scheme steps-1 times
    for idx in range(1,steps):
        result_array[idx] = diff_func(result_array[idx-1], **func_params_dict) * traj.dt + \
                            result_array[idx-1]
    # Note the **func_params_dict unzips the dictionary, it's the reverse of **kwargs in function
    # definitions!

    #Finally we want to keep the results
    traj.f_add_result('euler_evolution', data=result_array, comment='Our time series data!')
def euler_scheme ( traj , diff_func ) : steps = traj . steps initial_conditions = traj . initial_conditions dimension = len ( initial_conditions ) # This array will collect the results result_array = np . zeros ( ( steps , dimension ) ) # Get the function parameters stored into `traj` as a dictionary # with the (short) names as keys : func_params_dict = traj . func_params . f_to_dict ( short_names = True , fast_access = True ) # Take initial conditions as first result result_array [ 0 ] = initial_conditions # Now we compute the Euler Scheme steps-1 times for idx in range ( 1 , steps ) : result_array [ idx ] = diff_func ( result_array [ idx - 1 ] , * * func_params_dict ) * traj . dt + result_array [ idx - 1 ] # Note the **func_params_dict unzips the dictionary, it's the reverse of **kwargs in function # definitions! #Finally we want to keep the results traj . f_add_result ( 'euler_evolution' , data = result_array , comment = 'Our time series data!' )
Simulation function for Euler integration.

    :param traj:

        Container for parameters and results

    :param diff_func:

        The differential equation we want to integrate
Simulation function for Euler integration .