This project pertains to the numerical resolution of the Cahn-Hilliard equation in its dimensionless, constant mobility form,
and with variable mobility,
Two projects at the UCLouvain were completed based on the solvers implemented in this repository. The first one was made for the LMECA2300 course and is a short report going over the implementation details. The second one was made for the LINMA2720 course and is written in french. It focuses more on the mathematical models behind the Cahn-Hilliard equation. There are three different available implementations:
- Python
- C
- CUDA
The files can be found in the python subfolder. The installation requirements are fairly simple and we recommend the following procedure:
# Create venv & install requirements
cd /path/to/python
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
# Run one of the scripts
source venv/bin/activate
python spectral.py
There are three python implementations:
- naive.py using finite differences & an explicit euler time stepping scheme
- spectral.py using Fourier spectral differentiation methods and various more advanced solvers (such as IMEX and ETDRK4).
- vmobility.py implementing the Cahn-Hilliard equation with variable mobility M(c) = (1-ac²).
Should you wish to save a movie of the animation, you can easily do so by changing the if False:
into if True:
in the main subroutine of the scripts.
The files can be found in the C subfolder. The installation requirements will be detailled later, as it is a bit more complex. First, we will detail the compilation & running procedure:
cd /path/to/C
mkdir build
cd build
cmake ..
make
./ch
When successful, a window should appear with the animation of the Cahn-Hilliard solver. It is possible to choose different compilation parameters to change the simulation parameters or choose different solvers. Those parameters are flags you may add to the cmake
command:
-DN_DISCR=128|256|512|...
(default is 128): sets the discretisation level of the N-by-N grid. To avoid any problem (and for the sake of efficiency), this number should always be a power of 2 and greater or equal to 128, though it should work for any integer as long as CUDA is turned off.-DSOLVER=ETDRK4|IMEX
(default is ETDRK4): changes the time stepping scheme. ETDRK4 is a bit slower per iteration than the IMEX schemes, but otherwise way more precise and much faster to reach a given precision and has a bigger stability region. Therefore, it should always be preferred.-DUSE_CUDA=off|on
(default is OFF): whether to use CUDA to accelerate the simulation or not. Only available if you have a Nvidia GPU and CUDA installed. As it is much faster, it should be used whenever possible.-DMOBILITY=CONSTANT|VARIABLE
(default is CONSTANT): switch to variable mobility simulation. The simulation parameters then change accordingly.
The following installation instructions are specifically made for the apt
package manager, but should be equally easy to follow with other package managers with a bit of Googling skills. However, we do not provide any help for Windows (the best help you may find is to install a Linux-based OS...).
The visualisation is made using OpenGL & GLFW3. You will need to make sure you have OpenGL, GLFW3 and GLEW installed on your system:
sudo apt-get install freeglut3-dev libglfw3-dev libglew-dev
You will need to install one of the two following libraries to perform the FFT's necessary to run the code. You can choose either Intel's MKL, which may be installed using the following:
sudo apt-get install intel-mkl-full
or install FFTW3:
sudo apt-get install libfftw3-dev
By default, the compiler will choose Intel's MKL if both libraries are available as it proved a bit more efficient (at least on our computers, which are both Intel-based processors).
The CUDA version of the solver uses cuFFT to perform the FFT's and uses CUDA kernels to accelerate various computations. To run this version, you will need a Nvidia GPU as well as to install CUDA. As the installation procedure is a bit more tedious, we recommend you to follow this official installation guide.
[1] A. Quiriny, G. Poncelet, "LMECA2300: Project report", 2021. [2] P. Veldeman, G. Poncelet, "Rapport LINMA2720 – L’équation de Cahn-Hilliard avec une mobilité variable : application d’une méthode spectrale", 2021.