Skip to content
Snippets Groups Projects
Commit a50673be authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Adjust the interpolation of dirichlet data to the new Expression style

parent 42c9cd29
No related branches found
No related tags found
No related merge requests found
...@@ -777,30 +777,43 @@ def define_compositegfs_parameterfunction(name, *children): ...@@ -777,30 +777,43 @@ def define_compositegfs_parameterfunction(name, *children):
', '.join(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 @symbol
def name_boundary_function(expr): def _name_boundary_function(element, boundary, name=None):
from ufl import MixedElement, VectorElement, TensorElement from ufl import MixedElement, VectorElement, TensorElement
if isinstance(expr, (VectorElement, TensorElement)): if isinstance(element, (VectorElement, TensorElement)):
element, (_, boundary) = get_constraints_metadata(expr)
from dune.perftool.generation import get_global_context_value from dune.perftool.generation import get_global_context_value
name = get_global_context_value("data").object_names.get(id(boundary), "zero") basename = get_global_context_value("data").object_names.get(id(boundary), "veczero")
define_boundary_function(boundary, name) 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())))
return name define_compositegfs_parameterfunction(basename, *children)
if isinstance(expr, MixedElement): return basename
children = tuple(name_boundary_function(el) for el in expr.sub_elements()) if isinstance(element, MixedElement):
children = tuple(name_boundary_function(el) for el in element.sub_elements())
name = '_'.join(children) name = '_'.join(children)
define_compositegfs_parameterfunction(name, *children) define_compositegfs_parameterfunction(name, *children)
return name 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 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) define_boundary_function(boundary, name)
return 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 @symbol
def name_solution_function(expr): def name_solution_function(expr):
......
v_bctype = Expression("if (x[0] < 1. - 1e-8) return 1; else return 0;", on_intersection=True) 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_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 g = g_v * g_p
......
v_bctype = Expression("if (x[0] < 1. - 1e-8) return 1; else return 0;", on_intersection=True) 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 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) P1 = FiniteElement("Lagrange", cell, 1)
P2_stress = TensorElement("Lagrange", cell, 2) P2_stress = TensorElement("Lagrange", cell, 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment