Comment 3 for bug 1130354

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
>