ffc team mailing list archive
-
ffc team
-
Mailing list archive
-
Message #02010
Re: Adding/subtracting mixed functions
On Tue, Dec 23, 2008 at 08:50:49PM +0000, Garth N. Wells wrote:
>
>
> Anders Logg wrote:
> > 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?
> >
>
> 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
Attachment:
signature.asc
Description: Digital signature
References