Skip to content

time_domain

A collection of time-discretizations required for odeiter solvers.

TimeDomain

An iterable class representing the discretization of a temporal domain. This is used as an input to the odeiter.time_integrator.TimeInterator solvers.

Source code in src/odeiter/time_domain.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class TimeDomain:
    """
    An iterable class representing the discretization of a temporal domain.
    This is used as an input to the `odeiter.time_integrator.TimeInterator` solvers.
    """

    def __init__(self, start: float, spacing: float, steps: int):
        """
        A discretization of the interval $[\\text{start},\\  \\text{start} +
        \\text{spacing}\\cdot\\text{steps}]$.

        Parameters:
            start: The inital time.
            spacing: The space between time-steps.
            steps: The total number of time steps.

        Examples:
            >>> t0 = 0
            >>> dt = 0.1
            >>> steps = 5
            >>> time = TimeDomain(t0, dt, steps)
            >>> print(time.array)
            [0.  0.1 0.2 0.3 0.4 0.5]
        """
        self.start = start
        self.spacing = spacing
        self.steps = steps
        self.initialze_array()

    def initialze_array(self):
        self.array = self.start + self.spacing * np.arange(self.steps + 1, dtype=float)

    def __iter__(self):
        yield from self.array

__init__(start, spacing, steps)

A discretization of the interval \([\text{start},\ \text{start} + \text{spacing}\cdot\text{steps}]\).

Parameters:

Name Type Description Default
start float

The inital time.

required
spacing float

The space between time-steps.

required
steps int

The total number of time steps.

required

Examples:

>>> t0 = 0
>>> dt = 0.1
>>> steps = 5
>>> time = TimeDomain(t0, dt, steps)
>>> print(time.array)
[0.  0.1 0.2 0.3 0.4 0.5]
Source code in src/odeiter/time_domain.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def __init__(self, start: float, spacing: float, steps: int):
    """
    A discretization of the interval $[\\text{start},\\  \\text{start} +
    \\text{spacing}\\cdot\\text{steps}]$.

    Parameters:
        start: The inital time.
        spacing: The space between time-steps.
        steps: The total number of time steps.

    Examples:
        >>> t0 = 0
        >>> dt = 0.1
        >>> steps = 5
        >>> time = TimeDomain(t0, dt, steps)
        >>> print(time.array)
        [0.  0.1 0.2 0.3 0.4 0.5]
    """
    self.start = start
    self.spacing = spacing
    self.steps = steps
    self.initialze_array()

TimeDomain_Start_Stop_MaxSpacing

Bases: TimeDomain

Source code in src/odeiter/time_domain.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class TimeDomain_Start_Stop_MaxSpacing(TimeDomain):
    def __init__(self, start: float, stop: float, max_spacing: float):
        """An iterable discretization of the inverval $[\\text{start},\\ \\text{stop}]$
        with a spacing of `max_spacing` or smaller.

        Parameters:
            start: The initial time.
            stop: The final time.
            max_spacing: an upper bound on the temporal step-size.

        Examples:
            >>> t0 = 0
            >>> tf = 0.5
            >>> max_dt = 0.11
            >>> time = TimeDomain_Start_Stop_MaxSpacing(t0, tf, max_dt)
            >>> print(time.array)
            [0.  0.1 0.2 0.3 0.4 0.5]
        """
        self.start = start
        self.steps = math.ceil((stop - start) / max_spacing)
        self.spacing = (stop - start) / self.steps
        self.initialze_array()

__init__(start, stop, max_spacing)

An iterable discretization of the inverval \([\text{start},\ \text{stop}]\) with a spacing of max_spacing or smaller.

Parameters:

Name Type Description Default
start float

The initial time.

required
stop float

The final time.

required
max_spacing float

an upper bound on the temporal step-size.

required

Examples:

>>> t0 = 0
>>> tf = 0.5
>>> max_dt = 0.11
>>> time = TimeDomain_Start_Stop_MaxSpacing(t0, tf, max_dt)
>>> print(time.array)
[0.  0.1 0.2 0.3 0.4 0.5]
Source code in src/odeiter/time_domain.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def __init__(self, start: float, stop: float, max_spacing: float):
    """An iterable discretization of the inverval $[\\text{start},\\ \\text{stop}]$
    with a spacing of `max_spacing` or smaller.

    Parameters:
        start: The initial time.
        stop: The final time.
        max_spacing: an upper bound on the temporal step-size.

    Examples:
        >>> t0 = 0
        >>> tf = 0.5
        >>> max_dt = 0.11
        >>> time = TimeDomain_Start_Stop_MaxSpacing(t0, tf, max_dt)
        >>> print(time.array)
        [0.  0.1 0.2 0.3 0.4 0.5]
    """
    self.start = start
    self.steps = math.ceil((stop - start) / max_spacing)
    self.spacing = (stop - start) / self.steps
    self.initialze_array()

TimeDomain_Start_Stop_Steps

