Remove hacky type 'Data' and implement a better type for holding coefficient mapping of derivative

Issue #37 resolved
Martin Sandve Alnæs created an issue

When doing derivative(F, u, v, coefficient_derivatives={f:g, h:q}), the dict with derivatives g,q of f,h is just wrapped in a Data object which doesn't behave as a proper ufl type.

Besides being an ugly hack, this leads to a very concrete problem. First of all it doesn't curretly have a way to compute its signature, although that could be remedied if it was the only problem.

To be able to compute the form signature before differentiation, a numbering of coefficients must be enumerated. To do this all coefficients must be extracted from a form; however the Data object hides the coefficients it references.

The solution seems to be to introduce a type instead that more explicitly represents what Data is used for, a mapping between coefficients and other symbolic expressions.

class CoefficientMapping(Operator):
    def __init__(self, mapping):
        self._operands = sum(((k,v) for k,v in mapping.iteritems()), ())

    def operands(self):
        return self._operands

    def free_indices(self):
        error
    etc.

This could possibly be used to represent delayed evaluation of 'replace' as well, together with a type 'PartialEvaluation' or something like that.

Comments (7)

  1. Log in to comment