The Python script to solve the Cahn-Hilliard equation using an implicit pseudospectral algorithm
Author, date: Wentao Gong, On Sep 04, 2023
References:
Lecture 19 Part VI: Dynamics, the Cahn-Hilliard Equation
Phase Field methods: From fundamentals to applications
Multi-Phase Fluid Flows: The Cahn-Hilliard Navier-Stokes Framework by Rahul Pandit
Papers in the tutorial folder
Cahn-Hilliard Equation: This equation models the time evolution of a scalar field
Where
Phase-field model for liquid-liquid phase separation
with M being a mobility and the functional of free-energy given by
Here,
For the above functional, the functional derivative
This expression provides the "force" that acts to change the concentration field
where f is the bulk free-energy density given by
- Simplicity: The concept simplifies complex landscapes of potential energy, especially for systems with multiple possible pathways.
- Non-Equilibrium Systems: The thermodynamic barrier is a concept mainly applicable to systems near or at equilibrium. For systems far from equilibrium, the concept might not be directly applicable.
The next Figure presents this bulk free-energy.
In the study of partial differential equations (PDEs) like the Cahn-Hilliard equation, various numerical methods can be employed for solving them, including Fourier methods, Finite Difference Methods (FDM), Finite Volume Methods (FVM), and Finite Element Methods (FEM).
- High Accuracy: The method approximates the solution in the entire domain simultaneously, offering high-order accuracy for smooth solutions.
- Efficiency: By utilizing Fast Fourier Transforms (FFT), the pseudo-spectral method can be computationally more efficient than finite-difference methods for certain types of problems.
- Deal with Nonlinearity: The Cahn-Hilliard equation often contains nonlinear terms. The pseudo-spectral method is well-equipped to handle such nonlinearities through techniques like operator splitting.
- Periodic Boundary Conditions: For problems where periodic boundary conditions are relevant, the pseudo-spectral method is particularly advantageous.
- Reduced Numerical Diffusion: Compared to finite difference or finite volume methods, pseudo-spectral methods often demonstrate reduced numerical diffusion, which can be crucial for capturing sharp gradients and preserving interface integrity.
- Spectral Convergence: For smooth solutions, spectral methods can offer exponential convergence, making them more accurate than other methods for a given computational cost.
- Limited to Smooth Solutions: If the solution has discontinuities or sharp gradients, the method might not be effective due to Gibbs phenomenon.
- Complexity: Requires a more sophisticated understanding of the Fourier or other basis functions being used.
- Boundary Conditions: The method is most naturally suited for periodic problems and can be challenging to implement for more complex boundary conditions.
- Time-Stepping: Due to high accuracy in spatial discretization, time-stepping methods must also be chosen carefully to maintain stability.
- Simplicity: Easier to implement and understand.
- Flexibility: Works well for complex geometries and diverse boundary conditions.
- Stability: Known for numerical stability in time-dependent problems.
- Accuracy: Generally less accurate than spectral methods.
- Stiff Equations: May require implicit solvers, increasing complexity.
- Conservation Laws: Excellent for problems where conservation properties need to be preserved.
- Robustness: Good for handling discontinuities.
- Unstructured Grids: Can be used on unstructured, complex geometries.
- Computational Cost: Can be computationally intensive.
- Complexity: Requires the understanding of flux and control volumes.
- Generalizability: Excellent for a wide variety of problems, including non-linear and complex geometries.
- High Accuracy: Allows for high-order accuracy.
- Adaptive Meshing: Allows mesh refinement in regions of interest.
- Implementation Difficulty: Complex to implement and requires a deep understanding of the method.
- Computational Cost: High computational expense for three-dimensional problems.
The choice of method depends on several factors, such as the type of problem you're dealing with, the properties you want to preserve, and the computational resources available.
The spectral method offers a powerful tool for solving the Cahn-Hilliard equation efficiently and accurately under the right conditions. Its ability to deal with complex and nonlinear terms efficiently makes it an appealing choice for researchers working on phase separation problems.
However, if you're dealing with non-periodic boundaries, complex geometries, or need to capture discontinuities accurately, FEM, FDM or FVM might be more appropriate.
To simplify solving this equation, Fourier transform can be applied. The Fourier Transform of a function g(x) is defined as:
where
The Fourier coefficients are given by
$$
\widehat{c}_{\boldsymbol{k}}(t)=\mathcal {FT}{c(\boldsymbol{r},t)}=\int c(\boldsymbol{r},t)e^{i\boldsymbol{k}\boldsymbol{r}}d\boldsymbol{r}
$$
and
The Fourier transform of the dynamical equation is $$ \frac{\partial\widehat{c}{\boldsymbol{k}}}{\partial t}= M[-\kappa k^4\widehat{c}{\boldsymbol{k}}-k^2\mathcal {FT}{f'}] $$
-
$\frac{\partial \hat{c}(k, t)}{\partial t}$ : Rate of change of the Fourier component of$c$ with respect to time$t$ . -
$-k^4 \hat{c}_{\boldsymbol{k}}$ : The Laplacian term in Fourier space.$k^4$ is a consequence of two spatial derivatives$\nabla^2$ . -
$k^2 \hat{f'}$ : Fourier transform of the derivative of free energy density.$k^2$ arises from one spatial derivative$\nabla^2$ .
and using an implicit Euler integration, we have
$$
\frac{\widehat{c}{\boldsymbol{k}}^{n+1}-\widehat{c}{\boldsymbol{k}}^{n}}{\Delta t}=M[-\kappa k^4 \widehat{c}{\boldsymbol{k}}^{n+1}-k^2 \mathcal{FT}{f'(c^n)}]
$$
Solver for $\widehat{c}{\boldsymbol{k}}^{n+1}$: isolate $\widehat{c}{\boldsymbol{k}}^{n+1}$ to find its value at the next time step:
$$
\widehat{c}{\boldsymbol{k}}^{n+1}=\frac{\widehat{c}_{\boldsymbol{k}}-\Delta tMk^2\mathcal{FT}{f'(c^n)} }{1+\Delta t\kappa M k^4}
$$
where
- Inverse Fourier Transform:Take the inverse Fourier transform of $\widehat{c}{\boldsymbol{k}}^{n+1}$ to find ${c}{\boldsymbol{k}}^{n+1}$ the concentration at the next time step in real space.
- Repeat: Go back to implicit Euler scheme and repeat for all desired time steps.
The following figure is a result for the system with M=1.0, W=2.0,
And the system is evolved until N = 1000 steps.