Bases: TimeDomain

Source code in src/odeiter/time_domain.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class TimeDomain_Start_Stop_Steps(TimeDomain):
    def __init__(self, start: float, stop: float, steps: int):
        """An iterable discretization of the inverval $[\\text{start},\\ \\text{stop}]$
        with $\\text{steps} + 1$ equally spaced ponits.

        Parameters:
            start: The initial time.
            stop: The final time.
            steps: The number of time steps.

        Examples:
            >>> t0 = 0
            >>> tf = 0.5
            >>> steps = 5
            >>> time = TimeDomain_Start_Stop_Steps(t0, tf, steps)
            >>> print(time.array)
            [0.  0.1 0.2 0.3 0.4 0.5]
        """
        self.start = start
        self.steps = steps
        self.spacing = (stop - start) / steps
        self.initialze_array()

__init__(start, stop, steps)

An iterable discretization of the inverval \([\text{start},\ \text{stop}]\) with \(\text{steps} + 1\) equally spaced ponits.

Parameters:

Name Type Description Default
start float

The initial time.

required
stop float

The final time.

required
steps int

The number of time steps.

required

Examples:

>>> t0 = 0
>>> tf = 0.5
>>> steps = 5
>>> time = TimeDomain_Start_Stop_Steps(t0, tf, steps)
>>> print(time.array)
[0.  0.1 0.2 0.3 0.4 0.5]
Source code in src/odeiter/time_domain.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def __init__(self, start: float, stop: float, steps: int):
    """An iterable discretization of the inverval $[\\text{start},\\ \\text{stop}]$
    with $\\text{steps} + 1$ equally spaced ponits.

    Parameters:
        start: The initial time.
        stop: The final time.
        steps: The number of time steps.

    Examples:
        >>> t0 = 0
        >>> tf = 0.5
        >>> steps = 5
        >>> time = TimeDomain_Start_Stop_Steps(t0, tf, steps)
        >>> print(time.array)
        [0.  0.1 0.2 0.3 0.4 0.5]
    """
    self.start = start
    self.steps = steps
    self.spacing = (stop - start) / steps
    self.initialze_array()

TimeRay

Bases: TimeDomain

A variant of Timedomain that has no end time.

Only use this with odeiter.TimeIntegrator.solution_generator. This is effectively a while-loop, so always program a termination condition.

Do not use this with odeiter.TimeIntegrator.solve or odeiter.TimeIntgegraor.t_final. Doing so will resut in an infinite loop.

This is useful for simulating a system into the future for an amount of time that is unkown from the start. For example, simulating until the difference between two solutions is above a threshold.

Source code in src/odeiter/time_domain.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
class TimeRay(TimeDomain):
    """
    A variant of Timedomain that has no end time.

    Only use this with odeiter.TimeIntegrator.solution_generator.
    This is effectively a while-loop, so always program a termination condition.

    Do not use this with odeiter.TimeIntegrator.solve or odeiter.TimeIntgegraor.t_final.
    Doing so will resut in an infinite loop.

    This is useful for simulating a system into the future for an amount of time that is
    unkown from the start. For example, simulating until the difference between two
    solutions is above a threshold.
    """

    def __init__(self, start: float, spacing: float):
        """An iterable discretization of the inverval $[\\text{start},\\ \\infty)$
        with with `spacing` space between points.

        Parameters:
            start: The initial time.
            spacing: The space between time-steps.

        Examples:
            >>> t0 = 0
            >>> spacing = 0.1
            >>> time = TimeRay(t0, spacing)
            >>> for t, _ in zip(time, range(6)):
            ...     print(t)
            0.0
            0.1
            0.2
            0.30000000000000004
            0.4
            0.5
        """
        self.start = start
        self.spacing = spacing

    @property
    def array(self):
        return Ray(self.start, self.spacing)

    def __iter__(self):
        return self.array.__iter__()

__init__(start, spacing)

An iterable discretization of the inverval \([\text{start},\ \infty)\) with with spacing space between points.

Parameters:

Name Type Description Default
start float

The initial time.

required
spacing float

The space between time-steps.

required

Examples:

>>> t0 = 0
>>> spacing = 0.1
>>> time = TimeRay(t0, spacing)
>>> for t, _ in zip(time, range(6)):
...     print(t)
0.0
0.1
0.2
0.30000000000000004
0.4
0.5
Source code in src/odeiter/time_domain.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def __init__(self, start: float, spacing: float):
    """An iterable discretization of the inverval $[\\text{start},\\ \\infty)$
    with with `spacing` space between points.

    Parameters:
        start: The initial time.
        spacing: The space between time-steps.

    Examples:
        >>> t0 = 0
        >>> spacing = 0.1
        >>> time = TimeRay(t0, spacing)
        >>> for t, _ in zip(time, range(6)):
        ...     print(t)
        0.0
        0.1
        0.2
        0.30000000000000004
        0.4
        0.5
    """
    self.start = start
    self.spacing = spacing