From e5a9685936fc676025cf13840e57e95a9f7442ea Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Tue, 11 Dec 2018 11:02:13 +0100 Subject: [PATCH] Remove interface entirely --- .../dune/codegen/blockstructured/__init__.py | 22 ------------------- .../codegen/blockstructured/accumulation.py | 13 +++++++++-- python/dune/codegen/options.py | 2 +- python/dune/codegen/pdelab/__init__.py | 10 --------- python/dune/codegen/pdelab/driver/visitor.py | 3 +-- python/dune/codegen/pdelab/localoperator.py | 13 +---------- python/dune/codegen/sumfact/__init__.py | 6 ----- python/dune/codegen/ufl/visitor.py | 6 ++--- 8 files changed, 16 insertions(+), 59 deletions(-) diff --git a/python/dune/codegen/blockstructured/__init__.py b/python/dune/codegen/blockstructured/__init__.py index fe3eb1f7..8810750f 100644 --- a/python/dune/codegen/blockstructured/__init__.py +++ b/python/dune/codegen/blockstructured/__init__.py @@ -4,25 +4,3 @@ import dune.codegen.blockstructured.geometry import dune.codegen.blockstructured.spaces import dune.codegen.blockstructured.basis import dune.codegen.blockstructured.transformations -from dune.codegen.options import get_form_option -from dune.codegen.blockstructured.spaces import lfs_inames -from dune.codegen.blockstructured.basis import (pymbolic_reference_gradient, - pymbolic_basis) -from dune.codegen.blockstructured.geometry import (pymbolic_jacobian_inverse, - pymbolic_jacobian_determinant, - pymbolic_facet_jacobian_determinant, - to_global) -from dune.codegen.blockstructured.tools import sub_element_inames -from dune.codegen.pdelab import PDELabInterface - - -class BlockStructuredInterface(PDELabInterface): - def __init__(self): - PDELabInterface.__init__(self) - - def generate_accumulation_instruction(self, expr, visitor): - if get_form_option('vectorization_blockstructured'): - from dune.codegen.blockstructured.accumulation import generate_accumulation_instruction - return generate_accumulation_instruction(expr, visitor) - else: - return PDELabInterface.generate_accumulation_instruction(self, expr, visitor) diff --git a/python/dune/codegen/blockstructured/accumulation.py b/python/dune/codegen/blockstructured/accumulation.py index 0f54fbe9..dc987cb6 100644 --- a/python/dune/codegen/blockstructured/accumulation.py +++ b/python/dune/codegen/blockstructured/accumulation.py @@ -1,8 +1,8 @@ -from dune.codegen.generation import instruction +from dune.codegen.generation import accumulation_mixin, instruction from dune.codegen.loopy.target import dtype_floatingpoint from dune.codegen.options import get_form_option from dune.codegen.pdelab.geometry import world_dimension -from dune.codegen.pdelab.localoperator import determine_accumulation_space +from dune.codegen.pdelab.localoperator import determine_accumulation_space, GenericAccumulationMixin from dune.codegen.pdelab.argument import name_accumulation_variable from dune.codegen.pdelab.localoperator import boundary_predicates from dune.codegen.generation.loopy import function_mangler, globalarg @@ -12,6 +12,15 @@ import pymbolic.primitives as prim from loopy.match import Writes +@accumulation_mixin("blockstructured") +class BlockStructuredAccumulationMixin(GenericAccumulationMixin): + def generate_accumulation_instruction(self, expr): + if get_form_option('vectorization_blockstructured'): + return generate_accumulation_instruction(expr, self) + else: + return GenericAccumulationMixin.generate_accumulation_instruction(self, expr) + + def name_accumulation_alias(container, accumspace): name = container + "_" + accumspace.lfs.name + "_alias" name_tail = container + "_" + accumspace.lfs.name + "_alias_tail" diff --git a/python/dune/codegen/options.py b/python/dune/codegen/options.py index db7a1440..3e41ef98 100644 --- a/python/dune/codegen/options.py +++ b/python/dune/codegen/options.py @@ -110,7 +110,7 @@ class CodegenFormOptionsArray(ImmutableRecord): geometry_mixins = CodegenOption(default="generic", helpstr="A comma separated list of mixin identifiers to use for geometries. Currently implemented mixins: generic, axiparallel, equidistant, sumfact_multilinear, sumfact_axiparallel, sumfact_equidistant") quadrature_mixins = CodegenOption(default="generic", helpstr="A comma separated list of mixin identifiers to use for quadrature. Currently implemented: generic, sumfact") basis_mixins = CodegenOption(default="generic", helpstr="A comma separated list of mixin identifiers to use for basis function evaluation. Currently implemented: generic, sumfact") - accumulation_mixins = CodegenOption(default="generic", helpstr="A comma separated list of mixin identifiers to use for accumulation. Currently implemented: generic, sumfact, control") + accumulation_mixins = CodegenOption(default="generic", helpstr="A comma separated list of mixin identifiers to use for accumulation. Currently implemented: generic, sumfact, control, blockstructured") enable_volume = CodegenOption(default=True, helpstr="Whether to assemble volume integrals") enable_skeleton = CodegenOption(default=True, helpstr="Whether to assemble skeleton integrals") enable_boundary = CodegenOption(default=True, helpstr="Whether to assemble boundary integrals") diff --git a/python/dune/codegen/pdelab/__init__.py b/python/dune/codegen/pdelab/__init__.py index 10175f38..e69de29b 100644 --- a/python/dune/codegen/pdelab/__init__.py +++ b/python/dune/codegen/pdelab/__init__.py @@ -1,10 +0,0 @@ -""" The pdelab specific parts of the code generation process """ - -# Trigger some imports that are needed to have all backend implementations visible -# to the selection mechanisms - - -class PDELabInterface(object): - def __init__(self): - # The visitor instance will be registered by its init method - self.visitor = None diff --git a/python/dune/codegen/pdelab/driver/visitor.py b/python/dune/codegen/pdelab/driver/visitor.py index 0c45871f..6fab5574 100644 --- a/python/dune/codegen/pdelab/driver/visitor.py +++ b/python/dune/codegen/pdelab/driver/visitor.py @@ -14,8 +14,7 @@ def set_lop_to_starting_time(): class DriverUFL2PymbolicVisitor(UFL2LoopyVisitor): def __init__(self): - from dune.codegen.pdelab import PDELabInterface - UFL2LoopyVisitor.__init__(self, PDELabInterface(), "exterior_facet", {}) + UFL2LoopyVisitor.__init__(self, "exterior_facet", {}) def __call__(self, expr): self.preambles = [] diff --git a/python/dune/codegen/pdelab/localoperator.py b/python/dune/codegen/pdelab/localoperator.py index 95c946b5..65627da0 100644 --- a/python/dune/codegen/pdelab/localoperator.py +++ b/python/dune/codegen/pdelab/localoperator.py @@ -464,17 +464,6 @@ def generate_accumulation_instruction(expr, visitor): def get_visitor(measure, subdomain_id): - # Get a transformer instance for this kernel - if get_form_option('sumfact'): - from dune.codegen.sumfact import SumFactInterface - interface = SumFactInterface() - elif get_form_option('blockstructured'): - from dune.codegen.blockstructured import BlockStructuredInterface - interface = BlockStructuredInterface() - else: - from dune.codegen.pdelab import PDELabInterface - interface = PDELabInterface() - # Construct the visitor taking into account geometry mixins from dune.codegen.ufl.visitor import UFL2LoopyVisitor mixins = get_form_option("geometry_mixins").split(",") @@ -492,7 +481,7 @@ def get_visitor(measure, subdomain_id): mixins = get_form_option("accumulation_mixins").split(",") VisitorType = construct_from_mixins(base=VisitorType, mixins=mixins, mixintype="accumulation", name="UFLVisitor") - return VisitorType(interface, measure, subdomain_id) + return VisitorType(measure, subdomain_id) def visit_integral(integral): diff --git a/python/dune/codegen/sumfact/__init__.py b/python/dune/codegen/sumfact/__init__.py index ea07249e..0b5fe733 100644 --- a/python/dune/codegen/sumfact/__init__.py +++ b/python/dune/codegen/sumfact/__init__.py @@ -1,9 +1,3 @@ import dune.codegen.sumfact.geometry import dune.codegen.sumfact.accumulation import dune.codegen.sumfact.switch - -from dune.codegen.pdelab import PDELabInterface - - -class SumFactInterface(PDELabInterface): - pass diff --git a/python/dune/codegen/ufl/visitor.py b/python/dune/codegen/ufl/visitor.py index 8bbfe6db..e55232d2 100644 --- a/python/dune/codegen/ufl/visitor.py +++ b/python/dune/codegen/ufl/visitor.py @@ -42,9 +42,7 @@ import numpy as np class UFL2LoopyVisitor(ModifiedTerminalTracker): - def __init__(self, interface, measure, subdomain_id): - self.interface = interface - self.interface.visitor = self + def __init__(self, measure, subdomain_id): self.measure = measure self.subdomain_id = subdomain_id @@ -271,7 +269,7 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): def inverse(self, o): from dune.codegen.pdelab.tensors import pymbolic_matrix_inverse - return self.interface.pymbolic_matrix_inverse(o) + return pymbolic_matrix_inverse(o, self) # # Handlers for arithmetic operators and functions -- GitLab