From 91a012fec32c45584aa4726fdb33bdffd48b5015 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 7 Sep 2021 15:09:01 -0500 Subject: [PATCH] Add some comments --- sumpy/kernel.py | 5 +++++ sumpy/tools.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/sumpy/kernel.py b/sumpy/kernel.py index 26f27adc..03936891 100644 --- a/sumpy/kernel.py +++ b/sumpy/kernel.py @@ -1030,12 +1030,15 @@ class AxisTargetDerivative(DerivativeBase): target_vec = make_sympy_vector(self.target_array_name, self.dim) + # bvec = tgt - ctr expr = self.inner_kernel.postprocess_at_target(expr, bvec) if isinstance(expr, DifferentiatedExprDerivativeTaker): transformation = diff_transformation(expr.derivative_transformation, self.axis, target_vec) return DifferentiatedExprDerivativeTaker(expr.taker, transformation) else: + # Since `bvec` and `tgt` are two different symbolic variables + # need to differentiate by both to get the correct answer return expr.diff(bvec[self.axis]) + expr.diff(target_vec[self.axis]) def replace_base_kernel(self, new_base_kernel): @@ -1129,6 +1132,8 @@ class DirectionalTargetDerivative(DirectionalDerivative): if not isinstance(expr, DifferentiatedExprDerivativeTaker): result = 0 for axis in range(self.dim): + # Since `bvec` and `tgt` are two different symbolic variables + # need to differentiate by both to get the correct answer result += (expr.diff(bvec[axis]) + expr.diff(target_vec[axis])) \ * dir_vec[axis] return result diff --git a/sumpy/tools.py b/sumpy/tools.py index df708053..d37ef2aa 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -433,11 +433,19 @@ class DifferentiatedExprDerivativeTaker: def diff_transformation(derivative_transformation, variable_idx, variables): + """Differentiate a derivative transformation dictionary using the + variable given by **variable_idx** and return a new derivative transformation + dictionary + """ new_transformation = defaultdict(lambda: 0) for mi, coeff in derivative_transformation.items(): + # In the case where we have x * u.diff(x), the result should + # be x.diff(x) + x * u.diff(x, x) + # Calculate the first term by differentiating the coefficients new_coeff = sym.sympify(coeff).diff(variables[variable_idx]) if new_coeff != 0: new_transformation[mi] += new_coeff + # Next calculate the second term by differentitating the derivatives new_mi = list(mi) new_mi[variable_idx] += 1 new_transformation[tuple(new_mi)] += coeff -- GitLab