← Back to team overview

ffc team mailing list archive

Re: Adding/subtracting mixed functions

 

On Tue, Dec 23, 2008 at 07:31:06PM +0000, Garth N. Wells wrote:
> 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

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

Attachment: signature.asc
Description: Digital signature


Follow ups

References