| 1 |
This example demonstrates the solution of a particular nonlinear |
| 2 |
time-dependent fourth-order equation, known as the Cahn-Hilliard |
| 3 |
equation. In particular it demonstrates the use of |
| 4 |
|
| 5 |
* The built-in Newton solver |
| 6 |
* Advanced use of the base class ``NonlinearProblem`` |
| 7 |
* Automatic linearisation |
| 8 |
* A mixed finite element method |
| 9 |
* The :math:`\theta`-method for time-dependent equations |
| 10 |
* User-defined Expressions as Python classes |
| 11 |
* Form compiler options |
| 12 |
* Interpolation of functions |
| 13 |
|
| 14 |
|
| 15 |
Equation and problem definition |
| 16 |
------------------------------- |
| 17 |
|
| 18 |
The Cahn-Hilliard equation is a parabolic equation and is typically |
| 19 |
used to model phase separation in binary mixtures. It involves |
| 20 |
first-order time derivatives, and second- and fourth-order spatial |
| 21 |
derivatives. The equation reads: |
| 22 |
|
| 23 |
.. math:: |
| 24 |
\frac{\partial c}{\partial t} - \nabla \cdot M \left(\nabla\left(\frac{d f}{d c} |
| 25 |
- \lambda \nabla^{2}c\right)\right) &= 0 \quad {\rm in} \ \Omega, \\ |
| 26 |
M\left(\nabla\left(\frac{d f}{d c} - \lambda \nabla^{2}c\right)\right) \cdot n &= 0 \quad {\rm on} \ \partial\Omega, \\ |
| 27 |
M \lambda \nabla c \cdot n &= 0 \quad {\rm on} \ \partial\Omega. |
| 28 |
|
| 29 |
where :math:`c` is the unknown field, the function :math:`f` is |
| 30 |
usually non-convex in :math:`c` (a fourth-order polynomial is commonly |
| 31 |
used), :math:`n` is the outward directed boundary normal, and |
| 32 |
:math:`M` is a scalar parameter. |
| 33 |
|
| 34 |
Mixed form |
| 35 |
^^^^^^^^^^ |
| 36 |
|
| 37 |
The Cahn-Hilliard equation is a fourth-order equation, so casting it |
| 38 |
in a weak form would result in the presence of second-order spatial |
| 39 |
derivatives, and the problem could not be solved using a standard |
| 40 |
Lagrange finite element basis. A solution is to rephrase the problem |
| 41 |
as two coupled second-order equations: |
| 42 |
|
| 43 |
.. math:: |
| 44 |
\frac{\partial c}{\partial t} - \nabla \cdot M \nabla\mu &= 0 \quad {\rm in} \ \Omega, \\ |
| 45 |
\mu - \frac{d f}{d c} + \lambda \nabla^{2}c &= 0 \quad {\rm in} \ \Omega. |
| 46 |
|
| 47 |
The unknown fields are now :math:`c` and :math:`\mu`. The weak |
| 48 |
(variational) form of the problem reads: find :math:`(c, \mu) \in V |
| 49 |
\times V` such that |
| 50 |
|
| 51 |
.. math:: |
| 52 |
\int_{\Omega} \frac{\partial c}{\partial t} q \, {\rm d} x + \int_{\Omega} M \nabla\mu \cdot \nabla q \, {\rm d} x |
| 53 |
&= 0 \quad \forall \ q \in V, \\ |
| 54 |
\int_{\Omega} \mu v \, {\rm d} x - \int_{\Omega} \frac{d f}{d c} v \, {\rm d} x - \int_{\Omega} \lambda \nabla c \cdot \nabla v \, {\rm d} x |
| 55 |
&= 0 \quad \forall \ v \in V. |
| 56 |
|
| 57 |
Time discretisation |
| 58 |
^^^^^^^^^^^^^^^^^^^ |
| 59 |
|
| 60 |
Before being able to solve this problem, the time derivative must be |
| 61 |
dealt with. Apply the :math:`\theta`-method to the mixed weak form of |
| 62 |
the equation: |
| 63 |
|
| 64 |
.. math:: |
| 65 |
|
| 66 |
\int_{\Omega} \frac{c_{n+1} - c_{n}}{dt} q \, {\rm d} x + \int_{\Omega} M \nabla \mu_{n+\theta} \cdot \nabla q \, {\rm d} x |
| 67 |
&= 0 \quad \forall \ q \in V \\ |
| 68 |
\int_{\Omega} \mu_{n+1} v \, {\rm d} x - \int_{\Omega} \frac{d f_{n+1}}{d c} v \, {\rm d} x - \int_{\Omega} \lambda \nabla c_{n+1} \cdot \nabla v \, {\rm d} x |
| 69 |
&= 0 \quad \forall \ v \in V |
| 70 |
|
| 71 |
where :math:`dt = t_{n+1} - t_{n}` and :math:`\mu_{n+\theta} = |
| 72 |
(1-\theta) \mu_{n} + \theta \mu_{n+1}`. The task is: given |
| 73 |
:math:`c_{n}` and :math:`\mu_{n}`, solve the above equation to find |
| 74 |
:math:`c_{n+1}` and :math:`\mu_{n+1}`. |
| 75 |
|
| 76 |
|
| 77 |
Demo parameters |
| 78 |
^^^^^^^^^^^^^^^ |
| 79 |
|
| 80 |
The following domains, functions and time stepping parameters are used |
| 81 |
in this demo: |
| 82 |
|
| 83 |
* :math:`\Omega = (0, 1) \times (0, 1)` (unit square) |
| 84 |
* :math:`f = 100 c^{2} (1-c)^{2}` |
| 85 |
* :math:`\lambda = 1 \times 10^{-2}` |
| 86 |
* :math:`M = 1` |
| 87 |
* :math:`dt = 5 \times 10^{-6}` |
| 88 |
* :math:`\theta = 0.5` |
| 89 |
|
| 90 |
With the above input the solution for :math:`c` will look as follows: |
| 91 |
|
| 92 |
.. image:: ../cahn-hilliard_c.png |
| 93 |
:scale: 75 |
| 94 |
:align: center |