dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #16228
Re: Problem with Expressions in Python
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).
> 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".
--
Anders
> > My next problem now is that one needs to set the geometric dimension
> > at the time of construction for a C++ expression. How can I send this
> > to my Expression sub class from Python?
> For now you have to instantiate the parent Expression in your C++ code. This
> could be done with:
>
> code = """
> class MyExpression : public Expression
> MyExpression() : Expression(%d)
> ...
> """
>
> f = Expression(code%mesh.geometry().dim(), V=V)
>
> But this you have already found out...
>
> Johan
>
Attachment:
signature.asc
Description: Digital signature
Follow ups
References