You are on page 1of 3

clear all

% initialization
L=20; % lattice size
MCS=20000; % monte carlo step
avg=5; % average 10 MCS as one data point
lattice=zeros(L,L); % 0 for bare site, 1 for CO, 2 for O_a, 3 for O_s
n1=0; theta1=zeros(MCS/avg,1); % CO_ad
n2=0; theta2=zeros(MCS/avg,1); % O_ad
n3=0; theta3=zeros(MCS/avg,1); % O_sub
n_co2=0; rate=zeros(MCS/avg,1); % CO2 reaction rate per site per MCS
% pattern 10000mcs to 15000mcs
pattern=zeros(20,2000);
temp=zeros(L^2*avg,3); % temporary matrix for data average
near=zeros(1,2); % NN for Nearest-Neighbour index
next=zeros(1,2); % NNN for Next Nearest-Neighbour index
Ndiff=10; % diffusion control parameter
p_rea=1/(1+Ndiff);
T=522;
k_co=10.7;
k_o2=10.7;
k_LH=1.704*10^7*exp(-5054.15/T);
k_des=2*10^16*exp(-19205.78/T);
k_sub=8.971*10^3*exp(-4144.40/T);
k_rev=2.984*10^3*exp(-4144.40/T);
p_co=k_co/(k_LH+k_des);
p_o2=k_o2/(k_LH+k_des);
p_des=k_des/(k_LH+k_des);
p_ox=k_sub/(k_LH+k_des);
p_red=k_rev/k_LH;
x=0; y=0; % lattice site index
rou1=0; rou2=0; rou3=0; % random parameter
trial=0; % absorption-reaction trial number
index=0; % theta1 theta2 theta3 time index
% reaction marker
mark1=0; % CO diffusion
mark2=0; % CO adsorption
mark3=0; % O2 adsorption
mark4=0; % CO desorption
mark5=0; % LH
mark6=0; % Oxidation formation
mark7=0; % Oxidation reduction
reaction=zeros(100,7);
% monte carlo loop
while trial<MCS*L^2 % total number of monte carlo trials
rou1=rand(1); rou2=rand(1); rou3=rand(1);
x=randi(L); y=randi(L);
near=NN(x,y,L); next=NNN(x,y,L);
if rou1>p_rea
if lattice(x,y)==1 && lattice(near(1,1), near(1,2))==0
lattice(x,y)=0; lattice(near(1,1), near(1,2))=1;
mark1=mark1+1;
end
elseif rou1<=p_rea
if lattice(x,y)==0
if rou2<=p_co
lattice(x,y)=1; n1=n1+1; mark2=mark2+1;
elseif rou2>p_co && rou2<=(p_co+p_o2) && lattice(next(1,1), next(1,2
))==0
lattice(x,y)=2;
lattice(next(1,1), next(1,2))=2; n2=n2+2;
mark3=mark3+1;
end
elseif lattice(x,y)==2
if rou2<=p_ox
lattice(x,y)=3; n3=n3+1; n2=n2-1; mark6=mark6+1;
elseif rou2>p_ox && lattice(near(1,1), near(1,2))==1
lattice(x,y)=0;
lattice(near(1,1), near(1,2))=0; n1=n1-1; n2=n2-1; n_co2=n_co2+1
;
mark5=mark5+1;
end
elseif lattice(x,y)==1
if rou2<=p_des
lattice(x,y)=0; n1=n1-1; mark4=mark4+1;
elseif rou2>p_des && lattice(near(1,1), near(1,2))==2
lattice(x,y)=0;
lattice(near(1,1), near(1,2))=0; n1=n1-1; n2=n2-1; n_co2=n_co2+1
;
mark5=mark5+1;
elseif rou2>p_des && lattice(near(1,1), near(1,2))==3
if rou3<=p_red
lattice(x,y)=0;
lattice(near(1,1), near(1,2))=0; n1=n1-1; n3=n3-1; n_co2=n_c
o2+1;
mark7=mark7+1;
end
end
elseif lattice(x,y)==3
if rou3<=p_red && lattice(near(1,1),near(1,2))==1
lattice(x,y)=0;
lattice(near(1,1), near(1,2))=0; n3=n3-1; n1=n1-1; n_co2=n_co2+1
;
mark7=mark7+1;
end
end

temp(mod(trial, L^2*avg)+1,1)=n1;
temp(mod(trial, L^2*avg)+1,2)=n2;
temp(mod(trial, L^2*avg)+1,3)=n3;
if mod(trial+1, L^2*avg)==0
index=(trial+1)/(L^2*avg);
theta1(index)=sum(temp(:,1))/L^2/(L^2*avg);
theta2(index)=sum(temp(:,2))/L^2/(L^2*avg);
theta3(index)=sum(temp(:,3))/L^2/(L^2*avg);
rate(index)=n_co2/L^2/avg;
n_co2=0;
if index>2000 && index<=3000 && mod(index-2000,10)==0
pattern(:,((index-2010)*2+1):(index-2000)*2)=lattice;
reaction((index-2000)/10,1)=mark1/avg/10;
reaction((index-2000)/10,2)=mark2/avg/10;
reaction((index-2000)/10,3)=mark3/avg/10;
reaction((index-2000)/10,4)=mark4/avg/10;
reaction((index-2000)/10,5)=mark5/avg/10;
reaction((index-2000)/10,6)=mark6/avg/10;
reaction((index-2000)/10,7)=mark7/avg/10;
mark1=0;
mark2=0;
mark3=0;
mark4=0;
mark5=0;
mark6=0;
mark7=0;
end
end
trial=trial+1;
end
end
% real time scale
time=zeros(MCS/avg,1);
i=0;
for i=1:MCS/avg
time(i)=avg*i/k_tot;
end

You might also like