← Back to team overview

dolfin team mailing list archive

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

 

Great, can you merge your fix into dolfin?
The advantage of using mesh is that it's more
consistent with declaration of FunctionSpaces.

I currently get around it with this code:

def MyConstant(value, cell):
    "An alternative to Constant which allows defining the cell."
    e = Expression("value", element=FiniteElement("DG", cell, 0))
    e.value = value
    return e

-- 
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