4.8.1 pde.trackers.base module

Base classes for trackers.

TrackerBase

Base class for implementing trackers.

TrackerCollection

List of trackers providing methods to handle them efficiently.

TransformedTrackerBase

Tracker that allows modifying incoming data.

FinishedSimulation

Exception for signaling that simulation finished successfully.

exception FinishedSimulation[source]

Bases: StopIteration

Exception for signaling that simulation finished successfully.

class TrackerBase(interrupts=1)[source]

Bases: object

Base class for implementing trackers.

Parameters:

interrupts (InterruptData) – Determines when the tracker interrupts the simulation. A single numbers determines an interval (measured in the simulation time unit) of regular interruption. A string is interpreted as a duration in real time assuming the format ‘hh:mm:ss’. A list of values is taken as explicit simulation time points. More fine- grained control is possible by passing an instance of classes defined in interrupts.

finalize(info=None)[source]

Finalize the tracker, supplying additional information.

Parameters:

info (dict) – Extra information from the simulation

Return type:

None

classmethod from_data(data, **kwargs)[source]

Create tracker class from given data.

Parameters:
  • data (str or TrackerBase) – Data describing the tracker

  • **kwargs – Additional keyword arguments passed to the tracker constructor

Returns:

An instance representing the tracker

Return type:

TrackerBase

abstractmethod handle(field, t)[source]

Handle data supplied to this tracker.

Parameters:
  • field (FieldBase) – The current state of the simulation

  • t (float) – The associated time

Return type:

None

initialize(field, info=None)[source]

Initialize the tracker with information about the simulation.

Parameters:
  • field (FieldBase) – An example of the data that will be analyzed by the tracker

  • info (dict) – Extra information from the simulation

Returns:

The first time the tracker needs to handle data

Return type:

float

class TrackerCollection(trackers=None)[source]

Bases: object

List of trackers providing methods to handle them efficiently.

trackers

List of the trackers in the collection

Type:

list

Parameters:

trackers (list[TrackerBase]) – List of trackers that are to be handled.

finalize(info=None)[source]

Finalize the tracker, supplying additional information.

Parameters:

info (dict) – Extra information from the simulation

Return type:

None

classmethod from_data(data, **kwargs)[source]

Create tracker collection from given data.

Parameters:
Returns:

An instance representing the tracker collection

Return type:

TrackerCollection

handle(state, t, atol=1e-08)[source]

Handle all trackers.

Parameters:
  • state (FieldBase) – The current state of the simulation

  • t (float) – The associated time

  • atol (float) – An absolute tolerance that is used to determine whether a tracker should be called now or whether the simulation should be carried on more timesteps. This is basically used to predict the next time to decided which one is closer.

Returns:

The next time the simulation needs to be interrupted to handle a tracker.

Return type:

float

initialize(field, info=None)[source]

Initialize the tracker with information about the simulation.

Parameters:
  • field (FieldBase) – An example of the data that will be analyzed by the tracker

  • info (dict) – Extra information from the simulation

Returns:

The first time the tracker needs to handle data

Return type:

float

time_next_action: float

The time of the next interrupt of the simulation

Type:

float

tracker_action_times: list[float]

Times at which the trackers need to be handled next

Type:

list

class TransformedTrackerBase(interrupts=1, *, transformation=None)[source]

Bases: TrackerBase

Tracker that allows modifying incoming data.

To support the transformations sub-classes need to call self._transform(field, t) to obtain the transformed field.

Parameters:
  • interrupts (InterruptData) – Determines when the tracker interrupts the simulation. A single numbers determines an interval (measured in the simulation time unit) of regular interruption. A string is interpreted as a duration in real time assuming the format ‘hh:mm:ss’. A list of values is taken as explicit simulation time points. More fine- grained control is possible by passing an instance of classes defined in interrupts.

  • transformation (callable, optional) – A function that transforms the current state into a new field or field collection, which is then used in the tracker. This allows to process derived quantities of the field during calculations. The argument needs to be a callable function taking 1 or 2 arguments. The first argument always is the current field, while the optional second argument is the associated time.

registered_trackers()[source]

Returns all trackers that are currently registered.

Returns:

a dictionary with the names of the trackers and the associated class

Return type:

dict