Azzera filtri
Azzera filtri

Phase separation Contor graph of 2D Allen Cahn Equation

8 visualizzazioni (ultimi 30 giorni)
How can we plot the phase sepration contor graph for 2D Allen Cahn equation? The contor graph is changing with time and record the video.

Risposte (1)

Rahul
Rahul il 23 Ago 2024
I understand that you want to plot the phase separation contour graph for 2D Allen Cahn equation. You want the contour graph to change with time and record its video.
An approach you can use for obtaining the desired result is:
Initially set the parameters and conditions for the phase field and set the spatial grid.
L = 100; % domain size
N = 100; % number of grid points
dx = L/N; % grid spacing
dt = 0.1; % time step
M = 50; % number of time steps
epsilon = 1.0; % interface width
beta = 1.0; % reaction rate
% These parameters are just for example and should be changed according to
% specific use-case
% Spatial grid
x = linspace(-L/2, L/2, N);
y = linspace(-L/2, L/2, N);
[X, Y] = meshgrid(x, y);
After this, you can loop through the time-steps and obtain the laplacian at each time step using the "del2" function to update the Allen-Cahn equation. Each "contour" frame can be added to a "VideoWriter" object to update the video file using "getframe" and "writeVideo" functions.
phi = 2*rand(N, N) - 1;
v = VideoWriter('phase_separation.avi');
open(v);
for step = 1:M
laplacian_phi = del2(phi, dx);
% Allen-Cahn update
phi = phi + dt * (epsilon * laplacian_phi - beta * phi .* (phi.^2 - 1));
contourf(X, Y, phi, 20);
colorbar;
title(['Time Step: ', num2str(step)]);
xlabel('X');
ylabel('Y');
axis equal;
drawnow;
frame = getframe(gcf);
writeVideo(v, frame);
end
close(v);
You can refer to the following documentations to know more about these individual functions:
Note: Since the provided code plots the contour's as they are being updated and gets the frame from the figure during each time-step hence the figure is shown throughout the simulation and pop ups even if exitted. After the loop runs completely, the video is stored in the ".avi" file.
Hope this helps! Thanks.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by