Пример #1
0
def _create_foo_integral(prefix, form_id, integral_type, form_data,
                         parameters):
    """Compute intermediate representation of create_foo_integral."""

    subdomain_ids = []
    classnames = []

    itg_data = [
        itg_data for itg_data in form_data.integral_data
        if (itg_data.integral_type == integral_type
            and itg_data.subdomain_id == "otherwise")
    ]

    if len(itg_data) > 1:
        raise RuntimeError(
            "Expecting at most one default integral of each type.")
    elif len(itg_data) == 1:
        subdomain_ids += [-1]
        classnames += [
            classname.make_integral_name(prefix, integral_type,
                                         form_data.original_form, form_id,
                                         'otherwise', parameters)
        ]

    for itg_data in form_data.integral_data:
        if isinstance(itg_data.subdomain_id, int):
            if itg_data.subdomain_id < 0:
                raise ValueError(
                    "Integral subdomain ID must be non-negative, not {}".
                    format(itg_data.subdomain_id))
            if (itg_data.integral_type == integral_type):
                subdomain_ids += [itg_data.subdomain_id]
                classnames += [
                    classname.make_integral_name(prefix, integral_type,
                                                 form_data.original_form,
                                                 form_id,
                                                 itg_data.subdomain_id,
                                                 parameters)
                ]

    return subdomain_ids, classnames
Пример #2
0
def initialize_integral_code(ir, prefix, parameters):
    """Representation independent default initialization of code dict for
    integral from intermediate representation.

    """
    code = {}
    code["class_type"] = ir.integral_type + "_integral"
    code["classname"] = classname.make_integral_name(prefix, ir.integral_type, ir.form_id,
                                                     ir.subdomain_id)
    code["members"] = ""
    code["constructor"] = ""
    code["constructor_arguments"] = ""
    code["initializer_list"] = ""
    code["destructor"] = ""
    code["enabled_coefficients"] = generate_enabled_coefficients(ir.enabled_coefficients)
    code["additional_includes_set"] = set()  # FIXME: Get this out of code[]

    return code
Пример #3
0
def _compute_integral_ir(form_data, form_index, prefix, element_numbers,
                         classnames, parameters):
    """Compute intermediate represention for form integrals."""
    if form_data.representation == "uflacs":
        from ffc.ir.uflacs.uflacsrepresentation import compute_integral_ir
    elif form_data.representation == "tsfc":
        from ffc.ir.tsfcrepresentation import compute_integral_ir
    else:
        raise RuntimeError("Unknown representation: {}".format(
            form_data.representation))

    # Iterate over integrals
    irs = []
    for itg_data in form_data.integral_data:
        # FIXME: Can we remove form_index?
        # Compute representation
        ir = compute_integral_ir(itg_data, form_data, form_index,
                                 element_numbers, classnames, parameters)

        # Build classname
        ir["classname"] = classname.make_integral_name(prefix,
                                                       itg_data.integral_type,
                                                       form_index,
                                                       itg_data.subdomain_id)
        ir["classnames"] = classnames  # FIXME XXX: Use this everywhere needed?

        # Storing prefix here for reconstruction of classnames on code
        # generation side
        ir["prefix"] = prefix  # FIXME: Drop this?

        # Store metadata for later reference (eg. printing as comment)
        # NOTE: We make a commitment not to modify it!
        ir["integrals_metadata"] = itg_data.metadata
        ir["integral_metadata"] = [
            integral.metadata() for integral in itg_data.integrals
        ]

        irs.append(ir_integral(**ir))

    return irs