From 27a131fbea2a23fc0b4979e936e20c2c1f627e58 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Mon, 15 Apr 2019 13:41:20 +0200
Subject: [PATCH] Bugfix: For certain MRT methods the CSE failed

- replace_density_and_velocity simplification produced terms like
  0 * omega, because sympy's auto-eval is turned off
- sympys CSE routine can apparently only handle evaluated terms
- solution: evaluate multiplications with zero (i.e. replace them by 0)
---
 pystencils/sympyextensions.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pystencils/sympyextensions.py b/pystencils/sympyextensions.py
index e40c108..3dc84f1 100644
--- a/pystencils/sympyextensions.py
+++ b/pystencils/sympyextensions.py
@@ -250,7 +250,10 @@ def subs_additive(expr: sp.Expr, replacement: sp.Expr, subexpression: sp.Expr,
         if not param_list:
             return current_expr
         else:
-            return current_expr.func(*param_list, evaluate=False)
+            if current_expr.func == sp.Mul and sp.numbers.Zero() in param_list:
+                return sp.numbers.Zero()
+            else:
+                return current_expr.func(*param_list, evaluate=False)
 
     return visit(expr)
 
-- 
GitLab