- edited description
Constant() expressions don't use the cell parameter
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)
-
reporter -
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.
-
- changed status to invalid
div(c) is 0, and 0*v is 0, this is the known 0 forms issue.
-
reporter - changed status to open
div(c)
is 0 independently of whetherc
is defined as aConstant
or anExpression
, but the code does work withExpression
. -
div(c) is not 0 if the Expression has an element of degree > 0.
-
- changed status to invalid
-
reporter I don't understand why this is invalid. There's a discrepancy between
Constant()
andExpression()
here, and the above code shows is quite clearly (for functions of degree 0). If this was related to https://bitbucket.org/fenics-project/dolfin/issue/44/assemble-0-vectors (which also marked as invalid since it can't yet be marked as duplicate), then I'd expect bothConstant()
andExpression()
to fail. -
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.
-
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)?
-
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.
- Log in to comment