← Back to team overview

dolfin team mailing list archive

Re: Problem with Expressions in Python

 

On Fri, Oct 16, 2009 at 02:52:10PM +0200, Johan Hake wrote:
> On Friday 16 October 2009 14:44:31 Anders Logg wrote:
> > On Fri, Oct 16, 2009 at 02:39:36PM +0200, Johan Hake wrote:
> > > On Friday 16 October 2009 13:51:18 Anders Logg wrote:
> > > > My fault. The problem here was that I forgot to change from Function
> > > > to Expression in the code string. But perhaps the check needs to be
> > > > improved? The error message does not help.
> > >
> > > I think we need to extend the syntax if we want to have better messages.
> > > Now we first search for the string:
> > >
> > >   "class () public:Expression"
> > >
> > > If this is found we assume that the user wants to create a complex
> > > Expression.
> > >
> > > When this is not found we assume that the user want to create an
> > > Expression based on the simple syntax. We then check if any C++ keywords
> > > are used in that string, and it was this check that kicked in for you.
> > >
> > > If we want to keep the syntax we might change the error to:
> > >
> > >   TypeError: You are trying to compile a simple Expression and the C++
> > > keyword 'class' was detected in the passed string.
> > >
> > > We might also change the syntax all the way and make things easier for
> > > us. (More drastic change though...)
> > >
> > >   * class Expression is only used to subclass Expression in pure Python.
> > >   * function CompileExpression is used to compile:
> > >     1) simple expressions
> > >     2) complex expressions
> > >        Where we use kwargs do differentiate between the two.
> > >   * As before CompileExpression takes an ufl.FiniteElement or a
> > > FunctionSpace to instantiate the compiled class.
> > >   * CompileExpressions can do what Expressions do now, creating several
> > >     classes
> > >   * Remove the possibility to create compiled classes, only
> > >     instantiated ones.
> >
> > What does this last point mean? I have never used this (I think).
>
> Exactly! Another good point for removing it ;)
>
> Now you can create a compiled expression class by:
>
>   class MyExpression(Expression):
>      cpparg = ["sin(x[0])","code(x[1])"]
>
> not an instantiated one.
>
> > > This will:
> > >   * remove the need for metaclasses,
> > >   * make it explicit that we are using compiled stuff
> > >   * easier to maintain (soon leaving you know :) )
> >
> > I think this would be good. I for one don't understand the metaclass
> > stuff well enough to maintain it.
> >
> > If we go this way, then I suggest naming it "CompiledExpression".
>
> Agree with the naming.
>
> However not sure when I would get the time to fix this if we go for the
> suggested change...

Preferrably before you leave. :-)

--
Anders

Attachment: signature.asc
Description: Digital signature


References