child().child() fails for Function and FunctionSpaces in Python

Bug #1130354 reported by Simon Funke
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
DOLFIN
Fix Released
High
Johan Hake

Bug Description

It seems like there the children/parent information is not always correctly set when the adapt() function is called on FunctionSpaces or Functions.
The following code demontrates the problem:

-----------------------------------------------------------------------------------------------------------------
from dolfin import *

m0 = UnitIntervalMesh(2)
adapt(adapt(m0))
m1 = m0.child()
m2 = m1.child()

V = FunctionSpace(m0, "CG", 1)
f = Function(V)

adapt(adapt(f, m1), m2)

assert(f.depth() == 3) # Passes

assert(f.child().has_child() == True) # Fails
assert(f.child().depth() == 3) # Fails, gives depth == 1
f.child().child() # TypeError: expected a FunctionSpace or a Function as argument 1
-----------------------------------------------------------------------------------------------------------------

The same problem occurs if one adapts a FunctionSpace twice and tries to call .child().child() on it.
Similarly the parent information seems to he faulty, as .parent().parent() on the leaf node also produces this error.

Related branches

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

Thanks for the report. Is this related to the recent changes for adapt/child in the Python layer, meaning, did it work before)?

I think this is related to Bug#1077923; I'll try to sit down with Johan and take a look at that and this when chance arises.

Changed in dolfin:
status: New → Confirmed
assignee: nobody → Marie Rognes (meg-simula)
Revision history for this message
Simon Funke (simon-funke) wrote :

It verified this bug on dolfin 1.1 and dolfin trunk.

Revision history for this message
Johan Hake (johan-hake) wrote : Re: [Bug 1130354] [NEW] child().child() fails for Function and FunctionSpaces in Python

The Python wrapped versions of child/parent/aso returns a shallow copy
of the original Function. In this copy the Hierarchical information is lost.

Try the following patch. (My dolfin is again broken with new PASTIX
requirements...)

Johan

=== modified file 'dolfin/common/Hierarchical.h'
--- dolfin/common/Hierarchical.h 2012-12-04 20:34:24 +0000
+++ dolfin/common/Hierarchical.h 2013-02-20 10:46:11 +0000
@@ -16,7 +16,7 @@
 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
 //
 // First added: 2011-01-30
-// Last changed: 2012-11-29
+// Last changed: 2013-02-20

 #ifndef __HIERARCHICAL_H
 #define __HIERARCHICAL_H

@@ -44,7 +44,8 @@

   public:

     /// Constructor
- Hierarchical(T& self) : _self(reference_to_no_delete_pointer(self)) {}
+ Hierarchical(T& self) : _self(reference_to_no_delete_pointer(self)),
+ _parent(self._parent), _child(self._child) {}

     /// Destructor
     ~Hierarchical() {}

On 02/19/2013 09:46 PM, Simon Funke wrote:
> Public bug reported:
>
> It seems like there the children/parent information is not always correctly set when the adapt() function is called on FunctionSpaces or Functions.
> The following code demontrates the problem:
>
> -----------------------------------------------------------------------------------------------------------------
> from dolfin import *
>
> m0 = UnitIntervalMesh(2)
> adapt(adapt(m0))
> m1 = m0.child()
> m2 = m1.child()
>
> V = FunctionSpace(m0, "CG", 1)
> f = Function(V)
>
> adapt(adapt(f, m1), m2)
>
> assert(f.depth() == 3) # Passes
>
> assert(f.child().has_child() == True) # Fails
> assert(f.child().depth() == 3) # Fails, gives depth == 1
> f.child().child() # TypeError: expected a FunctionSpace or a Function as argument 1
> -----------------------------------------------------------------------------------------------------------------
>
> The same problem occurs if one adapts a FunctionSpace twice and tries to call .child().child() on it.
> Similarly the parent information seems to he faulty, as .parent().parent() on the leaf node also produces this error.
>
> ** Affects: dolfin
> Importance: Undecided
> Status: New
>

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

I just realize that wont work as T is the templated type, and self wont have the _child and _parent attributes.

Any other suggestion of passing that information? Maybe add a copy constructor?

Johan

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

Fixing Hiearchical stuff in Python layer is and has always been painful... Here we need a way to make a shallow copy of Function.

Johan

Revision history for this message
Johannes Ring (johannr) wrote :

Just wanted to confirm that this works fine in 1.0.x, but is broken in 1.1.x and trunk.

Changed in dolfin:
importance: Undecided → High
Johan Hake (johan-hake)
Changed in dolfin:
milestone: none → 1.2.0
status: Confirmed → Fix Committed
assignee: Marie Rognes (meg-simula) → Johan Hake (johan-hake)
Revision history for this message
Simon Funke (simon-funke) wrote :

I can confirm that this bug is fixed now.
Thank you very much for your effort Johan!

Revision history for this message
Johan Hake (johan-hake) wrote : Re: [Bug 1130354] Re: child().child() fails for Function and FunctionSpaces in Python

On 03/12/2013 09:32 PM, Simon Funke wrote:
> I can confirm that this bug is fixed now.
> Thank you very much for your effort Johan!

You are most welcome! Lets hope the fix, which took dynamic typing in
Python to another level, does not bite us in the back ;)

Johan

Johannes Ring (johannr)
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

Remote bug watches

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