From a50673beeb1f3871330963608e515789d8165080 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de>
Date: Tue, 6 Sep 2016 13:42:44 +0200
Subject: [PATCH] Adjust the interpolation of dirichlet data to the new
 Expression style

---
 python/dune/perftool/pdelab/driver.py | 37 ++++++++++++++++++---------
 test/stokes/stokes.ufl                |  2 +-
 test/stokes/stokes_stress.ufl         |  6 +++--
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/python/dune/perftool/pdelab/driver.py b/python/dune/perftool/pdelab/driver.py
index 97f876eb..dfbaf7c4 100644
--- a/python/dune/perftool/pdelab/driver.py
+++ b/python/dune/perftool/pdelab/driver.py
@@ -777,30 +777,43 @@ def define_compositegfs_parameterfunction(name, *children):
                                                                     ', '.join(children))
 
 
+def expression_splitter(expr, length):
+    if expr is None:
+        return (None,) * length
+    else:
+        from dune.perftool.ufl.execution import split_expression
+        return split_expression(expr)
+
+
 @symbol
-def name_boundary_function(expr):
+def _name_boundary_function(element, boundary, name=None):
     from ufl import MixedElement, VectorElement, TensorElement
-    if isinstance(expr, (VectorElement, TensorElement)):
-        element, (_, boundary) = get_constraints_metadata(expr)
+    if isinstance(element, (VectorElement, TensorElement)):
         from dune.perftool.generation import get_global_context_value
-        name = get_global_context_value("data").object_names.get(id(boundary), "zero")
-        define_boundary_function(boundary, name)
-        return name
-    if isinstance(expr, MixedElement):
-        children = tuple(name_boundary_function(el) for el in expr.sub_elements())
+        basename = get_global_context_value("data").object_names.get(id(boundary), "veczero")
+        children = tuple(_name_boundary_function(el, exp, basename + '_' + str(i)) for el, exp, i in zip(element.sub_elements(), expression_splitter(boundary, element.num_sub_elements()), range(element.num_sub_elements())))
+        define_compositegfs_parameterfunction(basename, *children)
+        return basename
+    if isinstance(element, MixedElement):
+        children = tuple(name_boundary_function(el) for el in element.sub_elements())
         name = '_'.join(children)
         define_compositegfs_parameterfunction(name, *children)
         return name
 
-    # This is a scalar leaf of the ansatz function tree
-    element, (_, boundary) = get_constraints_metadata(expr)
-
     from dune.perftool.generation import get_global_context_value
-    name = get_global_context_value("data").object_names.get(id(boundary), "zero")
+    if name is None:
+        name = get_global_context_value("data").object_names.get(id(boundary), "zero")
 
     define_boundary_function(boundary, name)
     return name
 
+def name_boundary_function(expr):
+    # This is a scalar leaf of the ansatz function tree
+    element, (_, boundary) = get_constraints_metadata(expr)
+
+    return _name_boundary_function(element, boundary)
+
+
 
 @symbol
 def name_solution_function(expr):
diff --git a/test/stokes/stokes.ufl b/test/stokes/stokes.ufl
index e88a011a..da632caf 100644
--- a/test/stokes/stokes.ufl
+++ b/test/stokes/stokes.ufl
@@ -1,6 +1,6 @@
 v_bctype = Expression("if (x[0] < 1. - 1e-8) return 1; else return 0;", on_intersection=True)
 g_v = Expression(("4*x[1]*(1.-x[1])", "0.0"))
-g_p = Expression("8*x[0]")
+g_p = Expression("8*(1.-x[0])")
 
 g = g_v * g_p
 
diff --git a/test/stokes/stokes_stress.ufl b/test/stokes/stokes_stress.ufl
index 9eb4f3b7..71a32399 100644
--- a/test/stokes/stokes_stress.ufl
+++ b/test/stokes/stokes_stress.ufl
@@ -1,8 +1,10 @@
 v_bctype = Expression("if (x[0] < 1. - 1e-8) return 1; else return 0;", on_intersection=True)
-v_dirichlet = Expression("Dune::FieldVector<double, 2> y(0.0); y[0] = 4*x[1]*(1.-x[1]); return y;")
+g_v = Expression(("4*x[1]*(1.-x[1])", "0.0"))
+g_p = Expression("8*(1.-x[0])")
+g = g_v * g_p
 
 cell = triangle
-P2 = VectorElement("Lagrange", cell, 2, dirichlet_constraints=v_bctype, dirichlet_expression=v_dirichlet)
+P2 = VectorElement("Lagrange", cell, 2, dirichlet_constraints=v_bctype, dirichlet_expression=g_v)
 P1 = FiniteElement("Lagrange", cell, 1)
 P2_stress = TensorElement("Lagrange", cell, 2)
 
-- 
GitLab