diff --git a/python/dune/perftool/__init__.py b/python/dune/perftool/__init__.py index 3b55e4441f0fde199f06f8a2b3c29b91fc34397a..d433436b0e7e0024df83591a7f96bb16efb66de3 100644 --- a/python/dune/perftool/__init__.py +++ b/python/dune/perftool/__init__.py @@ -5,4 +5,4 @@ import dune.perftool.loopy.symbolic # to the selection mechanisms import dune.perftool.pdelab import dune.perftool.sumfact -import dune.perftool.blockstructured \ No newline at end of file +import dune.perftool.blockstructured diff --git a/python/dune/perftool/blockstructured/__init__.py b/python/dune/perftool/blockstructured/__init__.py index 0185e2cbf7f39d080240c3f7e358323fe88a698a..a3ed2718fc0a59f2cd9bf24b9e0a9eea3510f9ab 100644 --- a/python/dune/perftool/blockstructured/__init__.py +++ b/python/dune/perftool/blockstructured/__init__.py @@ -39,7 +39,7 @@ class BlockStructuredInterface(PDELabInterface): return pymbolic_jacobian_determinant() def pymbolic_jacobian_inverse_transposed(self, i, j, restriction): - return pymbolic_jacobian_inverse_transposed(i,j,restriction) + return pymbolic_jacobian_inverse_transposed(i, j, restriction) def pymbolic_facet_jacobian_determinant(self): return pymbolic_facet_jacobian_determinant() diff --git a/python/dune/perftool/blockstructured/argument.py b/python/dune/perftool/blockstructured/argument.py index a4f67c2bd6bfcfcf43630eded980a12a326b1df9..0f1ea01f294fb57e8aa59283006da284df449c7d 100644 --- a/python/dune/perftool/blockstructured/argument.py +++ b/python/dune/perftool/blockstructured/argument.py @@ -1,12 +1,12 @@ from dune.perftool.generation import (backend, kernel_cached, - valuearg,get_global_context_value) + valuearg) from dune.perftool.pdelab.argument import CoefficientAccess from dune.perftool.blockstructured.tools import micro_index_to_macro_index from loopy.types import NumpyType -from pymbolic.primitives import Variable, Call import pymbolic.primitives as prim + # TODO remove the need for element @kernel_cached @backend(interface="pymbolic_coefficient", name="blockstructured") @@ -16,8 +16,7 @@ def pymbolic_coefficient(container, lfs, element, index): valuearg(lfs, dtype=NumpyType("str")) # If the LFS is not yet a pymbolic expression, make it one - from pymbolic.primitives import Expression - if not isinstance(lfs, Expression): - lfs = Variable(lfs) + if not isinstance(lfs, prim.Expression): + lfs = prim.Variable(lfs) - return Call(CoefficientAccess(container), (lfs, micro_index_to_macro_index(element, index),)) + return prim.Call(CoefficientAccess(container), (lfs, micro_index_to_macro_index(element, index),)) diff --git a/python/dune/perftool/blockstructured/basis.py b/python/dune/perftool/blockstructured/basis.py index 84353a338aa7ab1453b2af3a748ff6a8f37f5385..4533179eb938bad9dbc3d85bcf766f3d8cbd4de9 100644 --- a/python/dune/perftool/blockstructured/basis.py +++ b/python/dune/perftool/blockstructured/basis.py @@ -11,7 +11,6 @@ from dune.perftool.tools import get_pymbolic_basename from dune.perftool.pdelab.basis import (declare_cache_temporary, name_localbasis_cache, type_localbasis, - restricted_name, FEM_name_mangling) from dune.perftool.pdelab.driver import (basetype_range, isPk, @@ -19,10 +18,6 @@ from dune.perftool.pdelab.driver import (basetype_range, from dune.perftool.pdelab.geometry import world_dimension from dune.perftool.pdelab.quadrature import pymbolic_quadrature_position_in_cell from dune.perftool.pdelab.spaces import type_gfs -from dune.perftool.blockstructured.spaces import lfs_inames -from dune.perftool.blockstructured.tools import tensor_index_to_sequential_index -import pymbolic.primitives as prim - @backend(interface="typedef_localbasis", name="blockstructured") diff --git a/python/dune/perftool/blockstructured/geometry.py b/python/dune/perftool/blockstructured/geometry.py index 8c5fcfed28920e865b7b740cf7fb11c381a860a8..d39889114a11d610fbd42bb7efd59f985fe0b1c8 100644 --- a/python/dune/perftool/blockstructured/geometry.py +++ b/python/dune/perftool/blockstructured/geometry.py @@ -15,11 +15,11 @@ import pymbolic.primitives as prim @backend(interface="pymbolic_jacobian_determinant", name="blockstructured") def pymbolic_jacobian_determinant(): return prim.Quotient(prim.Variable(name_jacobian_determinant()), - prim.Power(get_option("number_of_blocks"),local_dimension())) + prim.Power(get_option("number_of_blocks"), local_dimension())) @backend(interface="pymbolic_jacobian_inverse_transposed", name="blockstructured") -def pymbolic_jacobian_inverse_transposed(i,j,restriction): +def pymbolic_jacobian_inverse_transposed(i, j, restriction): return prim.Product((get_option("number_of_blocks"), prim.Subscript(prim.Variable(name_jacobian_inverse_transposed(restriction)), (j, i)))) @@ -27,7 +27,7 @@ def pymbolic_jacobian_inverse_transposed(i,j,restriction): @backend(interface="pymbolic_facet_jacobian_determinant", name="blockstructured") def pymbolic_facet_jacobian_determinant(): return prim.Quotient(prim.Variable(name_facet_jacobian_determinant()), - prim.Power(get_option("number_of_blocks"),local_dimension())) + prim.Power(get_option("number_of_blocks"), local_dimension())) def define_point_in_macro(name, point_in_micro): @@ -48,6 +48,8 @@ def define_point_in_macro(name, point_in_micro): ) +# TODO add subelem inames if this function gets called +# TODO change input parameter to string def name_point_in_macro(point_in_micro): assert isinstance(point_in_micro, prim.Expression) name = get_pymbolic_basename(point_in_micro) + "_macro" diff --git a/python/dune/perftool/blockstructured/quadrature.py b/python/dune/perftool/blockstructured/quadrature.py index 4c4319d374ca61b7ec8758ff1c304f4f14b1472c..cb97bac4db61f2b22c6606a6c7d67905e512036b 100644 --- a/python/dune/perftool/blockstructured/quadrature.py +++ b/python/dune/perftool/blockstructured/quadrature.py @@ -1,7 +1,6 @@ from dune.perftool.generation import (backend) from dune.perftool.pdelab.quadrature import (name_quadrature_points, - quadrature_iname - ) + quadrature_iname) from dune.perftool.blockstructured.geometry import name_point_in_macro import pymbolic.primitives as prim @@ -20,4 +19,4 @@ def pymbolic_quadrature_position(): def pymbolic_quadrature_position_in_cell(restriction): from dune.perftool.pdelab.geometry import to_cell_coordinates quad_pos = pymbolic_quadrature_position() - return to_cell_coordinates(quad_pos, restriction) \ No newline at end of file + return to_cell_coordinates(quad_pos, restriction) diff --git a/python/dune/perftool/blockstructured/spaces.py b/python/dune/perftool/blockstructured/spaces.py index 95eb919f94f10e14b371c48326510eb24ea6358d..40a764db2d4d4c9d71bff3b2e22af0b0e3d9c593 100644 --- a/python/dune/perftool/blockstructured/spaces.py +++ b/python/dune/perftool/blockstructured/spaces.py @@ -16,6 +16,6 @@ def lfs_inames(element, restriction, count=None, context=''): lfs = name_leaf_lfs(element, restriction) name = "micro_{}_{}_index".format(lfs, context) - domain(name, pow(element._degree+1,world_dimension())) + domain(name, pow(element.degree() + 1, world_dimension())) return (name, ) diff --git a/python/dune/perftool/blockstructured/tools.py b/python/dune/perftool/blockstructured/tools.py index 4dda85b507ec8828bfb1ff0a1b4043678c7df589..cf2475999108aef311d26cffe116253cef064564 100644 --- a/python/dune/perftool/blockstructured/tools.py +++ b/python/dune/perftool/blockstructured/tools.py @@ -9,7 +9,7 @@ from dune.perftool.pdelab.geometry import (local_dimension, name_localcenter, pymbolic_in_cell_coordinates) -from dune.perftool.pdelab.quadrature import (quadrature_inames) +from dune.perftool.pdelab.quadrature import quadrature_inames from dune.perftool.generation.counter import get_counted_variable from dune.perftool.options import get_option import pymbolic.primitives as prim @@ -29,7 +29,7 @@ def sub_element_inames(): def sub_facet_inames(): subelem_inames = sub_element_inames() - + center = pymbolic_in_cell_coordinates(prim.Variable(name_localcenter()), Restriction.NEGATIVE) def predicate(index): @@ -37,12 +37,12 @@ def sub_facet_inames(): def conditional_instruction(index): instruction(assignee=prim.Variable(inames[index]), - expression=prim.Variable(subelem_inames[1 if index==2 else 0]), + expression=prim.Variable(subelem_inames[1 if index == 2 else 0]), within_inames=frozenset(subelem_inames).union(frozenset(quadrature_inames())), predicates=frozenset([predicate(index)]) ) instruction(assignee=prim.Variable(inames[index]), - expression=prim.Product(((k-1),prim.Subscript(center, (index,)))), + expression=prim.Product(((k - 1), prim.Subscript(center, (index,)))), within_inames=frozenset(subelem_inames).union(frozenset(quadrature_inames())), predicates=frozenset([prim.LogicalNot(predicate(index))]) ) @@ -70,7 +70,7 @@ def sub_facet_inames(): predicates=frozenset([prim.LogicalAnd((predicate(1), predicate(0)))]) ) instruction(assignee=prim.Variable(inames[1]), - expression=prim.Product(((k-1),prim.Subscript(center, (1,)))), + expression=prim.Product(((k - 1), prim.Subscript(center, (1,)))), within_inames=frozenset(subelem_inames).union(frozenset(quadrature_inames())), predicates=frozenset([prim.LogicalNot(predicate(1))]) ) @@ -86,13 +86,15 @@ def tensor_index_to_sequential_index(indices, k): return prim.Sum(tuple(index * k ** i for i, index in enumerate(indices))) -# TODO better name -def to_tensor_index(iname): - return tuple(prim.RightShift(prim.BitwiseAnd((prim.Variable(iname),2**n)), n) for n in range(world_dimension())) +def to_tensor_index(iname, k): + return tuple(prim.RightShift(prim.BitwiseAnd((prim.Variable(iname), 2**n)), n) for n in range(world_dimension())) + +def to_tensor_index_v2(iname, k): + return tuple(prim.Remainder(prim.Variable(iname) / (k**i), k) for i in range(world_dimension())) -# TODO 3d -def micro_index_to_macro_index(iname): + +def micro_index_to_macro_index(element, iname): it = get_global_context_value("integral_type") if it == "cell": subelem_inames = sub_element_inames() @@ -100,8 +102,8 @@ def micro_index_to_macro_index(iname): subelem_inames = sub_facet_inames() k = get_option("number_of_blocks") - modified_index = prim.Sum((tensor_index_to_sequential_index(to_tensor_index(iname), k+1), + p = element.degree() + modified_index = prim.Sum((tensor_index_to_sequential_index(to_tensor_index_v2(iname, p + 1), k + 1), tensor_index_to_sequential_index(tuple(prim.Variable(iname) for iname in subelem_inames), k + 1))) return modified_index - diff --git a/python/dune/perftool/loopy/target.py b/python/dune/perftool/loopy/target.py index b9bce516edf4ed36f1768660aff653e18d5307c9..113e3b76ab040bf937006a8c4509cc65414721c5 100644 --- a/python/dune/perftool/loopy/target.py +++ b/python/dune/perftool/loopy/target.py @@ -119,7 +119,6 @@ class DuneCExpressionToCodeMapper(CExpressionToCodeMapper): else: return CExpressionToCodeMapper.map_remainder(self, expr, enclosing_prec) - def map_bitwise_and(self, expr, enclosing_prec): return self.parenthesize_if_needed( self.join_rec(" & ", expr.children, PREC_BITWISE_AND), @@ -132,8 +131,6 @@ class DuneCExpressionToCodeMapper(CExpressionToCodeMapper): enclosing_prec, PREC_SHIFT) - - class DuneASTBuilder(CASTBuilder): def function_manglers(self): return CASTBuilder.function_manglers(self) + retrieve_cache_functions("mangler") diff --git a/python/dune/perftool/pdelab/__init__.py b/python/dune/perftool/pdelab/__init__.py index 832a3e7dc8a2a9e7b35015d40afed0f0ed5faf92..10c944d08723ff4b56617964bfb02bb26e1a990a 100644 --- a/python/dune/perftool/pdelab/__init__.py +++ b/python/dune/perftool/pdelab/__init__.py @@ -116,7 +116,7 @@ class PDELabInterface(object): return pymbolic_jacobian_determinant() def pymbolic_jacobian_inverse_transposed(self, i, j, restriction): - return pymbolic_jacobian_inverse_transposed(i,j,restriction) + return pymbolic_jacobian_inverse_transposed(i, j, restriction) def name_unit_inner_normal(self): return name_unit_inner_normal() diff --git a/python/dune/perftool/pdelab/driver.py b/python/dune/perftool/pdelab/driver.py index e2993aea16412e5cba3e263acffa5399b540b07e..3aba1351a03cff1c989ae003a07c926af8d4b008 100644 --- a/python/dune/perftool/pdelab/driver.py +++ b/python/dune/perftool/pdelab/driver.py @@ -596,7 +596,7 @@ def name_gfs(expr): return name -#TODO adjust for blockstructured +# TODO adjust for blockstructured @preamble def define_dofestimate(name): # Provide a worstcase estimate for the number of entries per row based on the given gridfunction space and cell geometry @@ -1809,7 +1809,7 @@ def generate_driver(formdatas, data): # The driver module uses a global dictionary for storing necessary data set_driver_data(formdatas, data) - #TODO find a better solution ... + # TODO find a better solution ... if get_option("blockstructured"): set_blockstructured_degree() @@ -1861,6 +1861,6 @@ def generate_driver(formdatas, data): from dune.perftool.generation import delete_cache_items delete_cache_items() - #TODO find a better solution ... + # TODO find a better solution ... if get_option("blockstructured"): unset_blockstructured_degree() diff --git a/python/dune/perftool/pdelab/geometry.py b/python/dune/perftool/pdelab/geometry.py index 131b32779482f594bd012d27c9d8dc36d583656f..b018f83279bcc71870d13f6d20cdc5b682c2ab9b 100644 --- a/python/dune/perftool/pdelab/geometry.py +++ b/python/dune/perftool/pdelab/geometry.py @@ -350,8 +350,9 @@ def name_jacobian_inverse_transposed(restriction): get_backend(interface="define_jit", selector=option_switch("constant_transformation_matrix"))(name, restriction) return name + @backend(interface="pymbolic_jacobian_inverse_transposed", name="default") -def pymbolic_jacobian_inverse_transposed(i,j,restriction): +def pymbolic_jacobian_inverse_transposed(i, j, restriction): # Dune only has JacobianInverseTransposed as a first class citizen, # so we need to switch the indices around! return prim.Subscript(prim.Variable(name_jacobian_inverse_transposed(restriction)), (j, i)) @@ -421,7 +422,8 @@ def apply_to_global_transformation(name, local): depends_on=frozenset({Writes(get_pymbolic_basename(local))}) ) -#TODO check backend & function name for consistency + +# TODO check backend & function name for consistency @backend(interface="to_global", name="default") def to_global(local): assert isinstance(local, prim.Expression) diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py index 29153ba59288069c41c1860743065604bac4605b..d18496374ee0b0adca2cd78dfa56635d2756482f 100644 --- a/python/dune/perftool/pdelab/localoperator.py +++ b/python/dune/perftool/pdelab/localoperator.py @@ -246,11 +246,10 @@ def determine_accumulation_space(expr, number, measure, idims=None): iname, = get_backend("lfs_inames", selector=option_switch("blockstructured"))(subel, ma.restriction, count=number) if get_option("blockstructured"): from dune.perftool.blockstructured.tools import micro_index_to_macro_index - lfsi = micro_index_to_macro_index(iname) + lfsi = micro_index_to_macro_index(subel, iname) else: lfsi = Variable(iname) - # If the LFS is not yet a pymbolic expression, make it one from pymbolic.primitives import Expression if not isinstance(lfs, Expression):