Commit f5d742d7 authored by Martin Bauer's avatar Martin Bauer
Browse files

new lbm module: macroscopic values & bugfixes

parent d9f5dbd7
import sympy as sp
from copy import copy, deepcopy
from pystencils.sympyextensions import fastSubs, countNumberOfOperations
from copy import deepcopy
from pystencils.sympyextensions import fastSubs, countNumberOfOperations, sortEquationsTopologically
class EquationCollection:
......@@ -64,7 +64,7 @@ class EquationCollection:
if addSubstitutionsAsSubexpressions:
newSubexpressions = [sp.Eq(b, a) for a, b in substitutionDict.items()] + newSubexpressions
return self.copy(newEquations, newSubexpressions)
return self.copy(newEquations, sortEquationsTopologically(newSubexpressions))
def addSimplificationHint(self, key, value):
"""
......
......@@ -311,7 +311,7 @@ def numpyDataTypeToC(dtype):
return "float"
elif dtype == np.int32:
return "int"
raise NotImplementedError()
raise NotImplementedError("Cannot convert type " + str(dtype))
def offsetComponentToDirectionString(coordinateId, value):
......
......@@ -367,3 +367,8 @@ def getSymmetricPart(term, vars):
"""
substitutionDict = {e: -e for e in vars}
return sp.Rational(1, 2) * (term + fastSubs(term, substitutionDict))
def sortEquationsTopologically(equationSequence):
res = sp.cse_main.reps_toposort([[e.lhs, e.rhs] for e in equationSequence])
return [sp.Eq(a, b) for a, b in res]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment