1% DIFFFLAME - An opposed-flow diffusion flame.
2% This example uses the CounterFlowDiffusionFlame function to solve an
3% opposed-flow diffusion flame for Ethane in Air. This example is the same
4% as the diffusion_flame.py example without radiation.
5%
6
7%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8%
9
10runtime = cputime;  % Record the starting time
11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12% Parameter values of inlet streams
13%
14
15p          =   oneatm;              % Pressure
16tin        =   300.0;               % Inlet temperature
17mdot_o     =   0.72;                % Air mass flux, kg/m^2/s
18mdot_f     =   0.24;                % Fuel mass flux, kg/m^2/s
19transport  =  'Mix';                % Transport model
20% NOTE: Transport model needed if mechanism file does not have transport
21% properties.
22%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23% Set-up initial grid, loglevel, tolerances. Enable/Disable grid
24% refinement.
25%
26
27initial_grid = 0.02*[0.0 0.2 0.4 0.6 0.8 1.0];  % Units: m
28tol_ss    = [1.0e-5 1.0e-9];        % [rtol atol] for steady-state problem
29tol_ts    = [1.0e-3 1.0e-9];        % [rtol atol] for time stepping
30loglevel  = 1;                      % Amount of diagnostic output (0 to 5)
31refine_grid = 1;                    % 1 to enable refinement, 0 to disable
32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33% Create the gas objects for the fuel and oxidizer streams. These objects
34% will be used to evaluate all thermodynamic, kinetic, and transport
35% properties.
36%
37
38fuel = GRI30(transport);
39ox = GRI30(transport);
40oxcomp     =  'O2:0.21, N2:0.78';   % Air composition
41fuelcomp   =  'C2H6:1';             % Fuel composition
42% Set each gas mixture state with the corresponding composition.
43set(fuel,'T', tin, 'P', p, 'X', fuelcomp);
44set(ox,'T',tin,'P',p,'X', oxcomp);
45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46% Set-up the flow object. For this problem, the AxisymmetricFlow model is
47% needed. Set the state of the flow as the fuel gas object. This is
48% arbitrary and is only used to initialize the flow object. Set the grid to
49% the initial grid defined prior, same for the tolerances.
50%
51
52f = AxisymmetricFlow(fuel,'flow');
53set(f, 'P', p, 'grid', initial_grid);
54set(f, 'tol', tol_ss, 'tol-time', tol_ts);
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56% Create the fuel and oxidizer inlet steams. Specify the temperature, mass
57% flux, and composition correspondingly.
58%
59
60% Set the oxidizer inlet.
61inlet_o = Inlet('air_inlet');
62set(inlet_o, 'T', tin, 'MassFlux', mdot_o, 'X', oxcomp);
63%
64% Set the fuel inlet.
65inlet_f = Inlet('fuel_inlet');
66set(inlet_f, 'T', tin, 'MassFlux', mdot_f, 'X', fuelcomp);
67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68% Once the inlets have been created, they can be assembled
69% to create the flame object. Function CounterFlorDiffusionFlame
70% (in Cantera/1D) sets up the initial guess for the solution using a
71% Burke-Schumann flame. The input parameters are: fuel inlet object, flow
72% object, oxidizer inlet object, fuel gas object, oxidizer gas object, and
73% the name of the oxidizer species as in character format.
74%
75
76fl = CounterFlowDiffusionFlame(inlet_f, f, inlet_o, fuel, ox, 'O2');
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78% Solve with fixed temperature profile first. Grid refinement is turned off
79% for this process in this example. To turn grid refinement on, change 0 to
80% 1 for last input is solve function.
81%
82
83solve(fl, loglevel, 0);
84%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85% Enable the energy equation. The energy equation will now be solved to
86% compute the temperature profile. We also tighten the grid refinement
87% criteria to get an accurate final solution. The explanation of the
88% setRefineCriteria function is located on cantera.org in the Matlab User's
89% Guide and can be accessed by help setRefineCriteria
90%
91
92enableEnergy(f);
93setRefineCriteria(fl, 2, 200.0, 0.1, 0.2);
94solve(fl, loglevel, refine_grid);
95saveSoln(fl,'c2h6.xml','energy',['solution with energy equation']);
96%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97% Show statistics of solution and elapsed time.
98%
99
100writeStats(fl);
101elapsed = cputime - runtime;
102e = sprintf('Elapsed CPU time: %10.4g',elapsed);
103disp(e);
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105% Make a single plot showing temperature and mass fraction of select
106% species along axial distance from fuel inlet to air inlet.
107%
108
109z = grid(fl, 'flow');                    % Get grid points of flow
110spec = speciesNames(fuel);               % Get species names in gas
111T = solution(fl, 'flow', 'T');           % Get temperature solution
112for i = 1:length(spec)
113    % Get mass fraction of all species from solution
114    y(i,:) = solution(fl, 'flow', spec{i});
115end
116j = speciesIndex(fuel, 'O2');            % Get index of O2 in gas object
117k = speciesIndex(fuel, 'H2O');           % Get index of H2O in gas object
118l = speciesIndex(fuel, 'C2H6');          % Get index of C2H6 in gas object
119m = speciesIndex(fuel, 'CO2');           % Get index of CO2 in gas object
120clf;
121yyaxis left
122plot(z,T)
123xlabel('z (m)');
124ylabel('Temperature (K)');
125yyaxis right
126plot(z,y(j,:),'r',z,y(k,:),'g',z,y(l,:),'m',z,y(m,:),'b');
127ylabel('Mass Fraction');
128legend('T','O2','H2O','C2H6','CO2');
129