예제 #1
0
    def __init__(self, core, config=None, label=None):
        """
        Parameters
        -----------

        core: pyphs.Core
            The core Port-Hamiltonian structure on wich the method is build.

        config: dict or None
            A dictionary of simulation parameters. If None, the standard
            pyphs.config.simulations is used (the default is None).
            keys and default values are

              'fs': 48e3,           # Sample rate (Hz)
              'grad': 'discret',    # In {'discret', 'theta', 'trapez'}
              'theta': 0.,          # Theta-scheme for the structure
              'split': True,        # split implicit from explicit part
              'maxit': 10,          # Max number of iterations for NL solvers
        """
        Method.__init__(self, core, config=config, label=label)

        if VERBOSE >= 2:
            print('    Build {}'.format('ijactempFll'))
        self.setexpr('ijactempFll', self.jactempFll().inverse_LU())

        if VERBOSE >= 2:
            print('    Build {}'.format('ud_vl'))
        ud_vl = matvecprod(-self.ijactempFll, self.Gl())
        self.setexpr('ud_vl', list(ud_vl))

        if VERBOSE >= 2:
            print('    Build {}'.format('Fnl'))
        temp = matvecprod(self.jactempFnll() * self.ijactempFll, self.Gl())
        Fnl = list(types.matrix_types[0](self.Gnl()) -
                   types.matrix_types[0](temp))

        if VERBOSE >= 2:
            print('    Simplify {}'.format('jacFnlnl'))
        jacFnlnl = simplify(self.jacGnlnl() - self.jactempFnll() *
                            self.ijactempFll * self.jacGlnl())

        if VERBOSE >= 2:
            print('    Inverse {}'.format('jacFnlnl'))
        if jacFnlnl.shape == (0, 0):
            ijacFnlnl = jacFnlnl
        else:
            ijacFnlnl = jacFnlnl.inv()

        if VERBOSE >= 2:
            print('    Build {} for Faust code generation'.format('ud_vnl'))
        ud_vnl = list(
            sympy.simplify(types.matrix_types[0](self.vnl()) -
                           types.matrix_types[0](
                               (matvecprod(ijacFnlnl, Fnl)))))
        self.setexpr('ud_vnl', list(ud_vnl))

        self.init_funcs()
예제 #2
0
    def __init__(self, core, config=None, label=None):
        """
        Parameters
        -----------

        core: pyphs.Core
            The core Port-Hamiltonian structure on wich the method is build.

        config: dict or None
            A dictionary of simulation parameters. If None, the standard
            pyphs.config.simulations is used (the default is None).
            keys and default values are

              'fs': 48e3,           # Sample rate (Hz)
              'grad': 'discret',    # In {'discret', 'theta', 'trapez'}
              'theta': 0.,          # Theta-scheme for the structure
              'split': True,        # split implicit from explicit part
              'maxit': 10,          # Max number of iterations for NL solvers
        """
        Method.__init__(self, core, config=config, label=label)

        if VERBOSE >= 2:
            print('    Build {}'.format('ijactempFll'))
        self.setexpr('ijactempFll', self.jactempFll().inverse_LU())

        if VERBOSE >= 2:
            print('    Build {}'.format('ud_vl'))
        ud_vl = matvecprod(-self.ijactempFll, self.Gl())
        self.setexpr('ud_vl', list(ud_vl))

        if VERBOSE >= 2:
            print('    Build {}'.format('Fnl'))
        temp = matvecprod(self.jactempFnll()*self.ijactempFll, self.Gl())
        Fnl = list(types.matrix_types[0](self.Gnl()) -
                   types.matrix_types[0](temp))

        if VERBOSE >= 2:
            print('    Simplify {}'.format('jacFnlnl'))
        jacFnlnl = simplify(self.jacGnlnl() -
                            self.jactempFnll()*self.ijactempFll*self.jacGlnl())

        if VERBOSE >= 2:
            print('    Inverse {}'.format('jacFnlnl'))
        if jacFnlnl.shape == (0, 0):
            ijacFnlnl = jacFnlnl
        else:
            ijacFnlnl = jacFnlnl.inv()

        if VERBOSE >= 2:
            print('    Build {} for Faust code generation'.format('ud_vnl'))
        ud_vnl = list(types.matrix_types[0](self.vnl()) -
                      types.matrix_types[0]((matvecprod(ijacFnlnl, Fnl))))
        self.setexpr('ud_vnl', list(ud_vnl))

        self.init_funcs()
예제 #3
0
            def func():

                v = geteval(method, 'v')
                Mvv = geteval(method, 'Mvv')
                Mvy = geteval(method, 'Mvy')
                f = geteval(method, 'f')
                u = geteval(method, 'u')
                temp = [
                    sp.sympify(0),
                ] * len(geteval(method, 'v'))
                temp = sumvecs(temp, matvecprod(method.I(''), v),
                               [-e for e in matvecprod(Mvv, f)],
                               [-e for e in matvecprod(Mvy, u)])
                return temp
예제 #4
0
 def func():
     Fa = geteval(method, 'tempF' + a)
     vl = geteval(method, 'vl')
     JacFal = geteval(
         method,
         'jactempF' + a + 'l',
     )
     return sumvecs(Fa, [-e for e in matvecprod(JacFal, vl)])
예제 #5
0
            def func():

                v = geteval(method, 'v' + suffix)
                Mvvl = geteval(method, 'Mv' + suffix + 'vl')
                Mvvnl = geteval(method, 'Mv' + suffix + 'vnl')
                Mvy = geteval(method, 'Mv' + suffix + 'y')
                fl = geteval(method, 'fl')
                fnl = geteval(method, 'fnl')
                u = geteval(method, 'u')
                temp = [
                    sp.sympify(0),
                ] * len(geteval(method, 'v' + suffix))
                temp = sumvecs(temp, matvecprod(method.I(suffix), v),
                               [-e for e in matvecprod(Mvvl, fl)],
                               [-e for e in matvecprod(Mvvnl, fnl)],
                               [-e for e in matvecprod(Mvy, u)])
                return temp
예제 #6
0
 def func():
     F = geteval(method, 'tempF')
     vl = geteval(method, 'vl')
     JacFl = jacobian(F, vl)
     G = sumvecs(F, [-e for e in matvecprod(JacFl, vl)])
     return list(G)