TimeSolver#

class TimeSolver#

Bases: object

Evolve the world in time.

Each world has already its own TimeSolver. This TimeSolver can be accessed through the world.timesolver property.

TimeSolvers should not be initialized by the end user.

__init__(impl)#
set_method(method_name)#

Set the Runga Kutta method used by the time solver.

Implemented methods are:

  • ‘Heun’

  • ‘BogackiShampine’

  • ‘CashKarp’

  • ‘Fehlberg’

  • ‘DormandPrince’

The default and recommended Runge Kutta method is ‘Fehlberg’.

steps(nsteps, initial_timestep=None)#

Make n steps with the time solver.

Parameters:
  • nsteps (int) – The number of steps to take.

  • initial_timestep (float, optional) – The time step is set to this value before running the solver. If None (default), the initial time step is set to a sensible value if adaptive timestepping is enabled, or remains unchanged if disabled.

See also

_assure_sensible_timestep

run_while(condition, initial_timestep=None)#

Run the solver while the evaluation of the condition is True.

Parameters:
  • condition (Callable[[], bool]) – Callable condition returning a boolean.

  • initial_timestep (float, optional) – The time step is set to this value before running the solver. If None (default), the initial time step is set to a sensible value if adaptive timestepping is enabled, or remains unchanged if disabled.

See also

run, solve, _assure_sensible_timestep

run(duration, initial_timestep=None)#

Run the solver for a given duration.

Parameters:
  • duration (float) – Duration in seconds.

  • initial_timestep (float, optional) – The time step is set to this value before running the solver. If None (default), the initial time step is set to a sensible value if adaptive timestepping is enabled, or remains unchanged if disabled.

See also

run_while, solve, _assure_sensible_timestep

solve(timepoints, quantity_dict, file_name=None, store_as_dict=True, initial_timestep=None, tqdm=False)#

Solve the differential equation.

The functions collects values of a list of specified quantities on specified timepoints.

Parameters:
  • timepoints (iterable[float]) – Specified timepoints.

  • quantity_dict (dict) – Specified quantities to collect.

  • file_name (str, optional) – Optional name of an output file, in which the data is also written as tab-separated values during the simulation.

  • store_as_dict (bool (default=True)) – Specify whether to store the evaluated quantities in an output dictionary.

  • initial_timestep (float, optional) – The time step is set to this value before running the solver. If None (default), the initial time step is set to a sensible value if adaptive timestepping is enabled, or remains unchanged if disabled.

  • tqdm (bool (default=False)) – Prints tqdm progress bar if set to True.

Returns:

output – Collected values of specified quantities at specified timepoints. If store_as_dict=False, this returns None.

Return type:

TimeSolverOutput

See also

run, run_while, _assure_sensible_timestep

property timestep: float#

Return the timestep value.

property adaptive_timestep: bool#

Return the adaptive_timestep value.

True if an adaptive time step is used, False otherwise. To enable an adaptive time step, set to True, to disable set to False.

property time: float#

Return the time value.

property max_error: float#

Return the maximum error per step the solver can tollerate.

The default value is 1e-5.

property headroom: float#

Return the solver headroom.

The default value is 0.8.

property lower_bound: float#

Return the lower bound which is used to cap the scaling of the time step from below.

The default value is 0.5.

property upper_bound: float#

Return the upper bound which is used to cap the scaling of the time step from the top.

The default value is 2.0.

property sensible_factor: float#

Return the sensible time step factor which is used as a scaling factor when determining a sensible timestep.

The default value is 0.01.

property sensible_timestep_default: float#

Return the time step which is used if no sensible time step can be calculated (e.g. when the total torque is zero).

The default value is 1e-14 s.

property sensible_timestep#

Return a calculated sensible time step.