diff --git a/include/cantera/oneD/Domain1D.h b/include/cantera/oneD/Domain1D.h index 70f2209cd..f997b02af 100644 --- a/include/cantera/oneD/Domain1D.h +++ b/include/cantera/oneD/Domain1D.h @@ -539,6 +539,16 @@ public: */ virtual void _finalize(const doublereal* x) {} + /** + * In some cases, for computational efficiency some properties (e.g. + * transport coefficients) may not be updated during Jacobian evaluations. + * Set this to `true` to force these properties to be udpated even while + * calculating Jacobian elements. + */ + void forceFullUpdate(bool update) { + m_force_full_update = update; + } + protected: doublereal m_rdt; size_t m_nv; @@ -572,6 +582,7 @@ protected: vector_int m_td; //!< @deprecated To be removed after Cantera 2.3. std::vector m_name; int m_bw; + bool m_force_full_update; }; } diff --git a/src/oneD/Domain1D.cpp b/src/oneD/Domain1D.cpp index 7956cec50..b33e31b14 100644 --- a/src/oneD/Domain1D.cpp +++ b/src/oneD/Domain1D.cpp @@ -25,7 +25,8 @@ Domain1D::Domain1D(size_t nv, size_t points, double time) : m_jstart(0), m_left(0), m_right(0), - m_bw(-1) + m_bw(-1), + m_force_full_update(false) { resize(nv, points); } diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index 516560f18..ae8658ce4 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -569,7 +569,13 @@ void Sim1D::evalSSJacobian() void Sim1D::solveAdjoint(const double* b, double* lambda) { + for (auto& D : m_dom) { + D->forceFullUpdate(true); + } evalSSJacobian(); + for (auto& D : m_dom) { + D->forceFullUpdate(false); + } // Form J^T size_t bw = bandwidth(); diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index cbe3c64dd..490bb0918 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -268,10 +268,12 @@ void StFlow::eval(size_t jg, doublereal* xg, // ------------ update properties ------------ updateThermo(x, j0, j1); - if (jg == npos) { - // update transport properties only if a Jacobian is not being evaluated + if (jg == npos || m_force_full_update) { + // update transport properties only if a Jacobian is not being + // evaluated, or if specifically requested updateTransport(x, j0, j1); - + } + if (jg == npos) { double* Yleft = x + index(c_offset_Y, jmin); m_kExcessLeft = distance(Yleft, max_element(Yleft, Yleft + m_nsp)); double* Yright = x + index(c_offset_Y, jmax);