diff --git a/examples/gas_dynamics/lbm-simple.py b/examples/gas_dynamics/lbm-simple.py index f99d5b76994b46f079b41af9f74bf69789ae18f5..2d3496da340fbda01adeb33b6a59290b76b1c698 100644 --- a/examples/gas_dynamics/lbm-simple.py +++ b/examples/gas_dynamics/lbm-simple.py @@ -63,12 +63,12 @@ def main(write_output=True, dtype=np.float32): from grudge.data import CompiledExpressionData def ic_expr(t, x, fields): - from grudge.symbolic import CFunction + from grudge.symbolic import FunctionSymbol from pymbolic.primitives import IfPositive from pytools.obj_array import make_obj_array - tanh = CFunction("tanh") - sin = CFunction("sin") + tanh = FunctionSymbol("tanh") + sin = FunctionSymbol("sin") rho = 1 u0 = 0.05 diff --git a/examples/wave/wiggly.py b/examples/wave/wiggly.py index f786074443d2123882bcaecf85972777b6694622..11c0121214982b70fb891b443dfec267ce5defb6 100644 --- a/examples/wave/wiggly.py +++ b/examples/wave/wiggly.py @@ -70,8 +70,8 @@ def main(write_output=True, from grudge.models.wave import StrongWaveOperator op = StrongWaveOperator(-1, discr.dimensions, source_f= - sym.CFunction("sin")(source_omega*sym.ScalarParameter("t")) - * sym.CFunction("exp")( + sym.FunctionSymbol("sin")(source_omega*sym.ScalarParameter("t")) + * sym.FunctionSymbol("exp")( -np.dot(sym_source_center_dist, sym_source_center_dist) / source_width**2), dirichlet_tag="boundary", diff --git a/grudge/execution.py b/grudge/execution.py index c20aa4bc6271f1b9a8f5620c8b3021c22563880c..9e48aba39cd6e3aa5481f0bf9f31f3340381e4f6 100644 --- a/grudge/execution.py +++ b/grudge/execution.py @@ -31,6 +31,7 @@ from pytools import memoize_in import grudge.symbolic.mappers as mappers from grudge import sym +from grudge.function_registry import base_function_registry import logging logger = logging.getLogger(__name__) @@ -50,6 +51,7 @@ class ExecutionMapper(mappers.Evaluator, super(ExecutionMapper, self).__init__(context) self.discrwb = bound_op.discrwb self.bound_op = bound_op + self.function_registry = bound_op.function_registry self.queue = queue # {{{ expression mappings ------------------------------------------------- @@ -95,45 +97,8 @@ class ExecutionMapper(mappers.Evaluator, return value def map_call(self, expr): - from pymbolic.primitives import Variable - assert isinstance(expr.function, Variable) - - # FIXME: Make a way to register functions - args = [self.rec(p) for p in expr.parameters] - from numbers import Number - representative_arg = args[0] - if ( - isinstance(representative_arg, Number) - or (isinstance(representative_arg, np.ndarray) - and representative_arg.shape == ())): - func = getattr(np, expr.function.name) - return func(*args) - - cached_name = "map_call_knl_" - - i = Variable("i") - func = Variable(expr.function.name) - if expr.function.name == "fabs": # FIXME - func = Variable("abs") - cached_name += "abs" - else: - cached_name += expr.function.name - - @memoize_in(self.bound_op, cached_name) - def knl(): - knl = lp.make_kernel( - "{[i]: 0<=i