u in u.function_space() returns False

Bug #888530 reported by Martin Sandve Alnæs
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
DOLFIN
Fix Released
Critical
Johan Hake

Bug Description

Script to reproduce with debugging prints

from dolfin import *

mesh = UnitSquare(3,3)

U = FunctionSpace(mesh, "CG", 1)
V = FunctionSpace(mesh, "DG", 0)
W = FunctionSpace(mesh, "CG", 1)
M = MixedFunctionSpace([U,V,W])

uvw = Function(M)
u, v, w = split(uvw)
L = dot(uvw,uvw)*dx
L_F = derivative(L, uvw)
L_J = derivative(L_F, uvw)

if 1:
    print
    print 'uvw'
    print str(uvw.function_space())
    print repr(uvw.function_space())
    print
    print 'M'
    print str(M)
    print repr(M)
    print

solve(L_J == -L_F, uvw)

Output when running:

uvw
<Function space of dimension 50 (<Mixed element: (<CG1 on a <triangle cell in R2>>, <DG0 on a <triangle cell in R2>>, <CG1 on a <triangle cell in R2>>)>)>
<dolfin.functions.functionspace.FunctionSpaceFromCpp; proxy of <Swig Object of type 'boost::shared_ptr< dolfin::FunctionSpace > *' at 0x332cde0> >

M
<Function space of dimension 50 (<Mixed element: (<CG1 on a <triangle cell in R2>>, <DG0 on a <triangle cell in R2>>, <CG1 on a <triangle cell in R2>>)>)>
<dolfin.functions.functionspace.MixedFunctionSpace; proxy of <Swig Object of type 'boost::shared_ptr< dolfin::FunctionSpace > *' at 0x332cc30> >

Traceback (most recent call last):
  File "bug.py", line 27, in <module>
    solve(L_J == -L_F, uvw)
  File "/home/martinal/opt/fenics/dorsal-unstable/lib/python2.7/site-packages/dolfin/fem/solving.py", line 250, in solve
    _solve_varproblem(*args, **kwargs)
  File "/home/martinal/opt/fenics/dorsal-unstable/lib/python2.7/site-packages/dolfin/fem/solving.py", line 268, in _solve_varproblem
    form_compiler_parameters=form_compiler_parameters)
  File "/home/martinal/opt/fenics/dorsal-unstable/lib/python2.7/site-packages/dolfin/fem/solving.py", line 83, in __init__
    cpp.LinearVariationalProblem.__init__(self, a, L, u, bcs)
  File "/home/martinal/opt/fenics/dorsal-unstable/lib/python2.7/site-packages/dolfin/cpp.py", line 20174, in __init__
    _cpp.LinearVariationalProblem_swiginit(self,_cpp.new_LinearVariationalProblem(*args))
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** https://answers.launchpad.net/dolfin
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to define linear variational problem a(u, v) = L(v) for all v.
*** Reason: Expecting the solution variable u to be a member of the trial space.
*** Where: This error was encountered inside LinearVariationalProblem.cpp.
*** -------------------------------------------------------------------------

Related branches

summary: - In Python, Function(M).function_space() is incompatible with M, triggers
- assertion in LinearVariationalProblem
+ In Python, Function(M).function_space() is incompatible with
+ MixedFunctionSpace M, triggers assertion in LinearVariationalProblem
Revision history for this message
Martin Sandve Alnæs (martinal) wrote : Re: In Python, Function(M).function_space() is incompatible with MixedFunctionSpace M, triggers assertion in LinearVariationalProblem

Much simplified test:

from dolfin import *
mesh = UnitSquare(3,3)

U = FunctionSpace(mesh, "CG", 1)
V = FunctionSpace(mesh, "DG", 0)
M = MixedFunctionSpace([U,V])

u = Function(M)
print u in M # True
print u in u.function_space() # False!

Changed in dolfin:
importance: Undecided → Critical
milestone: none → 1.0-rc1
Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

It's not related to mixed spaces actually:

from dolfin import *
mesh = UnitSquare(3,3)
U = FunctionSpace(mesh, "CG", 1)
u = Function(U)
print u in U, u in u.function_space() # True, False

summary: - In Python, Function(M).function_space() is incompatible with
- MixedFunctionSpace M, triggers assertion in LinearVariationalProblem
+ u in u.function_space() returns False
Revision history for this message
Johan Hake (johan-hake) wrote : Re: [Bug 888530] Re: In Python, Function(M).function_space() is incompatible with MixedFunctionSpace M, triggers assertion in LinearVariationalProblem

On Thursday November 10 2011 05:28:17 Martin Sandve Alnæs wrote:
> It's not related to mixed spaces actually:
>
> from dolfin import *
> mesh = UnitSquare(3,3)
> U = FunctionSpace(mesh, "CG", 1)
> u = Function(U)
> print u in U, u in u.function_space() # True, False
>
>
> ** Summary changed:
>
> - In Python, Function(M).function_space() is incompatible with
> MixedFunctionSpace M, triggers assertion in LinearVariationalProblem + u
> in u.function_space() returns False

This because the original Function::in method uses pointer comparison and the
way we do the wrapping of the cpp.FunctionSpace returned from DOLFIN into a
dolfin.FunctionSpace breaks that. This breaks down to not having a relyable
way of comparing two meshes, as it is not enough to compare the signature of
the element.

