The python script to solve the Cahn-Hilliard equation using finite difference method (FTCS) with 3 different type boundary conditions
Cahn-Hilliard Equation: This equation models the time evolution of a scalar field
Where
Phase-field model for liquid-liquid phase separation
where c is the concentration of binary mixture and can have values between -1 and 1, where -1 corresponds to the pure presence of one compoent, 1 corresponds to the pure presence of the other components
-
$\frac{\partial c}{\partial t}$ :the rate of change of the concentration with time -
$\mu$ is the chemnical potential represented by$c^3-c-\kappa\nabla^2c$
This equation descripes how the mixtures evolves while it tries its local free energy
The FTCS scheme is conditionally stable for certain types of problems. The stability condition for diffusion equation is
However, the presence of nonlinear terms and additional components related to
Main loop for time evolution
- Update
$\mu$ field based on current c field on the domain
- Update c field based on
$\mu$ field on the domian $$
\nabla^2\mu = \frac{\mu_{i+1,j}-2\mu_{i,j}+\mu_{i-1,j}}{(\Delta x)^2}+\frac{\mu_{i,j+1}-2\mu_{i,j}+\mu_{i,j-1}}{(\Delta y)^2} $$
- Store the updated c field for the next time step
The following figure is a result for the system with M= 1.0. dx=1.0,dt - 0.01,
And the system is evolved until N = 200 steps.
In the 4th-order Runge-Kutta method (RK4), the updating scheme has four stages, each with an intermediate step. Let's denote $ c^n $ as the value of $ c $ at the nth time step, and $ \Delta t $ as the time step size. The scheme for RK4 is:
- $ k_1 = f(c^n) $
- $ k_2 = f\left(c^n + \frac{\Delta t}{2} k_1\right) $
- $ k_3 = f\left(c^n + \frac{\Delta t}{2} k_2\right) $
- $ k_4 = f\left(c^n + \Delta t k_3\right) $
Then, the update formula is:
Here,$ f(c) = M\nabla^2\mu$
- Update
$\mu$ field based on current c field on the domain
- Update c field based on
$\mu$ field on the domian
$ f(c) = M \nabla^2\left(-\left(c^3 - c\right) + \nabla^2 c\right) $.
The Laplacian in 2D can be approximated by the 5-point stencil as follows:
By following these steps, we can discretize the 2D Cahn-Hilliard equation in time using the 4th-order Runge-Kutta scheme with 2nd order spatial discretization.