← Back to team overview

dolfin team mailing list archive

[Bug 785192] Re: Taking the gradient of an expression with a Constant crashes

 

The example provided in the first post is not really interesting, so let
me illustrate why this is a problem with a better example:

from dolfin import *
mesh = UnitSquare(3,3)
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
c = Constant(1.)
print assemble(grad(c*u)[0]*dx)

Since undefined cells in UFL was not allowed in the original design,
it's highly likely that many corner cases exist that cannot be solved
easily. So we need an easy workaround in the official PyDOLFIN.

-- 
You received this bug notification because you are a member of DOLFIN
Team, which is subscribed to DOLFIN.
https://bugs.launchpad.net/bugs/785192

Title:
  Taking the gradient of an expression with a Constant crashes

Status in DOLFIN:
  New

Bug description:
  Since a Constant does not have any way to provide a cell, PyDOLFIN
  forces me to use python floats instead as coefficients in some forms,
  thereby significantly increasing the amount of recompilation I have to
  do. PyDOLFIN therefore does not support the full range of expressions
  possible to express in UFL. This can be remedied by adding an optional
  cell or mesh argument to Constant.__init__ in PyDOLFIN. Mesh is
  probably more convenient/consistent in a PyDOLFIN setting.

  # This currently crashes:
      from dolfin import Constant, grad
      grad(Constant(1e-1))

  # This syntax would make it possible to express fully ufl compliant constant coefficients in PyDOLFIN
      from dolfin import Constant, grad, UnitSquare
      mesh = UnitSquare(3,3)
      grad(Constant(1e-1, mesh))


References