Skip to content
Snippets Groups Projects
Commit 69ec4168 authored by Martin Bauer's avatar Martin Bauer
Browse files

new_lbm: SRT simplifications working

parent 2ab418a8
No related merge requests found
...@@ -53,13 +53,16 @@ class EquationCollection: ...@@ -53,13 +53,16 @@ class EquationCollection:
res.subexpressionSymbolNameGenerator = self.subexpressionSymbolNameGenerator res.subexpressionSymbolNameGenerator = self.subexpressionSymbolNameGenerator
return res return res
def newWithSubstitutionsApplied(self, substitutionDict): def newWithSubstitutionsApplied(self, substitutionDict, addSubstitutionsAsSubexpresions=False):
""" """
Returns a new equation collection, where terms are substituted according to the passed `substitutionDict`. Returns a new equation collection, where terms are substituted according to the passed `substitutionDict`.
Substitutions are made in the subexpression terms and the main equations Substitutions are made in the subexpression terms and the main equations
""" """
newSubexpressions = [fastSubs(eq, substitutionDict) for eq in self.subexpressions] newSubexpressions = [fastSubs(eq, substitutionDict) for eq in self.subexpressions]
newEquations = [fastSubs(eq, substitutionDict) for eq in self.mainEquations] newEquations = [fastSubs(eq, substitutionDict) for eq in self.mainEquations]
if addSubstitutionsAsSubexpresions:
newSubexpressions = [sp.Eq(b, a) for a, b in substitutionDict.items()] + newSubexpressions
res = EquationCollection(newEquations, newSubexpressions, self.simplificationHints) res = EquationCollection(newEquations, newSubexpressions, self.simplificationHints)
res.subexpressionSymbolNameGenerator = self.subexpressionSymbolNameGenerator res.subexpressionSymbolNameGenerator = self.subexpressionSymbolNameGenerator
return res return res
......
...@@ -53,7 +53,7 @@ def subexpressionSubstitutionInExistingSubexpressions(equationCollection): ...@@ -53,7 +53,7 @@ def subexpressionSubstitutionInExistingSubexpressions(equationCollection):
equationCollection.subexpressionSymbolNameGenerator) equationCollection.subexpressionSymbolNameGenerator)
def subexpressionSubstitutionInUpdateEquations(equationCollection): def subexpressionSubstitutionInMainEquations(equationCollection):
"""Replaces already existing subexpressions in the equations of the equationCollection""" """Replaces already existing subexpressions in the equations of the equationCollection"""
result = [] result = []
for s in equationCollection.mainEquations: for s in equationCollection.mainEquations:
...@@ -62,3 +62,22 @@ def subexpressionSubstitutionInUpdateEquations(equationCollection): ...@@ -62,3 +62,22 @@ def subexpressionSubstitutionInUpdateEquations(equationCollection):
newRhs = replaceAdditive(newRhs, subExpr.lhs, subExpr.rhs, requiredMatchReplacement=1.0) newRhs = replaceAdditive(newRhs, subExpr.lhs, subExpr.rhs, requiredMatchReplacement=1.0)
result.append(sp.Eq(s.lhs, newRhs)) result.append(sp.Eq(s.lhs, newRhs))
return equationCollection.newWithAdditionalSubexpressions(result, []) return equationCollection.newWithAdditionalSubexpressions(result, [])
def addSubexpressionsForDivisions(equationCollection):
divisors = set()
def searchDivisors(term):
if term.func == sp.Pow:
if term.exp.is_integer and term.exp.is_number and term.exp < 0:
divisors.add(term)
else:
for a in term.args:
searchDivisors(a)
for eq in equationCollection.allEquations:
searchDivisors(eq.rhs)
newSymbolGen = equationCollection.subexpressionSymbolNameGenerator
substitutions = {divisor: newSymbol for newSymbol, divisor in zip(newSymbolGen, divisors)}
return equationCollection.newWithSubstitutionsApplied(substitutions, True)
...@@ -14,7 +14,7 @@ class SimplificationStrategy: ...@@ -14,7 +14,7 @@ class SimplificationStrategy:
def __init__(self): def __init__(self):
self._rules = [] self._rules = []
def addSimplificationRule(self, rule): def add(self, rule):
""" """
Adds the given simplification rule to the end of the collection. Adds the given simplification rule to the end of the collection.
:param rule: function that taking one equation collection and returning a (simplified) equation collection :param rule: function that taking one equation collection and returning a (simplified) equation collection
......
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