From 6807ec472c1f2971d2173cee781b2906b92c4d38 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Fri, 16 Mar 2018 12:20:13 +0100
Subject: [PATCH] Phase field tutorials + small changes in functional
 derivative code

---
 chapman_enskog/chapman_enskog.py | 7 ++++---
 phasefield/analytical.py         | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/chapman_enskog/chapman_enskog.py b/chapman_enskog/chapman_enskog.py
index 33b82e1b..b0ef2b38 100644
--- a/chapman_enskog/chapman_enskog.py
+++ b/chapman_enskog/chapman_enskog.py
@@ -367,11 +367,12 @@ def getTaylorExpandedLbEquation(pdfSymbolName="f", pdfsAfterCollisionOperator="\
 
     functions = [pdf, collidedPdf]
     eq_4_5 = taylorOperator - dt * collidedPdf
-    applied_eq_4_5 = expandUsingLinearity(DiffOperator.apply(eq_4_5, pdf), functions)
+    applied_eq_4_5 = expandUsingLinearity(DiffOperator.apply(eq_4_5, pdf, applyToConstants=False), functions)
 
     if shift:
         operator = ((dt / 2) * (Dt + c.dot(Dx))).expand()
-        opTimesEq_4_5 = expandUsingLinearity(DiffOperator.apply(operator, applied_eq_4_5), functions).expand()
+        opTimesEq_4_5 = expandUsingLinearity(DiffOperator.apply(operator, applied_eq_4_5, applyToConstants=False),
+                                             functions).expand()
         opTimesEq_4_5 = normalizeDiffOrder(opTimesEq_4_5, functions)
         eq_4_7 = (applied_eq_4_5 - opTimesEq_4_5).subs(dt ** (taylorOrder+1), 0)
     else:
@@ -671,7 +672,7 @@ class SteadyStateChapmanEnskogAnalysis(object):
         c = sp.Matrix([expandedSymbol("c", subscript=i) for i in range(dim)])
         Dx = sp.Matrix([DiffOperator(target=l) for l in range(dim)])
         differentialOperator = sum((dt * eps * c.dot(Dx)) ** n / sp.factorial(n) for n in range(1, order + 1))
-        taylorExpansion = DiffOperator.apply(differentialOperator.expand(), f)
+        taylorExpansion = DiffOperator.apply(differentialOperator.expand(), f, applyToConstants=False)
         epsDict = useChapmanEnskogAnsatz(taylorExpansion,
                                          spatialDerivativeOrders=None,  # do not expand the differential operator itself
                                          pdfs=(['f', 0, order + 1],))  # expand only the 'f' terms
diff --git a/phasefield/analytical.py b/phasefield/analytical.py
index 97709692..95c5bff2 100644
--- a/phasefield/analytical.py
+++ b/phasefield/analytical.py
@@ -195,7 +195,8 @@ def chemicalPotentialsFromFreeEnergy(freeEnergy, orderParameters=None):
         orderParameters.sort(key=lambda e: e.name)
         orderParameters = orderParameters[:-1]
     constants = [s for s in syms if s not in orderParameters]
-    return sp.Matrix([functionalDerivative(freeEnergy, op, constants) for op in orderParameters])
+    return sp.Matrix([expandUsingLinearity(functionalDerivative(freeEnergy, op),constants=constants)
+                      for op in orderParameters])
 
 
 def forceFromPhiAndMu(orderParameters, dim, mu=None):
-- 
GitLab