コード例 #1
0
 def __init__(self, label, nodes, **kwargs):
     PHSGraph.__init__(self, label=label)
     if not isinstance(kwargs['coeff'], PHSArgument):
         coeff = PHSArgument(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)
コード例 #2
0
    def __init__(self, label, nodes, **kwargs):
        PHSGraph.__init__(self, label)
        if 'p' not in kwargs:
            p = 1
        else:
            p = kwargs.pop('p')

        if 'alpha' not in kwargs:
            alpha = 0.5
        else:
            alpha = kwargs.pop('alpha')

        diagRmu, diagQmu = fractionalIntegratorWeights(p, alpha, **kwargs)

        # Truncation of poles with null Q
        nbPoles = diagRmu.__len__()

        Ndeb = nodes.pop()
        Nend = nodes[-1]
        for n in range(nbPoles):
            # here, diagRmu[n] is a resistance (flux-controlled)
            Rn = diagRmu[n]
            self += PHSDissipativeLinear(label + 'R' + str(n), (Ndeb, Nend),
                                         coeff=Rn)

            Qn = diagQmu[n]
            Ndeb = nodes[0]
            self += PHSStorageLinear(label + 'Q' + str(n), (Ndeb, Nend),
                                     coeff=Qn,
                                     inv_coeff=True)
コード例 #3
0
ファイル: port.py プロジェクト: loicforma/pyphs
    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']})
コード例 #4
0
ファイル: storages.py プロジェクト: loicforma/pyphs
 def __init__(self, label, nodes, **kwargs):
     PHSGraph.__init__(self, label=label)
     if not isinstance(kwargs['value'], PHSArgument):
         coeff = PHSArgument(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:
         self.core.p += [
             coeff.symb,
         ]
コード例 #5
0
    def __init__(self, label, edges, w, z, **kwargs):
        if not hasattr(w, '__len__'):
            w = [
                w,
            ]
        if not hasattr(z, '__len__'):
            z = [
                z,
            ]
        assert len(w) == len(z),\
            'len(z)={0!s} is not equal to len(w)={1!s}.'.format(len(z), len(w))
        # init PortHamiltonianObject
        PHSGraph.__init__(self, label=label)
        # 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 z by correspondances in 'dicpars'
        for i, zz in enumerate(z):
            z[i] = zz.subs(dicpars)
        for e, edge in enumerate(edges):
            if 'z' in edge[2].keys():
                for k in ['e_ctrl', 'f_ctrl']:
                    edges[e][2]['z'][k] = edge[2]['z'][k].subs(dicpars)

        # add dissipative component
        self.core.add_dissipations(w, z)
        # update phs.Graph with edges
        self.add_edges_from(edges)
コード例 #6
0
ファイル: generic.py プロジェクト: loicforma/pyphs
 def __init__(self, label, edges, **kwargs):
     # init PortHamiltonianObject
     PHSGraph.__init__(self, label=label)
     # 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)
     # update phs.Graph with edges
     self.add_edges_from(edges)
コード例 #7
0
ファイル: storages.py プロジェクト: loicforma/pyphs
 def __init__(self, label, edges, x, H, **kwargs):
     # init PortHamiltonianObject
     PHSGraph.__init__(self, label=label)
     # 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 H by correspondances in 'dicpars'
     H = H.subs(dicpars)
     # add dissipative component
     self.core.add_storages(x, H)
     # update phs.Graph with edges
     self.add_edges_from(edges)
コード例 #8
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)
コード例 #9
0
    def __init__(self, label, nodes, **kwargs):
        PHSGraph.__init__(self, label=label)
        if 'p' not in kwargs:
            p = 1
        else:
            p = kwargs.pop('p')

        if 'alpha' not in kwargs:
            alpha = 0.5
        else:
            alpha = kwargs.pop('alpha')

        diagR, diagQ = fractionalDifferenciatorWeights(p, alpha, **kwargs)

        # Truncation of poles with null Q
        nbPoles = diagR.__len__()

        Ndeb, Nend = nodes
        N1 = Ndeb
        for n in range(nbPoles):
            if n < nbPoles - 1:
                N2 = 'N' + label + str(n) + "_1"
            else:
                N2 = Nend
            Rn = diagR[n]  # here, diagR[n] is a res (flux-controlled)
            self += PHSDissipativeLinear(label + 'R' + str(n), (N2, N1),
                                         ctrl='f',
                                         coeff=Rn,
                                         inv_coef=False)

            Qn = diagQ[n]
            N3 = 'N' + label + str(n) + "_2"
            self += PHSStorageLinear(label + 'Q' + str(n), (N3, datum),
                                     value=Qn,
                                     inv_coeff=False,
                                     ctrl='e')

            Nend = nodes[1]
            self += Transformer(label + 'alpha' + str(n), (N1, N2, N3, datum),
                                alpha=Rn)
            N1 = N2
