From 0f36c9fac9eedc38fc4e6d0231e3810a1d97096d Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Thu, 6 Oct 2016 11:30:06 +0200 Subject: [PATCH] Merge geometry visitor into main visitor --- python/dune/perftool/pdelab/geometry.py | 50 ------------------------ python/dune/perftool/ufl/visitor.py | 51 ++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/python/dune/perftool/pdelab/geometry.py b/python/dune/perftool/pdelab/geometry.py index 12593147..bb548d8d 100644 --- a/python/dune/perftool/pdelab/geometry.py +++ b/python/dune/perftool/pdelab/geometry.py @@ -15,56 +15,6 @@ from ufl.algorithms import MultiFunction from pymbolic.primitives import Variable -class GeometryMapper(MultiFunction): - """ - A collection of visitors for geometry related UFL nodes - NB: This is kind of 'abstract' as it needs to be combined - with a ModifiedTerminalTracker through multi inheritance. - """ - def __init__(self): - super(GeometryMapper, self).__init__() - - def facet_normal(self, o): - # The normal must be restricted to be well-defined - assert self.restriction is not Restriction.NONE - - from pymbolic.primitives import Variable - if self.restriction == Restriction.POSITIVE: - return Variable(name_unit_outer_normal()) - if self.restriction == Restriction.NEGATIVE: - # It is highly unnatural to have this generator function, - # but I do run into subtle trouble with return -1*outer - # as the indexing into the normal happens only later. - # Not investing more time into this cornercase right now. - return Variable(name_unit_inner_normal()) - - # TODO This one was just copied over so, it might need some tweaking - def facet_area(self, o): - from dune.perftool.pdelab.geometry import name_facetarea - return Variable(name_facetarea()) - - def quadrature_weight(self, o): - from dune.perftool.pdelab.quadrature import name_quadrature_weight - return Variable(name_quadrature_weight()) - - def jacobian_determinant(self, o): - return Variable(name_jacobian_determinant()) - - def jacobian_inverse(self, o): - restriction = self.restriction - if self.measure == 'exterior_facet': - restriction = Restriction.NEGATIVE - - self.transpose_necessary = True - return Variable(name_jacobian_inverse_transposed(restriction)) - - def jacobian(self, o): - raise NotImplementedError("How did you get Jacobian into your form? We only support JacobianInverse right now. Report!") - - def facet_jacobian_determinant(self, o): - return Variable(name_facet_jacobian_determinant()) - - @iname def _dimension_iname(context, count): if context: diff --git a/python/dune/perftool/ufl/visitor.py b/python/dune/perftool/ufl/visitor.py index 26c381b6..8009bc2b 100644 --- a/python/dune/perftool/ufl/visitor.py +++ b/python/dune/perftool/ufl/visitor.py @@ -5,7 +5,6 @@ to pymbolic and loopy. from dune.perftool import Restriction from dune.perftool.ufl.modified_terminals import ModifiedTerminalTracker -from dune.perftool.pdelab.geometry import GeometryMapper from dune.perftool.generation import (domain, get_temporary_name, global_context, @@ -27,7 +26,7 @@ from pymbolic.primitives import Subscript, Variable from ufl.algorithms import MultiFunction -class UFL2LoopyVisitor(ModifiedTerminalTracker, GeometryMapper): +class UFL2LoopyVisitor(ModifiedTerminalTracker): def __init__(self, measure, subdomain_id, dimension_indices): # Some variables describing the integral measure of this integral self.measure = measure @@ -384,3 +383,51 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker, GeometryMapper): else: from pymbolic.primitives import Call return Call('abs', self.call(o.ufl_operands[0])) + + # + # Handlers for geometric quantities + # + + def facet_normal(self, o): + # The normal must be restricted to be well-defined + assert self.restriction is not Restriction.NONE + + from pymbolic.primitives import Variable + if self.restriction == Restriction.POSITIVE: + from dune.perftool.pdelab.geometry import name_unit_outer_normal + return Variable(name_unit_outer_normal()) + if self.restriction == Restriction.NEGATIVE: + # It is highly unnatural to have this generator function, + # but I do run into subtle trouble with return -1*outer + # as the indexing into the normal happens only later. + # Not investing more time into this cornercase right now. + from dune.perftool.pdelab.geometry import name_unit_inner_normal + return Variable(name_unit_inner_normal()) + + def facet_area(self, o): + from dune.perftool.pdelab.geometry import name_facetarea + return Variable(name_facetarea()) + + def quadrature_weight(self, o): + from dune.perftool.pdelab.quadrature import name_quadrature_weight + return Variable(name_quadrature_weight()) + + def jacobian_determinant(self, o): + from dune.perftool.pdelab.geometry import name_jacobian_determinant + return Variable(name_jacobian_determinant()) + + def jacobian_inverse(self, o): + restriction = self.restriction + if self.measure == 'exterior_facet': + restriction = Restriction.NEGATIVE + + self.transpose_necessary = True + from dune.perftool.pdelab.geometry import name_jacobian_inverse_transposed + return Variable(name_jacobian_inverse_transposed(restriction)) + + def jacobian(self, o): + raise NotImplementedError("How did you get Jacobian into your form? We only support JacobianInverse right now. Report!") + + def facet_jacobian_determinant(self, o): + from dune.perftool.pdelab.geometry import name_facet_jacobian_determinant + return Variable(name_facet_jacobian_determinant()) \ No newline at end of file -- GitLab