← Back to team overview

dolfin team mailing list archive

Re: New Expression syntax

 

On Friday 27 November 2009 14:44:12 Garth N. Wells wrote:
> Johan Hake wrote:
> > On Friday 27 November 2009 11:53:00 Garth N. Wells wrote:
> >> Johan Hake wrote:
> >>> On Friday 27 November 2009 03:02:08 Anders Logg wrote:
> >>>> On Fri, Nov 27, 2009 at 09:41:03AM +0000, Garth N. Wells wrote:
> >>>>> Anders Logg wrote:
> >>>>>> On Fri, Nov 27, 2009 at 08:37:08AM +0000, Garth N. Wells wrote:
> >>>>>>> Is it still possible with the new Expression syntax to do something
> >>>>>>> like:
> >>>>>>>
> >>>>>>>  f2, f3 = Expressions("sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2])",
> >>>>>>>                       "1.0 + 3.0*x[0] + 4.0*x[1] + 0.5*x[2]", V=V)
> >>>>>>>
> >>>>>>> The above is used in the unit tests. Or to keep things simple
> >>>>>>> should we remove this kind of fancy feature?
> >>>>>>
> >>>>>> I guess it's a nice feature to have but it's nothing I care that
> >>>>>> much for.
> >>>>>
> >>>>> All tests except the unit test for function are working. Expression
> >>>>> needs to be updated for some of the fancier syntax.
> >>>>>
> >>>>> Garth
> >>>>
> >>>> I made a very simple fix in expression.py to get Expressions()
> >>>> working.
> >>>>
> >>>> It currently createas a separate Expression class for each argument so
> >>>> it will call compile_expressions() for each one, which is less
> >>>> efficient than compiling a bunch of expressions at once.
> >>
> >> Doesn't seem to work when I tried.
> >>
> >>> The whole point of using Expressions, is to avoid double compilations
> >>> :)
> >>>
> >>>> Johan, could you have a look at this function?
> >>>>
> >>>> I also commented out the unit test testSameBases since I couldn't
> >>>> figure out what it's supposed to do or if it is still valid after the
> >>>> interface changes.
> >>>>
> >>>> Please have a look.
> >>>
> >>> Will do!
> >>
> >> I had a look, but haven't committed anything yet.
> >
> > Commit anything if you like. I have time to look at it this evening
> > (night for you ;))
> 
> I'll leave it to you because expression.py is leaving me confused,
> namely why does Expression involve the metaclass ExpressionMetaClass,
> but Expressions doesn't? As a result why do we want the __init__
> function defined inside create_expression_class to be called for an
> Expression but not the expressions in an Expressions?

Ok, I'll look at it.

create_expression_class is called in Expressions. It is used to create the 
full fledged Expression class that inherits, dolfin.Expression, ufl.Function 
and the newly compiled class that inherits cpp.Expression.

Whenever a class is created that either is or inherits dolfin.Expression, the 
ExpressionMetaClass.__new__ is employed. However we do not want to make any 
costumizations in classes returned by create_expression_class, which means we 
just want to return the class as it is passed to the 
ExpressionMetaClass.__new__ method. Therefore I have the lines 213-217, which 
just do that.

Put

  print name, bases

first in the ExpressionMetaClass.__new__ method and try to create some user 
defined Expressions, and you might get a clue of what is happening.

Johan

> There is a lot of magic going on which makes it hard to follow.
> 
> Garth
> 
> > Johan
> >
> >> Garth
> >>
> >>> Johan
> >>>
> >>>> --
> >>>> Anders
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
> 



Follow ups

References