The module CahnHilliard is meant to be used to:
- Compute a numerical solution for the Cahn-Hilliard equation, i.e. the time evolution of the concentration field
- Choose different initial conditions and physical parameters (like diffusivity
Dand interfacial parametera) - Compute time evolution of concentration, its distribution and its Fourier transform
- Create gifs to show the time evolution of these quantities
For a detaieled description of the module see ModuleDescription.md.
Cahn Hilliard equations describe the so called spinodal decomposition. This is an example of continous phase transformation, that can happen for example in a binary alloy. The order parameter describing this kind of phase transformations is the concentration of one metal in the alloy, call it
The main features of spinodal decomposition can be understood by considering the free energy density of the system (the binary alloy) as function of the concentration. Indeed, two different phases of the alloy (defined by their respective concentrations
so, in the spinodal region, where
We can take into account the contribution of gradients by adding to the free energy density of the homogeneous system
Then, assuming the free energy density of the system to be given by equation (1), the total energy of the system will be a functional of the concentration
Then, if we compute how the variation in total free energy
Now, since the concentration is a conserved order parameter, the evolution of the concentration profile
and assuming M to be constant with respect to position, substituting the expression for
Now we can make an assumption about the form of the homogenenous free energy density function. The simplest one is a forth order polynomial of the kind:
shown in figure
Then if we set
Go navigate to the folder where you want to put your project, then clone the repository and enter the CahnHilliard directory:
git clone https://github.com/LeonardoRazzai/CahnHilliard.git
cd CahnHilliardThen set up the python environment and activate it running:
python -m venv .venv
./.venv/Scripts/activateor see https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/; then install the required dependencies:
pip install -r requirements.txt>>> from CahnHilliard import *
>>> L = 40 # side length of domain
>>> N = 400 # number of points per spatial dimension
>>> dx = L / N # spatial step along x
>>> dy = L / N # spatial step along y
>>> x, y = np.meshgrid(np.linspace(-L/2, L/2, N), np.linspace(-L/2, L/2, N))
>>> mean = 0.0 # average concentration
>>> conc0 = np.zeros((N, N)) + mean
>>> D = dx**2 * 3 # diffusivity cm**2 / s
>>> gamma = 500
>>> beta = N / dx / gamma # in this way lmax is 2*pi * L/gamma
>>> a = dx**4 * beta**2 # fatstest growing wavevector is 1/sqrt(a)
>>> amp = 0.01
>>> conc0 = conc0 + amp * np.random.randn(N, N) # initial concentration
>>> tmax = 4.5
>>> Nt = 500
>>> time = np.linspace(0, tmax, Nt)
>>> CH_system = Sol_CahnHilliard(L, N, D, a)
>>> CH_system.compute_sol(conc0, time) # Simulate the time evolution of the concentration field
>>> CH_system.set_step(10) # Set the step size for data analysis and visualization
>>> CH_system.ComputeFT() # Compute the average Fourier transform of concentration profiles
>>> CH_system.Compute_histo() # Compute concentration histograms over time
>>> CH_system.MakeGif_sol(file_name='cahn_hilliard.gif') # Create GIF animations
>>> CH_system.MakeGif_FT(filename='ft_vs_time.gif')
>>> CH_system.MakeGif_tot(file_name='cahn_hilliard_tot.gif')- Add a method to compute the initial growth rate of the fastest growing fourier component, to compare with small perturbation analysis result
- Add method to save in separate files the data that are computed by the class for additional analysis (e.g. study the time evolution of the typical length scale).
