Пример #1
0
    def __init__(self, label, nodes, **kwargs):

        # instanciate a Graph object
        Graph.__init__(self, label=label)

        assert 'file' in kwargs, "pwl.dissipative component need 'file' argument"
        path = kwargs.pop('file')
        data = np.vstack(map(np.array, data_generator(path)))
        w_vals = data[0, :]
        z_vals = data[1, :]

        assert all(z_vals[np.nonzero(w_vals >= 0)] >= 0), 'All values z(w) for\
 w>=0 must be non-negative (component {})'.format(label)

        assert all(z_vals[np.nonzero(w_vals >= 0)] >= 0), 'All values z(w) for\
 w<0 must be negative (component {})'.format(label)

        assert all(z_vals[np.nonzero(w_vals == 0)] == 0), 'z(0) must be zero \
(component {})'.format(label)

        ctrl = kwargs.pop('ctrl')

        # state  variable
        w = symbols("w" + label)
        # storage funcion
        z = pwl_func(w_vals, z_vals, w, **kwargs)

        if ctrl == 'e':
            not_ctrl = 'f'
        else:
            assert ctrl == 'f'
            not_ctrl = 'e'

        # edge data
        data = {
            'label': w,
            'type': 'dissipative',
            'ctrl': ctrl,
            'z': {
                ctrl + '_ctrl': z,
                not_ctrl + '_ctrl': sp.sympify(0)
            },
            'link': None
        }
        N1, N2 = nodes

        # edge
        edge = (N1, N2, data)

        # init component
        self += edges.DissipativeNonLinear(label, [
            edge,
        ], w, z, **kwargs)
Пример #2
0
    def _data_generator(self,
                        name,
                        ind=None,
                        postprocess=None,
                        imin=None,
                        imax=None,
                        decim=None):
        opts = self.config['load']
        options = {
            'imin': opts['imin'] if imin is None else imin,
            'imax': opts['imax'] if imax is None else imax,
            'decim': opts['decim'] if decim is None else decim
        }

        path = self.config['path'] + os.sep + 'data'
        filename = path + os.sep + name + '.txt'
        generator = data_generator(filename,
                                   ind=ind,
                                   postprocess=postprocess,
                                   **options)
        return generator
Пример #3
0
    def __init__(self, label, nodes, **kwargs):

        # instanciate a PHSGraph object
        PHSGraph.__init__(self, label=label)

        assert 'file' in kwargs, "pwl.storage component need 'file' argument"
        path = kwargs.pop('file')
        vals = np.vstack(map(np.array, data_generator(path)))
        x_vals = vals[0, :]
        h_vals = vals[1, :]

        assert all(h_vals[np.nonzero(x_vals >= 0)] >= 0), 'All values h(x) for\
 x>=0 must be non-negative (component {})'.format(label)

        if kwargs['integ']:
            assert all(h_vals[np.nonzero(x_vals < 0)] < 0), 'All values dxh(x)\
 for x<0 must be negative (component {})'.format(label)
        else:
            assert all(h_vals[np.nonzero(x_vals < 0)] >= 0), 'All values h(x)\
 for x<0 must be non-negative (component {})'.format(label)

        assert h_vals[np.nonzero(x_vals == 0)] == 0, 'dxh(0) and h(0) must be \
zero (component {})'.format(label)

        ctrl = kwargs.pop('ctrl')

        # state  variable
        x = symbols("x" + label)
        # storage funcion
        h = pwl_func(x_vals, h_vals, x, **kwargs)

        # edge data
        data = {'label': x, 'type': 'storage', 'ctrl': ctrl, 'link': None}
        N1, N2 = nodes

        # edge
        edge = (N1, N2, data)

        # init component
        self += edges.PHSStorageNonLinear(label, [edge], x, h, **kwargs)