← Back to team overview

dolfin team mailing list archive

Re: Expressions without elements

 

On Tuesday 20 October 2009 13:57:16 Anders Logg wrote:
> Here's an issue I've run into lately.
> 
> The current design of the Expression class forces the specification
> of a FunctionSpace or UFL FiniteElement when one creates an Expression:
> 
>   v = Expression("sin(x[0])", V=V)  or
>   v = Expression("sin(x[0])", element=element)
> 
> This is only necessary in Python, but not in C++ where it's enough to
> set the geometric dimension.

All you ask for is already here for you, but not in a shiny easy accessible 
way.

  CompiledClass = compile_expressions(["sin(x[0])"],[{}])[0]
  expr = CompiledClass(2)

This is a cpp.Expression, which you cannot use in a ufl form and it does not 
have the nice __call__ method.

> Would it be possible to add an optional constructor that just takes
> the geometric dimension as an argument?

This is what the above do.
 
> I'm writing some code where I create various Expressions and project
> to different function spaces (for some theoretical studies related to
> adaptivity). Then it shouldn't matter (and it doesn't) which function
> space or element I originally specify in the constructor of my sin(x)
> expression.
> 
> If necessary, we can automatically create either a piecewise linear
> Lagrange element based on the incoming geometric dimension. Another
> option would be to use a QuadratureElement.

I will not make this shine for now. However, the future CompileExpression 
could take an argument dim, that if given, will create a cpp.Expression only 
class which cannot be used in ufl.forms.

I also suggest that we keep the future dolfin.Expression class as a combined 
cpp.Expression/ufl.Function class. If not we could add a new class called 
FormExpression which has the dual inheritance, and Expression which 
essentially just is cpp.Expression.

Johan


Follow ups

References