npsolve.solvers module

Created on Fri May 22 10:36:19 2020

@author: Reuben

This module contains more specialised solvers based on scipy.

class npsolve.solvers.Integrator(status, logger, framerate=60.0, interface_cls=None, integrator_name='lsoda', squeeze=True, x_name='time', update_inits=False, **kwargs)

Bases: npsolve.core.Solver

A versatile integrator, with extra logging and stop flag

This integrator allows variables to be logged during the integration, which are then included in the output. In addition, Partial instances can set a flag to stop the integration at any point.

Parameters:
  • status (defaultdict) – A dictionary that contains status flags. Key flags are npsolve.solvers.FINAL and npsolve.solvers.STOP (which are strings). The default should be a function that returns None. Obtain one by calling npsolve.get_status(<name>).
  • logger (defaultdict) – A dictionary in which the default values are lists. Obtain one by calling npsolve.get_solver(<name>).
  • framerate (float) – [OPTIONAL] The number of return values per unit x (which is often time). Defaults to 60.0.
  • interface_cls (class) – [OPTIONAL] The class of interface to use for integrator algorithms. Defaults to scipy.intergrate.ode if scipy is found.
  • integrator_name (str) – [OPTIONAL] The name of the integrator to use. Defaults to ‘lsoda’.
  • squeeze (bool) – [OPTIONAL] Ensure output arrays are squeezed. Defaults to True.
  • x_name (str) – [OPTIONAL]: The name for the x value, which is logged in the outputs. Defaults to ‘time’.
  • update_inits (bool) – [OPTIONAL] Update the initial values of the Partial instances with the solution at the end. Defaults to False.
  • keyword arguments (Other) – [OPTIONAL] Are passed to the integrator by the call interface_cls.set_integrator(integrator_name, **kwargs).
Returns:

A dictionary of integrated values. The values are ndarrays, which are at the framerate specified by the ‘framerate’ argument.

Return type:

dict

Adding logged variables:

Only log variables when the solver has finalised the current frame. Integrators like scipy’s ode ‘lsoda’ use variable time steps, and take numerous guesses at the state as they jump around in time. Once it has reached an accurate state for the x value at the end of the frame, status[npsolve.solvers.FINAL] is set to True. Only log values when this flat is True. An example:

if status[FINAL]:
    logger['variable_name_1'] = current_value
Stopping the integration:
Stop the integration by setting status[npsolve.solvers.STOP] to True.
run(end, **kwargs)

Run the solver

Parameters:end (float) – The end point for the integration. Integration starts from 0 and will end at this value. Often this is a time.
Returns:A dictionary where keys are the variable names and other logged names, and the values are ndarrays of the values through time.
Return type:dict