Ejemplo n.º 1
0
    def __str__(self):
        args = [f"source={self.source}"]
        for i, density in enumerate(self.densities):
            args.append(f"density{i}={density}")

        from pytential.symbolic.mappers import StringifyMapper, stringify_where
        strify = StringifyMapper()

        lines = []
        for o in self.outputs:
            if o.target_name != self.source:
                tgt_str = " @ {}".format(stringify_where(o.target_name))
            else:
                tgt_str = ""

            if o.qbx_forced_limit == 1:
                limit_str = "[+] "
            elif o.qbx_forced_limit == -1:
                limit_str = "[-] "
            elif o.qbx_forced_limit == 2:
                limit_str = "[(+)] "
            elif o.qbx_forced_limit == -2:
                limit_str = "[(-)] "
            elif o.qbx_forced_limit == "avg":
                limit_str = "[avg] "
            elif o.qbx_forced_limit is None:
                limit_str = ""
            else:
                raise ValueError(
                    f"unrecognized limit value: {o.qbx_forced_limit}")

            source_kernels_str = " + ".join([
                f"density{i} * {source_kernel}"
                for i, source_kernel in enumerate(self.source_kernels)
            ])
            target_kernel = self.target_kernels[o.target_kernel_index]
            target_kernel_str = str(target_kernel)
            base_kernel_str = str(target_kernel.get_base_kernel())
            kernel_str = target_kernel_str.replace(base_kernel_str,
                                                   f"({source_kernels_str})")

            line = "{}{} <- {}{}".format(o.name, tgt_str, limit_str,
                                         kernel_str)

            lines.append(line)

        for arg_name, arg_expr in self.kernel_arguments.items():
            arg_expr_lines = strify(arg_expr).split("\n")
            lines.append("  {} = {}".format(arg_name, arg_expr_lines[0]))
            lines.extend("  " + s for s in arg_expr_lines[1:])

        return "{{ /* Pot({}) */\n  {}\n}}".format(", ".join(args),
                                                   "\n  ".join(lines))
Ejemplo n.º 2
0
    def __str__(self):
        args = ["density=%s" % self.density, "source=%s" % self.source]

        from pytential.symbolic.mappers import StringifyMapper, stringify_where
        strify = StringifyMapper()

        lines = []
        for o in self.outputs:
            if o.target_name != self.source:
                tgt_str = " @ %s" % stringify_where(o.target_name)
            else:
                tgt_str = ""

            if o.qbx_forced_limit == 1:
                limit_str = "[+] "
            elif o.qbx_forced_limit == -1:
                limit_str = "[-] "
            elif o.qbx_forced_limit == 2:
                limit_str = "[(+)] "
            elif o.qbx_forced_limit == -2:
                limit_str = "[(-)] "
            elif o.qbx_forced_limit == 'avg':
                limit_str = "[avg] "
            elif o.qbx_forced_limit is None:
                limit_str = ""
            else:
                raise ValueError("unrecognized limit value: %s" %
                                 o.qbx_forced_limit)

            line = "%s%s <- %s%s" % (o.name, tgt_str, limit_str,
                                     self.kernels[o.kernel_index])

            lines.append(line)

        for arg_name, arg_expr in six.iteritems(self.kernel_arguments):
            arg_expr_lines = strify(arg_expr).split("\n")
            lines.append("  %s = %s" % (arg_name, arg_expr_lines[0]))
            lines.extend("  " + s for s in arg_expr_lines[1:])

        return "{ /* Pot(%s) */\n  %s\n}" % (", ".join(args),
                                             "\n  ".join(lines))
Ejemplo n.º 3
0
    def __str__(self):
        args = ["density=%s" % self.density,
                "source=%s" % self.source]

        from pytential.symbolic.mappers import StringifyMapper, stringify_where
        strify = StringifyMapper()

        lines = []
        for o in self.outputs:
            if o.target_name != self.source:
                tgt_str = " @ %s" % stringify_where(o.target_name)
            else:
                tgt_str = ""

            if o.qbx_forced_limit == 1:
                limit_str = "[+] "
            elif o.qbx_forced_limit == -1:
                limit_str = "[-] "
            elif o.qbx_forced_limit == 0:
                limit_str = "[0] "
            elif o.qbx_forced_limit is None:
                limit_str = ""
            else:
                raise ValueError("unrecognized limit value: %s" % o.qbx_forced_limit)

            line = "%s%s <- %s%s" % (o.name, tgt_str, limit_str,
                    self.kernels[o.kernel_index])

            lines.append(line)

        for arg_name, arg_expr in six.iteritems(self.kernel_arguments):
            arg_expr_lines = strify(arg_expr).split("\n")
            lines.append("  %s = %s" % (
                arg_name, arg_expr_lines[0]))
            lines.extend("  " + s for s in arg_expr_lines[1:])

        return "{ /* Pot(%s) */\n  %s\n}" % (
                ", ".join(args), "\n  ".join(lines))