%(c) Rabi Chhantyal Pun <rc13564@bristol.ac.uk>, University of Bristol 2018

clear all;

%%
%All concentrations (molecule cm^(-3)) obtained from STOCHEM-CRI
POA=1.32; %Primary organic aerosol concentration in microgram/m
Criegee=[19.83 18.27 0.15 0 103483 1.92 0.27 5.1 10.82 97.39 13.7 0.18 21.89 184.03];
Pinonic=1.0E8;
X=0;
Adduct=0;
OH=1.57E6;
OH_product=0;
SOA=0;
SOA_deposit=0;
%%
%SAR_k=[6.6 6.7 8.3 7.6 6.7 6.9 6.2 7.3 7.2 7.4 4.5 4.9 5.3 5.7]*1E-10;
SAR_k=[6.6 6.7/2 8.3 7.6 6.7/2 6.9 6.2 7.3 7.2/2 7.4 4.5/2 4.9 5.3/2 5.7]*1E-10; %rate coefficient from Table S4 for pinonic acid
k2=1E7; %arbitrarily fast rate coefficient for cycling pinonic acid and Criegee 
k_OH=[4.7E-12 6.9E-12 6.9E-12 4E-12 3.8E-12 3.8E-12 3.8E-12 3.8E-12 1.2E-12 1.2E-12 1.2E-12 1.2E-12 1.2E-12 1.2E-12]; %rate coefficient of adduct with OH from EPI suite software 
kin_POA=6.2E-3*POA; %rate coefficient for condensation of adduct onto POA
k_out=[35 1.61 1.61 1.08 4.41E-1 4.41E-1 4.41E-1 4.41E-1 5.58E-3 5.58E-3 1.65E-4 1.65E-4 2.66E-4 2.66E-4]; %depsorption rate coefficient
k_deposit=1/(5*24*60*60); %deposition loss rate coefficeint for SOA

MW=[230.3 244.3 244.3 258.3 270.3 270.3 270.3 270.3 338.4 338.4 368.5 368.5 368.5 368.5];
%%
k={};
Initial={};
days=50;
for c=1:length(SAR_k)
    Criegee_c=Criegee(c);
    initial_c = [Criegee_c Pinonic X Adduct OH OH_product SOA SOA_deposit];
    SAR_k_c=SAR_k(c);
    k_OH_c=k_OH(c);
    k_out_c=k_out(c);
    k_c=[SAR_k_c, k2, k_OH_c, kin_POA, k_out_c, k_deposit];
    MW_c=MW(c);
    Initial{c}=initial_c;
    k{c}=k_c; 
    timespan=[0 days*24*60*60]; %Time step for numerical integration
    [t,C] = ode15s(@(t,C) SOA_model_V(t,C,k_c),timespan,initial_c); %Numerical ODE solver
    SOA_concentration_c=C(length(C),7)*1E12/6.023E23*MW(c); %SOA concentration microgram/m3
    SOA_concentration(c)=SOA_concentration_c;
    
end
    
Total_SOA=sum(SOA_concentration)