The FEniCS project allows for simple solution of partial differential equations. However, getting started from examples is so quick, it is easy to miss how the inner-workings of it behave. This should not happen (especially if it is a PhD project). There are three vital pieces of the puzzle that it might not be clear what they are for, and the documentation does not help here: the functions TrialFunction, TestFunction, and Function.

The thing is that, in the usual Finite Element Methods, we only have the distinction between the trial function and test function , and even then the distinction is often blurry. In fact, technically, the spaces and can be different. However, most of the time we take them to be the same (for example, the same discrete space of piecewise linear functions). The names we give them is just to have clearer in our heads what role they play in the game, but we could as well say “two functions in “. Then why would FEniCS have even a three-fold difference? You can quickly check for yourself that, for example, if you swap the TrialFunction for a Function, FEniCS will complain.

There is no documentation on the topic as far as I have found, so these are my (maybe mistaken) deductions.

The meaning of the TrialFunction is to let FEniCS know what function we are solving for. In fact, when we call

1 |
solve(A, u_.vector(), b) |

FEniCS expects to find a TrialFunction in A, which is supposed to be the function we are looking for. On the other hand, `u_`

is the symbol in which the result will be stored, and this needs to be a `Function`

(not `Trial`

, not `Test`

, just a regular `Function`

).

Continue reading “FEniCS differences between Function, TrialFunction and TestFunction”