Comment 4 for bug 1124653

Revision history for this message
Martin Sandve Alnæs (martinal) wrote : Re: [Bug 1124653] Re: Forms generated with adapt() can not be assembled

I havent looked at the code, but in principle I guess dolfin.Form could be
made working with a dolfin::Form for assembly. The information is all
there, it just has to be passed on to C++ when assembling. The dolfin.Form
code is a bit fragile though...

Martin
Den 15. feb. 2013 00:55 skrev "Johan Hake" <email address hidden>
følgende:

> Marie and Simon!
>
> I think adding something like:
>
> def adapt(...):
>
> ret = cpp.adapt(...)
> if isinstance(ret, cpp.FunctionSpace):
> from dolfin.functions.functionspace import FunctionSpaceFromCpp
> return = FunctionSpaceFromCpp(ret)
> elif isinstance(ret, cpp.Function):
> from dolfin.functions.function import Function
> return Function(HierarchicalFunction._leaf_node(self))
> aso...
>
> should fix the issue. This fix is also in line with similar fixes for
> leaf, parent and other Hierarchical methods
>
> I can fix this once my trunk is compiling ;)
>
> Johan
>
> On 02/14/2013 04:12 PM, Marie Rognes wrote:
> > Hi Simon,
> >
> > The underlying cause of this issue, and most other similar issues with
> > adapt, is that adapt here accepts Python objects but the new, adapted
> > objects are created in the C++ layer. The Python versions typically
> > carry more information than the C++ objects, and this additional
> > information is then not available for the adapted objects.
> >
> > A fix would be to essentially reimplement most of the adapt functions in
> > the Python interface. Johan, could you comment on whether this is a good
> > idea?
> >
> > ** Changed in: dolfin
> > Status: New => Confirmed
> >
> > ** Changed in: dolfin
> > Assignee: (unassigned) => Marie Rognes (meg-simula)
> >
>
> --
> You received this bug notification because you are a member of DOLFIN
> Core Team, which is subscribed to DOLFIN.
> https://bugs.launchpad.net/bugs/1124653
>
> Title:
> Forms generated with adapt() can not be assembled
>
> Status in DOLFIN:
> Confirmed
>
> Bug description:
> Hi,
>
> I would like to assemble a form on two different meshes using the
> adapt() function.
> Unfortunately, the objects that are generated by adapt can not be
> directly passed to the assembly function
> as demonstrated below (code with tested on trunk):
>
> from dolfin import *
>
> mesh = UnitSquareMesh(2,2)
> adapt(mesh)
>
> V = FunctionSpace(mesh, "CG", 1)
> u = TrialFunction(V)
> w = TestFunction(V)
>
> form = inner(u, w)*dx
> dolfin_form = Form(form) # Ideally I would want
> to call adapt(form), but that does not work...
> adapt(dolfin_form, mesh.child(), False)
> print type(dolfin_form) # <class
> 'dolfin.fem.form.Form'> - as expected
> print type(dolfin_form.child()) # <class
> 'dolfin.cpp.fem.Form'> - the type should not have changed
> A1 = assemble(dolfin_form) # Does work.
> A2 = assemble(dolfin_form.child()) # Does not work!
>
> # Let's try and apply some boundary conditions
> bc = DirichletBC(V, Constant(0), "on_boundary")
> adapt(bc, mesh.child(), V.child())
> print type(bc) #
> <class 'dolfin.fem.bcs.DirichletBC'> - as expected
> print type(bc.child()) # <class
> 'dolfin.cpp.fem.DirichletBC'> - the type should not have changed
> bc.apply(A1)
> bc.child().apply(A2)
>
>
> The error message I get is:
>
> Traceback (most recent call last):
> File "adapt_test.py", line 16, in <module>
> A2 = assemble(dolfin_form.child()) # Does not work!
> File
> "/home/funsi/src/dolfin/local/lib/python2.7/site-packages/dolfin/fem/assembling.py",
> line 155, in assemble
> common_cell=common_cell)
> File
> "/home/funsi/src/dolfin/local/lib/python2.7/site-packages/dolfin/fem/form.py",
> line 63, in __init__
> self._compiled_form = form._compiled_form
> AttributeError: 'Form' object has no attribute '_compiled_form'
>
>
> Thanks,
>
> Simon
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/dolfin/+bug/1124653/+subscriptions
>