From 011c9cb6c35ed91a15289ba06b59186fd776aea8 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 13 Feb 2016 18:24:03 -0500 Subject: [PATCH] [1D] Improve finite-difference Jacobian Preserve the sign of elements of the solution vector when perturbing them in order to avoid triggering discontinuous behavior as the cross zero (which is caused by the way rate evaluation is handled for negative species concentrations). --- src/oneD/MultiJac.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/oneD/MultiJac.cpp b/src/oneD/MultiJac.cpp index d1a342a61..dd2ad2317 100644 --- a/src/oneD/MultiJac.cpp +++ b/src/oneD/MultiJac.cpp @@ -56,9 +56,13 @@ void MultiJac::eval(doublereal* x0, doublereal* resid0, doublereal rdt) for (j = 0; j < m_points; j++) { nv = m_resid->nVars(j); for (n = 0; n < nv; n++) { - // perturb x(n) + // perturb x(n); preserve sign(x(n)) xsave = x0[ipt]; - dx = m_atol + fabs(xsave)*m_rtol; + if (xsave >= 0) { + dx = xsave*m_rtol + m_atol; + } else { + dx = xsave*m_rtol - m_atol; + } x0[ipt] = xsave + dx; dx = x0[ipt] - xsave; rdx = 1.0/dx;