Esempio n. 1
0
    def get_header(self):
        object = self.object
        helpers = []
        headers = []
        headers.extend(get_cython_code(object.kernel))
        if hasattr(object.kernel, '_get_helpers_'):
            helpers.extend(object.kernel._get_helpers_())

        # get headers from the Equations
        for equation in object.all_group.equations:
            headers.extend(get_cython_code(equation))
            if hasattr(equation, '_get_helpers_'):
                for helper in equation._get_helpers_():
                    if helper not in helpers:
                        helpers.append(helper)

        headers.extend(get_helper_code(helpers))

        # Kernel wrappers.
        cg = CythonGenerator(known_types=self.known_types)
        cg.parse(object.kernel)
        headers.append(cg.get_code())

        # Equation wrappers.
        self.known_types['SPH_KERNEL'] = KnownType(
            object.kernel.__class__.__name__)
        headers.append(object.all_group.get_equation_wrappers(
            self.known_types))

        return '\n'.join(headers)
Esempio n. 2
0
def get_helper_code(helpers):
    """Given a list of helpers, return the helper code suitably wrapped.
    """
    result = []
    result.append('# Helpers')
    cg = CythonGenerator()
    for helper in helpers:
        cg.parse(helper)
        result.append(cg.get_code())
    return result