コード例 #1
0
def generator(ir, parameters):
    """Generate UFC code for a finite element."""
    d = {}
    d["factory_name"] = ir.classname
    d["signature"] = "\"{}\"".format(ir.signature)
    d["geometric_dimension"] = ir.geometric_dimension
    d["topological_dimension"] = ir.topological_dimension
    d["cell_shape"] = ir.cell_shape
    d["space_dimension"] = ir.space_dimension
    d["value_rank"] = len(ir.value_shape)
    d["value_size"] = ufl.product(ir.value_shape)
    d["reference_value_rank"] = len(ir.reference_value_shape)
    d["reference_value_size"] = ufl.product(ir.reference_value_shape)
    d["degree"] = ir.degree
    d["family"] = "\"{}\"".format(ir.family)
    d["num_sub_elements"] = ir.num_sub_elements

    import ffc.codegeneration.C.cnodes as L

    d["value_dimension"] = value_dimension(L, ir.value_shape)
    d["reference_value_dimension"] = reference_value_dimension(
        L, ir.reference_value_shape)

    statements = evaluate_reference_basis(L, ir, parameters)
    d["evaluate_reference_basis"] = L.StatementList(statements)

    statements = evaluate_reference_basis_derivatives(L, ir, parameters)
    d["evaluate_reference_basis_derivatives"] = L.StatementList(statements)

    statements = transform_reference_basis_derivatives(L, ir, parameters)
    d["transform_reference_basis_derivatives"] = L.StatementList(statements)

    statements = transform_values(L, ir, parameters)
    d["transform_values"] = L.StatementList(statements)

    statements = tabulate_reference_dof_coordinates(L, ir, parameters)
    d["tabulate_reference_dof_coordinates"] = L.StatementList(statements)

    statements = create_sub_element(L, ir)
    d["sub_element_declaration"] = sub_element_declaration(L, ir)
    d["create_sub_element"] = statements

    # Check that no keys are redundant or have been missed
    from string import Formatter
    fieldnames = [
        fname
        for _, fname, _, _ in Formatter().parse(ufc_finite_element.factory)
        if fname
    ]
    assert set(fieldnames) == set(
        d.keys()), "Mismatch between keys in template and in formattting dict"

    # Format implementation code
    implementation = ufc_finite_element.factory.format_map(d)

    # Format declaration
    declaration = ufc_finite_element.declaration.format(
        factory_name=ir.classname)

    return declaration, implementation
コード例 #2
0
ファイル: coordinate_mapping.py プロジェクト: knut0815/ffcx
def generator(ir, parameters):
    """Generate UFC code for a coordinate mapping"""

    d = {}

    # Attributes
    d["factory_name"] = ir.classname
    d["signature"] = "\"{}\"".format(ir.signature)
    d["geometric_dimension"] = ir.geometric_dimension
    d["topological_dimension"] = ir.topological_dimension
    d["cell_shape"] = ir.cell_shape

    import ffc.codegeneration.C.cnodes as L

    # Functions
    d["create_coordinate_finite_element"] = create_coordinate_finite_element(L, ir)
    d["coordinate_finite_element_declaration"] = coordinate_finite_element_declaration(L, ir)
    d["create_coordinate_dofmap"] = create_coordinate_dofmap(L, ir)
    d["coordinate_dofmap_declaration"] = coordinate_dofmap_declaration(L, ir)

    statements = compute_physical_coordinates(L, ir)
    d["compute_physical_coordinates"] = L.StatementList(statements)
    d["evaluate_reference_basis_declaration"] = evaluate_reference_basis_declaration(L, ir)

    statements = compute_reference_coordinates(L, ir)
    d["compute_reference_coordinates"] = L.StatementList(statements)

    statements = compute_reference_geometry(L, ir)
    d["compute_reference_geometry"] = L.StatementList(statements)
    d["evaluate_reference_basis_derivatives_declaration"] = evaluate_reference_basis_derivatives_declaration(L, ir)

    statements = compute_jacobians(L, ir)
    d["compute_jacobians"] = L.StatementList(statements)

    d["compute_jacobian_determinants"] = compute_jacobian_determinants(L, ir)
    d["compute_jacobian_inverses"] = compute_jacobian_inverses(L, ir)

    statements = compute_geometry(L, ir)
    d["compute_geometry"] = L.StatementList(statements)

    statements = compute_midpoint_geometry(L, ir)
    d["compute_midpoint_geometry"] = L.StatementList(statements)

    # Check that no keys are redundant or have been missed
    from string import Formatter
    fields = [
        fname for _, fname, _, _ in Formatter().parse(ufc_coordinate_mapping.factory) if fname
    ]
    assert set(fields) == set(
        d.keys()), "Mismatch between keys in template and in formattting dict."

    # Format implementation code
    implementation = ufc_coordinate_mapping.factory.format_map(d)

    # Format declaration
    declaration = ufc_coordinate_mapping.declaration.format(factory_name=ir.classname)

    return declaration, implementation
