← Back to team overview

dolfin team mailing list archive

Re: new Function design in C++

 



Anders Logg wrote:
On Wed, Oct 22, 2008 at 12:08:43PM +0100, Garth N. Wells wrote:
The thread on the new Function design has digressed from the immediate issue, so I'm restarting it.

The issue is how to deal with user defined functions in C++. What if we have a design such that:

- All Functions must have a FunctionSpace

Yes.

- A FunctionSpace does not have to be complete (a complete FunctionSpace having a Mesh, a FiniteElement and a DofMap). As a minimum requirement, and FunctionSpace must have a Mesh.

I think it should always need to be complete. We can avoid a lot of
trouble if we make firm requirements: a Function is always associated
with a FunctionSpace and the FunctionSpace is always completely
defined.

- A FiniteElement and/or DofMap can be attached to a FunctionSpace after its creation


Related to the functions Function::interpolate(double* coefficients, ..) for interpolating Functions on cells

- The new Function::interpolate functions do not take a FiniteElement as an argument, so it is not possible to interpolate a function in a different space. Is it desirable to allow Functions from one space to be
interpolated in another?

Yes, it's desirable. This can be done globally when needed:

  Function v(V);
  Vector coefficients;
  v.interpolate(coefficients, W);

This will compute the global coefficient vector for v on W.

This is currently implemented with the assumption that the meshes for
V and W are the same but could quite easily be extended to
non-matching meshes now that functions can be evaluated at arbitrary
points (using GTS).

If we do this, would:

- The above allow FiniteElement types to be checked at runtime for consistency (the FiniteElement passed to Function::interpolate should be the same as the Functions own FiniteElement for discrete Functions. This is what we did with the old design.)>

- The above deal with the issue of user-defined functions which have a a FunctionSpace but no FiniteElement?

- The above deal with special functions, like the mesh size h?

Here's my suggestion for how to handle initialization of Functions in C++.
There is no need for a circular dependency. First some simple facts:

  1. The constructor of a Form may require one or more Functions
  2. The constructor of a Function requires a FunctionSpace

From this it follows that we must do something like

  Function f(V);
  Poisson::BilinearForm a;
  Poisson::LinearForm L(f);

The question is now how to initialize the FunctionSpace V. My
suggestion would be to extend the code generation to generate code for
creating the FunctionSpace(s), just like we do already when we
generate UFC code + some extra code for defining the Form classes
(when using -l dolfin in FFC). This does not make FFC DOLFIN-specific
or DOLFIN FFC-specific. One can still use other form compilers, but the
interface will not be as nice.

So, one would do something like this:

  #include "Poisson.h"

  int main()
  {
    Mesh mesh("mesh.xml");
    Poisson::TestSpace V(mesh);

Why 'TestSpace'? Also, when many functions are present, how would we identify each one? Could FFC create a class Poisson::FunctionSpace::foo when 'foo' is the name of the function in the FFC input?

    Function f(V);
    Poisson::BilinearForm a;
    Poisson::LinearForm L(f);
    ...
  }

First V, then f, then L.


Would this work for all the Functions in SpecialFunction.h?

Garth

?



------------------------------------------------------------------------

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


Follow ups

References