def __init__(self, *systems):
"""
Initialize a BlockDiagram, with an optional list of systems to start
the diagram.
"""
if len(systems) == 0:
self.systems = np.array([], dtype=object)
self.connections = np.array([], dtype=np.bool_).reshape((0, 0))
self.dts = np.array([], dtype=np.float_)
self.events = np.array([], dtype=np.bool_)
self.cum_inputs = np.array([0], dtype=np.int_)
self.cum_outputs = np.array([0], dtype=np.int_)
self.cum_states = np.array([0], dtype=np.int_)
self.cum_events = np.array([0], dtype=np.int_)
else:
self.systems = np.array(systems, dtype=object)
self.dts = np.zeros_like(self.systems, dtype=np.float_)
self.events = np.zeros_like(self.systems, dtype=np.bool_)
self.cum_inputs = np.zeros(self.systems.size+1, dtype=np.int_)
self.cum_outputs = np.zeros(self.systems.size+1, dtype=np.int_)
self.cum_states = np.zeros(self.systems.size+1, dtype=np.int_)
self.cum_events = np.zeros(self.systems.size+1, dtype=np.int_)
for i, sys in enumerate(self.systems):
self.dts[i] = sys.dt
self.events[i] = (
getattr(sys, 'event_equation_function', None) and
getattr(sys, 'update_equation_function', None)
)
self.cum_inputs[i+1] = self.cum_inputs[i] + sys.dim_input
self.cum_outputs[i+1] = self.cum_outputs[i] + sys.dim_output
self.cum_states[i+1] = self.cum_states[i] + sys.dim_state
self.cum_events[i+1] = self.cum_events[i] + self.events[i]
self.connections = np.zeros(
(self.cum_outputs[-1], self.cum_inputs[-1]),
dtype=np.bool_)
评论列表
文章目录