Subject: [FFC-dev] Adding/subtracting mixed functions

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 23 Dec 2008 19:31:06 +0000

I'm getting an error when trying something really simple with FFC. 
Compiling

     U       = VectorElement("Lagrange", "triangle", 2)
     C       = FiniteElement("Lagrange", "triangle", 2)
     element = U + C

     (v, c)  = Functions(element)
     v_h     = Function(U)

     e = v - v_h

leads to

Traceback (most recent call last):
   File "/usr/bin/ffc", line 221, in <module>
     sys.exit(main(sys.argv[1:]))
   File "/usr/bin/ffc", line 104, in main
     execfile(script, {})
   File "Error.py", line 37, in <module>
     e = v - v_h
   File 
"/usr/lib/python2.5/site-packages/ffc/compiler/language/algebra.py", 
line 73, in __rsub__
     return Form(-self) + other
   File 
"/usr/lib/python2.5/site-packages/ffc/compiler/language/algebra.py", 
line 645, in __add__
     w1 = Form(other)
   File 
"/usr/lib/python2.5/site-packages/ffc/compiler/language/algebra.py", 
line 635, in __init__
     raise FormError, (other, "Unable to create Form from given 
expression.")
ffc.common.exceptions.FormError

If I do

     U       = VectorElement("Lagrange", "triangle", 2)
     C       = FiniteElement("Lagrange", "triangle", 2)
     element = U + C

     v       = Function(U)
     v_h     = Function(U)

     e = v - v_h

it works fine. Is this an obvious bug to fix?

Garth

---

From: Anders Logg <[email-masked]>
Date: Tue, 23 Dec 2008 21:40:40 +0100

> it works fine. Is this an obvious bug to fix?

It could presumably be fixed by modifying __rsub__ for the Element
class in ffc/compiler/language/algebra.py to do something like

def __rsub__(self, other):
        "Operator: Element + Element (other - self)"
        if isinstance(other, list):
            return [other[i] - self[i] for i in range(len(other))]
        return Form(-self) + other

But maybe it's not worth the effort, considering we will soon throw
away algebra.py and replace it by UFL?

-- 
Anders

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 23 Dec 2008 20:50:49 +0000

> away algebra.py and replace it by UFL?

Will this happen in January? Is UFL complete?

Garth

> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> FFC-dev mailing list
> [email-masked]
> http://www.fenics.org/mailman/listinfo/ffc-dev

---

From: Anders Logg <[email-masked]>
Date: Tue, 23 Dec 2008 22:14:52 +0100

> Will this happen in January? Is UFL complete?

UFL is not finished but it's already at a level far beyond the FFC
form language. In particular, all FFC demos can easily be expressed in
UFL. Take a look at test/ffcforms.py which runs all FFC demos in UFL
notation which is close to FFC but with some improvements.

I expect the transition to begin in January. I can't promise it will
be finished (most likely not), but it depends on how hard we work.

-- 
Anders