diff --git a/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py b/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py new file mode 100644 index 000000000..6f97c2a12 --- /dev/null +++ b/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py @@ -0,0 +1,72 @@ +""" +A freely-propagating, premixed hydrogen flat flame with multicomponent +transport properties. +""" + +import csv +import cantera as ct + +# Simulation parameters +p = ct.OneAtm # pressure [Pa] +Tin = 300.0 # unburned gas temperature [K] +reactants = 'H2:1.1, O2:1, AR:5' # premixed gas composition + +initial_grid = [0.0, 0.001, 0.01, 0.02, 0.029, 0.03] # m +tol_ss = [1.0e-5, 1.0e-13] # [rtol atol] for steady-state problem +tol_ts = [1.0e-4, 1.0e-10] # [rtol atol] for time stepping +loglevel = 1 # amount of diagnostic output (0 to 8) +refine_grid = True # 'True' to enable refinement, 'False' to disable + +# IdealGasMix object used to compute mixture properties +gas = ct.Solution('h2o2.xml') +gas.TPX = Tin, p, reactants + +# Flame object +f = ct.FreeFlame(gas, initial_grid) +f.flame.setSteadyTolerances(default=tol_ss) +f.flame.setTransientTolerances(default=tol_ts) + +# Set properties of the upstream fuel-air mixture +f.inlet.T = Tin +f.inlet.X = reactants + +f.showSolution() + +# Solve with the energy equation disabled +f.energyEnabled = False +f.setMaxJacAge(10, 10) +f.setTimeStep(1e-5, [2, 5, 10, 20]) +f.solve(loglevel=loglevel, refine_grid=False) +f.save('h2_adiabatic.xml', 'no_energy', + 'solution with the energy equation disabled') + +# Solve with the energy equation enabled +f.setRefineCriteria(ratio=3, slope=0.06, curve=0.12) +f.energyEnabled = True +f.solve(loglevel=loglevel, refine_grid=refine_grid) +f.save('h2_adiabatic.xml', 'energy', + 'solution with mixture-averaged transport') +f.showSolution() +print('mixture-averaged flamespeed = {:7f} m/s'.format(f.u[0])) + +# Solve with multi-component transport properties +f.transportModel = 'Multi' +f.solve(loglevel, refine_grid) +f.showSolution() +print('multicomponent flamespeed = {:7f} m/s'.format(f.u[0])) +f.save('h2_adiabatic.xml','energy_multi', + 'solution with multicomponent transport') + +# write the velocity, temperature, density, and mole fractions to a CSV file +z = f.flame.grid +T = f.T +u = f.u +V = f.V + +with open('h2_adiabatic.csv', 'w') as csvfile: + writer = csv.writer(csvfile) + writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] + + list(gas.speciesNames)) + for n in range(f.flame.nPoints): + f.setGasState(n) + writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X)) diff --git a/interfaces/cython/cantera/examples/onedim/burner_flame.py b/interfaces/cython/cantera/examples/onedim/burner_flame.py new file mode 100644 index 000000000..aa1790cab --- /dev/null +++ b/interfaces/cython/cantera/examples/onedim/burner_flame.py @@ -0,0 +1,68 @@ +""" +A burner-stabilized lean premixed hydrogen-oxygen flame at low pressure. +""" + +import cantera as ct +import csv + +p = 0.05 * ct.OneAtm +tburner = 373.0 +mdot = 0.06 +reactants = 'H2:1.5, O2:1, AR:7' # premixed gas composition + +initial_grid = [0.0, 0.02, 0.04, 0.06, 0.08, 0.1, + 0.15, 0.2, 0.4, 0.49, 0.5] # m +tol_ss = [1.0e-5, 1.0e-13] # [rtol atol] for steady-state problem +tol_ts = [1.0e-4, 1.0e-10] # [rtol atol] for time stepping +loglevel = 1 # amount of diagnostic output (0 to 5) +refine_grid = 1 # 1 to enable refinement, 0 to disable + +gas = ct.Solution('h2o2.xml') +gas.TPX = tburner, p, reactants + +f = ct.BurnerFlame(gas, initial_grid) + +f.burner.T = tburner +f.burner.X = reactants +f.burner.mdot = mdot + +f.setInitialGuess() +f.flame.setSteadyTolerances(default=tol_ss) +f.flame.setTransientTolerances(default=tol_ts) +f.showSolution() + +f.energyEnabled = False +f.setMaxJacAge(10, 10) +f.solve(loglevel, refine_grid=False) +f.save('h2_burner_flame.xml', 'no_energy', + 'solution with the energy equation disabled') + +f.setRefineCriteria(ratio=3.0, slope=0.05, curve=0.1) +f.energyEnabled = True +f.solve(loglevel, refine_grid) +f.save('h2_burner_flame.xml', 'energy', + 'solution with the energy equation enabled') + +#print('mixture-averaged flamespeed = ', f.u[0]) + +f.transportModel = 'Multi' +f.solve(loglevel, refine_grid) +f.showSolution() +print('multicomponent flamespeed = ', f.u[0]) +f.save('h2_burner_flame.xml','energy_multi', + 'solution with the energy equation enabled and multicomponent transport') + +z = f.flame.grid +T = f.T +u = f.u +V = f.V + +with open('h2_burner_flame.csv', 'w') as csvfile: + writer = csv.writer(csvfile) + writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] + + list(gas.speciesNames)) + for n in range(f.flame.nPoints): + f.setGasState(n) + writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X)) + +print('solution saved to h2_burner_flame.csv') diff --git a/interfaces/cython/cantera/examples/onedim/diffusion_flame.py b/interfaces/cython/cantera/examples/onedim/diffusion_flame.py new file mode 100644 index 000000000..1349a3103 --- /dev/null +++ b/interfaces/cython/cantera/examples/onedim/diffusion_flame.py @@ -0,0 +1,66 @@ +""" +An opposed-flow ethane/air diffusion flame +""" + +import cantera as ct +import numpy as np +import csv + +p = ct.OneAtm # pressure +tin_f = 300.0 # fuel inlet temperature +tin_o = 300.0 # oxidizer inlet temperature +mdot_o = 0.72 # kg/m^2/s +mdot_f = 0.24 # kg/m^2/s + +comp_o = 'O2:0.21, N2:0.78, AR:0.01' # air composition +comp_f = 'C2H6:1' # fuel composition + +initial_grid = np.linspace(0, 0.02, 6) + +tol_ss = [1.0e-5, 1.0e-12] # [rtol, atol] for steady-state problem +tol_ts = [5.0e-4, 1.0e-9] # [rtol, atol] for time stepping + +loglevel = 1 # amount of diagnostic output (0 to 5) +refine_grid = 1 # 1 to enable refinement, 0 to disable + +gas = ct.Solution('gri30.xml', 'gri30_mix') +gas.TP = gas.T, p + +f = ct.CounterflowDiffusionFlame(gas, initial_grid) +f.fuel_inlet.mdot = mdot_f +f.fuel_inlet.X = comp_f +f.fuel_inlet.T = tin_f + +f.oxidizer_inlet.mdot = mdot_o +f.oxidizer_inlet.X = comp_o +f.oxidizer_inlet.T = tin_o + +f.flame.setSteadyTolerances(default=tol_ss) +f.flame.setTransientTolerances(default=tol_ts) + +f.setInitialGuess(fuel='C2H6') +f.energyEnabled = False +f.solve(loglevel, refine_grid=False) + +f.energyEnabled = True +f.setRefineCriteria(ratio=4, slope=0.2, curve=0.3, prune=0.04) +f.solve(loglevel, refine_grid=refine_grid) + +f.showSolution() + +f.save('c2h6_diffusion.xml') + +z = f.flame.grid +T = f.T +u = f.u +V = f.V + +with open('c2h6_diffusion.csv', 'w') as csvfile: + writer = csv.writer(csvfile) + writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] + + list(gas.speciesNames)) + for n in range(f.flame.nPoints): + f.setGasState(n) + writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X)) + +print('solution saved to c2h6_diffusion.csv')