Skip to content

Commit

Permalink
[1D/Examples] eliminate unnecessary setting of tolerances
Browse files Browse the repository at this point in the history
For most problems, these new default tolerances for both time stepping and
steady state solves are more likely to converge than tighter tolerances, but
still give well-resolved results. Tighter tolerances are required in some cases,
e.g. when evaluating sensitivity coefficients by finite difference.
  • Loading branch information
speth committed Mar 27, 2016
1 parent 059e657 commit b56094b
Show file tree
Hide file tree
Showing 13 changed files with 5 additions and 86 deletions.
9 changes: 5 additions & 4 deletions include/cantera/oneD/Domain1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ class Domain1D
m_name.resize(m_nv,"");
m_max.resize(m_nv, 0.0);
m_min.resize(m_nv, 0.0);
m_rtol_ss.resize(m_nv, 1.0e-8);
m_atol_ss.resize(m_nv, 1.0e-15);
m_rtol_ts.resize(m_nv, 1.0e-8);
m_atol_ts.resize(m_nv, 1.0e-15);
// Default error tolerances for all domains
m_rtol_ss.resize(m_nv, 1.0e-4);
m_atol_ss.resize(m_nv, 1.0e-9);
m_rtol_ts.resize(m_nv, 1.0e-4);
m_atol_ts.resize(m_nv, 1.0e-11);
m_points = np;
m_z.resize(np, 0.0);
m_slast.resize(m_nv * m_points, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ def solve_flame(gas):
sim.reactants.mdot = 0.12 # kg/m^2/s
sim.products.mdot = 0.06 # kg/m^2/s

sim.flame.set_steady_tolerances(default=[1.0e-7, 1.0e-13])
sim.flame.set_transient_tolerances(default=[1.0e-7, 1.0e-11])
sim.set_initial_guess()

sim.energy_enabled = False
sim.solve(0, refine_grid=False)
sim.set_refine_criteria(ratio=3, slope=0.1, curve=0.2)
Expand Down
5 changes: 0 additions & 5 deletions interfaces/cython/cantera/examples/onedim/adiabatic_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
reactants = 'H2:1.1, O2:1, AR:5' # premixed gas composition

width = 0.03 # m
tol_ss = [1.0e-5, 1.0e-13] # [rtol atol] for steady-state problem
tol_ts = [1.0e-4, 1.0e-13] # [rtol atol] for time stepping
loglevel = 1 # amount of diagnostic output (0 to 8)
refine_grid = True # 'True' to enable refinement, 'False' to disable

Expand All @@ -24,9 +22,6 @@

# Flame object
f = ct.FreeFlame(gas, width=width)
f.flame.set_steady_tolerances(default=tol_ss)
f.flame.set_transient_tolerances(default=tol_ts)

f.show_solution()

# Solve with the energy equation disabled
Expand Down
4 changes: 0 additions & 4 deletions interfaces/cython/cantera/examples/onedim/burner_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
reactants = 'H2:1.5, O2:1, AR:7' # premixed gas composition

width = 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

Expand All @@ -23,8 +21,6 @@
f.burner.mdot = mdot

f.set_initial_guess()
f.flame.set_steady_tolerances(default=tol_ss)
f.flame.set_transient_tolerances(default=tol_ts)
f.show_solution()

f.energy_enabled = False
Expand Down
7 changes: 0 additions & 7 deletions interfaces/cython/cantera/examples/onedim/diffusion_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

width = 0.02 # Distance between inlets is 2 cm

tol_ss = [1.0e-5, 1.0e-12] # [rtol, atol] for steady-state problem
tol_ts = [5.0e-4, 1.0e-11] # [rtol, atol] for time stepping

loglevel = 1 # amount of diagnostic output (0 to 5)
refine_grid = 1 # 1 to enable refinement, 0 to disable

Expand All @@ -43,10 +40,6 @@
f.oxidizer_inlet.X = comp_o
f.oxidizer_inlet.T = tin_o

# Set error tolerances
f.flame.set_steady_tolerances(default=tol_ss)
f.flame.set_transient_tolerances(default=tol_ts)

# Set the boundary emissivities
f.set_boundary_emissivities(0.0, 0.0)
# Turn radiation off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@
f.oxidizer_inlet.X = 'O2:1'
f.oxidizer_inlet.T = 300 # K

# Define relative and absolute error tolerances
f.flame.set_steady_tolerances(default=[1.0e-5, 1.0e-12])
f.flame.set_transient_tolerances(default=[5.0e-4, 1.0e-11])

# Set refinement parameters, if used
f.set_refine_criteria(ratio=3.0, slope=0.1, curve=0.2, prune=0.03)
f.set_grid_min(1e-20)

# Define a limit for the maximum temperature below which the flame is
# considered as extinguished and the computation is aborted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,10 @@
f.oxidizer_inlet.X = 'O2:1'
f.oxidizer_inlet.T = 500 # K

# Define relative and absolute error tolerances
f.flame.set_steady_tolerances(default=[1.0e-5, 1.0e-12])
f.flame.set_transient_tolerances(default=[5.0e-4, 1.0e-11])

# Enable refinement
refine = True
# Set refinement parameters
f.set_refine_criteria(ratio=3.0, slope=0.1, curve=0.2, prune=0.03)
f.set_grid_min(1e-20)

# Define a limit for the maximum temperature below which the flame is
# considered as extinguished and the computation is aborted
Expand Down
5 changes: 0 additions & 5 deletions interfaces/cython/cantera/examples/onedim/flame_fixed_T.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# The solution domain is chosen to be 1 cm
width = 0.01 # m

tol_ss = [1.0e-5, 1.0e-9] # [rtol atol] for steady-state problem
tol_ts = [1.0e-5, 1.0e-4] # [rtol atol] for time stepping
loglevel = 1 # amount of diagnostic output (0 to 5)
refine_grid = True # 'True' to enable refinement

Expand Down Expand Up @@ -46,9 +44,6 @@
# set the temperature profile to the values read in
f.flame.set_fixed_temp_profile(zloc, tvalues)

f.flame.set_steady_tolerances(default=tol_ss)
f.flame.set_transient_tolerances(default=tol_ts)

# show the initial estimate for the solution
f.show_solution()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
comp = 'H2:1.6, O2:1, AR:7' # premixed gas composition

width = 0.2 # m
tol_ss = [1.0e-7, 1.0e-13] # [rtol atol] for steady-state problem
tol_ts = [1.0e-7, 1.0e-11] # [rtol atol] for time stepping
loglevel = 1 # amount of diagnostic output (0 to 5)

# Grid refinement parameters
Expand All @@ -41,8 +39,6 @@
sim.reactants.mdot = mdot_reactants
sim.products.mdot = mdot_products

sim.flame.set_steady_tolerances(default=tol_ss)
sim.flame.set_transient_tolerances(default=tol_ts)
sim.set_initial_guess() # assume adiabatic equilibrium products
sim.show_solution()

Expand Down
4 changes: 0 additions & 4 deletions interfaces/cython/cantera/examples/onedim/stagnation_flame.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
# The solution domain is chosen to be 20 cm
width = 0.2 # m

tol_ss = [1.0e-5, 1.0e-13] # [rtol atol] for steady-state problem
tol_ts = [1.0e-4, 1.0e-9] # [rtol atol] for time stepping
loglevel = 1 # amount of diagnostic output (0 to 5)
refine_grid = True

Expand All @@ -62,8 +60,6 @@
# set the surface state
sim.surface.T = tsurf

sim.flame.set_steady_tolerances(default=tol_ss)
sim.flame.set_transient_tolerances(default=tol_ts)
sim.set_grid_min(1e-4)
sim.energy_enabled = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
# The inlet/surface separation is 10 cm.
width = 0.1 # m

# numerical parameters
tol_ss = [1.0e-5, 1.0e-9] # [rtol, atol] for steady-state problem
tol_ts = [1.0e-4, 1.0e-9] # [rtol, atol] for time stepping

loglevel = 1 # amount of diagnostic output (0 to 5)
refine_grid = True # enable or disable refinement

Expand Down Expand Up @@ -74,10 +70,6 @@
sim.inlet.X = comp1
sim.surface.T = tsurf

# Set error tolerances
sim.flame.set_steady_tolerances(default=tol_ss)
sim.flame.set_transient_tolerances(default=tol_ts)

# Show the initial solution estimate
sim.show_solution()

Expand Down
4 changes: 0 additions & 4 deletions src/oneD/StFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ StFlow::StFlow(IdealGasPhase* ph, size_t nsp, size_t points) :
setBounds(4+k, -1.0e-7, 1.0e5);
}

