Get rid of arguments to compute_form_data

Issue #7 duplicate
Martin Sandve Alnæs created an issue

We must get rid of the arguments to compute_form_data for a bunch of reasons. This affects UFL, FFC, and DOLFIN.

Here's two of the reasons from the old launchpad pages:

Attaching form data to Form instance is bug prone

If preprocess didn't have any arguments, the attachment of form data to a form would be safe since it would be a pure cache mechanism and repeating the preprocess call would always have the same result.

However, since preprocess has arguments, the result will depend on those arguments, and preprocessing the form twice with different arguments will give the wrong result.

This is closely related to caching mechanisms involving pydolfin and form compilers, and cannot be handled by a pure ufl fix.

Assembling a functional on 2D and 3D mesh in PyDOLFIN fails

While the problem is in UFL code, I'm filing it under dolfin because it is a PyDOLFIN support feature that fails.

The attachment of form data to a ufl.Form object was initially a kind of caching, which was guaranteed to be functionally correct since forms are immutable. However, with the introduction of incompletely specified forms in PyDOLFIN (missing cells and elements), the form data computation required additional data. Thus there is no longer a unique mapping from ufl.Form to FormData, and associating one unique FormData object with one Form object is not correct. When specifying an incomplete form in PyDOLFIN and using it in two contexts leading to different input to ufl.Form.compute_form_data(...), a conflict arises and UFL bails out.

The code below shows how to avoid the problem as well as how to trigger it, so this is not critical. I believe it will always fail and not cause subtle undetected problems, but I cannot guarantee that, at least not for future releases.

Code to reproduce:

from dolfin import *
c = Constant(1.2)
mesh2 = UnitSquare(5,5)
mesh3 = UnitCube(5,5,5)

# This is ok, since a new form is created each time:
M2 = c*dx
print assemble(M2, mesh=mesh2)
M3 = c*dx
print assemble(M3, mesh=mesh3)

# Storing functional as a Form object and reusing it does not work:
M = c*dx
assemble(M, mesh=mesh2)
assemble(M, mesh=mesh3) # Crash!

Comments (8)

  1. Prof Garth Wells

    Since DOLFIN depends heavily on the code at fault, the best way to get this fixed is to discuss a solution that keeps the necessary DOLFIN functionality but fixes the UFL problem. I can have a look at the code in question in the next week to give my thoughts. It would be good if others could too.

  2. Log in to comment