From fcc6c6fd0f64d3939b25d908f3a9a92a22baac7a Mon Sep 17 00:00:00 2001 From: Alexandru Fikl <alexfikl@gmail.com> Date: Sat, 2 May 2020 16:31:25 -0500 Subject: [PATCH] operators: only bind interp when necessary * skip when the dd_in == dd_out * skip for constants --- grudge/symbolic/operators.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/grudge/symbolic/operators.py b/grudge/symbolic/operators.py index c1360b16..cb88fa64 100644 --- a/grudge/symbolic/operators.py +++ b/grudge/symbolic/operators.py @@ -146,15 +146,21 @@ class ElementwiseLinearOperator(Operator): class InterpolationOperator(Operator): def __init__(self, dd_in, dd_out): - import grudge.symbolic.primitives as prim - official_dd_in = prim.as_dofdesc(dd_in) - official_dd_out = prim.as_dofdesc(dd_out) + super(InterpolationOperator, self).__init__(dd_in, dd_out) - if official_dd_in == official_dd_out: - raise ValueError("Interpolating from {} to {}" - " does not do anything.".format(official_dd_in, official_dd_out)) + def __call__(self, expr): + from pytools.obj_array import with_object_array_or_scalar - super(InterpolationOperator, self).__init__(dd_in, dd_out) + def interp_one(subexpr): + if self.dd_in == self.dd_out: + return subexpr + elif isinstance(subexpr, (int, float, complex, np.number)): + return subexpr + else: + from grudge.symbolic.primitives import OperatorBinding + return OperatorBinding(self, subexpr) + + return with_object_array_or_scalar(interp_one, expr) mapper_method = intern("map_interpolation") -- GitLab