UFL Library Errors with Indexed Expressions

I’ve encountered an issue with the UFL library that prevents me from working with indexed expressions and halts me with the following error. For example, for the simple program below, which was provided as an answer to one of the topics here, it gives me the following error.

the program:
from dolfin import *
from ufl import indices

mesh = UnitSquareMesh(5,5)
V = VectorFunctionSpace(mesh, ‘CG’,1)

A = Constant(((1,2), (3,4)))
x = Constant((5,6))

i,j = indices(2)

u = as_vector(A[i,j]*x[i], (j))
v = project(u, V)

and the error:

Not expecting i_8.
Traceback (most recent call last):

File /usr/lib/python3/dist-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)

File ~/Desktop/WorkDir/Paper/ufltest.py:12
u = as_vector(A[i,j]*x[i], (j))

File /usr/lib/python3/dist-packages/ufl_legacy/exproperators.py:438 in _getitem
all_indices, slice_indices, repeated_indices = create_slice_indices(component, shape, self.ufl_free_indices)

File /usr/lib/python3/dist-packages/ufl_legacy/index_combination_utils.py:166 in create_slice_indices
error(“Not expecting {0}.”.format(ind))

File /usr/lib/python3/dist-packages/ufl_legacy/log.py:158 in error
raise self._exception_type(self._format_raw(*message))

UFLException: Not expecting i_8.

Does anyone know where the source of this problem might be?

I cannot reproduce this. What version of UFL and dolfin are you running?

1 Like

Thank you for your response. The versions are as follows:
for dolfin
fenics-dolfin == 2019.2.0.dev0
for ufl
fenics-ufl == 2019.2.0.dev0
fenics-ufl-legacy == 2022.3.0

The ufl version you reported appears to be incorrect. I think the problem is that you’re trying to using latest ufl with legacy dolfin. ufl is no longer compatible with legacy dolfin. To continue running legacy dolfin scripts, you should update any references from ufl to ufl_legacy instead. See Announcement: ufl_legacy and legacy dolfin