Пример #1
0
def compile_form(forms, object_names={}, prefix="Form",\
                 parameters=default_parameters()):
    """This function generates UFC code for a given UFL form or list
    of UFL forms."""

    info("Compiling form %s\n" % prefix)

    # Reset timing
    cpu_time_0 = time()

    # Check input arguments
    forms = _check_forms(forms)
    parameters = _check_parameters(parameters)
    if not forms: return

    # Stage 1: analysis
    cpu_time = time()
    analysis = analyze_forms(forms, parameters)
    _print_timing(1, time() - cpu_time)
    # embed()
    # Stage 2: intermediate representation
    cpu_time = time()
    ir = compute_ir(analysis, parameters)
    _print_timing(2, time() - cpu_time)
    # embed()
    # Stage 3: optimization
    cpu_time = time()
    oir = optimize_ir(ir, parameters)
    _print_timing(3, time() - cpu_time)

    # Stage 4: code generation
    cpu_time = time()
    code = generate_code(oir, prefix, parameters)
    _print_timing(4, time() - cpu_time)

    # Stage 4.1: generate wrappers
    cpu_time = time()
    wrapper_code = generate_wrapper_code(analysis, prefix, object_names,
                                         parameters)
    _print_timing(4.1, time() - cpu_time)

    # Stage 5: format code
    cpu_time = time()
    format_code(code, wrapper_code, prefix, parameters)
    _print_timing(5, time() - cpu_time)

    info_green("FFC finished in %g seconds.", time() - cpu_time_0)
Пример #2
0
def compile_form(forms, object_names={}, prefix="Form",\
                 parameters=default_parameters()):
    """This function generates UFC code for a given UFL form or list
    of UFL forms."""

    info("Compiling form %s\n" % prefix)

    # Reset timing
    cpu_time_0 = time()

    # Check input arguments
    forms = _check_forms(forms)
    parameters = _check_parameters(parameters)
    if not forms: return

    # Stage 1: analysis
    cpu_time = time()
    analysis = analyze_forms(forms, object_names, parameters)
    _print_timing(1, time() - cpu_time)

    # Stage 2: intermediate representation
    cpu_time = time()
    ir = compute_ir(analysis, parameters)
    _print_timing(2, time() - cpu_time)

    # Stage 3: optimization
    cpu_time = time()
    oir = optimize_ir(ir, parameters)
    _print_timing(3, time() - cpu_time)

    # Stage 4: code generation
    cpu_time = time()
    code = generate_code(oir, prefix, parameters)
    _print_timing(4, time() - cpu_time)

    # Stage 4.1: generate wrappers
    cpu_time = time()
    wrapper_code = generate_wrapper_code(analysis, prefix, parameters)
    _print_timing(4.1, time() - cpu_time)

    # Stage 5: format code
    cpu_time = time()
    format_code(code, wrapper_code, prefix, parameters)
    _print_timing(5, time() - cpu_time)

    info_green("FFC finished in %g seconds.", time() - cpu_time_0)
Пример #3
0
def compute_tensor_representation(form):
    """Compute tensor representation for given form. This function may
    be useful for those (Hi Matt!) that want to access the FFC tensor
    representation from outside FFC."""

    # Set parameters
    parameters = default_parameters()
    parameters["representation"] = "tensor"
    #parameters["optimize"] = "optimize"

    # The below steps basically duplicate the compiler process but
    # skip the code formatting step. Instead, we extract the relevant
    # portions for tabulate_tensor.

    # Stage 1: analysis
    cpu_time = time()
    analysis = analyze_forms([form], {}, parameters)
    _print_timing(1, time() - cpu_time)

    # Stage 2: intermediate representation
    cpu_time = time()
    ir = compute_ir(analysis, parameters)
    _print_timing(2, time() - cpu_time)

    # Stage 3: optimization
    cpu_time = time()
    oir = optimize_ir(ir, parameters)
    _print_timing(3, time() - cpu_time)

    # Stage 4: code generation
    cpu_time = time()
    code = generate_code(oir, "foo", parameters)
    _print_timing(4, time() - cpu_time)

    # Extract representations
    ir_elements, ir_dofmaps, ir_integrals, ir_forms = ir

    # Extract entries in reference tensor
    reference_tensors = []
    for i in ir_integrals:
        if i["integral_type"] == "cell":
            t = [A0.A0 for (A0, GK, dummy) in i["AK"]]
            if len(t) == 1: t = t[0]
        elif i["integral_type"] == "exterior_facet":
            t = [A0.A0 for j in i["AK"] for (A0, GK, dummy) in j]
            if len(t) == 1: t = t[0]
        elif i["integral_type"] == "interior_facet":
            t = [A0.A0 for j in i["AK"] for k in j for (A0, GK, dummy) in k]
            if len(t) == 1: t = t[0]
        else:
            raise RuntimeError("Unhandled domain type: %s" % str(i["integral_type"]))
        reference_tensors.append(t)

    # Extract code
    code_elements, code_dofmaps, code_integrals, code_forms = code

    # Extract code for computing the geometry tensor
    geometry_tensor_codes = [c["tabulate_tensor"].split("// Compute element tensor")[0] for c in code_integrals]

    # Simplify return values when there is just one term
    if len(reference_tensors) == 1:
        reference_tensors = reference_tensors[0]
    if len(geometry_tensor_codes) == 1:
        geometry_tensor_codes = geometry_tensor_codes[0]

    return reference_tensors, geometry_tensor_codes
