Subject: [Ffc] [[email-masked]: [Branch ~ffc-core/ffc/dev] Rev 1484: Lots of fixes in many places. DOLFIN Poisson demo now compiles. But an assertion]

From: Anders Logg <[email-masked]>
Date: Mon, 18 Jan 2010 21:30:06 +0100

Marie, could you have a look at init_mesh? There seems to be a small
bug. For P1 elements, it generates

  _global_dimension = m.num_entities[1];

It should be

  _global_dimension = m.num_entities[0];

--
Anders

Subject: [Branch ~ffc-core/ffc/dev] Rev 1484: Lots of fixes in many places. DOLFIN Poisson demo now compiles. But an assertion
From: [email-masked]
To: Anders Logg <[email-masked]>
Date: Mon, 18 Jan 2010 20:27:15 -0000

------------------------------------------------------------
revno: 1484
committer: Anders Logg <[email-masked]>
branch nick: ffc-dev
timestamp: Mon 2010-01-18 21:24:30 +0100
message:
  Lots of fixes in many places. DOLFIN Poisson demo now compiles. But an assertion
  fails: demo: ./dolfin/fem/DofMap.h:78: unsigned int dolfin::DofMap::global_dimension() const: Assertion `_ufc_dofmap->global_dimension() > 0' failed.
modified:
  ffc/analysis.py
  ffc/codegeneration.py
  ffc/compiler.py
  ffc/cpp.py
  ffc/evaluatedof.py
  ffc/tensor/tensorgenerator.py
  ffc/wrappers.py
  scripts/ffc

--
lp:~ffc-core/ffc/dev
https://code.launchpad.net/~ffc-core/ffc/dev

You are subscribed to branch lp:~ffc-core/ffc/dev.
To unsubscribe from this branch go to https://code.launchpad.net/~ffc-core/ffc/dev/+edit-subscription.
=== modified file 'ffc/analysis.py'
--- ffc/analysis.py	2010-01-18 18:50:57 +0000
+++ ffc/analysis.py	2010-01-18 20:24:30 +0000
@@ -22,7 +22,7 @@
 from ffc.log import log, info, begin, end
 from ffc.quadratureelement import default_quadrature_degree
 
-def analyze_forms(forms, options):
+def analyze_forms(forms, object_names, options):
     """
     Analyze form(s), returning
 
@@ -34,7 +34,7 @@
     begin("Compiler stage 1: Analyzing form(s)")
 
     # Analyze forms
-    form_and_data = [analyze_form(form, options) for form in forms]
+    form_and_data = [analyze_form(form, object_names, options) for form in forms]
 
     # Extract unique elements
     unique_elements = []
@@ -42,14 +42,14 @@
     for (form, form_data) in form_and_data:
         for element in form_data.unique_elements:
             if not element in element_map:
+                element_map[element] = len(unique_elements)
                 unique_elements.append(element)
-                element_map[element] = len(unique_elements)
 
     end()
 
     return form_and_data, unique_elements, element_map
 
-def analyze_form(form, options):
+def analyze_form(form, object_names, options):
     "Analyze form, returning preprocessed form and form data."
 
     # Preprocess form
@@ -57,7 +57,7 @@
         form = preprocess(form)
 
     # Compute form data
-    form_data = FormData(form)
+    form_data = FormData(form, object_names=object_names)
     info(str(form_data))
 
     # Adjust cell and degree for elements when unspecified

=== modified file 'ffc/codegeneration.py'
--- ffc/codegeneration.py	2010-01-18 18:52:59 +0000
+++ ffc/codegeneration.py	2010-01-18 20:24:30 +0000
@@ -126,7 +126,7 @@
     code["max_local_dimension"] = ret(ir["max_local_dimension"])
     code["geometric_dimension"] = ret(ir["geometric_dimension"])
     code["num_facet_dofs"] = ret(ir["num_facet_dofs"])
-    code["num_entity_dofs"] = switch("d", [ret(num) for num in ir["num_entity_dofs"]])
+    code["num_entity_dofs"] = switch("d", [ret(num) for num in ir["num_entity_dofs"]], ret("0"))
     code["tabulate_dofs"] = _tabulate_dofs(ir["tabulate_dofs"])
     code["tabulate_facet_dofs"] = _tabulate_facet_dofs(ir["tabulate_facet_dofs"])
     code["tabulate_entity_dofs"] = _tabulate_entity_dofs(ir["tabulate_entity_dofs"])
@@ -176,9 +176,9 @@
     code["num_interior_facet_integrals"] = ret(ir["num_interior_facet_integrals"])
     code["create_finite_element"] = _create_foo(ir["create_finite_element"], prefix, "finite_element")
     code["create_dof_map"] = _create_foo(ir["create_dof_map"], prefix, "dof_map")
-    code["create_cell_integral"] = _create_foo(ir["create_cell_integral"], prefix, "cell_integral")
-    code["create_exterior_facet_integral"] = _create_foo(ir["create_exterior_facet_integral"], prefix, "exterior_facet_integral")
-    code["create_interior_facet_integral"] = _create_foo(ir["create_interior_facet_integral"], prefix, "interior_facet_integral")
+    code["create_cell_integral"] = _create_foo_integral(ir, "cell", prefix)
+    code["create_exterior_facet_integral"] = _create_foo_integral(ir, "exterior_facet", prefix)
+    code["create_interior_facet_integral"] = _create_foo_integral(ir, "interior_facet", prefix)
 
     # Postprocess code
     _postprocess_code(code, options)
@@ -197,13 +197,13 @@
     return format["switch"]("i", [ret(n) for n in ir])
 
 def _needs_mesh_entities(ir):
-    """Generate code for needs_mesh_entities. ir is a list of num dofs
+    """
+    Generate code for needs_mesh_entities. ir is a list of num dofs
     per entity.
     """
-
     ret = format["return"]
     boolean = format["bool"]
-    return format["switch"]("d", [ret(boolean(c)) for c in ir])
+    return format["switch"]("d", [ret(boolean(c)) for c in ir], ret(boolean(False)))
 
 def _init_mesh(ir):
     "Generate code for init_mesh. ir is a list of num dofs per entity."
@@ -359,9 +359,15 @@
 def _create_foo(numbers, prefix, class_name):
     "Generate code for create_<foo>."
     class_names = ["%s_%s_%d" % (prefix.lower(), class_name, i) for i in numbers]
-    cases  = [format["return"]("new " + name + "()") for name in class_names]
-    cases += [format["return"](0)]
-    return format["switch"]("i", cases)
+    cases = [format["return"]("new " + name + "()") for name in class_names]
+    default = format["return"](0)
+    return format["switch"]("i", cases + [default], default)
+
+def _create_foo_integral(ir, integral_type, prefix):
+    "Generate code for create_<foo>_integral."
+    class_name = integral_type + "_integral_" + str(ir["id"])
+    numbers = ir["create_" + integral_type + "_integral"]
+    return _create_foo(numbers, prefix, class_name)
 
 def _postprocess_code(code, options):
     "Postprocess generated code."

=== modified file 'ffc/compiler.py'
--- ffc/compiler.py	2010-01-18 18:50:57 +0000
+++ ffc/compiler.py	2010-01-18 20:24:30 +0000
@@ -114,7 +114,7 @@
 from ffc.formatting import format_code
 from ffc.wrappers import generate_wrapper_code
 
-def compile_form(forms, prefix="Form", options=FFC_OPTIONS.copy()):
+def compile_form(forms, object_names={}, prefix="Form", options=FFC_OPTIONS.copy()):
     """This function generates UFC code for a given UFL form or list
     of UFL forms."""
 
@@ -127,7 +127,7 @@
     cpu_time = time()
 
     # Stage 1: analysis
-    analysis = analyze_forms(forms, options)
+    analysis = analyze_forms(forms, object_names, options)
     _print_timing(1, time() - cpu_time)
 
     # Stage 2: intermediate representation
@@ -143,7 +143,7 @@
     _print_timing(4, time() - cpu_time)
 
     # Stage 4.1: generate wrappers
-    wrapper_code = generate_wrapper_code(analysis[0], prefix, options)
+    wrapper_code = generate_wrapper_code(analysis, prefix, options)
     _print_timing(4.1, time() - cpu_time)
 
     # Stage 5: format code
@@ -153,7 +153,7 @@
     info("Code generation complete.")
     return analysis
 
-def compile_element(elements, prefix="Element", options=FFC_OPTIONS.copy()):
+def compile_element(elements, object_names={}, prefix="Element", options=FFC_OPTIONS.copy()):
     """This function generates UFC code for a given UFL element or
     list of UFL elements."""

=== modified file 'ffc/cpp.py'
--- ffc/cpp.py	2010-01-18 18:50:57 +0000
+++ ffc/cpp.py	2010-01-18 20:24:30 +0000
@@ -23,7 +23,7 @@
 # Program flow
 format.update({"return":     lambda v: "return %s;" % str(v),
                "grouping":   lambda v: "(%s)" % v,
-               "switch":     lambda v, cases: _generate_switch(v, cases),
+               "switch":     lambda v, cases, default=None: _generate_switch(v, cases, default),
                "exception":  lambda v: "throw std::runtime_error(\"%s\");" % v,
                "comment":    lambda v: "// %s" % v,
                "if":         lambda c, v: "if (%s) {\n%s\n}\n" % (c, v),
@@ -162,7 +162,7 @@
     map_name = {"J": "J", "JINV": "K"}[type] + {None: "", "+": "0", "-": "1"}[r]
     return (map_name + "_%d%d") % (j, k)
 
-def _generate_switch(variable, cases):
+def _generate_switch(variable, cases, default=None):
     "Generate switch statement from given variable and cases"
 
     # Special case: no cases:
@@ -177,7 +177,11 @@
     code = "switch (%s)\n{\n" % variable
     for i in range(len(cases)):
         code += "case %d:\n%s\n  break;\n" % (i, indent(cases[i], 2))
-    code += "}"
+    code += "}\n"
+
+    # Default value
+    if default:
+        code += "\n" + default
 
     return code

=== modified file 'ffc/evaluatedof.py'
--- ffc/evaluatedof.py	2010-01-14 20:42:23 +0000
+++ ffc/evaluatedof.py	2010-01-18 20:24:30 +0000
@@ -60,7 +60,7 @@
     code = []
     code.append(reqs)
     code.append(comment("Evaluate degree of freedom of function"))
-    code.append(format["switch"]("i", cases))
+    code.append(format["switch"]("i", cases, format["return"]("0.0")))
 
     # Removed unused variables from code (Add computation of set of
     # used variables if ever bottle-neck)

=== modified file 'ffc/tensor/tensorgenerator.py'
--- ffc/tensor/tensorgenerator.py	2010-01-18 18:50:57 +0000
+++ ffc/tensor/tensorgenerator.py	2010-01-18 20:24:30 +0000
@@ -20,8 +20,6 @@
 def generate_integral_code(ir, prefix, options):
     "Generate code for integral from intermediate representation."
 
-    print ir
-
     # Prefetch formatting to speedup code generation
     do_nothing = format["do nothing"]
     classname = format["classname " + ir["integral_type"]]
@@ -73,7 +71,7 @@
         cases = [None for i in range(num_facets)]
         for i in range(num_facets):
             cases[i] = _generate_tensor_contraction(AK[i], options, g_set)
-        t_code = switch("i", cases)
+        t_code = switch("facet", cases)
 
         # Generate code for geometry tensors
         g_code = _generate_geometry_tensors(AK[0], j_set, g_set)
@@ -90,7 +88,7 @@
         for i in range(num_facets):
             for j in range(num_facets):
                 cases[i][j] = _generate_tensor_contraction(AK[i][j], options, g_set)
-        t_code = switch("i", [switch("j", cases[i]) for i in range(len(cases))])
+        t_code = switch("facet0", [switch("facet1", cases[i]) for i in range(len(cases))])
 
         # Generate code for geometry tensors
         g_code = _generate_geometry_tensors(AK[0][0], j_set, g_set)

=== modified file 'ffc/wrappers.py'
--- ffc/wrappers.py	2010-01-18 13:56:31 +0000
+++ ffc/wrappers.py	2010-01-18 20:24:30 +0000
@@ -13,7 +13,7 @@
 from ffc.utils import all_equal
 from ffc.cpp import format
 
-def generate_wrapper_code(form_and_data, prefix, options):
+def generate_wrapper_code(analysis, prefix, options):
     "Generate code for additional wrappers."
 
     # Skip if wrappers not requested
@@ -27,6 +27,9 @@
 
     begin("Compiler stage 4.1: Generating additional wrapper code")
 
+    # Extract data from analysis
+    form_and_data, elements, element_map = analysis
+
     # Special case: single element
     #if len(generated_forms) == 1 and generated_forms[0][1].form is None:
     #    fn = UFCFormNames("0",
@@ -39,7 +42,10 @@
     # Generate name data for each form
     form_names = []
     for (i, (form, form_data)) in enumerate(form_and_data):
-        element_numbers = [form_data.element_map[e] for e in form_data.elements]
+        element_numbers = [element_map[e] for e in form_data.elements]
+
+        print form_data.coefficient_names
+
         form_names.append(UFCFormNames("%d" % i,
                                        form_data.coefficient_names,
                                        format["classname form"](prefix, i),
@@ -47,7 +53,7 @@
                                        [format["classname dof_map"](prefix, j) for j in element_numbers]))
 
     # Check if all elements are equal
-    if all_equal([e for e in chain([form_data.elements for (form, form_data) in form_and_data])]):
+    if all_equal(elements):
         common_space = (0, 0)
     else:
         common_space = None

=== modified file 'scripts/ffc'
--- scripts/ffc	2010-01-14 10:57:07 +0000
+++ scripts/ffc	2010-01-18 20:24:30 +0000
@@ -13,7 +13,7 @@
 # Modified by Ola Skavhaug, 2006.
 # Modified by Dag Lindbo, 2008.
 # Modified by Kristian B. Oelgaard 2009.
-# Last changed: 2010-01-14
+# Last changed: 2010-01-18
 
 # Python modules.
 import sys
@@ -146,15 +146,15 @@
         # Catch exceptions only when not in debug mode
         if options["log_level"] <= DEBUG:
             if len(ufd.forms) > 0:
-                compile_form(ufd.forms, prefix, options)
+                compile_form(ufd.forms, ufd.object_names, prefix, options)
             else:
-                compile_element(ufd.elements, prefix, options)
+                compile_element(ufd.elements, ufd.object_names, prefix, options)
         else:
             try:
                 if len(ufd.forms) > 0:
-                    compile_form(ufd.forms, prefix, options)
+                    compile_form(ufd.forms, ufd.object_names, prefix, options)
                 else:
-                    compile_element(ufd.elements, prefix, options)
+                    compile_element(ufd.elements, ufd.object_names, prefix, options)
             except Exception, exception:
                 info("")
                 error(str(exception))

---

From: Marie Rognes <[email-masked]>
Date: Mon, 18 Jan 2010 21:42:34 +0100

>   _global_dimension = m.num_entities[0];

Fixed.

--
Marie

> --
> Anders
>   
>
> ------------------------------------------------------------------------
>
> Subject:
> [Branch ~ffc-core/ffc/dev] Rev 1484: Lots of fixes in many places. 
> DOLFIN Poisson demo now compiles. But an assertion
> From:
> [email-masked]
> Date:
> ------------------------------------------------------------------------
>
> _______________________________________________
> Mailing list: https://launchpad.net/~ffc
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ffc
> More help   : https://help.launchpad.net/ListHelp

---

From: Anders Logg <[email-masked]>
Date: Mon, 18 Jan 2010 22:07:58 +0100

> >  _global_dimension = m.num_entities[0];

Great! Now the Poisson demo runs but the solution looks wrong.

--
Anders

---

From: Marie Rognes <[email-masked]>
Date: Mon, 18 Jan 2010 22:33:55 +0100

> Great! Now the Poisson demo runs but the solution looks wrong.

There seems to be some coefficients missing in the generated tabulate_tensor
for the right-hand side?

--
Marie

---

From: Anders Logg <[email-masked]>
Date: Tue, 19 Jan 2010 00:21:31 +0100

> There seems to be some coefficients missing in the generated tabulate_tensor

Ah, yes. Very strange. I have some other things planned for tomorrow
so I might not be able to fix it until late tomorrow or Wednesday.

--
Anders