UFL

DOLFIN not attaching spatial dim to UFL functions (from Python)

Bug #844642 reported by Garth Wells
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UFL
Fix Released
High
Martin Sandve Alnæs

Bug Description

I'm getting a UFL error from the Python interface when using the UFL commands lhs/rhs because UFL is not getting the spatial dim for coefficient functions in forms. lhs/rhs calls expand_derivatives, and then this bails out because the spatial dim is unknown (although I'm taking derivatives of the coefficient function). I expect that DOLFIN is failing to attach this data.

I'll post a short piece of code soon and look into, unless someone sees a quick fix.

Related branches

Changed in dolfin:
status: New → Confirmed
importance: Undecided → High
milestone: none → 1.0-rc1
Revision history for this message
Garth Wells (garth-wells) wrote :

On closer inspection, I do have a derivative. The problem is in taking spatial derivatives of a Constant, which behind the scenes is a 'Real'. Can UFL be updated to handle this case?

Revision history for this message
Martin Sandve Alnæs (martinal) wrote : Re: [Bug 844642] Re: DOLFIN not attaching spatial dim to UFL functions (from Python)

I need a concrete example to figure that out.

Martin
Den 8. sep. 2011 11.31 skrev "Garth Wells" <email address hidden>
følgende:
> On closer inspection, I do have a derivative. The problem is in taking
> spatial derivatives of a Constant, which behind the scenes is a 'Real'.
> Can UFL be updated to handle this case?
>
> --
> You received this bug notification because you are a member of DOLFIN
> Core Team, which is subscribed to DOLFIN.
> https://bugs.launchpad.net/bugs/844642
>
> Title:
> DOLFIN not attaching spatial dim to UFL functions (from Python)
>
> Status in DOLFIN:
> Confirmed
>
> Bug description:
> I'm getting a UFL error from the Python interface when using the UFL
> commands lhs/rhs because UFL is not getting the spatial dim for
> coefficient functions in forms. lhs/rhs calls expand_derivatives, and
> then this bails out because the spatial dim is unknown (although I'm
> taking derivatives of the coefficient function). I expect that DOLFIN
> is failing to attach this data.
>
> I'll post a short piece of code soon and look into, unless someone
> sees a quick fix.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/dolfin/+bug/844642/+subscriptions

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

Anyway, the workaround is to provide a cell to the Constant.

Martin
Den 8. sep. 2011 13.59 skrev "Martin Sandve Alnæs" <email address hidden>
følgende:
> I need a concrete example to figure that out.
>
> Martin
> Den 8. sep. 2011 11.31 skrev "Garth Wells" <email address hidden>
> følgende:
>> On closer inspection, I do have a derivative. The problem is in taking
>> spatial derivatives of a Constant, which behind the scenes is a 'Real'.
>> Can UFL be updated to handle this case?
>>
>> --
>> You received this bug notification because you are a member of DOLFIN
>> Core Team, which is subscribed to DOLFIN.
>> https://bugs.launchpad.net/bugs/844642
>>
>> Title:
>> DOLFIN not attaching spatial dim to UFL functions (from Python)
>>
>> Status in DOLFIN:
>> Confirmed
>>
>> Bug description:
>> I'm getting a UFL error from the Python interface when using the UFL
>> commands lhs/rhs because UFL is not getting the spatial dim for
>> coefficient functions in forms. lhs/rhs calls expand_derivatives, and
>> then this bails out because the spatial dim is unknown (although I'm
>> taking derivatives of the coefficient function). I expect that DOLFIN
>> is failing to attach this data.
>>
>> I'll post a short piece of code soon and look into, unless someone
>> sees a quick fix.
>>
>> To manage notifications about this bug go to:
>> https://bugs.launchpad.net/dolfin/+bug/844642/+subscriptions

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

This is either:
- Defined as not a bug but a feature (since coefficients without cells is a wanted feature by Anders even though it is not well formed UFL)
- Maybe a bug, if it is fixable, but to reproduce I still need the context.

Anders Logg (logg)
Changed in dolfin:
assignee: nobody → Anders Logg (logg)
Revision history for this message
Marie Rognes (meg-simula) wrote :

Sample test case:

