Coverage for src/gncpy/dynamics/basic/dynamics_base.py: 80%
25 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-13 06:15 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-13 06:15 +0000
1from abc import abstractmethod, ABC
4class DynamicsBase(ABC):
5 r"""Defines common attributes for all dynamics models.
7 Attributes
8 ----------
9 control_model : callable or list of callables, optional
10 For objects of :class:`gncpy.dynamics.LinearDynamicsBase` it is a
11 callable with the signature `t, *ctrl_args` and returns the
12 input matrix :math:`G_k` from :math:`x_{k+1} = F_k x_k + G_k u_k`.
13 For objects of :class:`gncpy.dynamics.NonlinearDynamicsBase` it is a
14 list of callables where each callable returns the modification to the
15 corresponding state, :math:`g(t, x_i, u_i)`, in the differential equation
16 :math:`\dot{x}_i = f(t, x_i) + g(t, x_i, u_i)` and has the signature
17 `t, x, u, *ctrl_args`.
18 state_constraint : callable
19 Has the signature `t, x` where `t` is the current timestep and `x`
20 is the propagated state. It returns the propagated state with
21 any constraints applied to it.
22 """
24 state_names = ()
25 """Tuple of strings for the name of each state. The order should match
26 that of the state vector.
27 """
29 def __init__(self, control_model=None, state_constraint=None):
30 super().__init__()
31 self._control_model = control_model
32 self.state_constraint = state_constraint
34 @property
35 def allow_cpp(self):
36 return False
38 @property
39 def control_model(self):
40 return self._control_model
42 @control_model.setter
43 def control_model(self, model):
44 self._control_model = model
46 @abstractmethod
47 def propagate_state(self, timestep, state, u=None, state_args=None, ctrl_args=None):
48 """Abstract method for propagating the state forward in time.
50 Must be overridden in child classes.
52 Parameters
53 ----------
54 timestep : float
55 timestep.
56 state : N x 1 numpy array
57 state vector.
58 u : Nu x 1 numpy array, optional
59 Control effort vector. The default is None.
60 state_args : tuple, optional
61 Additional arguments needed by the `get_state_mat` function. The
62 default is ().
63 ctrl_args : tuple, optional
64 Additional arguments needed by the get input mat function. The
65 default is (). Only used if a control effort is supplied.
67 Raises
68 ------
69 NotImplementedError
70 If child class does not implement this function.
72 Returns
73 -------
74 next_state : N x 1 numpy array
75 The propagated state.
76 """
77 raise NotImplementedError()
79 @abstractmethod
80 def get_state_mat(self, timestep, *args, **kwargs):
81 """Abstract method for getting the discrete time state matrix.
83 Must be overridden in child classes.
85 Parameters
86 ----------
87 timestep : float
88 timestep.
89 args : tuple, optional
90 any additional arguments needed.
92 Returns
93 -------
94 N x N numpy array
95 state matrix.
96 """
97 raise NotImplementedError()
99 @abstractmethod
100 def get_input_mat(self, timestep, *args, **kwargs):
101 """Should return the input matrix.
103 Must be overridden by the child class.
105 Parameters
106 ----------
107 timestep : float
108 Current timestep.
109 *args : tuple
110 Placeholder for additional arguments.
111 **kwargs : dict
112 Placeholder for additional arguments.
114 Raises
115 ------
116 NotImplementedError
117 Child class must implement this.
119 Returns
120 -------
121 N x Nu numpy array
122 input matrix for the system
123 """
124 raise NotImplementedError()