コード例 #10
0
ファイル: pwl.py プロジェクト: loicforma/pyphs
    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)
コード例 #11
0
    def __init__(self, label, nodes, **kwargs):
        PHSGraph.__init__(self, label=label)

        if 'p' not in kwargs:
            p = 1
        else:
            p = kwargs.pop('p')

        if 'beta' not in kwargs:
            beta = 0.5
        else:
            beta = kwargs.pop('beta')

        self.core.subs.update({
            self.core.symbols('p_' + label): p,
            self.core.symbols('beta_' + label): beta
        })

        diagRmu, diagQmu = fractionalIntegratorWeights(p, beta, **kwargs)

        # Truncation of poles with null Q
        nbPoles = diagRmu.__len__()

        for n in range(nbPoles):
            Rn = diagRmu[n]  # here, diagRmu[n] is a resistance (f-ctrl)
            Nend = nodes[1]
            Ncomp = 'iN_' + label + str(n)
            temp_phs = PHSDissipativeLinear('R_' + label + str(n),
                                            (Ncomp, Nend),
                                            coeff=Rn)
            self += temp_phs

            Qn = diagQmu[n]
            Ndeb = nodes[0]
            temp_phs = PHSStorageLinear(label + str(n), (Ndeb, Ncomp),
                                        value=Qn,
                                        name='pL_',
                                        inv_coeff=True)
            self += temp_phs
コード例 #12
0
ファイル: pwl.py プロジェクト: loicforma/pyphs
    def __init__(self, label, nodes, **kwargs):

        # instanciate a PHSGraph object
        PHSGraph.__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)

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

        # edge
        edge = (N1, N2, data)

        # init component
        self += edges.PHSDissipativeNonLinear(label, [
            edge,
        ], w, z, **kwargs)
コード例 #13
0
    def __init__(self, label, nodes, **kwargs):
        PHSGraph.__init__(self, label=label)
        if 'p' not in kwargs:
            p = 1
        else:
            p = kwargs.pop('p')

        if 'alpha' not in kwargs:
            alpha = 0.5
        else:
            alpha = kwargs.pop('alpha')

        diagR, diagQ = fractionalDifferenciatorWeights(p, alpha, **kwargs)

        # Truncation of poles with null Q
        nbPoles = diagR.__len__()

        Ndeb, Nend = nodes
        for n in range(nbPoles):

            Rn = diagR[n]  # here, diagR[n] is a conductance (e-ctrl)

            N1 = 'N' + label + str(n) + "_1"
            N2 = 'N' + label + str(n) + "_2"
            self += PHSDissipativeLinear(label + 'R' + str(n), (N1, Ndeb),
                                         inv_coeff=True,
                                         coeff=Rn,
                                         ctrl='e')

            Qn = diagQ[n]
            self += PHSStorageLinear(label + 'Q' + str(n), (N2, datum),
                                     value=Qn,
                                     ctrl='f',
                                     inv_coeff=False)

            self += Transformer(label + 'alpha' + str(n),
                                (N1, Nend, N2, datum),
                                alpha=Rn**-1)
コード例 #14
0
    def __init__(self, label, nodes, **kwargs):
        PHSGraph.__init__(self, label)
        if 'p' not in kwargs:
            p = 1
        else:
            p = kwargs.pop('p')

        if 'alpha' not in kwargs:
            alpha = 0.5
        else:
            alpha = kwargs.pop('alpha')

        diagRmu, diagQmu = fractionalDifferenciatorWeights(p, alpha, **kwargs)

        # Truncation of poles with null Q
        nbPoles = diagRmu.__len__()

        datum = self.graph.netlist.datum
        for n in range(nbPoles):

            Rn = diagRmu[n]  # here, diagRmu[n] is a res (flux-controlled)
            Ndeb = nodes[0]
            N1 = 'N' + label + str(n) + "_2"
            self += PHSDissipativeLinear(label + 'R' + str(n), (Ndeb, N1),
                                         coeff=Rn)

            Qn = diagQmu[n]
            N2 = 'N' + label + str(n) + "_2"
            self += PHSStorageLinear(label + 'Q' + str(n), (N2, datum),
                                     coeff=Qn,
                                     inv_coeff=True)

            Nend = nodes[1]
            self += Transformer(label + 'alpha' + str(n),
                                (Ndeb, Nend, N2, datum),
                                alpha=diagRmu[n]**-1)