class FormOperations(unittest.TestCase):

    def test_lhs_rhs_simple(self):
        # Test taking lhs/rhs of forms involving constants. Most else
        # should be testable in UFL itself.

        mesh = UnitSquare(2, 2)
        V = FunctionSpace(mesh, "CG", 1)
        f = Constant(1.0)
        v = TestFunction(V)
        u = TrialFunction(V)

        F = inner(grad(f*v), grad(u))*dx + f*v*dx
        a, L = system(F)

        assert(len(a._integrals) == 1)
        assert(len(L._integrals) == 1)

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

A simpler case:

from dolfin import *

mesh = UnitSquare(2, 2)
V = FunctionSpace(mesh, "CG", 1)
f = Constant(1.0)
v = TestFunction(V)

F = grad(f*v)[0]*dx
a, L = system(F)

This is expected. Just pass cell to Constant to create
a well formed UFL expression and it will work fine:
f = Constant(1.0, cell=mesh.ufl_cell())

Revision history for this message
Marie Rognes (meg-simula) wrote :

On 11/10/2011 02:16 PM, Martin Sandve Alnæs wrote:
> A simpler case:
>
>
> from dolfin import *
>
> mesh = UnitSquare(2, 2)
> V = FunctionSpace(mesh, "CG", 1)
> f = Constant(1.0)
> v = TestFunction(V)
>
> F = grad(f*v)[0]*dx
> a, L = system(F)
>
>
> This is expected. Just pass cell to Constant to create
> a well formed UFL expression and it will work fine:
> f = Constant(1.0, cell=mesh.ufl_cell())
>

Yes.

So, let's mark the bug as a no fix, and add the "fixed" version as a
unit test to please the blueprint. Ok?

--
Marie

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

Actually, I think I've fixed it instead :)

Martin

On 10 November 2011 15:10, Marie Rognes <email address hidden> wrote:
> On 11/10/2011 02:16 PM, Martin Sandve Alnæs wrote:
>> A simpler case:
>>
>>
>> from dolfin import *
>>
>> mesh = UnitSquare(2, 2)
>> V = FunctionSpace(mesh, "CG", 1)
>> f = Constant(1.0)
>> v = TestFunction(V)
>>
>> F = grad(f*v)[0]*dx
>> a, L = system(F)
>>
>>
>> This is expected. Just pass cell to Constant to create
>> a well formed UFL expression and it will work fine:
>> f = Constant(1.0, cell=mesh.ufl_cell())
>>
>
> Yes.
>
> So, let's mark the bug as a no fix, and add the "fixed" version as a
> unit test to please the blueprint. Ok?
>
> --
> Marie
>
> --
> You received this bug notification because you are a member of DOLFIN
> Core Team, which is subscribed to DOLFIN.
> https://bugs.launchpad.net/bugs/844642
>
> Title:
>  DOLFIN not attaching spatial dim to UFL functions (from Python)
>
> Status in DOLFIN:
>  Confirmed
>
> Bug description:
>  I'm getting a UFL error from the Python interface when using the UFL
>  commands lhs/rhs because UFL is not getting the spatial dim for
>  coefficient functions in forms. lhs/rhs calls expand_derivatives, and
>  then this bails out because the spatial dim is unknown (although I'm
>  taking derivatives of the coefficient function). I expect that DOLFIN
>  is failing to attach this data.
>
>  I'll post a short piece of code soon and look into, unless someone
>  sees a quick fix.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/dolfin/+bug/844642/+subscriptions
>

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

I don't want to push my fixes until I can test it towards a green buildbot.
Can whoever feels responsible fix? Then I can push tomorrow.
My fix is available on lp:~martinal/ufl/work/ now.

Martin

