Hi Kamensky,
thank you for your share. So, indices() function needs ufl import.
I just tried a part of the code you posted, using dolfin and ufl import.
from dolfin import *
from ufl import *
mesh = UnitSquareMesh(2,2)
i,j,k,l = indices(4)
# Tensor from StackExchange thread:
d = mesh.geometry().dim()
delta = Identity(d)
I = as_tensor(0.5*(delta[i,k]*delta[j,l] + delta[i,l]*delta[j,k]),(i,j,k,l))
f = Constant(0.0)
The indices() function is work, but the Constant function is error:
---------------------------------------------------------------------------
UFLException Traceback (most recent call last)
<ipython-input-3-c87f29c3fa26> in <module>
9 delta = Identity(d)
10 I = as_tensor(0.5*(delta[i,k]*delta[j,l] + delta[i,l]*delta[j,k]),(i,j,k,l))
---> 11 f = Constant(0.0)
~/anaconda3/envs/fenicsproject/lib/python3.7/site-packages/ufl/coefficient.py in Constant(domain, count)
123 def Constant(domain, count=None):
124 """UFL value: Represents a globally constant scalar valued coefficient."""
--> 125 domain = as_domain(domain)
126 element = FiniteElement("Real", domain.ufl_cell(), 0)
127 fs = FunctionSpace(domain, element)
~/anaconda3/envs/fenicsproject/lib/python3.7/site-packages/ufl/domain.py in as_domain(domain)
294 # closer to the user interface?
295 # TODO: Make this configurable to be an error from the dolfin side?
--> 296 cell = as_cell(domain)
297 return default_domain(cell)
298
~/anaconda3/envs/fenicsproject/lib/python3.7/site-packages/ufl/cell.py in as_cell(cell)
327 return TensorProductCell(cell)
328 else:
--> 329 error("Invalid cell %s." % cell)
~/anaconda3/envs/fenicsproject/lib/python3.7/site-packages/ufl/log.py in error(self, *message)
170 "Write error message and raise an exception."
171 self._log.error(*message)
--> 172 raise self._exception_type(self._format_raw(*message))
173
174 def begin(self, *message):
UFLException: Invalid cell 0.0.
Do I miss somthing, or is this a bug?
The code works well if I just import: from ufl import indices.
Thank you.