From 49721d12b0faa489f7fea0a31b531ab2d46744fd Mon Sep 17 00:00:00 2001 From: Isuru Fernando <isuruf@gmail.com> Date: Mon, 24 Jun 2019 20:12:08 +0200 Subject: [PATCH] Remove deriv multiplier --- sumpy/expansion/__init__.py | 9 +++------ sumpy/expansion/pde_utils.py | 37 +----------------------------------- sumpy/tools.py | 12 ------------ 3 files changed, 4 insertions(+), 54 deletions(-) diff --git a/sumpy/expansion/__init__.py b/sumpy/expansion/__init__.py index 384fe64a..60f6eb5b 100644 --- a/sumpy/expansion/__init__.py +++ b/sumpy/expansion/__init__.py @@ -30,7 +30,7 @@ from pytools import memoize_method import sumpy.symbolic as sym from collections import defaultdict from sumpy.tools import add_mi, find_linear_independent_row, CoeffIdentifier -from .pde_utils import (make_pde_syms, process_pde, laplacian, div, grad, +from .pde_utils import (make_pde_syms, laplacian, div, grad, PDE) __doc__ = """ @@ -485,7 +485,6 @@ class LinearPDEBasedExpansionTermsWrangler(ExpansionTermsWrangler): from sumpy.tools import nullspace pdes, iexpr, nexpr = self.get_pdes() - pdes, multiplier = process_pde(pdes) if nexpr == 1: return pdes @@ -523,11 +522,9 @@ class LinearPDEBasedExpansionTermsWrangler(ExpansionTermsWrangler): indep_row = find_linear_independent_row(n) if len(indep_row) > 0: pde_dict = {} - min_order = min(sum(mis[k]) for k in indep_row.keys()) + mult = indep_row[max(indep_row.keys())] for k, v in indep_row.items(): - mi = mis[k] - mult = multiplier**(sum(mi)-min_order) - pde_dict[CoeffIdentifier(mi, 0)] = v * mult + pde_dict[CoeffIdentifier(mis[k], 0)] = v / mult plog.done() return PDE(self.dim, pde_dict) diff --git a/sumpy/expansion/pde_utils.py b/sumpy/expansion/pde_utils.py index 23152e9a..34c669ac 100644 --- a/sumpy/expansion/pde_utils.py +++ b/sumpy/expansion/pde_utils.py @@ -23,8 +23,7 @@ THE SOFTWARE. """ from collections import defaultdict -from sumpy.tools import CoeffIdentifier, add_mi, nth_root_assume_positive -import sumpy.symbolic as sym +from sumpy.tools import CoeffIdentifier, add_mi class PDE(object): @@ -152,40 +151,6 @@ def div(pde): return PDE(pde.dim, dict(result)) -def process_pde(pde): - """ - Process a PDE object to return a PDE and a multiplier such that - the sum of multiplier ** order * derivative * coefficient gives the - original PDE `pde`. - """ - multiplier = None - for eq in pde.eqs: - for ident1, val1 in eq.items(): - for ident2, val2 in eq.items(): - s1 = sum(ident1.mi) - s2 = sum(ident2.mi) - if s1 == s2: - continue - m = nth_root_assume_positive(val1/val2, s2 - s1) - if multiplier is None and not isinstance(m, (int, sym.Integer)): - multiplier = m - - if multiplier is None: - return pde, 1 - eqs = [] - for eq in pde.eqs: - new_eq = dict() - for i, (k, v) in enumerate(eq.items()): - new_eq[k] = v * multiplier**sum(k.mi) - if i == 0: - val = new_eq[k] - new_eq[k] /= sym.sympify(val) - if isinstance(new_eq[k], sym.Integer): - new_eq[k] = int(new_eq[k]) - eqs.append(new_eq) - return PDE(pde.dim, *eqs), multiplier - - def make_pde_syms(dim, nexprs): """ Returns a list of expressions of size `nexprs` to create a PDE diff --git a/sumpy/tools.py b/sumpy/tools.py index 38a021d4..345b176f 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -757,18 +757,6 @@ def solve_symbolic(A, b): # noqa: N803 CoeffIdentifier = namedtuple('CoeffIdentifier', ['mi', 'iexpr']) -def nth_root_assume_positive(expr, n): - """ - Get the nth root of a symbolic expression assuming that - the symbols are positive. - """ - expr = sym.sympify(expr) - if expr.is_Pow: - return expr.args[0] ** (expr.args[1] / sym.Integer(n)) - else: - return expr ** (sym.Integer(1)/n) - - def find_linear_independent_row(nullspace): """ This method does elementary row operations to figure out the first row -- GitLab