Ejemplo n.º 1
0
    def __init__(self, label, nodes, **kwargs):

        # update default parameters
        parameters = {'ctrl': '?', 'const': None}
        parameters.update(kwargs)

        PHSGraph.__init__(self, label=label)
        # set starting node to datum if not provided
        if nodes.__len__() == 1:
            node1 = datum
            node2 = nodes[0]
        elif nodes.__len__() == 2:
            node1 = nodes[0]
            node2 = nodes[1]
        # define symbols
        u, y = symbols((nicevarlabel('u', label), nicevarlabel('y', label)))
        # add port to phs
        self.core.add_ports([u], [y])
        # check edge control type (dual of input control type in values[0])
        assert parameters['ctrl'] in ('e', 'f', '?')
        # define edge data
        edge_data = {
            'label': y,
            'type': 'port',
            'ctrl': parameters['ctrl'],
            'link': None
        }
        # add edge to phs.Graph
        self.add_edges_from([(node1, node2, edge_data)])
        # check if constant value is provided
        if parameters['const'] is not None:
            self.core.subs.update({u: parameters['const']})
Ejemplo n.º 2
0
    def __init__(self, label, nodes, **kwargs):

        # update default parameters
        parameters = {'ctrl': '?', 'const': None}
        parameters.update(kwargs)

        Graph.__init__(self, label=label)
        # set starting node to datum if not provided
        if nodes.__len__() == 1:
            node1 = datum
            node2 = nodes[0]
        elif nodes.__len__() == 2:
            node1 = nodes[0]
            node2 = nodes[1]
        # define symbols
        u, y = symbols((nicevarlabel('u', label),
                        nicevarlabel('y', label)))
        # add port to phs
        self.core.add_ports([u], [y])
        # check edge control type (dual of input control type in values[0])
        assert parameters['ctrl'] in ('e', 'f', '?')
        # define edge data
        edge_data = {'label': y,
                     'type': 'port',
                     'ctrl': parameters['ctrl'],
                     'link': None}
        # add edge to phs.Graph
        self.add_edges_from([(node1, node2, edge_data)])
        # check if constant value is provided
        if parameters['const'] is not None:
            self.core.subs.update({u: parameters['const']})
Ejemplo n.º 3
0
    def __init__(self, label, nodes, **kwargs):

        Graph.__init__(self, label=label)
        if not isinstance(kwargs['coeff'], Argument):
            coeff = Argument(label + 'coeff', kwargs['coeff'])
        else:
            coeff = kwargs['coeff']
        w_label = nicevarlabel("w", label)
        w = self.core.symbols(w_label)
        z_f_ctrl = coeff.symb * w
        z_e_ctrl = w / coeff.symb
        if 'inv_coeff' in kwargs and kwargs['inv_coeff']:
            z_f_ctrl, z_e_ctrl = z_e_ctrl, z_f_ctrl
        self.core.add_dissipations([w], [z_f_ctrl])
        edge_data_dic = {
            'label': w,
            'type': 'dissipative',
            'ctrl': '?',
            'z': {
                'e_ctrl': z_e_ctrl,
                'f_ctrl': z_f_ctrl
            },
            'link': None
        }
        edge = (nodes[0], nodes[1], edge_data_dic)
        self.add_edges_from([edge])
        self.core.subs.update(coeff.sub)
        if len(coeff.sub) == 0:
            self.core.p += [
                coeff.symb,
            ]
Ejemplo n.º 4
0
 def __init__(self, label, nodes, **kwargs):
     Graph.__init__(self, label=label)
     if not isinstance(kwargs['value'], Argument):
         coeff = Argument(label + 'coeff', kwargs['value'])
     else:
         coeff = kwargs['value']
     x = nicevarlabel("x", label)
     x = self.core.symbols(x)
     if kwargs['inv_coeff']:
         coeff.symb = coeff.symb**-1
     H = coeff.symb * x**2 / 2.
     self.core.add_storages([x], H)
     edge_data_dic = {
         'label': x,
         'type': 'storage',
         'ctrl': kwargs['ctrl'],
         'link': None
     }
     edge = (nodes[0], nodes[1], edge_data_dic)
     self.add_edges_from([edge])
     self.core.subs.update(coeff.sub)
     if len(coeff.sub) == 0 and kwargs['inv_coeff']:
         self.core.p += [
             coeff.symb**-1,
         ]
     elif len(coeff.sub) == 0:
         self.core.p += [
             coeff.symb,
         ]
Ejemplo n.º 5
0
 def __init__(self, label, nodes, **kwargs):
     # init PortHamiltonianObject
     PHSGraph.__init__(self, label=label)
     # pop connector type
     connector_type = kwargs.pop('connector_type')
     # build correspondance between labels in subs and pars (dicpars)...
     # ... and build the correspondance between symbols and subs (subs)
     dicpars, subs = mappars(self, **kwargs)
     # update dict of subs in phs
     self.core.subs.update(subs)
     # replace parameters in alpha by correspondances in 'dicpars'
     alpha = self.core.symbols('alpha')
     alpha = alpha.subs(dicpars)
     # symbols for inputs and outputs:
     u1, u2 = self.core.symbols(
         [nicevarlabel('u', label + str(el)) for el in (1, 2)])
     y1, y2 = self.core.symbols(
         [nicevarlabel('y', label + str(el)) for el in (1, 2)])
     # add connector component
     ny = self.core.dims.y()
     self.core.add_ports((u1, u2), (y1, y2))
     self.core.add_connector((ny, ny + 1), alpha)
     # update phs.Graph with edges
     edge1_data = {
         'type': 'connector',
         'connector_type': connector_type,
         'alpha': alpha,
         'ctrl': '?',
         'label': y1,
         'link': y2
     }
     edge2_data = {
         'type': 'connector',
         'connector_type': connector_type,
         'alpha': None,
         'ctrl': '?',
         'label': y2,
         'link': y1
     }
     N1, N2, N3, N4 = nodes
     edges = [(N1, N2, edge1_data), (N3, N4, edge2_data)]
     # update phs.Graph with edges
     self.add_edges_from(edges)
Ejemplo n.º 6
0
 def __init__(self, label, nodes, **kwargs):
     # init PortHamiltonianObject
     Graph.__init__(self, label=label)
     # pop connector type
     connector_type = kwargs.pop('connector_type')
     # build correspondance between labels in subs and pars (dicpars)...
     # ... and build the correspondance between symbols and subs (subs)
     dicpars, subs = mappars(self, **kwargs)
     # update dict of subs in phs
     self.core.subs.update(subs)
     # replace parameters in alpha by correspondances in 'dicpars'
     alpha = self.core.symbols('alpha')
     alpha = alpha.subs(dicpars)
     # symbols for inputs and outputs:
     u1, u2 = self.core.symbols([nicevarlabel('u', label + str(el))
                                 for el in (1, 2)])
     y1, y2 = self.core.symbols([nicevarlabel('y', label + str(el))
                                 for el in (1, 2)])
     # add connector component
     ny = self.core.dims.y()
     self.core.add_ports((u1, u2), (y1, y2))
     self.core.add_connector((ny, ny+1), alpha)
     # update phs.Graph with edges
     edge1_data = {'type': 'connector',
                   'connector_type': connector_type,
                   'alpha': alpha,
                   'ctrl': '?',
                   'label': y1,
                   'link': y2}
     edge2_data = {'type': 'connector',
                   'connector_type': connector_type,
                   'alpha': None,
                   'ctrl': '?',
                   'label': y2,
                   'link': y1}
     N1, N2, N3, N4 = nodes
     edges = [(N1, N2, edge1_data), (N3, N4, edge2_data)]
     # update phs.Graph with edges
     self.add_edges_from(edges)
Ejemplo n.º 7
0
 def __init__(self, label, nodes, **kwargs):
     Graph.__init__(self, label=label)
     if not isinstance(kwargs['coeff'], Argument):
         coeff = Argument(label + 'coeff', kwargs['coeff'])
     else:
         coeff = kwargs['coeff']
     w_label = nicevarlabel("w", label)
     w = self.core.symbols(w_label)
     z_f_ctrl = coeff.symb*w
     z_e_ctrl = w/coeff.symb
     if 'inv_coeff' in kwargs and kwargs['inv_coeff']:
         z_f_ctrl, z_e_ctrl = z_e_ctrl, z_f_ctrl
     self.core.add_dissipations([w], [z_f_ctrl])
     edge_data_dic = {'label': w,
                      'type': 'dissipative',
                      'ctrl': '?',
                      'z': {'e_ctrl': z_e_ctrl, 'f_ctrl': z_f_ctrl},
                      'link': None}
     edge = (nodes[0], nodes[1], edge_data_dic)
     self.add_edges_from([edge])
     self.core.subs.update(coeff.sub)
     if len(coeff.sub) == 0:
         self.core.p  += [coeff.symb, ]
Ejemplo n.º 8
0
 def __init__(self, label, nodes, **kwargs):
     Graph.__init__(self, label=label)
     if not isinstance(kwargs['value'], Argument):
         coeff = Argument(label + 'coeff', kwargs['value'])
     else:
         coeff = kwargs['value']
     x = nicevarlabel("x", label)
     x = self.core.symbols(x)
     if kwargs['inv_coeff']:
         coeff.symb = coeff.symb**-1
     H = coeff.symb * x**2/2.
     self.core.add_storages([x], H)
     edge_data_dic = {'label': x,
                      'type': 'storage',
                      'ctrl': kwargs['ctrl'],
                      'link': None}
     edge = (nodes[0], nodes[1], edge_data_dic)
     self.add_edges_from([edge])
     self.core.subs.update(coeff.sub)
     if len(coeff.sub) == 0 and kwargs['inv_coeff']:
         self.core.p  += [coeff.symb**-1, ]
     elif len(coeff.sub) == 0:
         self.core.p  += [coeff.symb, ]