Search code examples
pythonnumerical-methodsfipy

Role of eqn3 in Fipy examples.cahnHilliard.mesh2DCoupled


I am currently working through the examples in the fipy documentation and am trying to adapt the examples.cahnHilliard.mesh2DCoupled to perform some simulations. The link is : https://www.ctcms.nist.gov/fipy/examples/cahnHilliard/generated/examples.cahnHilliard.mesh2DCoupled.html

It seems that the example code declares an eq3 and a dfdphi_ and does not use these equations anywhere else, even in the solution.

From the documentation:

>>> D = a = epsilon = 1.
>>> dfdphi = a**2 * phi * (1 - phi) * (1 - 2 * phi)
>>> dfdphi_ = a**2 * (1 - phi) * (1 - 2 * phi)
>>> d2fdphi2 = a**2 * (1 - 6 * phi * (1 - phi))
>>> eq1 = (TransientTerm(var=phi) == DiffusionTerm(coeff=D, var=psi))
>>> eq2 = (ImplicitSourceTerm(coeff=1., var=psi)
...        == ImplicitSourceTerm(coeff=d2fdphi2, var=phi) - d2fdphi2 * phi + dfdphi
...        - DiffusionTerm(coeff=epsilon**2, var=phi))
>>> eq3 = (ImplicitSourceTerm(coeff=1., var=psi)
...        == ImplicitSourceTerm(coeff=dfdphi_, var=phi)
...        - DiffusionTerm(coeff=epsilon**2, var=phi))
>>> eq = eq1 & eq2

and in the solution block:

>>> while elapsed < duration:
...     dt = min(100, numerix.exp(dexp))
...     elapsed += dt
...     dexp += 0.01
...     eq.solve(dt=dt)
...     if __name__ == "__main__":
...         viewer.plot()

I would appreciate any insight regarding what the eq3 and dfdphi_ terms do. And as an extension to that, how does the solver know to use the old values of $\phi$ to evaluate the linearised form after taylor expression since the solver block does not seem to account for this.


Solution

  • eqn2 and eqn3 encode, in the limit of infinitesimal time and space steps, the same equation. However, in their discretization they single out different terms for a more active role in the construction of the time step propagator.

    In the short term this should only lead to insignificant differences in the result, in the long term there may be more pronounced differences in stability and accuracy.

    That the "more natural" equation eq3 is present at all seems to be an indirect invitation to experiment with it, and perhaps to explore if the transformation in eq2 with its possible advantages is a coincidence or result of some more deeply founded idea.