-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathintegrator.py
More file actions
126 lines (91 loc) · 2.88 KB
/
integrator.py
File metadata and controls
126 lines (91 loc) · 2.88 KB
1
2
3
4
5
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#########################################################################################
##
## STANDARD INTEGRATOR BLOCK
## (blocks/integrator.py)
##
## Milan Rother 2024
##
#########################################################################################
# IMPORTS ===============================================================================
import numpy as np
from ._block import Block
from ..optim.operator import DynamicOperator
# BLOCKS ================================================================================
class Integrator(Block):
"""Integrates the input signal.
Uses a numerical integration engine like this:
.. math::
y(t) = \\int_0^t u(\\tau) \\ d \\tau
or in differential form like this:
.. math::
\\begin{align}
\\dot{x}(t) &= u(t) \\\\
y(t) &= x(t)
\\end{align}
The Integrator block is inherently MIMO capable, so `u`
and `y` can be vectors.
Example
-------
This is how to initialize the integrator:
.. code-block:: python
#initial value 0.0
i1 = Integrator()
#initial value 2.5
i2 = Integrator(2.5)
Parameters
----------
initial_value : float, array
initial value of integrator
"""
def __init__(self, initial_value=0.0):
super().__init__()
#save initial value
self.initial_value = initial_value
def __len__(self):
return 0
def update(self, t):
"""update system equation fixed point loop
Note
----
integrator does not have passthrough, therefore this
method is performance optimized for this case
Parameters
----------
t : float
evaluation time
"""
self.outputs.update_from_array(self.engine.state)
def solve(self, t, dt):
"""advance solution of implicit update equation of the solver
Parameters
----------
t : float
evaluation time
dt : float
integration timestep
Returns
-------
error : float
solver residual norm
"""
f = self.inputs.to_array()
return self.engine.solve(f, None, dt)
def step(self, t, dt):
"""compute timestep update with integration engine
Parameters
----------
t : float
evaluation time
dt : float
integration timestep
Returns
-------
success : bool
step was successful
error : float
local truncation error from adaptive integrators
scale : float
timestep rescale from adaptive integrators
"""
f = self.inputs.to_array()
return self.engine.step(f, dt)