From 95cf468b04ba251ab2f42c5352857c081956601e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20He=C3=9F?= <rene.hess@iwr.uni-heidelberg.de> Date: Tue, 6 Jun 2017 13:05:40 +0200 Subject: [PATCH] Rename component to tree_path --- python/dune/perftool/pdelab/__init__.py | 16 ++++----- python/dune/perftool/pdelab/argument.py | 24 ++++++------- python/dune/perftool/pdelab/basis.py | 12 +++---- python/dune/perftool/pdelab/parameter.py | 7 ++-- python/dune/perftool/pdelab/spaces.py | 22 ++++++------ python/dune/perftool/sumfact/__init__.py | 16 ++++----- python/dune/perftool/sumfact/basis.py | 34 +++++++++---------- python/dune/perftool/ufl/dimensionindex.py | 10 +++--- .../dune/perftool/ufl/modified_terminals.py | 19 ++++------- python/dune/perftool/ufl/visitor.py | 10 +++--- 10 files changed, 82 insertions(+), 88 deletions(-) diff --git a/python/dune/perftool/pdelab/__init__.py b/python/dune/perftool/pdelab/__init__.py index d05bcad5..10d2b951 100644 --- a/python/dune/perftool/pdelab/__init__.py +++ b/python/dune/perftool/pdelab/__init__.py @@ -67,17 +67,17 @@ class PDELabInterface(object): def pymbolic_reference_gradient(self, element, restriction, number): return pymbolic_reference_gradient(element, restriction, number) - def pymbolic_trialfunction_gradient(self, element, restriction, component): - return pymbolic_trialfunction_gradient(element, restriction, component) + def pymbolic_trialfunction_gradient(self, element, restriction, tree_path): + return pymbolic_trialfunction_gradient(element, restriction, tree_path) - def pymbolic_apply_function_gradient(self, element, restriction, component): - return pymbolic_apply_function_gradient(element, restriction, component) + def pymbolic_apply_function_gradient(self, element, restriction, tree_path): + return pymbolic_apply_function_gradient(element, restriction, tree_path) - def pymbolic_trialfunction(self, element, restriction, component): - return pymbolic_trialfunction(element, restriction, component) + def pymbolic_trialfunction(self, element, restriction, tree_path): + return pymbolic_trialfunction(element, restriction, tree_path) - def pymbolic_apply_function(self, element, restriction, component): - return pymbolic_apply_function(element, restriction, component) + def pymbolic_apply_function(self, element, restriction, tree_path): + return pymbolic_apply_function(element, restriction, tree_path) # # Parameter function related generator functions diff --git a/python/dune/perftool/pdelab/argument.py b/python/dune/perftool/pdelab/argument.py index 5a044e55..f9906902 100644 --- a/python/dune/perftool/pdelab/argument.py +++ b/python/dune/perftool/pdelab/argument.py @@ -89,35 +89,35 @@ def accumulation_mangler(target, func, dtypes): ) -def pymbolic_trialfunction_gradient(element, restriction, component): - rawname = "gradu" + "_".join(str(c) for c in component) +def pymbolic_trialfunction_gradient(element, restriction, tree_path): + rawname = "gradu" + "_".join(str(c) for c in tree_path) name = restricted_name(rawname, restriction) container = name_coefficientcontainer(restriction) - evaluate_coefficient_gradient(element, name, container, restriction, component) + evaluate_coefficient_gradient(element, name, container, restriction, tree_path) return Variable(name) -def pymbolic_trialfunction(element, restriction, component): - rawname = "u" + "_".join(str(c) for c in component) +def pymbolic_trialfunction(element, restriction, tree_path): + rawname = "u" + "_".join(str(c) for c in tree_path) name = restricted_name(rawname, restriction) container = name_coefficientcontainer(restriction) - evaluate_coefficient(element, name, container, restriction, component) + evaluate_coefficient(element, name, container, restriction, tree_path) return Variable(name) -def pymbolic_apply_function_gradient(element, restriction, component): - rawname = "gradz_func" + "_".join(str(c) for c in component) +def pymbolic_apply_function_gradient(element, restriction, tree_path): + rawname = "gradz_func" + "_".join(str(c) for c in tree_path) name = restricted_name(rawname, restriction) container = name_applycontainer(restriction) - evaluate_coefficient_gradient(element, name, container, restriction, component) + evaluate_coefficient_gradient(element, name, container, restriction, tree_path) return Variable(name) -def pymbolic_apply_function(element, restriction, component): - rawname = "z_func" + "_".join(str(c) for c in component) +def pymbolic_apply_function(element, restriction, tree_path): + rawname = "z_func" + "_".join(str(c) for c in tree_path) name = restricted_name(rawname, restriction) container = name_applycontainer(restriction) - evaluate_coefficient(element, name, container, restriction, component) + evaluate_coefficient(element, name, container, restriction, tree_path) return Variable(name) diff --git a/python/dune/perftool/pdelab/basis.py b/python/dune/perftool/pdelab/basis.py index 251258e8..25438f7e 100644 --- a/python/dune/perftool/pdelab/basis.py +++ b/python/dune/perftool/pdelab/basis.py @@ -130,9 +130,9 @@ def shape_as_pymbolic(shape): @kernel_cached -def evaluate_coefficient(element, name, container, restriction, component): +def evaluate_coefficient(element, name, container, restriction, tree_path): from ufl.functionview import select_subelement - sub_element = select_subelement(element, component) + sub_element = select_subelement(element, tree_path) # Determine the rank of the trialfunction tensor rank = len(sub_element.value_shape()) @@ -146,7 +146,7 @@ def evaluate_coefficient(element, name, container, restriction, component): leaf_element = sub_element.sub_elements()[0] temporary_variable(name, shape=shape, shape_impl=shape_impl) - lfs = name_lfs(element, restriction, component) + lfs = name_lfs(element, restriction, tree_path) basis = pymbolic_basis(leaf_element, restriction, 0, context='trial') index, = get_pymbolic_indices(basis) @@ -166,10 +166,10 @@ def evaluate_coefficient(element, name, container, restriction, component): @kernel_cached -def evaluate_coefficient_gradient(element, name, container, restriction, component): +def evaluate_coefficient_gradient(element, name, container, restriction, tree_path): # First we determine the rank of the tensor we are talking about from ufl.functionview import select_subelement - sub_element = select_subelement(element, component) + sub_element = select_subelement(element, tree_path) rank = len(sub_element.value_shape()) + 1 # We do then set some variables accordingly @@ -184,7 +184,7 @@ def evaluate_coefficient_gradient(element, name, container, restriction, compone # and proceed to call the necessary generator functions temporary_variable(name, shape=shape, shape_impl=shape_impl) - lfs = name_lfs(element, restriction, component) + lfs = name_lfs(element, restriction, tree_path) basis = pymbolic_reference_gradient(leaf_element, restriction, 0, context='trialgrad') index, _ = get_pymbolic_indices(basis) diff --git a/python/dune/perftool/pdelab/parameter.py b/python/dune/perftool/pdelab/parameter.py index 8e8af15b..cf2c73fe 100644 --- a/python/dune/perftool/pdelab/parameter.py +++ b/python/dune/perftool/pdelab/parameter.py @@ -67,8 +67,9 @@ def define_set_time_method(): return result -def component_to_tree_path(element, component): - subel = element.extract_subelement_component(component) +def combine_tree_path_argnumber(element, tree_path_int): + # Return string combining tree_path and argnumber. + subel = element.extract_subelement_component(tree_path_int) def _flatten(x): if isinstance(x, tuple): @@ -101,7 +102,7 @@ def define_parameter_function_class_member(name, expr, baset, shape, cell): from dune.perftool.ufl.execution import split_expression for i, subexpr in enumerate(split_expression(expr)): - child_name = "{}_{}".format(name, component_to_tree_path(expr.element, i)) + child_name = "{}_{}".format(name, combine_tree_path_argnumber(expr.element, i)) result.append(" result[{}] = {}({}, local);".format(i, child_name, geo)) define_parameter_function_class_member(child_name, subexpr, baset, shape[1:], cell) diff --git a/python/dune/perftool/pdelab/spaces.py b/python/dune/perftool/pdelab/spaces.py index d639fb9d..5a7e2852 100644 --- a/python/dune/perftool/pdelab/spaces.py +++ b/python/dune/perftool/pdelab/spaces.py @@ -104,34 +104,34 @@ def name_leaf_lfs(leaf_element, restriction, val=None): return val -@generator_factory(cache_key_generator=lambda e, r, c, **kw: (e, r, c), context_tags=("kernel",)) -def name_lfs(element, restriction, component, prefix=None): +@generator_factory(cache_key_generator=lambda e, r, t, **kw: (e, r, t), context_tags=("kernel",)) +def name_lfs(element, restriction, tree_path, prefix=None): # Omitting the prefix is only valid upon a second call, which will # result in a cache hit. assert prefix - def _name_lfs(prefix, component): + def _name_lfs(prefix, tree_path): name = prefix - if len(component) > 0: - name = name + '_' + '_'.join(str(i) for i in component) + if len(tree_path) > 0: + name = name + '_' + '_'.join(str(i) for i in tree_path) return name - name = _name_lfs(prefix, component) - if len(component) > 0: - father = _name_lfs(prefix, component[:-1]) + name = _name_lfs(prefix, tree_path) + if len(tree_path) > 0: + father = _name_lfs(prefix, tree_path[:-1]) # If this localfunction space is the child of another one, trigger # the extraction preamble. Necessary before going into recursion # for having the correct (top-down) order of preambles - define_lfs(name, father, component[-1]) + define_lfs(name, father, tree_path[-1]) # Recurse into the given element to define all other local function spaces! from ufl import MixedElement from ufl.functionview import select_subelement from ufl.classes import FixedIndex - subel = select_subelement(element, component) + subel = select_subelement(element, tree_path) if isinstance(subel, MixedElement): for i in range(subel.num_sub_elements()): - name_lfs(element, restriction, component + (FixedIndex(i),), prefix=prefix) + name_lfs(element, restriction, tree_path + (FixedIndex(i),), prefix=prefix) # Cache the name for the subelement name_leaf_lfs(subel, restriction, val=name) diff --git a/python/dune/perftool/sumfact/__init__.py b/python/dune/perftool/sumfact/__init__.py index 6b620316..a2b5623c 100644 --- a/python/dune/perftool/sumfact/__init__.py +++ b/python/dune/perftool/sumfact/__init__.py @@ -33,23 +33,23 @@ class SumFactInterface(PDELabInterface): self.visitor.indices = indices return ret - def pymbolic_trialfunction_gradient(self, element, restriction, component): - ret, indices = pymbolic_coefficient_gradient(element, restriction, component, name_coefficientcontainer, self.visitor.indices) + def pymbolic_trialfunction_gradient(self, element, restriction, tree_path): + ret, indices = pymbolic_coefficient_gradient(element, restriction, tree_path, name_coefficientcontainer, self.visitor.indices) self.visitor.indices = indices return ret - def pymbolic_trialfunction(self, element, restriction, component): - ret, indices = pymbolic_coefficient(element, restriction, component, name_coefficientcontainer, self.visitor.indices) + def pymbolic_trialfunction(self, element, restriction, tree_path): + ret, indices = pymbolic_coefficient(element, restriction, tree_path, name_coefficientcontainer, self.visitor.indices) self.visitor.indices = indices return ret - def pymbolic_apply_function_gradient(self, element, restriction, component): - ret, indices = pymbolic_coefficient_gradient(element, restriction, component, name_applycontainer, self.visitor.indices) + def pymbolic_apply_function_gradient(self, element, restriction, tree_path): + ret, indices = pymbolic_coefficient_gradient(element, restriction, tree_path, name_applycontainer, self.visitor.indices) self.visitor.indices = indices return ret - def pymbolic_apply_function(self, element, restriction, component): - ret, indices = pymbolic_coefficient(element, restriction, component, name_applycontainer, self.visitor.indices) + def pymbolic_apply_function(self, element, restriction, tree_path): + ret, indices = pymbolic_coefficient(element, restriction, tree_path, name_applycontainer, self.visitor.indices) self.visitor.indices = indices return ret diff --git a/python/dune/perftool/sumfact/basis.py b/python/dune/perftool/sumfact/basis.py index 9ef9b424..27f575a3 100644 --- a/python/dune/perftool/sumfact/basis.py +++ b/python/dune/perftool/sumfact/basis.py @@ -57,20 +57,20 @@ class LFSSumfactKernelInput(SumfactKernelInputBase, ImmutableRecord): coeff_func=None, coeff_func_index=None, element=None, - component=None, + tree_path=None, restriction=0, ): ImmutableRecord.__init__(self, coeff_func=coeff_func, coeff_func_index=coeff_func_index, element=element, - component=component, + tree_path=tree_path, restriction=restriction, ) def realize(self, sf, index, insn_dep): - lfs = name_lfs(self.element, self.restriction, self.component) - sub_element = select_subelement(self.element, self.component) + lfs = name_lfs(self.element, self.restriction, self.tree_path) + sub_element = select_subelement(self.element, self.tree_path) shape = sub_element.value_shape() + (self.element.cell().geometric_dimension(),) if isinstance(sub_element, (VectorElement, TensorElement)): @@ -118,29 +118,29 @@ class LFSSumfactKernelInput(SumfactKernelInputBase, ImmutableRecord): return None -def _basis_functions_per_direction(element, component): - """Number of basis functions per direction of a given component of an element""" - assert len(component.indices()) <= 1 - if len(component.indices()) == 0: +def _basis_functions_per_direction(element, tree_path): + """Number of basis functions per direction of a given tree_path of an element""" + assert len(tree_path.indices()) <= 1 + if len(tree_path.indices()) == 0: degree = element.degree() else: - index = component.indices()[0]._value + index = tree_path.indices()[0]._value degree = element.sub_elements()[index].degree() basis_size = degree + 1 return basis_size @kernel_cached -def pymbolic_coefficient_gradient(element, restriction, component, coeff_func, visitor_indices): - rawname = "gradu" + "_".join(str(c) for c in component) +def pymbolic_coefficient_gradient(element, restriction, tree_path, coeff_func, visitor_indices): + rawname = "gradu" + "_".join(str(c) for c in tree_path) name = restricted_name(rawname, restriction) # Number of basis functions per direction - basis_size = _basis_functions_per_direction(element, component) + basis_size = _basis_functions_per_direction(element, tree_path) # Get a temporary for the gradient from ufl.functionview import select_subelement - sub_element = select_subelement(element, component) + sub_element = select_subelement(element, tree_path) rank = len(sub_element.value_shape()) + 1 shape = sub_element.value_shape() + (world_dimension(),) shape_impl = ('arr',) * rank @@ -162,7 +162,7 @@ def pymbolic_coefficient_gradient(element, restriction, component, coeff_func, v inp = LFSSumfactKernelInput(coeff_func=coeff_func, coeff_func_index=coeff_func_index, element=element, - component=component, + tree_path=tree_path, restriction=restriction, ) @@ -182,9 +182,9 @@ def pymbolic_coefficient_gradient(element, restriction, component, coeff_func, v @kernel_cached -def pymbolic_coefficient(element, restriction, component, coeff_func, visitor_indices): +def pymbolic_coefficient(element, restriction, tree_path, coeff_func, visitor_indices): # Basis functions per direction - basis_size = _basis_functions_per_direction(element, component) + basis_size = _basis_functions_per_direction(element, tree_path) # Construct the matrix sequence for this sum factorization matrix_sequence = construct_basis_matrix_sequence(facedir=get_facedir(restriction), @@ -199,7 +199,7 @@ def pymbolic_coefficient(element, restriction, component, coeff_func, visitor_in inp = LFSSumfactKernelInput(coeff_func=coeff_func, coeff_func_index=coeff_func_index, element=element, - component=component, + tree_path=tree_path, restriction=restriction, ) diff --git a/python/dune/perftool/ufl/dimensionindex.py b/python/dune/perftool/ufl/dimensionindex.py index 62651b21..6aebaf42 100644 --- a/python/dune/perftool/ufl/dimensionindex.py +++ b/python/dune/perftool/ufl/dimensionindex.py @@ -9,7 +9,7 @@ class _DimensionIndexMapping(MultiFunction): def __call__(self, o): self.shape = 0 self.dimension_index_dict = {} - self.component = None + self.tree_path = None self.call(o) return self.dimension_index_dict @@ -19,14 +19,14 @@ class _DimensionIndexMapping(MultiFunction): self.call(op) def function_view(self, o): - self.component = o.ufl_operands[1] + self.tree_path = o.ufl_operands[1] self.call(o.ufl_operands[0]) - self.component = None + self.tree_path = None def argument(self, o): - if self.component: + if self.tree_path: from ufl.functionview import select_subelement - subelement = select_subelement(o.ufl_element(), self.component) + subelement = select_subelement(o.ufl_element(), self.tree_path) self.shape = len(subelement.value_shape()) def indexed(self, o): diff --git a/python/dune/perftool/ufl/modified_terminals.py b/python/dune/perftool/ufl/modified_terminals.py index f9d2ef7d..da555529 100644 --- a/python/dune/perftool/ufl/modified_terminals.py +++ b/python/dune/perftool/ufl/modified_terminals.py @@ -21,7 +21,7 @@ class ModifiedArgument(Record): index=None, reference_grad=False, restriction=Restriction.NONE, - component=MultiIndex(()), + tree_path=MultiIndex(()), reference=False, ): Record.__init__(self, @@ -31,17 +31,10 @@ class ModifiedArgument(Record): index=index, reference_grad=reference_grad, restriction=restriction, - component=component, + tree_path=tree_path, reference=reference, ) - @property - def tree_path(self): - if self.component: - return self.component - else: - return self.index - class ModifiedTerminalTracker(MultiFunction): """ A multifunction base that defines handler for @@ -57,7 +50,7 @@ class ModifiedTerminalTracker(MultiFunction): self.reference = True self.reference_grad = False self.restriction = Restriction.NONE - self.component = MultiIndex(()) + self.tree_path = MultiIndex(()) def positive_restricted(self, o): assert self.restriction == Restriction.NONE @@ -88,9 +81,9 @@ class ModifiedTerminalTracker(MultiFunction): return ret def function_view(self, o): - self.component = o.ufl_operands[1] + self.tree_path = o.ufl_operands[1] ret = self.call(o.ufl_operands[0]) - self.component = MultiIndex(()) + self.tree_path = MultiIndex(()) return ret def reference_value(self, o): @@ -122,7 +115,7 @@ class ModifiedArgumentAnalysis(ModifiedTerminalTracker): argexpr=o, index=self._index, restriction=self.restriction, - component=self.component, + tree_path=self.tree_path, grad=self.grad, reference_grad=self.reference_grad, reference=self.reference, diff --git a/python/dune/perftool/ufl/visitor.py b/python/dune/perftool/ufl/visitor.py index 954f8841..e12d7704 100644 --- a/python/dune/perftool/ufl/visitor.py +++ b/python/dune/perftool/ufl/visitor.py @@ -66,7 +66,7 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): restriction = Restriction.NEGATIVE # Select the correct subtree of the finite element - element = select_subelement(o.ufl_element(), self.component) + element = select_subelement(o.ufl_element(), self.tree_path) leaf_element = element # Now treat the case of this being a vector finite element @@ -111,14 +111,14 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): if self.reference_grad: if o.count() == 0: - return self.interface.pymbolic_trialfunction_gradient(o.ufl_element(), restriction, self.component) + return self.interface.pymbolic_trialfunction_gradient(o.ufl_element(), restriction, self.tree_path) else: - return self.interface.pymbolic_apply_function_gradient(o.ufl_element(), restriction, self.component) + return self.interface.pymbolic_apply_function_gradient(o.ufl_element(), restriction, self.tree_path) else: if o.count() == 0: - return self.interface.pymbolic_trialfunction(o.ufl_element(), restriction, self.component) + return self.interface.pymbolic_trialfunction(o.ufl_element(), restriction, self.tree_path) else: - return self.interface.pymbolic_apply_function(o.ufl_element(), restriction, self.component) + return self.interface.pymbolic_apply_function(o.ufl_element(), restriction, self.tree_path) # Check if this is a parameter function else: -- GitLab