From 2aaca43730d818ee4a190a8d6a54d1f1ef53690c Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Wed, 24 Oct 2018 15:01:35 +0200 Subject: [PATCH] Avoid more no op conditionals By looking at the possible values of the condition. --- python/dune/perftool/pdelab/localoperator.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py index 6d9c1dde..93b68e7e 100644 --- a/python/dune/perftool/pdelab/localoperator.py +++ b/python/dune/perftool/pdelab/localoperator.py @@ -301,6 +301,17 @@ def boundary_predicates(measure, subdomain_id): visitor = get_visitor(measure, subdomain_id) subdomain_data = visitor(subdomain_data, do_predicates=True) + # Often, boundary predicates are just nested conditionals. We try to find + # out which of these are unfulfillable in the first place. + def possible_values(expr): + if isinstance(expr, prim.If): + return set(possible_values(expr.then)).union(possible_values(expr.else_)) + else: + return set({expr}) + + if subdomain_id not in possible_values(subdomain_data): + return frozenset({False}) + p = prim.Comparison(subdomain_data, '==', subdomain_id) # Try to find conditions that are always 0 or always 1 @@ -308,7 +319,7 @@ def boundary_predicates(measure, subdomain_id): try: eval = evaluate(p) if not eval: - predicates.append(False) + return frozenset({False}) except: predicates.append(p) -- GitLab