Dear all,
I am trying to manipulate UFL forms, following the traverser example from the UFL user manual to be found here (page 87)
http://fenicsproject.org/pub/documents/ufl/ufl-user-manual/ufl-user-manual.pdf
The traverser example from there unfortunately fails, if the input form contains a vector. In particular, my traverser is
from dolfin import *
from ufl import algorithms
class Traverser(algorithms.transformer.ReuseTransformer):
def __init__(self):
algorithms.transformer.ReuseTransformer.__init__(self)
def sum(self, o):
operands = o.ufl_operands
print "SUM", map(str,operands)
newoperands = []
for e in operands:
newoperands.append( self.visit(e) )
return sum(newoperands)
and I use it on
FS = VectorFunctionSpace(mesh, "CG", 1)
e = Function(FS)
e.rename("e", "")
f = Function(FS)
f.rename("f", "")
g = Function(FS)
g.rename("g", "")
h = Function(FS)
h.rename("h", "")
a = inner(e, f+g+h)
r = Traverser()
print "Traverser Original:"
b = r.visit(a)
print "Done:", b
Now, if FS is declared a FunctionSpace, everything works. But if FS is declared a VectorFunctionSpace, the traverser crashes with
Can't add expressions with different shapes.
How do I make it dimension/vector/scalar independent? Any ideas are much appreciated...