Constant() expressions don't use the cell parameter

Issue #38 invalid
Nico Schlömer created an issue

The following code fails with Constant and succeeds with Expression while it should succeed with both.

from dolfin import *

mesh = UnitSquareMesh(20, 20)
V = FunctionSpace(mesh, 'CG', 1)

c = Constant((1.0, 2.0), cell=triangle)
#c = Expression(('1.0', '2.0'), cell=triangle)

v = TestFunction(V)

assemble(div(c) * v * dx)

Comments (10)

  1. Johan Hake

    Not sure of the inner workings of UFL and why it fails, but replacing the expression with:

    c = Expression(('1.0', '2.0'), element=VectorElement("Real", triangle, 0))
    

    generate the same error. Note that the default element of an Expression is CG 1.

  2. Nico Schlömer reporter
    • changed status to open

    div(c) is 0 independently of whether c is defined as a Constant or an Expression, but the code does work with Expression.

  3. Martin Sandve Alnæs

    Setting the cell does not imply DG0 or Real element for the Expression, the degree is (probably) set to 1. If you set the element, to Real like Johan shows or to DG0, you'll see that div(c) gets simplified to 0 as with the Constant.

  4. Nico Schlömer reporter

    I'm probably misunderstanding the notion of "degree" here. Are we talking about the quadrature degree that is associated with the Expression?

    When set to 1, I'd expect to retrieve the same result as with 0 since the expression is really of polynomial degree 0. Is that true modulo simplication of terms (which might be performed iff degree==1)?

  5. Martin Sandve Alnæs

    If you set Expression(..., degree=2) you set the degree of the element which the expression is interpolated into, not the quadrature degree of anything.

    From the UFL side dolfin.Expression is seen as a ufl.Coefficient, which has a ufl.FiniteElement, and if the degree of this element is > 0 derivatives are not simplified to 0.

  6. Log in to comment