示例#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 faust_expr(name, args, expr, subs):
    previous_expr = sp.sympify(0.)
    start = time.time()
    while previous_expr != expr and time.time() - start < 10:
        previous_expr = expr
        expr = simplify(previous_expr)
    code = '\n' + name + " = \(" + ('{}, ' * len(args)).format(
        *map(str, args))[:-2] + ').('
    code += ccode(expr)
    code += ');'
    return code.replace('(-', '(0-')