Skip to content

Commit

Permalink
Inherit test_tolerances to MoleReactors
Browse files Browse the repository at this point in the history
MoleReactors have varying orders of magnitude in comparsion to mass fraction
based Reactors. Tolerances that are too tight based on the state vector
cause test failures. This commit inherits the test and modifies tolerances
appropriately.
  • Loading branch information
anthony-walker committed Jan 9, 2023
1 parent c70643b commit 1d2a457
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/zeroD/IdealGasConstPressureMoleReactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ Eigen::SparseMatrix<double> IdealGasConstPressureMoleReactor::jacobian()
m_kin->getNetProductionRates(netProductionRates.data()); // "omega dot"
Eigen::SparseMatrix<double> dnk_dnj = m_kin->netProductionRates_ddN();
double molarVolume = m_thermo->molarVolume();
// Calculate ROP derivatives, excluding the term
// molarVolume * (wdot(j) - sum_k(X_k * dwdot_j/dX_k))
// which is small and would completely destroy the sparsity of the Jacobian
// Calculate ROP derivatives, excluding the terms where dnk/dnj is zero but
// molarVolume * wdot is not, as it reduces matrix sparsity and diminishes
// performance.
for (int k = 0; k < dnk_dnj.outerSize(); k++) {
for (Eigen::SparseMatrix<double>::InnerIterator it(dnk_dnj, k); it; ++it) {
it.valueRef() = it.value() + netProductionRates[it.row()] * molarVolume;
Expand Down
1 change: 0 additions & 1 deletion src/zeroD/MoleReactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ void MoleReactor::getState(double* y)
getSurfaceInitialConditions(y+m_nsp+m_sidx);
}


void MoleReactor::updateState(double* y)
{
// The components of y are [0] total internal energy, [1] the total volume, and
Expand Down
10 changes: 6 additions & 4 deletions test/python/test_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_equalize_pressure(self):
self.assertNear(self.gas1.P, self.gas2.P)
self.assertNotAlmostEqual(self.r1.T, self.r2.T)

def test_tolerances(self):
def test_tolerances(self, rtol_lim=1e-10, atol_lim=1e-20):
def integrate(atol, rtol):
P0 = 10 * ct.one_atm
T0 = 1100
Expand All @@ -257,9 +257,9 @@ def integrate(atol, rtol):

return nSteps

n_baseline = integrate(1e-10, 1e-20)
n_rtol = integrate(5e-7, 1e-20)
n_atol = integrate(1e-10, 1e-5)
n_baseline = integrate(rtol_lim, atol_lim)
n_rtol = integrate(rtol_lim * 1e2, atol_lim)
n_atol = integrate(rtol_lim, atol_lim * 1e15)
assert n_baseline > n_rtol
assert n_baseline > n_atol

Expand Down Expand Up @@ -873,6 +873,8 @@ def test_mole_reactor_surface_chem(self):
self.assertArrayNear(rsurf1.coverages, rsurf2.coverages, rtol=1e-4,
atol=1e-8)

def test_tolerances(self, rtol_lim=1e-8, atol_lim=1e-18):
super().test_tolerances(rtol_lim, atol_lim)

class TestIdealGasReactor(TestReactor):
reactorClass = ct.IdealGasReactor
Expand Down

0 comments on commit 1d2a457

Please sign in to comment.