diff --git a/examples/laplace.ufl b/examples/laplace.ufl index f9977e579dea275255847f8a5f4e87ca208b876a..29b6a4bd3d6da839ca622098a222079d716a4f9e 100644 --- a/examples/laplace.ufl +++ b/examples/laplace.ufl @@ -1,6 +1,5 @@ V = FiniteElement("CG", "triangle", 1) -k = Coefficient(V) -u = Coefficient(V) +u = TrialFunction(V) v = TestFunction(V) forms = [inner(grad(u), grad(v))*dx] diff --git a/python/dune/perftool/runtime_ufl.py b/python/dune/perftool/runtime_ufl.py new file mode 100644 index 0000000000000000000000000000000000000000..026f5b11d66de541f9f3e1a8a69416cdf28a5110 --- /dev/null +++ b/python/dune/perftool/runtime_ufl.py @@ -0,0 +1,30 @@ +""" This module is loaded instead of ufl when executing .ufl files. +So, this module contains all our extensions and monkey patches to +UFL. +""" + +import ufl +from ufl import * +from ufl.split_functions import split + +class TrialFunction(ufl.Coefficient): + """ A coefficient that always takes the reserved index 0 """ + def __init__(self, element, count=None): + if count and count is not 0: + raise ValueError("The trial function must be the coefficient of index 0 in uflpdelab") + ufl.Coefficient.__init__(self, element, count=0) + +class Coefficient(ufl.Coefficient): + """ A coefficient that honors the reserved index 0. """ + def __init__(self, element, count=None): + if count and count is 0: + raise ValueError("The coefficient of index 0 is reserved for the trial function in uflpdelab") + if not count and ufl.Coefficient._globalcount is 0: + count = 1 + ufl.Coefficient.__init__(self, element, count) + +def Coefficients(element): + return split(Coefficient(element)) + +def TrialFunctions(element): + return split(TrialFunction(element))