Skip to content

Commit

Permalink
[1D] Improve finite-difference Jacobian
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
speth committed Mar 25, 2016
1 parent d767049 commit 011c9cb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/oneD/MultiJac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 011c9cb

Please sign in to comment.