Subject: [Ffc] [[email-masked]: Re: [Branch ~ffc-core/ffc/dev] Rev 1471: Fixed compile_element. AL will probably dislike fix in formatting, so]

From: Anders Logg <[email-masked]>
Date: Fri, 15 Jan 2010 20:47:11 +0100

Subject: Re: [Branch ~ffc-core/ffc/dev] Rev 1471: Fixed compile_element. AL will probably dislike fix in formatting, so
From: Anders Logg <[email-masked]>
To: [email-masked]
Date: Fri, 15 Jan 2010 20:46:08 +0100

I'll try to find something which is a bit less of a hack. :-)

--
Anders

On Fri, Jan 15, 2010 at 02:56:24PM -0000, [email-masked] wrote:
> ------------------------------------------------------------
> revno: 1471
> committer: Marie E. Rognes <[email-masked]>
> branch nick: ffc-unstable
> timestamp: Fri 2010-01-15 15:54:15 +0100
> message:
>   Fixed compile_element. AL will probably dislike fix in formatting, so
>   feel free to modify ;)
> modified:
>   ffc/compiler.py
>   ffc/formatting.py
>   ffc/representation.py
>
>

> === modified file 'ffc/compiler.py'
> --- ffc/compiler.py	2010-01-14 20:54:57 +0000
> +++ ffc/compiler.py	2010-01-15 14:54:15 +0000
> @@ -164,6 +164,11 @@
>      """This function generates UFC code for a given UFL element or
>      list of UFL elements."""
>
> +    from ffc.representation import compute_element_ir
> +    from ffc.representation import compute_dofmap_ir
> +    from ffc.codegeneration import generate_element_code
> +    from ffc.codegeneration import generate_dofmap_code
> +
>      # Check options
>      options = _check_options(options)
>
> @@ -176,17 +181,26 @@
>          info("No elements specified, nothing to do.")
>          return
>
> -    # Create format
> -    format = Format(options)
> -
> -    # Compiler stage 4: generate element code
> -    #generated_elements = generate_element_code(elements, format.format)
> +    # FIXME:
> +    form_data = None
> +
> +    codes = []
> +    for e in elements:
> +
> +        # Compute intermediate representation
> +        element_ir = compute_element_ir(e, form_data)
> +        dofmap_ir = compute_dofmap_ir(e, form_data)
> +
> +        # Generate code
> +        codes += [([generate_element_code(0, element_ir, prefix, options)],
> +                   [generate_dofmap_code(0, dofmap_ir, prefix, options)])]
>
>      # Compiler stage 5: format code
> -    format_code(generated_elements, prefix, format, options)
> +    format_code(codes, prefix, options)
>
>      info("Code generation complete.")
>
> +
>  def _check_forms(forms):
>      "Initial check of forms."
>
>
> === modified file 'ffc/formatting.py'
> --- ffc/formatting.py	2010-01-14 22:09:08 +0000
> +++ ffc/formatting.py	2010-01-15 14:54:15 +0000
> @@ -15,7 +15,7 @@
>  __copyright__ = "Copyright (C) 2009 " + __author__
>  __license__  = "GNU GPL version 3 or any later version"
>
> -# Last changed: 2010-01-14
> +# Last changed: 2010-01-15
>
>  # Python modules
>  import os
> @@ -55,7 +55,10 @@
>      for code in codes:
>
>          # Extract generated code
> -        code_elements, code_dofmaps, code_integrals, code_form = code
> +        if len(code) == 4:
> +            code_elements, code_dofmaps, code_integrals, code_form = code
> +        else:
> +            code_elements, code_dofmaps = code
>
>          # Generate code for elements
>          for code_element in code_elements:
> @@ -65,6 +68,10 @@
>          for code_dofmap in code_dofmaps:
>              output += dof_map_combined % code_dofmap + "\n"
>
> +        # Skip form formatting if no form code generated
> +        if len(code) == 2:
> +            continue
> +
>          # Generate code for cell integrals
>          for code_integral in code_integrals[0]:
>              output += cell_integral_combined % code_integral + "\n"
>
> === modified file 'ffc/representation.py'
> --- ffc/representation.py	2010-01-14 20:54:57 +0000
> +++ ffc/representation.py	2010-01-15 14:54:15 +0000
> @@ -88,8 +88,7 @@
>      ir["evaluate_dofs"] = ir["evaluate_dof"]
>      ir["interpolate_vertex_values"] = _interpolate_vertex_values(element, cell)
>      ir["num_sub_elements"] = ufl_element.num_sub_elements()
> -    ir["create_sub_element"] = [form_data.element_map[e]
> -                                for e in ufl_element.sub_elements()]
> +    ir["create_sub_element"] = _create_sub_foo(ufl_element, form_data)
>
>      #debug_ir(ir, "finite_element")
>
> @@ -124,13 +123,20 @@
>      ir["tabulate_entity_dofs"] = (element.entity_dofs(), num_dofs_per_entity)
>      ir["tabulate_coordinates"] = _tabulate_coordinates(element)
>      ir["num_sub_dof_maps"] = ufl_element.num_sub_elements()
> -    ir["create_sub_dof_map"] = [form_data.element_map[e]
> -                                for e in ufl_element.sub_elements()]
> +    ir["create_sub_dof_map"] = _create_sub_foo(ufl_element, form_data)
>
>      #debug_ir(ir, "dofmap")
>
>      return ir
>
> +def _create_sub_foo(ufl_element, form_data):
> +    if form_data is None:
> +        return [0]*ufl_element.num_sub_elements()
> +
> +    return [form_data.element_map[e] for e in ufl_element.sub_elements()]
> +
> +
> +
>  def compute_integrals_ir(form, form_data, options):
>      "Compute intermediate represention of integrals."
>      # FIXME: Handle multiple representations here
>