[1D] Include transport derivatives when computing Jacobian for adjoint

This commit is contained in:
Ray Speth 2016-11-12 13:19:04 -05:00
parent ca8b101acc
commit 0bfdf146c0
4 changed files with 24 additions and 4 deletions

View file

@ -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<std::string> m_name;
int m_bw;
bool m_force_full_update;
};
}

View file

@ -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);
}

View file

@ -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();

View file

@ -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);