Пример #4
0
def compute_tensor_representation(form):
    """Compute tensor representation for given form. This function may
    be useful for those (Hi Matt!) that want to access the FFC tensor
    representation from outside FFC."""

    # Set parameters
    parameters = default_parameters()
    parameters["representation"] = "tensor"
    #parameters["optimize"] = "optimize"

    # The below steps basically duplicate the compiler process but
    # skip the code formatting step. Instead, we extract the relevant
    # portions for tabulate_tensor.

    # Stage 1: analysis
    cpu_time = time()
    analysis = analyze_forms([form], {}, parameters)
    _print_timing(1, time() - cpu_time)

    # Stage 2: intermediate representation
    cpu_time = time()
    ir = compute_ir(analysis, parameters)
    _print_timing(2, time() - cpu_time)

    # Stage 3: optimization
    cpu_time = time()
    oir = optimize_ir(ir, parameters)
    _print_timing(3, time() - cpu_time)

    # Stage 4: code generation
    cpu_time = time()
    code = generate_code(oir, "foo", parameters)
    _print_timing(4, time() - cpu_time)

    # Extract representations
    ir_elements, ir_dofmaps, ir_integrals, ir_forms = ir

    # Extract entries in reference tensor
    reference_tensors = []
    for i in ir_integrals:
        if i["integral_type"] == "cell":
            t = [A0.A0 for (A0, GK, dummy) in i["AK"]]
            if len(t) == 1: t = t[0]
        elif i["integral_type"] == "exterior_facet":
            t = [A0.A0 for j in i["AK"] for (A0, GK, dummy) in j]
            if len(t) == 1: t = t[0]
        elif i["integral_type"] == "interior_facet":
            t = [A0.A0 for j in i["AK"] for k in j for (A0, GK, dummy) in k]
            if len(t) == 1: t = t[0]
        else:
            raise RuntimeError("Unhandled domain type: %s" %
                               str(i["integral_type"]))
        reference_tensors.append(t)

    # Extract code
    code_elements, code_dofmaps, code_integrals, code_forms = code

    # Extract code for computing the geometry tensor
    geometry_tensor_codes = [
        c["tabulate_tensor"].split("// Compute element tensor")[0]
        for c in code_integrals
    ]

    # Simplify return values when there is just one term
    if len(reference_tensors) == 1:
        reference_tensors = reference_tensors[0]
    if len(geometry_tensor_codes) == 1:
        geometry_tensor_codes = geometry_tensor_codes[0]

    return reference_tensors, geometry_tensor_codes
Пример #5
0
def compile_form(forms, object_names=None, prefix="Form", parameters=None):
    """This function generates UFC code for a given UFL form or list
    of UFL forms."""

    info("Compiling form %s\n" % prefix)

    # Reset timing
    cpu_time_0 = time()

    # Check input arguments
    forms = _check_forms(forms)
    if not forms:
        return
    if prefix != os.path.basename(prefix):
        prefix = os.path.basename(prefix)
        warning("Invalid prefix, modified to {}.".format(prefix))
    if object_names is None:
        object_names = {}
    parameters = _check_parameters(parameters)

    # Stage 1: analysis
    cpu_time = time()
    analysis = analyze_forms(forms, parameters)
    _print_timing(1, time() - cpu_time)

    # Stage 2: intermediate representation
    cpu_time = time()
    ir = compute_ir(analysis, prefix, parameters, object_names=object_names)
    _print_timing(2, time() - cpu_time)

    # Stage 3: optimization
    cpu_time = time()
    oir = optimize_ir(ir, parameters)
    _print_timing(3, time() - cpu_time)

    # Return IR (PyOP2 mode) or code string (otherwise)
    if parameters["pyop2-ir"]:
        try:
            from ffc.quadrature.quadraturepyop2ir import generate_pyop2_ir
        except ImportError:
            raise ImportError("Format pyop2-ir depends on PyOP2, which is not available.")
        # Stage 4: build PyOP2 intermediate representation

        cpu_time = time()
        #FIXME: need a cleaner interface
        pyop2_ir = [generate_pyop2_ir(ir, prefix, parameters) for ir in oir[3]]
        _print_timing(4, time() - cpu_time)

        info_green("FFC finished in %g seconds.", time() - cpu_time_0)
        return pyop2_ir

    else:
        # Stage 4: code generation
        cpu_time = time()
        code = generate_code(oir, prefix, parameters)
        _print_timing(4, time() - cpu_time)

        # Stage 4.1: generate wrappers
        cpu_time = time()
        wrapper_code = generate_wrapper_code(analysis, prefix, object_names, parameters)
        _print_timing(4.1, time() - cpu_time)

        # Stage 5: format code
        cpu_time = time()
        code_h, code_c = format_code(code, wrapper_code, prefix, parameters)
        write_code(code_h, code_c, prefix, parameters) # FIXME: Don't write to file in this function (issue #72)
        _print_timing(5, time() - cpu_time)

        info_green("FFC finished in %g seconds.", time() - cpu_time_0)

        return code