FFC breaks immutability of elements when using quadrature elements

Issue #84 resolved
Martin Sandve Alnæs created an issue

This has been there forever, just making an issue for the record.

In ffc/analysis.py:

    # FIXME: This modifies the elements depending on the form compiler parameters,
    #        this is a serious breach of the immutability of ufl objects, since the
    #        element quad scheme is part of the signature and hash of the element...
    for element in form_data.unique_sub_elements:
        if element.family() == "Quadrature":
            element._quad_scheme = scheme

If you're using quadrature elements in multiple forms with different schemes, this will cause trouble.

Comments (6)

  1. Martin Sandve Alnæs reporter

    I'm fixing this by requiring the degree and scheme to be specified by the user and consistent with the form it's used in. If someone has a problem with that they can put in the work to find a better solution.

  2. Martin Sandve Alnæs reporter

    This should then be equivalent to todays

    def QuadratureElement(scheme, cell, degree):
        return FiniteElement("Quadrature", cell, degree, quad_scheme=scheme)
    
  3. Jan Blechta

    @martinal, could you check also quadrature degree, not just scheme, so that this

    mesh = UnitSquareMesh(1, 1)
    e = FiniteElement("Quadrature", mesh.ufl_cell(), 2, quad_scheme='default')
    f = Expression("x[0]", element=e)
    V = FunctionSpace(mesh, "Lagrange", 1)
    u = project(f, V) # complains about non-matching quadrature points
    u = project(f, V, form_compiler_parameters={'quadrature_degree': 2}) # passes fine
    

    complains earlier with message like non-matching quadrature degree of quadrature integrand ({}) and measure ({}) instead of letting this go so far and raising

    ('\npoints:\n', array([[ 0.65902762,  0.23193337],
           [ 0.65902762,  0.10903901],
           [ 0.23193337,  0.65902762],
           [ 0.23193337,  0.10903901],
           [ 0.10903901,  0.65902762],
           [ 0.10903901,  0.23193337]]))
    ('\nquad points:\n', array([[ 0.16666667,  0.16666667],
           [ 0.16666667,  0.66666667],
           [ 0.66666667,  0.16666667]]))
    Points must be equal to coordinates of quadrature points
    Traceback (most recent call last):
    ...
    Exception: Points must be equal to coordinates of quadrature points
    
  4. Log in to comment