← Back to team overview

dolfin team mailing list archive

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

 

It is very easy to add a member function which returns the ufc.Cell of a mesh. 
I can add that.

Johan

On Wednesday May 25 2011 01:15:56 Martin Sandve Alnæs wrote:
> Ok by me.
> 
> Is there a standard easy way to get the ufl cell matching a mesh?
> Otherwise can I suggest adding a function to the PyDOLFIN Mesh class?
> Or adding ufl_cell below to PyDOLFIN as a standalone function.
> 
> from dolfin import *
> 
> def ufl_cell(self):
>     import ufl
>     cells = { 1: ufl.interval, 2: ufl.triangle, 3: ufl.tetrahedron }
>     return cells[self.topology().dim()]
> 
> Mesh.ufl_cell = ufl_ceall
> mesh = UnitSquare(3,3)
> print mesh.ufl_cell()
> #Cell('triangle', Space(2))
> 
> # OR:
> print ufl_cell(mesh)
> 
> Martin
> 
> On 25 May 2011 07:57, Johan Hake <785192@xxxxxxxxxxxxxxxxxx> wrote:
> > ** Changed in: dolfin
> >       Status: In Progress => Fix Committed
> > 
> > --
> > You received this bug notification because you are a direct subscriber
> > of the bug.
> > https://bugs.launchpad.net/bugs/785192
> > 
> > Title:
> >  Taking the gradient of an expression with a Constant crashes
> > 
> > Status in DOLFIN:
> >  Fix Committed
> > 
> > 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))
> > 
> > To unsubscribe from this bug, go to:
> > https://bugs.launchpad.net/dolfin/+bug/785192/+subscribe

-- 
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:
  Fix Committed

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