Commit 650d2ead authored by Martin Bauer's avatar Martin Bauer Committed by Martin Bauer
Browse files

new lbm module: momentbased methods & new conserved quantity computation

parent 759f65ec
......@@ -37,18 +37,30 @@ class EquationCollection:
self.subexpressionSymbolNameGenerator = symbolGen()
def createNewWithAdditionalSubexpressions(self, newEquations, additionalSubExpressions):
def newWithAdditionalSubexpressions(self, newEquations, additionalSubExpressions):
Returns a new equation collection, that has `newEquations` as mainEquations.
The `additionalSubExpressions` are appended to the existing subexpressions.
Simplifications hints are copied over.
assert len(self.mainEquations) == len(newEquations), "Number of update equations cannot be changed"
return EquationCollection(newEquations,
self.subexpressions + additionalSubExpressions,
def createNewWithSubstitutionsApplied(self, substitutionDict):
def newWithSubstitutionsApplied(self, 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
newSubexpressions = [fastSubs(eq, substitutionDict) for eq in self.subexpressions]
newEquations = [fastSubs(eq, substitutionDict) for eq in self.mainEquations]
return EquationCollection(newEquations, newSubexpressions, self.simplificationHints)
def addSimplificationHint(self, key, value):
Adds an entry to the simplificationHints dictionary, and checks that is does not exist yet
assert key not in self.simplificationHints, "This hint already exists"
self.simplificationHints[key] = value
......@@ -56,6 +68,7 @@ class EquationCollection:
def allEquations(self):
"""Subexpression and main equations in one sequence"""
return self.subexpressions + self.mainEquations
......@@ -218,7 +231,7 @@ class EquationCollection:
:param module: same as sympy.lambdify paramter of same same, i.e. which module to use e.g. 'numpy'
:param fixedSymbols: dictionary with substitutions, that are applied before lambdification
eqs = self.createNewWithSubstitutionsApplied(fixedSymbols).insertSubexpressions().mainEquations
eqs = self.newWithSubstitutionsApplied(fixedSymbols).insertSubexpressions().mainEquations
lambdas = {eq.lhs: sp.lambdify(symbols, eq.rhs, module) for eq in eqs}
def f(*args, **kwargs):
......@@ -26,7 +26,7 @@ def sympyCSE(equationCollection):
def applyOnAllEquations(equationCollection, operation):
"""Applies sympy expand operation to all equations in collection"""
result = [operation(s) for s in equationCollection.mainEquations]
return equationCollection.createNewWithAdditionalSubexpressions(result, [])
return equationCollection.newWithAdditionalSubexpressions(result, [])
def applyOnAllSubexpressions(equationCollection, operation):
......@@ -57,6 +57,6 @@ def subexpressionSubstitutionInUpdateEquations(equationCollection):
for subExpr in equationCollection.subexpressions:
newRhs = replaceAdditive(newRhs, subExpr.lhs, subExpr.rhs, requiredMatchReplacement=1.0)
result.append(sp.Eq(s.lhs, newRhs))
return equationCollection.createNewWithAdditionalSubexpressions(result, [])
return equationCollection.newWithAdditionalSubexpressions(result, [])
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