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

Worked on waLBerla kernel generation

parent 3acbdbe8
import sympy as sp
from pystencils.equationcollection.equationcollection import EquationCollection
from pystencils.sympyextensions import replaceAdditive
def sympyCseOnEquationList(eqs):
ec = EquationCollection(eqs, [])
return sympyCSE(ec).allEquations
def sympyCSE(equationCollection):
"""
Searches for common subexpressions inside the equation collection, in both the existing subexpressions as well
......
......@@ -254,19 +254,18 @@ class Field(object):
if constantOffsets:
offsetName = offsetToDirectionString(offsets)
if field.indexDimensions == 0:
obj = super(Field.Access, self).__xnew__(self, fieldName + "_" + offsetName)
symbolName = fieldName + "_" + offsetName
elif field.indexDimensions == 1:
obj = super(Field.Access, self).__xnew__(self, fieldName + "_" + offsetName + "^" + str(idx[0]))
symbolName = fieldName + "_" + offsetName + "^" + str(idx[0])
else:
idxStr = ",".join([str(e) for e in idx])
obj = super(Field.Access, self).__xnew__(self, fieldName + "_" + offsetName + "^" + idxStr)
symbolName = fieldName + "_" + offsetName + "^" + idxStr
else:
offsetName = "%0.10X" % (abs(hash(tuple(offsetsAndIndex))))
obj = super(Field.Access, self).__xnew__(self, fieldName + "_" + offsetName)
symbolName = fieldName + "_" + offsetName
obj = super(Field.Access, self).__xnew__(self, "{" + symbolName + "}")
obj._field = field
obj._offsets = []
for o in offsets:
......
......@@ -501,7 +501,7 @@ def getSymmetricPart(term, vars):
: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))
return sp.Rational(1, 2) * (term + term.subs(substitutionDict))
def sortEquationsTopologically(equationSequence):
......
......@@ -12,7 +12,11 @@ class TypedSymbol(sp.Symbol):
def __new_stage2__(cls, name, dtype):
obj = super(TypedSymbol, cls).__xnew__(cls, name)
obj._dtype = createType(dtype)
try:
obj._dtype = createType(dtype)
except TypeError:
# on error keep the string
obj._dtype = dtype
return obj
__xnew__ = staticmethod(__new_stage2__)
......
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