# reactor1.m (Source)

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80``` ```function reactor1(g) % REACTOR1 Zero-dimensional kinetics: adiabatic, constant pressure. % % >>>> For a simpler way to carry out a constant-pressure simulation, % see example reactor3.m <<<<< % % This example illustrates how to use class 'Reactor' for % zero-dimensional kinetics simulations. Here the parameters are % set so that the reactor is adiabatic and very close to constant % pressure. % help reactor1 if nargin == 1 gas = g; else gas = GRI30; end nsp = nSpecies(gas); P = oneatm % set the initial conditions set(gas,'T',1001.0,'P',P,'X','H2:2,O2:1,N2:4'); % create a reactor, and insert the gas r = IdealGasReactor(gas); % create a reservoir to represent the environment a = IdealGasMix('air.cti'); set(a,'P',P) env = Reservoir(a); % Define a wall between the reactor and the environment and % make it flexible, so that the pressure in the reactor is held % at the environment pressure. w = Wall; install(w,r,env); % set expansion parameter. dV/dt = KA(P_1 - P_2) setExpansionRateCoeff(w, 1.0e6); % set wall area setArea(w, 1.0); % create a reactor network and insert the reactor: network = ReactorNet({r}); t = 0.0; dt = 1.0e-5; t0 = cputime; for n = 1:100 t = t + dt; advance(network, t); tim(n) = time(network); temp(n) = temperature(r); x(n,1:3) = moleFraction(gas,{'OH','H','H2'}); end disp(['CPU time = ' num2str(cputime - t0)]); clf; subplot(2,2,1); plot(tim,temp); xlabel('Time (s)'); ylabel('Temperature (K)'); subplot(2,2,2) plot(tim,x(:,1)); xlabel('Time (s)'); ylabel('OH Mole Fraction (K)'); subplot(2,2,3) plot(tim,x(:,2)); xlabel('Time (s)'); ylabel('H Mole Fraction (K)'); subplot(2,2,4) plot(tim,x(:,3)); xlabel('Time (s)'); ylabel('H2 Mole Fraction (K)'); clear all cleanup ```