-
Notifications
You must be signed in to change notification settings - Fork 3
/
CA2d_von.m
92 lines (86 loc) · 1.72 KB
/
CA2d_von.m
1
%% Copyright (c) 2018, Vishal_S% All rights reserved. Please read the "license.txt" for license terms.%% Project Title: CellularAutomaton% % Developer: Vishal S% % Contact Info: vishalsubbu97@gmail.com%%%%%% CA in 1D with probablitlyclear allclfclcmore offN = 100;n_p = 0.001;P = 0.04;Grain = zeros(N+2,N+2);temp = zeros(N+2,N+2);Grain_no = zeros(N+2,N+2);i = 1;m = 0;j = 10;mesh(Grain_no);view(2);pause(0);least = 0;do % nucleation step least = 0; for i = 2:N+1 for k = 2:N+1 if( Grain(i,k) == 0 ) probab = rand(); if(probab < n_p) temp(i,k) = 1.0; Grain_no(i,k) = j; j = j+10; endif; endif; endfor; endfor; % Growth Step for i = 2:N+1 for k = 2:N+1 for m = 1:4 if(temp(i,k) != 1) if( m == 1) index1 = i; index2 = k-1; elseif ( m==2) index1 = i; index2 = k+1; elseif ( m== 3) index1 = i+1; index2 = k; elseif ( m == 4) index1 = i-1; index2 = k; endif if(Grain(index1,index2) == 1 ) probab = rand(); if(probab<P) temp(i,k) = 1.0; Grain_no (i,k) = Grain_no(index1,index2); endif endif endif endfor; endfor; endfor; for i = 2:N+1 for k = 2:N+1 Grain(i,k) = temp(i,k); if(Grain(i,k) == 0 ) least ++; endif endfor; endfor; mesh(Grain_no); view(2); pause(0); no_of_deforned_grains = leastuntil ( least== 0);print -depsc CA2D_von.eps