← Back to team overview

ffc team mailing list archive

TestFunction and TrialFunction usage

 

As requested by a number of people, I have added two new classes to
the FFC form language: TestFunction and TrialFunction.

Here is the Poisson example with the new syntax:

    element = FiniteElement("Lagrange", "triangle", 1)

    v = TestFunction(element)
    U = TrialFunction(element)
    f = Function(element)

    a = dot(grad(v), grad(U))*dx
    L = v*f*dx

The old syntax with BasisFunction still works and may be useful to
define higher-arity forms when it is less clear what is the trial and
what is the test function.

The order in which one defines a TestFunction and TrialFunction is not
important. The order is encoded in the names, so that the TestFunction
corresponds to the first axis of the tensor (matrix row) and the
TrialFunction corresponds to the second axis of the tensor (matrix
column).

I have updated all the demos with the new syntax. This also works for
mixed systems so there is a class TestFunctions and also a class
TrialFunctions.

The implementation turned out to be very simple. The basic machinery
of general arity tensors remains the same and the only difference is
the two new classes with predefined positions:

class TestFunction(BasisFunction):

    def __init__(self, element):
        index = Index("primary")
        index.index = -2
        BasisFunction.__init__(self, element, index)
        return

class TrialFunction(BasisFunction):

    def __init__(self, element):
        index = Index("primary")
        index.index = -1
        BasisFunction.__init__(self, element, index)
        return

Enjoy!
/Anders