diff --git a/python/dune/perftool/pdelab/__init__.py b/python/dune/perftool/pdelab/__init__.py index ac9ad0e46f5203a23b52ef52090f28cd2a811b72..d05bcad57ddde467de202a09f337c873317c5452 100644 --- a/python/dune/perftool/pdelab/__init__.py +++ b/python/dune/perftool/pdelab/__init__.py @@ -35,6 +35,10 @@ from dune.perftool.pdelab.tensors import pymbolic_list_tensor, pymbolic_identity class PDELabInterface(object): + def __init__(self): + # The visitor instance will be registered by its init method + self.visitor = None + # # TODO: The following ones are actually entirely PDELab independent! # They should be placed elsewhere and be used directly in the visitor. @@ -63,16 +67,16 @@ 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, visitor=None): + def pymbolic_trialfunction_gradient(self, element, restriction, component): return pymbolic_trialfunction_gradient(element, restriction, component) - def pymbolic_apply_function_gradient(self, element, restriction, component, visitor=None): + def pymbolic_apply_function_gradient(self, element, restriction, component): return pymbolic_apply_function_gradient(element, restriction, component) - def pymbolic_trialfunction(self, element, restriction, component, visitor=None): + def pymbolic_trialfunction(self, element, restriction, component): return pymbolic_trialfunction(element, restriction, component) - def pymbolic_apply_function(self, element, restriction, component, visitor=None): + def pymbolic_apply_function(self, element, restriction, component): return pymbolic_apply_function(element, restriction, component) # @@ -89,8 +93,8 @@ class PDELabInterface(object): # Tensor expression related generator functions # - def pymbolic_list_tensor(self, o, visitor): - return pymbolic_list_tensor(o, visitor) + def pymbolic_list_tensor(self, o): + return pymbolic_list_tensor(o, self.visitor) def pymbolic_identity(self, o): return pymbolic_identity(o) @@ -99,7 +103,7 @@ class PDELabInterface(object): # Geometry related generator functions # - def pymbolic_spatial_coordinate(self, visitor=None): + def pymbolic_spatial_coordinate(self): return to_global(pymbolic_quadrature_position()) def name_facet_jacobian_determinant(self): diff --git a/python/dune/perftool/sumfact/__init__.py b/python/dune/perftool/sumfact/__init__.py index 3b519622af83ca6d535dacf5c553c61e1455a3f0..d0c8c0f5343362f8a3d34f7cc66b73b4a5a1e2b2 100644 --- a/python/dune/perftool/sumfact/__init__.py +++ b/python/dune/perftool/sumfact/__init__.py @@ -31,24 +31,24 @@ class SumFactInterface(PDELabInterface): def pymbolic_reference_gradient(self, element, restriction, number): return pymbolic_reference_gradient(element, restriction, number) - def pymbolic_trialfunction_gradient(self, element, restriction, component, visitor=None): - ret, indices = pymbolic_coefficient_gradient(element, restriction, component, name_coefficientcontainer, visitor.indices) - visitor.indices = indices + def pymbolic_trialfunction_gradient(self, element, restriction, component): + ret, indices = pymbolic_coefficient_gradient(element, restriction, component, name_coefficientcontainer, self.visitor.indices) + self.visitor.indices = indices return ret - def pymbolic_trialfunction(self, element, restriction, component, visitor=None): - ret, indices = pymbolic_coefficient(element, restriction, component, name_coefficientcontainer, visitor.indices) - visitor.indices = indices + def pymbolic_trialfunction(self, element, restriction, component): + ret, indices = pymbolic_coefficient(element, restriction, component, name_coefficientcontainer, self.visitor.indices) + self.visitor.indices = indices return ret - def pymbolic_apply_function_gradient(self, element, restriction, component, visitor=None): - ret, indices = pymbolic_coefficient_gradient(element, restriction, component, name_applycontainer, visitor.indices) - visitor.indices = indices + def pymbolic_apply_function_gradient(self, element, restriction, component): + ret, indices = pymbolic_coefficient_gradient(element, restriction, component, name_applycontainer, self.visitor.indices) + self.visitor.indices = indices return ret - def pymbolic_apply_function(self, element, restriction, component, visitor=None): - ret, indices = pymbolic_coefficient(element, restriction, component, name_applycontainer, visitor.indices) - visitor.indices = indices + def pymbolic_apply_function(self, element, restriction, component): + ret, indices = pymbolic_coefficient(element, restriction, component, name_applycontainer, self.visitor.indices) + self.visitor.indices = indices return ret def quadrature_inames(self): @@ -61,8 +61,8 @@ class SumFactInterface(PDELabInterface): # from dune.perftool.pdelab.geometry import to_global # return to_global(pymbolic_quadrature_position()) - def pymbolic_spatial_coordinate(self, visitor=None): + def pymbolic_spatial_coordinate(self): import dune.perftool.sumfact.geometry - ret, indices = get_backend(interface="spatial_coordinate", selector=option_switch("diagonal_transformation_matrix"))(visitor.indices) - visitor.indices = indices + ret, indices = get_backend(interface="spatial_coordinate", selector=option_switch("diagonal_transformation_matrix"))(self.visitor.indices) + self.visitor.indices = indices return ret diff --git a/python/dune/perftool/ufl/visitor.py b/python/dune/perftool/ufl/visitor.py index 6c7ddb1afa67c9abc3ed1e007a91e4ad4dbd94ee..2ecb0b999c30e3553e116682fc1b20e15ccf8780 100644 --- a/python/dune/perftool/ufl/visitor.py +++ b/python/dune/perftool/ufl/visitor.py @@ -41,6 +41,7 @@ import pymbolic.primitives as prim class UFL2LoopyVisitor(ModifiedTerminalTracker): def __init__(self, interface, measure, dimension_indices, donot_check_substrules=None): self.interface = interface + self.interface.visitor = self self.measure = measure self.dimension_indices = dimension_indices self.donot_check_substrules = donot_check_substrules @@ -131,14 +132,14 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): if self.reference_grad: if o.count() == 0: - return self.interface.pymbolic_trialfunction_gradient(o.ufl_element(), restriction, self.component, visitor=self) + return self.interface.pymbolic_trialfunction_gradient(o.ufl_element(), restriction, self.component) else: - return self.interface.pymbolic_apply_function_gradient(o.ufl_element(), restriction, self.component, visitor=self) + return self.interface.pymbolic_apply_function_gradient(o.ufl_element(), restriction, self.component) else: if o.count() == 0: - return self.interface.pymbolic_trialfunction(o.ufl_element(), restriction, self.component, visitor=self) + return self.interface.pymbolic_trialfunction(o.ufl_element(), restriction, self.component) else: - return self.interface.pymbolic_apply_function(o.ufl_element(), restriction, self.component, visitor=self) + return self.interface.pymbolic_apply_function(o.ufl_element(), restriction, self.component) # Check if this is a parameter function else: @@ -231,7 +232,7 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): return self._index_or_fixed_index(o) def list_tensor(self, o): - return self.interface.pymbolic_list_tensor(o, self) + return self.interface.pymbolic_list_tensor(o) def identity(self, o): return self.interface.pymbolic_identity(o) @@ -355,7 +356,7 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): if get_global_context_value("driver", False): return prim.Variable("x") else: - return self.interface.pymbolic_spatial_coordinate(self) + return self.interface.pymbolic_spatial_coordinate() def facet_normal(self, o): # The normal must be restricted to be well-defined