4.8.3 pde.trackers.interrupts module

Module defining classes for time interrupts for trackers.

The provided interrupt classes are:

ConstantInterrupts

Interrupts equidistantly spaced in time.

FixedInterrupts

Interrupts at fixed, predetermined times.

LogarithmicInterrupts

Interrupts with successively increased spacing.

GeometricInterrupts

Interrupts from the geometric sequence \(t_i = \Delta t f^i\)

RealtimeInterrupts

Interrupts spaced equidistantly in real time.

parse_interrupt

Create interrupt class from various data formats.

class ConstantInterrupts(dt=1, t_start=None)[source]

Bases: InterruptsBase

Interrupts equidistantly spaced in time.

Parameters:
  • dt (float) – The duration between subsequent interrupts. This is measured in simulation time units.

  • t_start (float, optional) – The time after which the tracker becomes active. If omitted, the tracker starts recording right away. This argument can be used for an initial equilibration period during which no data is recorded.

initialize(t)[source]

Initialize the interrupt class.

Parameters:

t (float) – The starting time of the simulation

Returns:

The first time the simulation needs to be interrupted

Return type:

float

next(t)[source]

Computes the next time point.

Parameters:

t (float) – The current time point of the simulation. The returned next time point lies later than this time, so interrupts might be skipped.

Returns:

The next time point

Return type:

float

class FixedInterrupts(interrupts)[source]

Bases: InterruptsBase

Interrupts at fixed, predetermined times.

Parameters:

interrupts (sequence of float) – A sequence of time points at which interrupts occur

copy()[source]
initialize(t)[source]

Initialize the interrupt class.

Parameters:

t (float) – The starting time of the simulation

Returns:

The first time the simulation needs to be interrupted

Return type:

float

next(t)[source]

Computes the next time point.

Parameters:

t (float) – The current time point of the simulation. The returned next time point lies later than this time, so interrupts might be skipped.

Returns:

The next time point

Return type:

float

class GeometricInterrupts(scale, factor)[source]

Bases: InterruptsBase

Interrupts from the geometric sequence \(t_i = \Delta t f^i\)

In contrast to LogarithmicInterrupts, this class ensures that time points lie on the geometric sequence given above. However, data points might be skipped if the simulations progress too quickly.

Parameters:
  • scale (float) – Time scale \(\Delta t\).

  • factor (float) – Scale factor \(f\).

initialize(t)[source]

Initialize the interrupt class.

Parameters:

t (float) – The starting time of the simulation

Returns:

The first time the simulation needs to be interrupted

Return type:

float

next(t)[source]

Computes the next time point.

Parameters:

t (float) – The current time point of the simulation. The returned next time point lies later than this time, so interrupts might be skipped.

Returns:

The next time point

Return type:

float

value(iteration)[source]

Calculate value of i-th interrupt.

Parameters:

iteration (int) – The iteration of the interrupt

Returns:

time of the i-th interrupt

Return type:

float

class LogarithmicInterrupts(dt_initial=1, factor=1, t_start=None)[source]

Bases: ConstantInterrupts

Interrupts with successively increased spacing.

The durations between interrupts increases by a constant factor \(f\):

\[t_{i+1} = t_i + \Delta t_i \qquad \text{with} \qquad \Delta t_{i+1} = f \Delta t_i\]

starting with initial values \(t_0\) and \(\Delta t_0\). This results in exponentially spaced interrupts \(t_i = a + b f^i\), where \(a = t_0 - \Delta t_0 (f - 1)^{-1}\) and \(b = \Delta t_0 (f - 1)^{-1}\).

Note that the geometric sequence described above can be disrupted if other interrupts interfere. This class ensures ever increasing durations between its interrupts, at the cost of potentially oddly spaced times. If a geometric sequence is required, use GeometricInterrupts instead.

Parameters:
  • dt_initial (float) – The initial duration \(\Delta t_0\) between subsequent interrupts. This is measured in simulation time units.

  • factor (float) – The factor \(f\) by which the time between interrupts is increased after every interrupt. Values larger than one lead to time interrupts that are increasingly further apart.

  • t_start (float, optional) – The time \(t_0\) after which the tracker becomes active. If omitted, the tracker starts recording right away. This argument can be used for an initial equilibration period during which no data is recorded.

next(t)[source]

Computes the next time point.

Parameters:

t (float) – The current time point of the simulation. The returned next time point lies later than this time, so interrupts might be skipped.

Returns:

The next time point

Return type:

float

value(iteration)[source]

Calculate value of i-th interrupt.

Parameters:

iteration (int) – The iteration of the interrupt

Returns:

time of the i-th interrupt

Return type:

float

class RealtimeInterrupts(duration, dt_initial=0.01)[source]

Bases: ConstantInterrupts

Interrupts spaced equidistantly in real time.

This spacing is only achieved approximately and depends on the initial value set by dt_initial and the actual variation in computation speed.

Parameters:
  • duration (float or str) – The duration (in real seconds) that the interrupts should be spaced apart. The duration can also be given as a string, which is then parsed using the function parse_duration().

  • dt_initial (float) – The initial duration between subsequent interrupts. This is measured in simulation time units.

initialize(t)[source]

Initialize the interrupt class.

Parameters:

t (float) – The starting time of the simulation

Returns:

The first time the simulation needs to be interrupted

Return type:

float

next(t)[source]

Computes the next time point.

Parameters:

t (float) – The current time point of the simulation. The returned next time point lies later than this time, so interrupts might be skipped.

Returns:

The next time point

Return type:

float

parse_interrupt(data)[source]

Create interrupt class from various data formats.

Parameters:

data (str or number or InterruptsBase) – Data determining the interrupt class. If this is a InterruptsBase, it is simply returned, numbers imply ConstantInterrupts, a string is generally parsed as a time for RealtimeInterrupts, and lists are interpreted as FixedInterrupts. Instance of GeometricInterrupts can be constructed with the special string "geometric(SCALE, FACTOR)", specifying the scale and factor values directly as numbers.

Returns:

An instance that represents the interrupt

Return type:

InterruptsBase