Skip to content
Snippets Groups Projects
Commit 467f2a3e authored by René Heß's avatar René Heß
Browse files

[!268] Handle subdomain_data in a maybe less hacky way

Merge branch 'feature/better-subdomain-handling' into 'master'

See merge request [dominic/dune-perftool!268]

  [dominic/dune-perftool!268]: Nonedominic/dune-perftool/merge_requests/268
parents 25781f9c ff780e09
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_
popd
pushd python/ufl
git apply ../../patches/ufl/conditional-uflid.patch
git apply ../../patches/ufl/0001-Remove-special-case-for-variable-in-ufl2dot.patch
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):
predicates = frozenset([])
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
from dune.perftool.generation import get_global_context_value
data = get_global_context_value("data")
original_form = data.object_by_name[get_form_option("form")]
sd = original_form.subdomain_data()
assert len(sd) == 1
subdomains, = list(sd.values())
domain, = list(sd.keys())
for k in list(subdomains.keys()):
if subdomains[k] is None:
del subdomains[k]
subdomains = []
for integral in original_form.integrals():
if integral.integral_type() == measure:
subdomains.append(integral.subdomain_data())
# Finally extract the original subdomain_data (which needs to be present!)
assert measure in subdomains
subdomain_data = subdomains[measure]
subdomain_data, = set(subdomains)
from ufl.classes import Expr
if isinstance(subdomain_data, Expr):
visitor = get_visitor(measure, subdomain_id)
cond = visitor(subdomain_data, do_predicates=True)
else:
raise NotImplementedError("Only UFL expressions allowed in subdomain_data right now.")
subdomain_data = visitor(subdomain_data, do_predicates=True)
predicates = predicates.union([prim.Comparison(cond, '==', subdomain_id)])
predicates = predicates.union([prim.Comparison(subdomain_data, '==', subdomain_id)])
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