Quoting "Ionut Vancea" <[email protected]>:

On Thu, Jan 29, 2009 at 4:24 PM, Daniel Wheeler
<[email protected]> wrote:

The equation should be

  >>> diffTerm4 = - DiffusionTerm((h**3, 1))
  >>> eqch = TransientTerm() == -DiffusionTerm((h**3, 1)) +
(fDerivative.getFaceGrad() * h**3).getDivergence()

May I ask you why did you write in this way? I can not see in my
equation the terms you wrote here.

The equation you gave us was

\partial_t \phi=-\nabla\{\phi^3\nabla[\triangle \phi -\partial_\phi f(\phi)]\}

which can be separated into three Terms:

 \partial_t \phi
 -\nabla\{\phi^3\nabla[\triangle \phi]\}
 -\nabla\{\phi^3\nabla[-\partial_\phi f(\phi)]\}

As you know, the first term is a TransientTerm().

The second Term is what we call a fourth-order DiffusionTerm. If you pass a single coefficient (not just a single value; it can be a field over Cells or Faces) when you create a DiffusionTerm, e.g. DiffusionTerm(coeff=D) or DiffusionTerm(coeff=(D,)), you get a conventional expression for diffusion: \nabla\cdot D \nabla \phi. If you pass a tuple of coefficients, then FiPy composes progressively higher-order derivatives, so DiffusionTerm(coeff=(h**3, 1)) will use h**3 as the coefficient of the outer divergence, and 1 as the coefficient of the inner divergence:
  \nabla\cdot\{\phi^3\nabla[\nabla\cdot(1 \times \nabla \phi)]\}
which can be simplified to
  \nabla\cdot\{\phi^3\nabla[\nabla^2\phi]\}
or
  \nabla\cdot\{\phi^3\nabla[triangle \phi]\}

As we discuss in examples.cahnHilliard.inputTanh1D in the manual, ideally the \nabla should be run through on the third Term, to give
   \nabla\{\phi^3 \partial^2_\phi f(\phi) \nabla \phi\}
which is represented as DiffusionTerm(coeff=h***3 * fSecondDeriv).

If, for some reason, you cannot write an expression for \partial^2_\phi f(\phi), then you will need to resort to what Daniel gave you, an explicit expression: \nabla[\partial_\phi f(\phi)] is written as fDerivative.getFaceGrad() (which assumes that fDerivative is a CellVariable, which it should be since it should be defined in terms of h, which, as you solution variable, must be a CellVariable). The full expression for the third Term is, therefore, as Daniel gave you
(h**3 * fDerivative.getFaceGrad()).getDivergence()



Have you gone through the Frequently Asked Questions in the manual? We go through each type of Term that FiPy can solve in FAQ 6.1. In Chapter 3, we go through more of the theoretical details of how each type of Term is rendered into a matrix equation.


I also modify the equation in this way, but I received an error.

Traceback (most recent call last):
  File "mytestsimul.py", line 43, in <module>
    eqch = TransientTerm() == -DiffusionTerm((h**3, 1)) +
(fDerivative.getFaceGrad() * h**3).getDivergence()
AttributeError: 'binOp' object has no attribute 'getFaceGrad'

That would lead me to believe that fDerivative is not a CellVariable. What is the definition of fDerivative?


To compare the equation with the example here I included also f(\phi):

\partial_t \phi=-\nabla\{\phi^3\nabla[\triangle \phi -\partial_\phi f(\phi)]\}

where f(\phi) = \frac{b}{2\phi^2}-e^{-\phi}

Please show us how you have written f(\phi) and \partial_\phi f(\phi) in Python.


Reply via email to