From 181a8e762191f5f9cab774247c8825146486cbba Mon Sep 17 00:00:00 2001 From: Martin Bauer <bauer_martin@gmx.de> Date: Mon, 23 Jan 2017 13:57:17 +0100 Subject: [PATCH] new lbmpy: boundaries --- sympyextensions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sympyextensions.py b/sympyextensions.py index dc5a0073b..a5121775f 100644 --- a/sympyextensions.py +++ b/sympyextensions.py @@ -356,3 +356,14 @@ def commonDenominator(expr): denominators = [r.q for r in expr.atoms(sp.Rational)] return sp.lcm(denominators) + +def getSymmetricPart(term, vars): + """ + Returns the symmetric part of a sympy expressions. + + :param term: sympy expression, labeled here as :math:`f` + :param vars: sequence of symbols which are considered as degrees of freedom, labeled here as :math:`x_0, x_1,...` + :returns: :math:`\frac{1}{2} [ f(x_0, x_1, ..) + f(-x_0, -x_1) ]` + """ + substitutionDict = {e: -e for e in vars} + return sp.Rational(1, 2) * (term + fastSubs(term, substitutionDict)) -- GitLab