From fae8197bd40167528f43b51ed74e921f67c5dc3e Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 15 Feb 2013 17:32:19 +0000 Subject: [PATCH] [Transport] Check that mole fractions are different before recalcuating This avoids recomputing and factorizing the L matrix under some circumstances, such as when both thermal conductivity and the Soret coefficients are requested for the same mixture. --- include/cantera/transport/MultiTransport.h | 3 +++ src/transport/MultiTransport.cpp | 27 ++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/cantera/transport/MultiTransport.h b/include/cantera/transport/MultiTransport.h index df75216a9..c4c7bb565 100644 --- a/include/cantera/transport/MultiTransport.h +++ b/include/cantera/transport/MultiTransport.h @@ -203,6 +203,9 @@ private: // work space vector_fp m_spwork1, m_spwork2, m_spwork3; + //! Mole fraction vector from last L-matrix evaluation + vector_fp m_molefracs_last; + void correctBinDiffCoeffs(); //! Boolean indicating viscosity is up to date diff --git a/src/transport/MultiTransport.cpp b/src/transport/MultiTransport.cpp index e8464ab2e..5db3c9eb2 100644 --- a/src/transport/MultiTransport.cpp +++ b/src/transport/MultiTransport.cpp @@ -78,6 +78,7 @@ bool MultiTransport::initGas(GasTransportParams& tr) m_a.resize(3*m_nsp, 1.0); m_b.resize(3*m_nsp, 0.0); m_aa.resize(m_nsp, m_nsp, 0.0); + m_molefracs_last.resize(m_nsp, -1.0); m_frot_298.resize(m_nsp); m_rotrelax.resize(m_nsp); @@ -166,6 +167,9 @@ void MultiTransport::solveLMatrixEquation() // if T has changed, update the temperature-dependent properties. updateThermal_T(); update_C(); + if (m_lmatrix_soln_ok) { + return; + } // Copy the mole fractions twice into the last two blocks of // the right-hand-side vector m_b. The first block of m_b was @@ -233,10 +237,9 @@ void MultiTransport::solveLMatrixEquation() "error in solving L matrix."); } m_lmatrix_soln_ok = true; - m_l0000_ok = false; + m_molefracs_last = m_molefracs; // L matrix is overwritten with LU decomposition - //} - m_lmatrix_soln_ok = true; + m_l0000_ok = false; } //==================================================================================================================== @@ -528,6 +531,7 @@ void MultiTransport::getMultiDiffCoeffs(const size_t ld, doublereal* const d) string(" invert returned ierr = ")+int2str(ierr)); } m_l0000_ok = false; // matrix is overwritten by inverse + m_lmatrix_soln_ok = false; //doublereal pres = m_thermo->pressure(); doublereal prefactor = 16.0 * m_temp @@ -562,18 +566,21 @@ void MultiTransport::update_T() void MultiTransport::update_C() { - // signal that concentration-dependent quantities will need to - // be recomputed before use, and update the local mole - // fraction array. - m_l0000_ok = false; - m_lmatrix_soln_ok = false; + // Update the local mole fraction array m_thermo->getMoleFractions(DATA_PTR(m_molefracs)); - // add an offset to avoid a pure species condition - // (check - this may be unnecessary) for (size_t k = 0; k < m_nsp; k++) { + // add an offset to avoid a pure species condition m_molefracs[k] = std::max(Tiny, m_molefracs[k]); + if (m_molefracs[k] != m_molefracs_last[k]) { + // If any mole fractions have changed, signal that concentration- + // dependent quantities will need to be recomputed before use. + m_l0000_ok = false; + m_lmatrix_soln_ok = false; + } } + m_l0000_ok = false; + m_lmatrix_soln_ok = false; } /*************************************************************************