From f84e5252e6c255625ec8127e797335e8751081b2 Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.r.kempf@gmail.com> Date: Sat, 29 Aug 2015 00:11:24 +0200 Subject: [PATCH] Add the runtime_ufl from uflpdelab it reserves the trial function as coefficient 0. --- examples/laplace.ufl | 3 +-- python/dune/perftool/runtime_ufl.py | 30 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 python/dune/perftool/runtime_ufl.py diff --git a/examples/laplace.ufl b/examples/laplace.ufl index f9977e57..29b6a4bd 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 00000000..026f5b11 --- /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)) -- GitLab