This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Convert 'cpp.fem.Form' to 'ufl.Form'

0 votes

I'd like to extract the residual_form and Jacobian_form from a NonlinearVariationalProblem, for use in another solver:

p = NonlinearVariationalProblem(F,u,bc, J)
print p.residual_form()
p2 = NonlinearVariationalProblem(p.residual_form(),p.solution(),p.bcs(), p.jacobian_form)

When I try this, I get an error:

*** Error:   Unable to creating dolfin.Form.
*** Reason:  Expected a ufl.Form..
*** Where:   This error was encountered inside form.py.

The print statement returns that the residual_form() is of type: dolfin.cpp.fem.Form . How can I convert the cpp Form to a UFL form so that the NonlinearVariationalProblem will work?

Thanks!

asked Jan 12, 2016 by mwelland FEniCS User (8,410 points)

1 Answer

0 votes

You can't. A UFL form has all the symbolic data attached that allows the form to be manipulated. a cpp Form just know how the tabulate matrix/vector on cell.

It looks like the p returned by NonlinearVariationalProblem(F,u,bc, J) is coming from the underlying c++ object, which doesn't know about UFL forms.

We probably need to extend the Python NonlinearVariationalProblem class to return the UFL forms. Could you register an issue on Bitbucket?

answered Jan 19, 2016 by Garth N. Wells FEniCS Expert (35,930 points)
...