← Back to team overview

dolfin team mailing list archive

Re: Special functions in new PyDOLFIN functions

 

On Thursday 25 December 2008 11:00:51 Harish Narayanan wrote:
> Apart from the spatial coordinates x[i], I would like to use t (time)
> and n[i] (components of the facet normal) when constructing the new
> JIT-compile styled functions in PyDOLFIN.

You can always define a complex JIT-compiled function in PyDOLFIN. Using this 
functionality, everything should just work ;)

  >>> cppcode = '''
  class MyFunc : public Function
  {
  public:
     MyFunc(FunctionSpace& V) : Function(V) {}
     void eval(double* values, const Data& data) const{
       double time = data.t;
       double first_normal = data.normal()[0];
       ...
     }
  };
  '''
  >>> f = Function(V,cppcode) 

> I've been told time ought to "just work," but will the Python gurus be
> adding support for other special functions like facet normals soon?

Well, sadly this is not true (for now). The time, 't', is passed with the Data 
argument to eval using the eval(double *value, const Data data) function of 
Function. When produce the code for the JIT-compiled functions using the 
simple c++-expressions, we overload the the simpler eval(double *value, const 
double *x) function. The descision for this was, that if a user want more 
complex expressions in its JIT compiled functions it should use the above 
explained JIT compilation.

We could add access to some of the common attributes of Data in the simpler 
c++-expression JIT compiled Functions too. By overloading eval(double *value, 
const Data data) and then map all use of:
  
  't' to 'data.t' 
  'n' to 'data.normal()'
  'h' to 'data.Cell().diameter()'

Doing this we should be able to support:

  >>> f = Function(V,"t*n[0]*h*sin(x[0])")

I desided not to implement this with reason mentioned above.

Any comments?

Johan


> Harish
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev




Follow ups

References