コード例 #3
0
def generator(ir, parameters):
    """Generate UFC code for a form"""

    factory_name = ir.classname

    d = {}
    d["factory_name"] = factory_name
    d["signature"] = "\"{}\"".format(ir.signature)
    d["rank"] = ir.rank
    d["num_coefficients"] = ir.num_coefficients

    d["num_cell_integrals"] = len(ir.create_cell_integral[0])
    d["num_exterior_facet_integrals"] = len(
        ir.create_exterior_facet_integral[0])
    d["num_interior_facet_integrals"] = len(
        ir.create_interior_facet_integral[0])
    d["num_vertex_integrals"] = len(ir.create_vertex_integral[0])
    d["num_custom_integrals"] = len(ir.create_custom_integral[0])

    import ffc.codegeneration.C.cnodes as L
    generator = UFCForm()

    statements = generator.original_coefficient_position(L, ir)
    d["original_coefficient_position"] = L.StatementList(statements)

    d["coefficient_name_map"] = generator.generate_coefficient_position_to_name_map(
        L, ir)

    d["create_coordinate_finite_element"] = generator.create_coordinate_finite_element(
        L, ir)
    d["coordinate_finite_element_declaration"] = generator.coordinate_finite_element_declaration(
        L, ir)
    d["create_coordinate_dofmap"] = generator.create_coordinate_dofmap(L, ir)
    d["coordinate_dofmap_declaration"] = generator.coordinate_dofmap_declaration(
        L, ir)
    d["create_coordinate_mapping"] = generator.create_coordinate_mapping(L, ir)
    d["coordinate_mapping_declaration"] = generator.coordinate_mapping_declaration(
        L, ir)
    d["create_finite_element"] = generator.create_finite_element(L, ir)
    d["finite_element_declaration"] = generator.finite_element_declaration(
        L, ir)
    d["create_dofmap"] = generator.create_dofmap(L, ir)
    d["dofmap_declaration"] = generator.dofmap_declaration(L, ir)

    d["get_cell_integral_ids"] = generator.get_cell_integral_ids(
        L, ir, parameters)
    d["get_exterior_facet_integral_ids"] = generator.get_exterior_facet_integral_ids(
        L, ir, parameters)
    d["get_interior_facet_integral_ids"] = generator.get_interior_facet_integral_ids(
        L, ir, parameters)
    d["get_vertex_integral_ids"] = generator.get_vertex_integral_ids(
        L, ir, parameters)
    d["get_custom_integral_ids"] = generator.get_custom_integral_ids(
        L, ir, parameters)

    d["create_cell_integral"] = generator.create_cell_integral(
        L, ir, parameters)
    d["create_interior_facet_integral"] = generator.create_interior_facet_integral(
        L, ir, parameters)
    d["create_exterior_facet_integral"] = generator.create_exterior_facet_integral(
        L, ir, parameters)
    d["create_vertex_integral"] = generator.create_vertex_integral(
        L, ir, parameters)
    d["create_custom_integral"] = generator.create_custom_integral(
        L, ir, parameters)

    # Check that no keys are redundant or have been missed
    from string import Formatter
    fields = [
        fname for _, fname, _, _ in Formatter().parse(ufc_form.factory)
        if fname
    ]
    assert set(fields) == set(
        d.keys()), "Mismatch between keys in template and in formattting dict"

    # Format implementation code
    implementation = ufc_form.factory.format_map(d)

    # Format declaration
    declaration = ufc_form.declaration.format(factory_name=factory_name)

    return declaration, implementation