//-------------------- default error tolerances ----------------
setTransientTolerances(1.0e-8, 1.0e-15);
setSteadyTolerances(1.0e-8, 1.0e-15);

//-------------------- grid refinement -------------------------
m_refiner->setActive(0, false);
m_refiner->setActive(1, false);
Expand Down
27 changes: 0 additions & 27 deletions src/oneD/boundaries1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ void Inlet1D::init()
setBounds(0, -1e5, 1e5); // mdot
setBounds(1, 200.0, 1e5); // T

// set tolerances
setSteadyTolerances(1e-4, 1e-5);
setTransientTolerances(1e-4, 1e-5);

// if a flow domain is present on the left, then this must be a right inlet.
// Note that an inlet object can only be a terminal object - it cannot have
// flows on both the left and right
Expand Down Expand Up @@ -265,10 +261,6 @@ string Empty1D::componentName(size_t n) const
void Empty1D::init()
{
setBounds(0, -1.0, 1.0);

// set tolerances
setSteadyTolerances(1e-4, 1e-4);
setTransientTolerances(1e-4, 1e-4);
}

void Empty1D::eval(size_t jg, doublereal* xg, doublereal* rg,
Expand Down Expand Up @@ -317,10 +309,6 @@ void Symm1D::init()
{
_init(1);
setBounds(0, -1.0, 1.0);

// set tolerances
setSteadyTolerances(1e-4, 1e-4);
setTransientTolerances(1e-4, 1e-4);
}

void Symm1D::eval(size_t jg, doublereal* xg, doublereal* rg, integer* diagg,
Expand Down Expand Up @@ -395,9 +383,6 @@ void Outlet1D::init()
_init(1);
setBounds(0, -1.0, 1.0);

// set tolerances
setSteadyTolerances(1e-4, 1e-4);
setTransientTolerances(1e-4, 1e-4);
if (m_flow_right) {
m_flow_right->setViscosityFlag(false);
}
Expand Down Expand Up @@ -509,10 +494,6 @@ void OutletRes1D::init()
// set bounds (dummy)
setBounds(0, -1.0, 1.0);

// set tolerances
setSteadyTolerances(1e-4, 1e-4);
setTransientTolerances(1e-4, 1e-4);

if (m_flow_left) {
m_flow = m_flow_left;
} else if (m_flow_right) {
Expand Down Expand Up @@ -639,10 +620,6 @@ void Surf1D::init()
_init(1);
// set bounds (T)
setBounds(0, 200.0, 1e5);

// set tolerances
setSteadyTolerances(1e-4, 1e-4);
setTransientTolerances(1e-4, 1e-4);
}

void Surf1D::eval(size_t jg, doublereal* xg, doublereal* rg,
Expand Down Expand Up @@ -719,10 +696,6 @@ void ReactingSurf1D::init()
for (size_t n = 0; n < m_nsp; n++) {
setBounds(n+1, -1.0e-5, 2.0);
}
setSteadyTolerances(1.0e-5, 1.0e-9);
setTransientTolerances(1.0e-5, 1.0e-9);
setSteadyTolerances(1.0e-5, 1.0e-4, 0);
setTransientTolerances(1.0e-5, 1.0e-4, 0);
}

void ReactingSurf1D::resetBadValues(double* xg) {
Expand Down

0 comments on commit b56094b

Please sign in to comment.