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

Handle subdomain_data in a maybe less hacky way

parent 25781f9c
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,5 @@ git apply ../../../patches/vectorclass/0001-Better-implementation-of-horizontal_ ...@@ -10,6 +10,5 @@ git apply ../../../patches/vectorclass/0001-Better-implementation-of-horizontal_
popd popd
pushd python/ufl pushd python/ufl
git apply ../../patches/ufl/conditional-uflid.patch
git apply ../../patches/ufl/0001-Remove-special-case-for-variable-in-ufl2dot.patch git apply ../../patches/ufl/0001-Remove-special-case-for-variable-in-ufl2dot.patch
popd popd
diff --git a/ufl/conditional.py b/ufl/conditional.py
index 352624c..ebd647f 100644
--- a/ufl/conditional.py
+++ b/ufl/conditional.py
@@ -27,6 +27,7 @@ from ufl.constantvalue import as_ufl
from ufl.precedence import parstr
from ufl.exprequals import expr_equals
from ufl.checks import is_true_ufl_scalar
+from ufl.core.ufl_id import attach_ufl_id
# --- Condition classes ---
@@ -221,10 +222,11 @@ class NotCondition(Condition):
@ufl_type(num_ops=3, inherit_shape_from_operand=1,
inherit_indices_from_operand=1)
+@attach_ufl_id
class Conditional(Operator):
- __slots__ = ()
+ __slots__ = ("_ufl_id")
- def __init__(self, condition, true_value, false_value):
+ def __init__(self, condition, true_value, false_value, ufl_id=None):
if not isinstance(condition, Condition):
error("Expectiong condition as first argument.")
true_value = as_ufl(true_value)
@@ -244,6 +246,7 @@ class Conditional(Operator):
condition.ufl_operands[1].ufl_free_indices == ())):
error("Non-scalar == or != is not allowed.")
+ self._ufl_id = self._init_ufl_id(ufl_id)
Operator.__init__(self, (condition, true_value, false_value))
def evaluate(self, x, mapping, component, index_values):
...@@ -284,37 +284,24 @@ def boundary_predicates(expr, measure, subdomain_id): ...@@ -284,37 +284,24 @@ def boundary_predicates(expr, measure, subdomain_id):
predicates = frozenset([]) predicates = frozenset([])
if subdomain_id not in ['everywhere', 'otherwise']: if subdomain_id not in ['everywhere', 'otherwise']:
# We need to reconstruct the subdomain_data parameter of the measure
# I am *totally* confused as to why this information is not at hand anyway,
# but conversation with Martin pointed me to dolfin.fem.assembly where this
# is done in preprocessing with the limitation of only one possible type of
# modified measure per integral type.
# Get the original form and inspect the present measures # Get the original form and inspect the present measures
from dune.perftool.generation import get_global_context_value from dune.perftool.generation import get_global_context_value
data = get_global_context_value("data") data = get_global_context_value("data")
original_form = data.object_by_name[get_form_option("form")] original_form = data.object_by_name[get_form_option("form")]
sd = original_form.subdomain_data() subdomains = []
assert len(sd) == 1 for integral in original_form.integrals():
subdomains, = list(sd.values()) if integral.integral_type() == measure:
domain, = list(sd.keys()) subdomains.append(integral.subdomain_data())
for k in list(subdomains.keys()):
if subdomains[k] is None:
del subdomains[k]
# Finally extract the original subdomain_data (which needs to be present!) subdomain_data, = set(subdomains)
assert measure in subdomains
subdomain_data = subdomains[measure]
from ufl.classes import Expr from ufl.classes import Expr
if isinstance(subdomain_data, Expr): if isinstance(subdomain_data, Expr):
visitor = get_visitor(measure, subdomain_id) visitor = get_visitor(measure, subdomain_id)
cond = visitor(subdomain_data, do_predicates=True) subdomain_data = visitor(subdomain_data, do_predicates=True)
else:
raise NotImplementedError("Only UFL expressions allowed in subdomain_data right now.")
predicates = predicates.union([prim.Comparison(cond, '==', subdomain_id)]) predicates = predicates.union([prim.Comparison(subdomain_data, '==', subdomain_id)])
return predicates return predicates
......
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