コード例 #15
0
    def __init__(self, label, nodes, **kwargs):
        PHSGraph.__init__(self, label=label)
        dic = {
            'A': 1e2,  # [N.s/m] Felt damping coefficient
            'B': 2.5,  # [#] Hysteresis coefficient for the felt
            'K': 5e5,  # [N/m] Stiffness of the felt
            'L': 1.5 * 1e-2,  # [m] Height of the felt at rest
        }
        dic.update(kwargs)
        dicpars, subs = mappars(self, **dic)
        # parameters
        pars = ['L', 'K', 'A', 'B']
        L, K, A, B = symbols(pars)

        xnl = symbols('q' + label)
        hnl = sp.Piecewise((0., xnl <= 0.),
                           ((L * K / (B + 1)) * (xnl / L)**(B + 1), True))
        hnl = hnl.subs(dicpars).simplify()
        # edge data
        data = {'label': xnl, 'type': 'storage', 'ctrl': 'e', 'link': None}
        self.add_edges_from([
            (nodes[0], nodes[1], data),
        ])
        self.core.add_storages(xnl, hnl)
        r = sp.Piecewise(
            (0., xnl <= 0.),
            ((A * L / B) * (xnl / L)**(B - 1), True))  # JSV eq (13)
        r = r.subs(dicpars).simplify()
        wnl = symbols('dtq' + label)
        # edge data
        data = {'label': wnl, 'type': 'dissipative', 'ctrl': 'e', 'link': None}
        self.add_edges_from([
            (nodes[0], nodes[1], data),
        ])
        self.core.add_dissipations(wnl, r * wnl)
        self.core.subs.update(subs)
コード例 #16
0
ファイル: cantilever.py プロジェクト: loicforma/pyphs
    def __init__(self, label, nodes, **kwargs):
        pars = parameters_JSV2016()
        pars.update(kwargs)
        PHSGraph.__init__(self, label=label)
        # [m] Tine length for the fondamental frequency f0[Hz]
        L = beamLength(pars['f0'], pars['r'], pars['m'], pars['E'])
        pars.update({'L': L})
        # [1/m] list of the nkmax first cantilever beam  modes with length L
        k, fk = waveNumbers(pars['nk'], L, pars['kappa'], pars['rho'])

        # truncate below the Nyquist frequency fe/2
        # list of the nk first modes below the Nyquist frequency fe/2 [1/m]
        # k = k[(fk < pars['n']/2).nonzero()]
        # list of the nk first frequencies below the Nyquist frequency fe/2 [Hz]
        # fk = fk[(fk < pars['fs']/2).nonzero()]

        # [#] number of simulated modes
        pars.update({'kmodes': k[0], 'fmodes': fk[0]})
        # [N/m**1] Modal damping coefficient
        a = pars['alpha']
        dp = pars['damping']
        pars.update({'alpha': a * 10**(linspace(0, dp, pars['nk']))})
        # Spatial distributions
        # HAMMER
        # [m] position of the hammer
        zh = pars['wh'] / 2. + pars['zh'] * (L - pars['wh'])
        pars.update({'zh': zh})
        # definition of stiffnesses values
        ka = pars['kappa']
        coeffs = ka * (k.flatten()**4)
        # definition of stiffnesses components
        for i, c in enumerate(coeffs):
            stiffness = Stiffness(label + 'K' + str(i),
                                  (datum, label + 'M' + str(i)),
                                  K=(label + 'K' + str(i), c))
            self += stiffness
        # definition of masses values
        coeffs = [pars['rho']] * pars['nk']
        # definition of masses components
        for i, c in enumerate(coeffs):
            mass = Mass(label + 'M' + str(i), (label + 'M' + str(i), ),
                        M=(label + 'M' + str(i), c))
            self += mass

        # definition of dampers components
        coeffs = list(pars['alpha'])
        # definition of dampers components
        for i, c in enumerate(coeffs):
            damper = Damper(label + 'A' + str(i),
                            (datum, label + 'M' + str(i)),
                            A=(label + 'A' + str(i), c))
            self += damper
        Omega = omega_const(pars)

        # transformers associated with the coefficients of modal projection
        A1 = nodes[0]  # system node
        # tail node for the serial connection of transformers primals
        if pars['nk'] == 1:
            A2 = datum
        else:
            A2 = label + 'T' + str(0)
        # iterate over coefficients values
        for i, o in enumerate(Omega):

            # define transfomer
            transfo = Transformer(label + 'T' + str(i),
                                  (A1, A2, datum, label + 'M' + str(i)),
                                  alpha=(label + 'alpha' + str(i), (o)))
            self += transfo

            # update nodes
            A1 = label + 'T' + str(i)
            if i == pars['nk'] - 2:
                A2 = datum
            else:
                A2 = label + 'T' + str(i + 1)