ode
DifferentialMode(t, state)
Bases: Generic[X, Input]
, OdeSystem[X]
Differential mode of a hybrid system.
This class represents a mode of a hybrid system by extending an OdeSystem with a transition function that determines the next mode.
Source code in src/flowcean/ode/ode_environment.py
79 80 81 82 83 84 85 86 87 |
|
transition(i)
abstractmethod
Transition to the next mode.
Determine the next mode based on the current input. This method should return the current mode if no transition is needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
Input
|
Input. |
required |
Returns:
Type | Description |
---|---|
DifferentialMode[X, Input]
|
Next mode. |
Source code in src/flowcean/ode/hybrid_system.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
HybridSystem(initial_mode, inputs, map_to_dataframe)
Bases: IncrementalEnvironment
, Generic[X, Input]
Hybrid system environment.
This environment generates samples by simulating a hybrid system. The system is defined by a set of differential modes and a sequence of inputs that determine the transitions between the modes.
Initialize the hybrid system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_mode
|
DifferentialMode[X, Input]
|
Initial mode of the system. |
required |
inputs
|
Iterator[tuple[float, Input]]
|
Timeseries of inputs (time, input). |
required |
map_to_dataframe
|
Callable[[Sequence[float], Sequence[Input], Sequence[X]], DataFrame]
|
Function to map times, inputs, and states to a DataFrame. |
required |
Source code in src/flowcean/ode/hybrid_system.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
IntegrationError()
Bases: Exception
Error while integrating an ODE.
This exception is raised when an error occurs while integrating an ordinary differential equation.
Initialize the exception.
Source code in src/flowcean/ode/ode_environment.py
21 22 23 |
|
OdeEnvironment(system, *, dt=1.0, map_to_dataframe)
Bases: IncrementalEnvironment
, Generic[X]
Environment governed by an ordinary differential equation.
This environment integrates an OdeSystem to generate a sequence of states.
Initialize the environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
system
|
OdeSystem[X]
|
ODE system. |
required |
dt
|
float
|
Time step. |
1.0
|
map_to_dataframe
|
Callable[[Sequence[float], Sequence[X]], DataFrame]
|
Function to map states to a DataFrame. |
required |
Source code in src/flowcean/ode/ode_environment.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
OdeState
Bases: ABC
State of a differential equation.
This class represents the state of a differential equation. It provides methods to convert the state to and from a numpy array for integration.
as_numpy()
abstractmethod
Convert the state to a numpy array.
Returns:
Type | Description |
---|---|
NDArray[float64]
|
State as a numpy array. |
Source code in src/flowcean/ode/ode_environment.py
33 34 35 36 37 38 39 |
|
from_numpy(state)
abstractmethod
classmethod
Create a state from a numpy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
NDArray[float64]
|
State as a numpy array. |
required |
Returns:
Type | Description |
---|---|
Self
|
State instance. |
Source code in src/flowcean/ode/ode_environment.py
41 42 43 44 45 46 47 48 49 50 51 |
|
OdeSystem(t, state)
Bases: ABC
, Generic[X]
System governed by an ordinary differential equation.
This class represents a continuous system. The system is defined by a differential flow function \(f\) that governs the evolution of the state \(x\).
The system can be integrated to obtain the state at a future time.
Attributes:
Name | Type | Description |
---|---|---|
t |
float
|
Current time. |
state |
X
|
Current state. |
Initialize the system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Initial time. |
required |
state
|
X
|
Initial state. |
required |
Source code in src/flowcean/ode/ode_environment.py
79 80 81 82 83 84 85 86 87 |
|
flow(t, state)
abstractmethod
Ordinary differential equation.
Compute the derivative of the state \(x\) at time \(t\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time. |
required |
state
|
NDArray[float64]
|
State. |
required |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
Derivative of the state. |
Source code in src/flowcean/ode/ode_environment.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
step(dt)
Step the mode forward in time.
Step the mode forward in time by integrating the differential equation for a time step of dt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float
|
Time step. |
required |
Returns:
Type | Description |
---|---|
tuple[Sequence[float], Sequence[X]]
|
Tuple of times and states of the integration. |
Source code in src/flowcean/ode/ode_environment.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|