Improve error message when preprocessing coefficient derivative without domain
Issue #96
new
from dolfin import *
#parameters.form_compiler.representation = "quadrature" # Works
#parameters.form_compiler.representation = "tensor" # Works
#parameters.form_compiler.representation = "uflacs" # Fails
#parameters.form_compiler.representation = "tsfc" # Fails
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, 'P', 1)
v = TestFunction(V)
element = FiniteElement("P", mesh.ufl_cell(), 1)
p = Expression('2.71 * x[0]', element=element)
assemble(p.dx(0)*v*dx)
fails with
File "/home/fenics/local/lib/python3.5/site-packages/ffc/analysis.py", line 174, in _analyze_form
do_apply_restrictions=True,
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/compute_form_data.py", line 295, in compute_form_data
form = apply_derivatives(form)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/apply_derivatives.py", line 1071, in apply_derivatives
return map_integrand_dags(rules, expression)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/map_integrands.py", line 58, in map_integrand_dags
form, only_integral_type)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/map_integrands.py", line 39, in map_integrands
for itg in form.integrals()]
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/map_integrands.py", line 39, in <listcomp>
for itg in form.integrals()]
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/map_integrands.py", line 46, in map_integrands
return itg.reconstruct(function(itg.integrand()))
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/map_integrands.py", line 57, in <lambda>
return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
File "/home/fenics/local/lib/python3.5/site-packages/ufl/corealg/map_dag.py", line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/corealg/map_dag.py", line 86, in map_expr_dags
r = handlers[v._ufl_typecode_](v, *[vcache[u] for u in v.ufl_operands])
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/apply_derivatives.py", line 1024, in grad
return map_expr_dag(rules, f)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/corealg/map_dag.py", line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/corealg/map_dag.py", line 84, in map_expr_dags
r = handlers[v._ufl_typecode_](v)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/algorithms/apply_derivatives.py", line 538, in reference_value
K = JacobianInverse(domain)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/geometry.py", line 104, in __init__
self._domain = as_domain(domain)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/domain.py", line 309, in as_domain
cell = as_cell(domain)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/cell.py", line 335, in as_cell
error("Invalid cell (null)." Pell)
File "/home/fenics/local/lib/python3.5/site-packages/ufl/log.py", line 172, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Invalid cell None.
It would be better to inform user that a domain should be specified. Indeed p = Expression('2.71 * x[0]', element=element, domain=mesh)
does the job.
Comments (5)
-
reporter -
reporter - edited description
Add stderr of the MWE.
-
I note there is a comment in
compute_form_data
(line 268 incompute_form_data.py
):if do_apply_function_pullbacks: # Rewrite coefficients and arguments in terms of their # reference cell values with Piola transforms and symmetry # transforms injected where needed. # Decision: Not supporting grad(dolfin.Expression) without a # Domain. Current dolfin works if Expression has a # cell but this should be changed to a mesh. form = apply_function_pullbacks(form)
If you want to support that, you need to reconstruct the expressions with a domain attached I think. You'll always need the
element
because otherwise UFL doesn't know how to pull back appropriately. -
reporter - marked as minor
- removed milestone
- changed title to Improve error message when preprocessing coefficient derivative without domain
- removed responsible
Thanks, @wence. You're right, specifying domain fixes the problem. Both
p = Expression('2.71 * x[0]', element=element, domain=mesh) p = Expression('2.71 * x[0]', degree=1, domain=mesh)
in the snippet above work. Nevertheless the error message is a bit unfortunate.
-
reporter - edited description
- Log in to comment
Please, reassign to me, @martinal, if busy.