On 10 November 2011 19:01, Martin Sandve Alnæs <email address hidden> wrote:
> Actually, I think I've fixed it instead :)
>
> Martin
>
>
> On 10 November 2011 15:10, Marie Rognes <email address hidden> wrote:
>> On 11/10/2011 02:16 PM, Martin Sandve Alnæs wrote:
>>> A simpler case:
>>>
>>>
>>> from dolfin import *
>>>
>>> mesh = UnitSquare(2, 2)
>>> V = FunctionSpace(mesh, "CG", 1)
>>> f = Constant(1.0)
>>> v = TestFunction(V)
>>>
>>> F = grad(f*v)[0]*dx
>>> a, L = system(F)
>>>
>>>
>>> This is expected. Just pass cell to Constant to create
>>> a well formed UFL expression and it will work fine:
>>> f = Constant(1.0, cell=mesh.ufl_cell())
>>>
>>
>> Yes.
>>
>> So, let's mark the bug as a no fix, and add the "fixed" version as a
>> unit test to please the blueprint. Ok?
>>
>> --
>> Marie
>>
>> --
>> You received this bug notification because you are a member of DOLFIN
>> Core Team, which is subscribed to DOLFIN.
>> https://bugs.launchpad.net/bugs/844642
>>
>> Title:
>>  DOLFIN not attaching spatial dim to UFL functions (from Python)
>>
>> Status in DOLFIN:
>>  Confirmed
>>
>> Bug description:
>>  I'm getting a UFL error from the Python interface when using the UFL
>>  commands lhs/rhs because UFL is not getting the spatial dim for
>>  coefficient functions in forms. lhs/rhs calls expand_derivatives, and
>>  then this bails out because the spatial dim is unknown (although I'm
>>  taking derivatives of the coefficient function). I expect that DOLFIN
>>  is failing to attach this data.
>>
>>  I'll post a short piece of code soon and look into, unless someone
>>  sees a quick fix.
>>
>> To manage notifications about this bug go to:
>> https://bugs.launchpad.net/dolfin/+bug/844642/+subscriptions
>>
>

Revision history for this message
Anders Logg (logg) wrote :

I'm working on it. The problem is that I enabled a bunch of unit tests
that had somehow gone missing from the top level driver file. So
new bugs have been introduced - it's only showing already existing
bugs or possibly broken unit tests.

--
Anders

On Thu, Nov 10, 2011 at 06:28:54PM -0000, Martin Sandve Alnæs wrote:
> I don't want to push my fixes until I can test it towards a green buildbot.
> Can whoever feels responsible fix? Then I can push tomorrow.
> My fix is available on lp:~martinal/ufl/work/ now.
>
> Martin
>
> On 10 November 2011 19:01, Martin Sandve Alnæs <email address hidden> wrote:
> > Actually, I think I've fixed it instead :)
> >
> > Martin
> >
> >
> > On 10 November 2011 15:10, Marie Rognes <email address hidden> wrote:
> >> On 11/10/2011 02:16 PM, Martin Sandve Alnæs wrote:
> >>> A simpler case:
> >>>
> >>>
> >>> from dolfin import *
> >>>
> >>> mesh = UnitSquare(2, 2)
> >>> V = FunctionSpace(mesh, "CG", 1)
> >>> f = Constant(1.0)
> >>> v = TestFunction(V)
> >>>
> >>> F = grad(f*v)[0]*dx
> >>> a, L = system(F)
> >>>
> >>>
> >>> This is expected. Just pass cell to Constant to create
> >>> a well formed UFL expression and it will work fine:
> >>> f = Constant(1.0, cell=mesh.ufl_cell())
> >>>
> >>
> >> Yes.
> >>
> >> So, let's mark the bug as a no fix, and add the "fixed" version as a
> >> unit test to please the blueprint. Ok?
> >>
> >>
> >>
> >> Title:
> >>  DOLFIN not attaching spatial dim to UFL functions (from Python)
> >>
> >> Status in DOLFIN:
> >>  Confirmed
> >>
> >> Bug description:
> >>  I'm getting a UFL error from the Python interface when using the UFL
> >>  commands lhs/rhs because UFL is not getting the spatial dim for
> >>  coefficient functions in forms. lhs/rhs calls expand_derivatives, and
> >>  then this bails out because the spatial dim is unknown (although I'm
> >>  taking derivatives of the coefficient function). I expect that DOLFIN
> >>  is failing to attach this data.
> >>
> >>  I'll post a short piece of code soon and look into, unless someone
> >>  sees a quick fix.
> >>
> >> To manage notifications about this bug go to:
> >> https://bugs.launchpad.net/dolfin/+bug/844642/+subscriptions
> >>
> >
>

affects: dolfin → ufl
Changed in ufl:
milestone: 1.0-rc1 → none
assignee: Anders Logg (logg) → Martin Sandve Alnæs (martinal)
status: Confirmed → Fix Committed
Changed in ufl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.