block_diagram.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:simupy 作者: sixpearls 项目源码 文件源码
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_)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号