Change Argument to use form argument number and part instead of count

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

By changing Argument from Argument(element, count) to Argument(element, number, part) where number is the explicit position in the form argument list and part is the block position within a block system, we gain a few advantages.

One is that TestFunction and TrialFunction can be explicitly positioned as arguments number 0 and 1, which will lead to cleaner error checking and clearer error messages.

def TestFunction(V, part=0):
    return Argument(V, number=0, part=part)
def TrialFunction(V, part=0):
    return Argument(V, number=1, part=part)

Another is that e.g. TestFunction(V) == TestFunction(V) since they get the same number instead of a rolling count.

A third one is the 'adjoint' operator implementation can be simplified, just swapping the numbering of test and trial functions explicitly. The derivative operator can create an Argument with number max+1 relative to the form.

For trilinear forms, this is much easier to explain than the current count ordering scheme:

u = Argument(V, number=0)
v = Argument(V, number=1)
w = Argument(V, number=2)

And finally, the reason for thinking about this in the first place, is that it's possible to distinguish between test functions for different parts of a form, making it possible to define block systems:

V0, V1 = finite elements
v0 = TestFunction(V0, part=0)
v1 = TestFunction(V1, part=1)
u0 = TrialFunction(V0, part=0)
u1 = TrialFunction(V1, part=1)
a = (inner(v0, u0) + inner(v0, u1) + inner(v1, u0) + inner(v1, u1)) * dx

which makes the implementation of algorithms extracting the different parts possible, something like this:

form_blocks = extract_blocks(a)
assert form_blocks[(v0, u1)] == inner(v0, u1)*dx
etc.

I believe this will be very useful to generate code for the ccfem implementation.

Comments (11)

  1. Martin Sandve Alnæs reporter

    Representation is in place, count has been changed to number a few places, all fairly painless. However the part cannot really be used yet, as there are quite a few places (algorithms) that will need updating.

  2. Martin Sandve Alnæs reporter
    • removed milestone

    Removed milestone because I'm not sure if this (the remaining 'part' argument) is a priority for 1.5.

  3. Martin Sandve Alnæs reporter

    The change to 'number' instead of 'count' has long since been completed. The 'part' is in Argument but still unused elsewhere. @logg are you aware of this change?

  4. Log in to comment