[1D/Examples] Use 'auto' to simplify 1D examples
This commit is contained in:
parent
2315da5230
commit
92ccda85fc
10 changed files with 34 additions and 97 deletions
|
|
@ -63,11 +63,8 @@ def solve_flame(gas):
|
|||
sim.reactants.mdot = 0.12 # kg/m^2/s
|
||||
sim.products.mdot = 0.06 # kg/m^2/s
|
||||
|
||||
sim.energy_enabled = False
|
||||
sim.solve(0, refine_grid=False)
|
||||
sim.set_refine_criteria(ratio=3, slope=0.1, curve=0.2)
|
||||
sim.energy_enabled = True
|
||||
sim.solve(0, refine_grid=True)
|
||||
sim.solve(0, auto=True)
|
||||
return sim
|
||||
|
||||
t1 = default_timer()
|
||||
|
|
|
|||
|
|
@ -10,43 +10,34 @@ import numpy as np
|
|||
p = ct.one_atm # pressure [Pa]
|
||||
Tin = 300.0 # unburned gas temperature [K]
|
||||
reactants = 'H2:1.1, O2:1, AR:5' # premixed gas composition
|
||||
|
||||
width = 0.03 # m
|
||||
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, set to the state of the
|
||||
# upstream fuel-air mixture
|
||||
gas = ct.Solution('h2o2.xml')
|
||||
gas.TPX = Tin, p, reactants
|
||||
|
||||
# Flame object
|
||||
# Set up flame object
|
||||
f = ct.FreeFlame(gas, width=width)
|
||||
f.set_refine_criteria(ratio=3, slope=0.06, curve=0.12)
|
||||
f.show_solution()
|
||||
|
||||
# Solve with the energy equation disabled
|
||||
f.energy_enabled = False
|
||||
# Solve with mixture-averaged transport model
|
||||
f.transport_model = 'Mix'
|
||||
f.solve(loglevel=loglevel, refine_grid=False)
|
||||
f.save('h2_adiabatic.xml', 'no_energy',
|
||||
'solution with the energy equation disabled')
|
||||
f.solve(loglevel=loglevel, auto=True)
|
||||
|
||||
# Solve with the energy equation enabled
|
||||
f.set_refine_criteria(ratio=3, slope=0.06, curve=0.12)
|
||||
f.energy_enabled = True
|
||||
f.solve(loglevel=loglevel, refine_grid=refine_grid)
|
||||
f.save('h2_adiabatic.xml', 'energy',
|
||||
'solution with mixture-averaged transport')
|
||||
f.save('h2_adiabatic.xml', 'mix', 'solution with mixture-averaged transport')
|
||||
f.show_solution()
|
||||
print('mixture-averaged flamespeed = {0:7f} m/s'.format(f.u[0]))
|
||||
|
||||
# Solve with multi-component transport properties
|
||||
f.transport_model = 'Multi'
|
||||
f.solve(loglevel, refine_grid)
|
||||
f.solve(loglevel) # don't use 'auto' on subsequent solves
|
||||
f.show_solution()
|
||||
print('multicomponent flamespeed = {0:7f} m/s'.format(f.u[0]))
|
||||
f.save('h2_adiabatic.xml','energy_multi',
|
||||
'solution with multicomponent transport')
|
||||
f.save('h2_adiabatic.xml','multi', 'solution with multicomponent transport')
|
||||
|
||||
# write the velocity, temperature, density, and mole fractions to a CSV file
|
||||
f.write_csv('h2_adiabatic.csv', quiet=False)
|
||||
|
|
|
|||
|
|
@ -9,39 +9,24 @@ p = 0.05 * ct.one_atm
|
|||
tburner = 373.0
|
||||
mdot = 0.06
|
||||
reactants = 'H2:1.5, O2:1, AR:7' # premixed gas composition
|
||||
|
||||
width = 0.5 # m
|
||||
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, width=width)
|
||||
f.burner.mdot = mdot
|
||||
|
||||
f.set_initial_guess()
|
||||
f.set_refine_criteria(ratio=3.0, slope=0.05, curve=0.1)
|
||||
f.show_solution()
|
||||
|
||||
f.energy_enabled = False
|
||||
f.transport_model = 'Mix'
|
||||
f.solve(loglevel, refine_grid=False)
|
||||
f.save('h2_burner_flame.xml', 'no_energy',
|
||||
'solution with the energy equation disabled')
|
||||
|
||||
f.set_refine_criteria(ratio=3.0, slope=0.05, curve=0.1)
|
||||
f.energy_enabled = 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.solve(loglevel, auto=True)
|
||||
f.save('h2_burner_flame.xml', 'mix', 'solution with mixture-averaged transport')
|
||||
|
||||
f.transport_model = 'Multi'
|
||||
f.solve(loglevel, refine_grid)
|
||||
f.solve(loglevel) # don't use 'auto' on subsequent solves
|
||||
f.show_solution()
|
||||
print('multicomponent flamespeed = ', f.u[0])
|
||||
f.save('h2_burner_flame.xml','energy_multi',
|
||||
'solution with the energy equation enabled and multicomponent transport')
|
||||
f.save('h2_burner_flame.xml', 'multi', 'solution with multicomponent transport')
|
||||
|
||||
f.write_csv('h2_burner_flame.csv', quiet=False)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ comp_f = 'C2H6:1' # fuel composition
|
|||
width = 0.02 # Distance between inlets is 2 cm
|
||||
|
||||
loglevel = 1 # amount of diagnostic output (0 to 5)
|
||||
refine_grid = 1 # 1 to enable refinement, 0 to disable
|
||||
|
||||
# Create the gas object used to evaluate all thermodynamic, kinetic, and
|
||||
# transport properties.
|
||||
|
|
@ -45,16 +44,10 @@ f.set_boundary_emissivities(0.0, 0.0)
|
|||
# Turn radiation off
|
||||
f.radiation_enabled = False
|
||||
|
||||
# First disable the energy equation and solve the problem without
|
||||
# refining the grid
|
||||
f.energy_enabled = False
|
||||
f.solve(loglevel, refine_grid=False)
|
||||
|
||||
# Now specify grid refinement criteria, turn on the energy equation,
|
||||
# and solve the problem again.
|
||||
f.energy_enabled = True
|
||||
f.set_refine_criteria(ratio=4, slope=0.2, curve=0.3, prune=0.04)
|
||||
f.solve(loglevel, refine_grid=refine_grid)
|
||||
|
||||
# Solve the problem
|
||||
f.solve(loglevel, auto=True)
|
||||
f.show_solution()
|
||||
f.save('c2h6_diffusion.xml')
|
||||
|
||||
|
|
@ -72,7 +65,7 @@ plt.xlim(0.000, 0.020)
|
|||
|
||||
# Turn on radiation and solve again
|
||||
f.radiation_enabled = True
|
||||
f.solve(loglevel = 1, refine_grid = 0)
|
||||
f.solve(loglevel=1, refine_grid=False)
|
||||
f.show_solution()
|
||||
|
||||
# Plot Temperature with radiation
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@ data_directory = 'diffusion_flame_batch_data/'
|
|||
if not os.path.exists(data_directory):
|
||||
os.makedirs(data_directory)
|
||||
|
||||
# Set refinement: False for fast simulations, True for smoother curves
|
||||
refine = True
|
||||
|
||||
# PART 1: INITIALIZATION
|
||||
|
||||
# Set up an initial hydrogen-oxygen counterflow flame at 1 bar and low strain
|
||||
|
|
@ -65,7 +62,7 @@ f.set_interrupt(interrupt_extinction)
|
|||
|
||||
# Initialize and solve
|
||||
print('Creating the initial solution')
|
||||
f.solve(loglevel=0, refine_grid=refine)
|
||||
f.solve(loglevel=0, auto=True)
|
||||
|
||||
# Save to data directory
|
||||
file_name = 'initial_solution.xml'
|
||||
|
|
@ -116,7 +113,7 @@ for p in p_range:
|
|||
|
||||
try:
|
||||
# Try solving the flame
|
||||
f.solve(loglevel=0, refine_grid=refine)
|
||||
f.solve(loglevel=0)
|
||||
file_name = 'pressure_loop_' + format(p, '05.1f') + '.xml'
|
||||
f.save(data_directory + file_name, name='solution', loglevel=1,
|
||||
description='Cantera version ' + ct.__version__ +
|
||||
|
|
@ -168,7 +165,7 @@ while np.max(f.T) > temperature_limit_extinction:
|
|||
f.set_profile('lambda', normalized_grid, f.L * strain_factor ** exp_lam_a)
|
||||
try:
|
||||
# Try solving the flame
|
||||
f.solve(loglevel=0, refine_grid=refine)
|
||||
f.solve(loglevel=0)
|
||||
file_name = 'strain_loop_' + format(n, '02d') + '.xml'
|
||||
f.save(data_directory + file_name, name='solution', loglevel=1,
|
||||
description='Cantera version ' + ct.__version__ +
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@ f.oxidizer_inlet.mdot = 3.0 # kg/m^2/s
|
|||
f.oxidizer_inlet.X = 'O2:1'
|
||||
f.oxidizer_inlet.T = 500 # K
|
||||
|
||||
# Enable refinement
|
||||
refine = True
|
||||
# Set refinement parameters
|
||||
f.set_refine_criteria(ratio=3.0, slope=0.1, curve=0.2, prune=0.03)
|
||||
|
||||
|
|
@ -54,7 +52,7 @@ temperature_limit_extinction = 500 # K
|
|||
|
||||
# Initialize and solve
|
||||
print('Creating the initial solution')
|
||||
f.solve(loglevel=0, refine_grid=refine)
|
||||
f.solve(loglevel=0, auto=True)
|
||||
|
||||
# Save to data directory
|
||||
file_name = 'initial_solution.xml'
|
||||
|
|
@ -117,7 +115,7 @@ while True:
|
|||
# Update pressure curvature
|
||||
f.set_profile('lambda', normalized_grid, f.L * strain_factor ** exp_lam_a)
|
||||
try:
|
||||
f.solve(loglevel=0, refine_grid=refine)
|
||||
f.solve(loglevel=0)
|
||||
except Exception as e:
|
||||
# Throw Exception if solution fails
|
||||
print('Error: Did not converge at n =', n, e)
|
||||
|
|
|
|||
|
|
@ -26,15 +26,9 @@ gas.TPX = Tin, p, reactants
|
|||
f = ct.FreeFlame(gas, width=width)
|
||||
f.flame.set_steady_tolerances(default=tol_ss)
|
||||
f.flame.set_transient_tolerances(default=tol_ts)
|
||||
|
||||
# Solve with the energy equation disabled
|
||||
f.energy_enabled = False
|
||||
f.solve(loglevel=1, refine_grid=False)
|
||||
|
||||
# Solve with the energy equation enabled
|
||||
f.set_refine_criteria(ratio=3, slope=0.07, curve=0.14)
|
||||
f.energy_enabled = True
|
||||
f.solve(loglevel=1, refine_grid=True)
|
||||
|
||||
f.solve(loglevel=1, auto=True)
|
||||
|
||||
Su0 = f.u[0]
|
||||
print('\nmixture-averaged flamespeed = {:7f} m/s\n'.format(f.u[0]))
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ flowfield, with an opposed flow consisting of equilibrium products.
|
|||
"""
|
||||
|
||||
import cantera as ct
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
# parameter values
|
||||
p = 0.05 * ct.one_atm # pressure
|
||||
|
|
@ -20,12 +18,6 @@ comp = 'H2:1.6, O2:1, AR:7' # premixed gas composition
|
|||
width = 0.2 # m
|
||||
loglevel = 1 # amount of diagnostic output (0 to 5)
|
||||
|
||||
# Grid refinement parameters
|
||||
ratio = 3
|
||||
slope = 0.1
|
||||
curve = 0.2
|
||||
prune = 0.02
|
||||
|
||||
# Set up the problem
|
||||
gas = ct.Solution(rxnmech)
|
||||
|
||||
|
|
@ -35,6 +27,9 @@ gas.TPX = T_in, p, comp
|
|||
# Create the flame simulation object
|
||||
sim = ct.CounterflowPremixedFlame(gas=gas, width=width)
|
||||
|
||||
# Set grid refinement parameters
|
||||
sim.set_refine_criteria(ratio=3, slope=0.1, curve=0.2, prune=0.02)
|
||||
|
||||
# set the boundary flow rates
|
||||
sim.reactants.mdot = mdot_reactants
|
||||
sim.products.mdot = mdot_products
|
||||
|
|
@ -42,12 +37,7 @@ sim.products.mdot = mdot_products
|
|||
sim.set_initial_guess() # assume adiabatic equilibrium products
|
||||
sim.show_solution()
|
||||
|
||||
sim.energy_enabled = False
|
||||
sim.solve(loglevel, False)
|
||||
|
||||
sim.set_refine_criteria(ratio=ratio, slope=slope, curve=curve, prune=prune)
|
||||
sim.energy_enabled = True
|
||||
sim.solve(loglevel)
|
||||
sim.solve(loglevel, auto=True)
|
||||
|
||||
# write the velocity, temperature, and mole fractions to a CSV file
|
||||
sim.write_csv('premixed_counterflow.csv', quiet=False)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ comp = 'H2:1.8, O2:1, AR:7' # premixed gas composition
|
|||
width = 0.2 # m
|
||||
|
||||
loglevel = 1 # amount of diagnostic output (0 to 5)
|
||||
refine_grid = True
|
||||
|
||||
# Grid refinement parameters
|
||||
ratio = 3
|
||||
|
|
@ -61,15 +60,12 @@ sim.inlet.mdot = mdot[0]
|
|||
sim.surface.T = tsurf
|
||||
|
||||
sim.set_grid_min(1e-4)
|
||||
sim.energy_enabled = False
|
||||
sim.set_refine_criteria(ratio=ratio, slope=slope, curve=curve, prune=prune)
|
||||
|
||||
sim.set_initial_guess(products='equil') # assume adiabatic equilibrium products
|
||||
sim.show_solution()
|
||||
|
||||
sim.solve(loglevel, refine_grid)
|
||||
|
||||
sim.set_refine_criteria(ratio=ratio, slope=slope, curve=curve, prune=prune)
|
||||
sim.energy_enabled = True
|
||||
sim.solve(loglevel, auto=True)
|
||||
|
||||
outfile = 'stflame1.xml'
|
||||
if os.path.exists(outfile):
|
||||
|
|
@ -77,7 +73,7 @@ if os.path.exists(outfile):
|
|||
|
||||
for m,md in enumerate(mdot):
|
||||
sim.inlet.mdot = md
|
||||
sim.solve(loglevel,refine_grid)
|
||||
sim.solve(loglevel)
|
||||
sim.save(outfile, 'mdot{0}'.format(m), 'mdot = {0} kg/m2/s'.format(md))
|
||||
|
||||
# write the velocity, temperature, and mole fractions to a CSV file
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ comp2 = 'CH4:0.095, O2:0.21, N2:0.78, AR:0.01'
|
|||
width = 0.1 # m
|
||||
|
||||
loglevel = 1 # amount of diagnostic output (0 to 5)
|
||||
refine_grid = True # enable or disable refinement
|
||||
|
||||
################ create the gas object ########################
|
||||
#
|
||||
|
|
@ -77,9 +76,6 @@ sim.show_solution()
|
|||
# sequential approach where solutions are first obtained for simpler problems
|
||||
# and used as the initial guess for more difficult problems.
|
||||
|
||||
# start with the energy equation on (default is 'off')
|
||||
sim.energy_enabled = True
|
||||
|
||||
# disable the surface coverage equations, and turn off all gas and surface
|
||||
# chemistry.
|
||||
sim.surface.coverage_enabled = False
|
||||
|
|
@ -88,7 +84,7 @@ gas.set_multiplier(0.0)
|
|||
|
||||
# solve the problem, refining the grid if needed, to determine the non-
|
||||
# reacting velocity and temperature distributions
|
||||
sim.solve(loglevel, refine_grid)
|
||||
sim.solve(loglevel, auto=True)
|
||||
|
||||
# now turn on the surface coverage equations, and turn the chemistry on slowly
|
||||
sim.surface.coverage_enabled = True
|
||||
|
|
@ -96,7 +92,7 @@ for mult in np.logspace(-5, 0, 6):
|
|||
surf_phase.set_multiplier(mult)
|
||||
gas.set_multiplier(mult)
|
||||
print('Multiplier =', mult)
|
||||
sim.solve(loglevel, refine_grid)
|
||||
sim.solve(loglevel)
|
||||
|
||||
# At this point, we should have the solution for the hydrogen/air problem.
|
||||
sim.show_solution()
|
||||
|
|
@ -108,7 +104,7 @@ sim.inlet.X = comp2
|
|||
sim.set_refine_criteria(100.0, 0.15, 0.2, 0.0)
|
||||
|
||||
# solve the problem for the final time
|
||||
sim.solve(loglevel, refine_grid)
|
||||
sim.solve(loglevel)
|
||||
|
||||
# show the solution
|
||||
sim.show_solution()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue