dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #22787
Re: [Bug 747289] Re: Python: DirichletBC arguments are deleted early
On Friday April 22 2011 09:40:37 Garth Wells wrote:
> On 22/04/11 16:41, Johan Hake wrote:
> > The C++ Director class, which inherits Expression is not destroyed, as
> > this is stored using shared_ptr. Just put in a print in the destructor
> > of Expression and you will see that it is not prematurely destroyed.
> > However, what is destroyed is the Python proxy class, which eventually
> > receives the callback. I am not sure why this whole thing doesn't just
> > crash, but then the SWIG Directory code probably take care of this
> > situation.
>
> I traced this through the C++ code, and concluded the same thing (but
> less elegantly).
>
> > Joachim's patch fixes this problem. I think it is ok to apply the patch.
> > We need to go over what other places this problem might be a problem.
> >
> > Once you think you sorted out things using shared_ptrs, this turns up...
>
> It turns out that one of the objects that the Python DirichletBc class
> stored no longer has to be stored thanks to the smart pointers ;).
Gain one, loose one. The melody of life ;)
Johan
> Garth
>
> > Johan
--
You received this bug notification because you are a member of DOLFIN
Team, which is subscribed to DOLFIN.
https://bugs.launchpad.net/bugs/747289
Title:
Python: DirichletBC arguments are deleted early
Status in DOLFIN:
Fix Committed
Bug description:
The following code fails with a strange error:
-----
from dolfin import *
class Boundary(SubDomain):
def inside(self, x, on_boundary):
return on_boundary
class BoundaryFunction(Expression):
def eval(self, values, x):
values[0] = 1 if near(x[1],1) else 0
mesh = UnitSquare(2,2)
V = FunctionSpace(mesh, "CG", 1)
v,u = TestFunction(V), TrialFunction(V)
A = assemble(v*u*dx)
bc = DirichletBC(V, BoundaryFunction(), Boundary())
bc.apply(A)
-----
Replacing the bc = line as follows also fails, with a different strange error:
-----
bf = BoundaryFunction()
bc = DirichletBC(V, BoundaryFunction(), Boundary())
----
Only this works:
-----
bf = BoundaryFunction()
bc = DirichletBC(V, bf, Boundary())
-----
I have attached a patch that works around this by saving a reference
to the arguments in DirichletBC. It's not the proper fix of course,
but I have no time to find the root cause.
References