Generalized assembly over any entity type

Issue #106 new
Martin Sandve Alnæs created an issue

Just sketching an idea here and looking for comments.

Is it feasible to merge the integral types and matching assembly routines into a single do-it-all routine if we generalize the ufc integral interface? Will this result in a major performance hit?

I'm pretty sure this is technically possible and it might even simplify code some places.

Several features people are working on are limited by the UFC abstractions of integral types (cell, exterior facet, interior facet) in various ways. Overlapping meshes, functions living on different meshes, functions living in lower dimensional manifolds, possibly other things. Maintenance of the assemblers in dolfin seems to require quite a bit of work and will only become harder with more features added. Adding integral types to UFC will result in adding new assembly routines to the assemblers in dolfin. The combination of all this seems to be a bottleneck in the fenics development.

Here are some UFC ideas for a more generalized interface:

// We may need to reintroduce the ufc cell class:
struct ufc::cell
{
    vector<double> vertices; // flattened vertices array
    ufc::cell_shape shape;
    int entity; // local facet number, local vertex number, cell number in macro cell
    int orientation;
};

struct ufc::generic_integral
{
    // We can easily throw in a bunch of utility functions in the
    // generated code to make the integral object queryable:

    vector<size_t> A_dims(); // all virtual const=0
    vector<size_t> A_strides();
    size_t A_size();

    size_t num_cells();
    size_t num_coefficients();

    size_t domain_gdim();
    size_t domain_tdim();
    size_t domain_id();
    size_t domain_cellshape();

    // And now for the generic tabulate_tensor interface:
    virtual void tabulate_tensor2(
        vector<double> & A,
        const vector<ufc::cell> & cells,
        const vector< vector< vector<double> > > & w, // w[cell][coeff][dof]
        ) = 0;
};

// Adaptor functions for specialized integrals is easy
struct interior_facet_integral: public generic_integral
{
    // Current interface:
    virtual void tabulate_tensor(double* A,
                             const double * const * w, // w[coeff][dof]
                             const double* vertex_coordinates_0,
                             const double* vertex_coordinates_1,
                             std::size_t facet_0,
                             std::size_t facet_1) const = 0;

    // I think this represents the additional runtime overhead we get:
    virtual void tabulate_tensor2(
        vector<double> & A,
        const vector<ufc::cell> & cells,
        const vector< vector< vector<double> > > & w, // w[cell][coeff][dof]
        )
    {
        tabulate_tensor(A,
                    w[0],
                    cells[0].vertices, cells[1].vertices,
                    cells[0].entity, cells[1].entity);
    }
};

struct ufc::form
{
    // We could even generalize create_foo_integral somehow.
    // I don't know what integraldomainrepr is, but something more
    // generic than (cell,ext_facet,int_facet) + domain_id:
    map<integraldomainrepr, generic_integral *> create_integrals();
};

Adapting the code generation to this interface is not the main hurdle. The generalized dolfin assembler will be rather complex. However it might replace multiple routines with one, so the question is if that's desirable.

Some notes:

  • We'll probably still generate code where all dimensions are fixed
  • Integration is always performed over cell 0
  • The integration cell and coefficient cells are not necessarily the same
  • In particular the generated code already knows how many cells there are
  • The generated code also knows which coefficient lives on which cell(*)
  • This interface can handle coefficients on different meshes, or on facets
  • To implement macro cell integrals, the size of A will vary
  • The interface can of course be introduced without having to implement all possible features before they're needed, but having the flexibility in ufc will make it easier for e.g. Andre Massing to experiment with cut cell configurations etc. :)

(*) This is maybe the point I'm the most unsure about how hard will be to handle in dolfin.

There is a major assumption here that the input "makes sense". In particular the integration cell must be contained by every coefficient cell for coefficients to be defined everywhere.

Comments (8)

  1. Johan Hake

    Looks interesting. It would be instructive though, if you could add some high level tentative examples (pseudo UFL or pydolfin code) illustrating typical forms which one should be able to integrate with the more general ufc::generic_integral class. Maybe annotated with present limitations in ufc together with the potential solutions as sketched by introducing ufc::generic_integral.

  2. Martin Sandve Alnæs reporter

    Main motivational example right now is the integral over the intersection of two cells from overlapping meshes. Then we need three cells: the integration entity produced by tesselation of the mesh intersection and the two cells from the two meshes that coefficients and arguments live on. Maybe we'll just add another integral type to begin with, these things gets quite complex...

  3. Jan Blechta

    This seems being possible to replace functionality of deprecated PUM compiler/library. (This is about enriching function space by DOFs located on a non-matching surface and integrating on this surface and on cells cut by this surface.)

  4. Prof Garth Wells

    Could be ok. It will of course depend on performance being good. I'd suggest starting a branch with a new experimental assembler.

  5. Prof Garth Wells

    As a comment, I think new proposals that are looking for comment and feedback are best started on the mailing list (fenics@fenicsproject.org). For one, it allows inline replies, which is important for maintaining the coherency of a discussion. Once a consensus is reached, the outcome can be summarised in an 'Issue'.

  6. Anders Logg (Chalmers)

    I agree with this. I monitor my bitbucket feed but important discussions risk being lost among commit messages and issues for many projects, papers etc.

  7. Martin Sandve Alnæs reporter

    Ok, so the pattern is then that a high level discussion at fenics@fenicsproject.org can be the source of many "issues", each dealing with the implementation of something concrete.

  8. Anders Logg (Chalmers)

    I think the mailing list should also be used when someone wants attention, even for details regarding an issue.

  9. Log in to comment