Subject: [FEniCS-users] UFL/matrices

From: David Beacham <[email-masked]>
Date: Sun, 25 Oct 2009 18:54:29 +0000

Hi all,

I've got a UFL file that compiles when using this form:

cell = triangle
P2 = VectorElement("Lagrange", cell, 2)
P1 = FiniteElement("Lagrange", cell, 1)
TH = P2 + P1

vq = TestFunction(TH)
dup = TrialFunction(TH)

up = Function(TH)         # Velocity/Pressure at t_{n+1}
Re = Constant(cell)     # Reynolds number

# split mixed functions
v, q = split(vq)
u, p = split(up)

def planarGrad(u):
  return as_matrix([[u[0].dx(0),u[0].dx(1)],
                    [u[1].dx(0),u[1].dx(1)]])

def epsilon(u):
  return 0.5*(planarGrad(u)+planarGrad(u).T)

def NS_a(u,v,Re):
  return inner(epsilon(u),epsilon(v))/Re

L = NS_a(u,v,Re)*dx
a = derivative(L, up, dup)

However, if I change planarGrad to:
def planarGrad(u):
  return as_matrix([[u[0].dx(0),      0     ,u[0].dx(1)],
                    [    0     ,      0     ,     0    ], 
                    [u[1].dx(0),      0     ,u[1].dx(1)]])

Then it won't compile, and I get these messages:
Traceback (most recent call last):
  File "/home/blackcabbage/fenics/stable/install/bin/ffc", line 153, in 
<module>
    sys.exit(main(sys.argv[1:]))
  File "/home/blackcabbage/fenics/stable/install/bin/ffc", line 130, in main
    ufd = load_ufl_file(filename)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/formfiles.py", 
line 148, in load_ufl_file
    validate_form(form)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/checks.py", 
line 32, in validate_form
    form = form.form_data().form # Is this ok? Unsure about the program 
flow here...
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/form.py", 
line 31, in form_data
    self._form_data = FormData(self)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/formdata.py", 
line 44, in __init__
    self.form = expand_derivatives(self.original_form)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/ad.py", 
line 70, in expand_derivatives
    return transform_integrands(form, _expand_derivatives)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 727, in transform_integrands
    integrand = transform(itg.integrand())
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/ad.py", 
line 68, in _expand_derivatives
    return aa.visit(expression)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 128, in visit
    r = h(o, *map(self.visit, o.operands()))
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/ad.py", 
line 28, in expr
    e = self.ad_routine(e)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/ad.py", 
line 57, in ad_routine
    return forward_ad(e, dim)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 592, in forward_ad
    result = compute_function_forward_ad(expr, dim)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 580, in compute_function_forward_ad
    e, ediff = alg.visit(f)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 128, in visit
    r = h(o, *map(self.visit, o.operands()))
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 132, in visit
    r = h(o)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 268, in index_sum
    A2, Ap = self.visit(A)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 132, in visit
    r = h(o)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 268, in index_sum
    A2, Ap = self.visit(A)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 128, in visit
    r = h(o, *map(self.visit, o.operands()))
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 132, in visit
    r = h(o)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 215, in indexed
    A2, Ap = self.visit(A)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 132, in visit
    r = h(o)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 238, in component_tensor
    A, Ap = self.visit(A)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 128, in visit
    r = h(o, *map(self.visit, o.operands()))
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 132, in visit
    r = h(o)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 215, in indexed
    A2, Ap = self.visit(A)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 128, in visit
    r = h(o, *map(self.visit, o.operands()))
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/transformations.py", 
line 132, in visit
    r = h(o)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/algorithms/forward_ad.py", 
line 245, in component_tensor
    op = ComponentTensor(Ap, ii._indices + jj)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/tensors.py", 
line 138, in __init__
    ufl_assert(len(missingset) == 0, "Missing indices %s in expression 
%s." % (missingset, expression))
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/indexed.py", 
line 60, in __str__
    return "%s[%s]" % (parstr(self._expression, self), self._indices)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/precedence.py", 
line 13, in parstr
    s = str(child)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/tensors.py", 
line 94, in __str__
    sub = substring(self._expressions, 0)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/tensors.py", 
line 90, in substring
    s = (ind+",\n").join(substring(e._expressions, indent+2) for e in 
expressions)
  File 
"/home/blackcabbage/fenics/stable/install/lib/python2.6/site-packages/ufl/tensors.py", 
line 90, in <genexpr>
    s = (ind+",\n").join(substring(e._expressions, indent+2) for e in 
expressions)
AttributeError: 'Zero' object has no attribute '_expressions'

I understand I could just use grad(u) instead, but my real goal is to 
have an axisymmetric form.

Thanks, David.

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 27 Oct 2009 10:29:54 +0100

I filed a bug report on:

https://bugs.launchpad.net/ufl/+bug/461775

Kristian

> _______________________________________________
> FEniCS-users mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/fenics-users
>