Maybe we can try comparing the pointers to the three (four?) shared entities
instead:

  finite_element, mesh, dof_map, (component?)

as these are all shared using shared_ptrs, they should be preserved.

Johan

Johan Hake (johan-hake)
Changed in dolfin:
status: New → Fix Committed
assignee: nobody → Johan Hake (johan-hake)
Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

Fix works great, but I think this issue propagates further. When using assemble_system from python with forms where this was a problem, this assertion is triggered:

python: /home/martinal/dev/fenics/dolfin/work/dolfin/fem/SystemAssembler.cpp:140: static void dolfin::SystemAssembler::assemble(dolfin::GenericMatrix&, dolfin::GenericVector&, const dolfin::Form&, const dolfin::Form&, const std::vector<const dolfin::DirichletBC*>&, const dolfin::MeshFunction<unsigned int>*, const dolfin::MeshFunction<unsigned int>*, const dolfin::MeshFunction<unsigned int>*, const dolfin::GenericVector*, bool, bool, bool): Assertion `a.function_space(1).get() == L.function_space(0).get()' failed.

I'm attaching a script which can trigger this. Search for FAIL to see how to make it fail or run.

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :
Revision history for this message
Johan Hake (johan-hake) wrote : Re: [Bug 888530] Re: u in u.function_space() returns False

On Monday November 14 2011 06:21:42 Martin Sandve Alnæs wrote:
> Fix works great, but I think this issue propagates further. When using
> assemble_system from python with forms where this was a problem, this
> assertion is triggered:
>
> python:
> /home/martinal/dev/fenics/dolfin/work/dolfin/fem/SystemAssembler.cpp:140:
> static void dolfin::SystemAssembler::assemble(dolfin::GenericMatrix&,
> dolfin::GenericVector&, const dolfin::Form&, const dolfin::Form&, const
> std::vector<const dolfin::DirichletBC*>&, const
> dolfin::MeshFunction<unsigned int>*, const dolfin::MeshFunction<unsigned
> int>*, const dolfin::MeshFunction<unsigned int>*, const
> dolfin::GenericVector*, bool, bool, bool): Assertion
> `a.function_space(1).get() == L.function_space(0).get()' failed.
>
> I'm attaching a script which can trigger this. Search for FAIL to see
> how to make it fail or run.

I see. If this propagate to other situation, we should implement an equality
operator.

Johan

Revision history for this message
Johan Hake (johan-hake) wrote :

On Monday November 14 2011 06:21:42 Martin Sandve Alnæs wrote:
> Fix works great, but I think this issue propagates further. When using
> assemble_system from python with forms where this was a problem, this
> assertion is triggered:
>
> python:
> /home/martinal/dev/fenics/dolfin/work/dolfin/fem/SystemAssembler.cpp:140:
> static void dolfin::SystemAssembler::assemble(dolfin::GenericMatrix&,
> dolfin::GenericVector&, const dolfin::Form&, const dolfin::Form&, const
> std::vector<const dolfin::DirichletBC*>&, const
> dolfin::MeshFunction<unsigned int>*, const dolfin::MeshFunction<unsigned
> int>*, const dolfin::MeshFunction<unsigned int>*, const
> dolfin::GenericVector*, bool, bool, bool): Assertion
> `a.function_space(1).get() == L.function_space(0).get()' failed.
>
> I'm attaching a script which can trigger this. Search for FAIL to see
> how to make it fail or run.

Should be fixed in the stable branch now.

Johan

Revision history for this message
Garth Wells (garth-wells) wrote :

On 16 Nov 2011, at 05:41, Johan Hake <email address hidden> wrote:

> On Monday November 14 2011 06:21:42 Martin Sandve Alnæs wrote:
>> Fix works great, but I think this issue propagates further. When using
>> assemble_system from python with forms where this was a problem, this
>> assertion is triggered:
>>
>> python:
>> /home/martinal/dev/fenics/dolfin/work/dolfin/fem/SystemAssembler.cpp:140:
>> static void dolfin::SystemAssembler::assemble(dolfin::GenericMatrix&,
>> dolfin::GenericVector&, const dolfin::Form&, const dolfin::Form&, const
>> std::vector<const dolfin::DirichletBC*>&, const
>> dolfin::MeshFunction<unsigned int>*, const dolfin::MeshFunction<unsigned
>> int>*, const dolfin::MeshFunction<unsigned int>*, const
>> dolfin::GenericVector*, bool, bool, bool): Assertion
>> `a.function_space(1).get() == L.function_space(0).get()' failed.
>>
>> I'm attaching a script which can trigger this. Search for FAIL to see
>> how to make it fail or run.
>
> Should be fixed in the stable branch now.
>

Something that may simplify this now is that all subclasses of Variable have a unique integer ID that can be compared. Only some care is required with threads.

Garth

> Johan
>
> --
> You received this bug notification because you are a member of DOLFIN
> Core Team, which is subscribed to DOLFIN.
> https://bugs.launchpad.net/bugs/888530
>
> Title:
> u in u.function_space() returns False
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/dolfin/+bug/888530/+subscriptions

Anders Logg (logg)
Changed in dolfin:
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

Bug attachments

Remote bug watches

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