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

How can I "look" at a (e.g. linear) form? (e.g. with form.x_repr_latex_)

+1 vote

Hello everyone,

After defining a form in (the python version) of fenics, is there any way to "look" at it later on?

So I want something similar to the following:

u = TrialFunction(function_space)
v = TestFunction(function_space)
form = inner(grad(u), grad(v))*dx
...
...
form.x_repr_latex_()

e.g. in order to make sure within the interactive python shell that I am using the right form or output the latex (or any human-readable) representation for documentation purposes.

But the above example returns an error message:

In [4]: error_form.x_repr_latex_()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-884e6a89853e> in <module>()
----> 1 form.x_repr_latex_()

/usr/lib/python2.7/dist-packages/ufl/form.pyc in x_repr_latex_(self)
    290     def x_repr_latex_(self): # TODO: This works, but enable when form latex rendering is fixed
    291         from ufl.algorithms import ufl2latex
--> 292         return "$$%s$$" % ufl2latex(self)
    293 
    294     def x_repr_png_(self): # TODO: This works, but enable when form latex rendering is fixed

/usr/lib/python2.7/dist-packages/ufl/algorithms/ufl2latex.pyc in ufl2latex(expression)
    532         form_data = compute_form_data(expression)
    533         preprocessed_form = form_data.preprocessed_form
--> 534         return form2latex(preprocessed_form, form_data)
    535     else:
    536         return expression2latex(expression)

/usr/lib/python2.7/dist-packages/ufl/algorithms/ufl2latex.pyc in form2latex(form, formdata)
    420 def form2latex(form, formdata):
    421 
--> 422     formname = formdata.name
    423     argument_names = formdata.argument_names
    424     coefficient_names = formdata.coefficient_names

AttributeError: 'FormData' object has no attribute 'name'

I am still quite new to python, but looking at (my Version of) the source code it really seems that all three of the above attributes are not set within the compute_form_data() function. Is this a bug or do I just need to compute the form differently? Having a latex representation would be my first choice but as mentioned, I could settle for any Human-readable representation.

regards

asked May 19, 2015 by multigrid202 FEniCS User (3,780 points)
...