From c2a4f3febe2e2519617c65a461881fab7c47c541 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de>
Date: Fri, 16 Dec 2016 17:36:31 +0100
Subject: [PATCH] Implement UFL variation

... really elegant.
---
 applications/poisson_dg/poisson_dg.mini | 15 ++++++++++-----
 applications/poisson_dg/poisson_dg.ufl  |  2 +-
 python/dune/perftool/compile.py         | 18 ++++++++++++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/applications/poisson_dg/poisson_dg.mini b/applications/poisson_dg/poisson_dg.mini
index 38b5f775..e7a0eedf 100644
--- a/applications/poisson_dg/poisson_dg.mini
+++ b/applications/poisson_dg/poisson_dg.mini
@@ -1,10 +1,15 @@
-__name = app_poisson_dg
+__name = app_poisson_dg_{__exec_suffix}
+__exec_suffix = deg{formcompiler.ufl_variants.degree}
 
-lowerleft = 0.0 0.0
-upperright = 1.0 1.0
-elements = 32 32
-elementType = simplical
+extension = 1.0 1.0 1.0
+cells = 16 16 16
 
 [wrapper.vtkcompare]
 name = {__name}
 extension = vtu
+
+[formcompiler]
+sumfact = 1
+
+[formcompiler.ufl_variants]
+degree = 1, 2 | expand
diff --git a/applications/poisson_dg/poisson_dg.ufl b/applications/poisson_dg/poisson_dg.ufl
index c34e0d2c..6a7e50f7 100644
--- a/applications/poisson_dg/poisson_dg.ufl
+++ b/applications/poisson_dg/poisson_dg.ufl
@@ -4,7 +4,7 @@ x = SpatialCoordinate(cell)
 f = -6.
 g = x[0]*x[0] + x[1]*x[1] + x[2]*x[2]
 
-V = FiniteElement("DG", cell, 1)
+V = FiniteElement("DG", cell, degree)
 
 u = TrialFunction(V)
 v = TestFunction(V)
diff --git a/python/dune/perftool/compile.py b/python/dune/perftool/compile.py
index e1e09294..43acf90b 100644
--- a/python/dune/perftool/compile.py
+++ b/python/dune/perftool/compile.py
@@ -41,7 +41,25 @@ def read_ufl(uflfile):
     """
     # Read the given ufl file and execute it
     uflcode = read_ufl_file(uflfile)
+
+    # Prepopulate a namespace with variation information
     namespace = globals()
+    ini = get_option("ini_file")
+    if ini:
+        from dune.common.parametertree.parser import parse_ini_file
+        ini = parse_ini_file(ini)
+
+        def type_guessing(val):
+            for t in [int, float]:
+                try:
+                    return t(val)
+                except TypeError:
+                    pass
+            return val
+
+        for k, v in ini.get("formcompiler.ufl_variants", {}).items():
+            namespace[k] = type_guessing(v)
+
     try:
         exec("from dune.perftool.ufl.execution import *\n" + uflcode, namespace)
     except:
-- 
GitLab