ConstantTransport: Transport properties are calcuated with fixed reference temperature

This commit is contained in:
ignis 2020-01-15 11:28:18 +09:00
parent 84acb57b4b
commit 6cee31cbb9
2 changed files with 174 additions and 48 deletions

View file

@ -24,65 +24,29 @@ namespace Cantera
class ConstantTransport : public MixTransport
{
public:
// ConstantTransport() {}
//! Default constructor.
ConstantTransport();
virtual std::string transportType() const {
return "Constant";
}
//! Returns the unity Lewis number approximation based diffusion
//! coefficients [m^2/s].
//! Update the internal parameters whenever the temperature has changed
/*!
* Returns the unity Lewis number approximation based diffusion coefficients
* for a gas, appropriate for calculating the mass averaged diffusive flux
* with respect to the mass averaged velocity using gradients of the mole
* fraction.
*
* \f[
* D^\prime_{km} = \frac{\lambda}{\rho c_p}
* \f]
*
* In order to obtain the expected behavior from a unity Lewis number model,
* this formulation requires that the correction velocity be computed as
*
* \f[
* V_c = \sum \frac{W_k}{\overline{W}} D^\prime_{km} \nabla X_k
* \f]
*
* @param[out] d Vector of diffusion coefficients for each species (m^2/s).
* length m_nsp.
* This is called whenever a transport property is requested if the
* temperature has changed since the last call to update_T().
*/
virtual void getMixDiffCoeffs(double* const d) {
double Dm = thermalConductivity() / (m_thermo->density() * m_thermo->cp_mass());
for (size_t k = 0; k < m_nsp; k++) {
d[k] = Dm;
}
}
virtual void update_T();
//! Not implemented for unity Lewis number approximation
virtual void getMixDiffCoeffsMole(double* const d){
throw NotImplementedError("ConstantTransport::getMixDiffCoeffsMole");
}
virtual void init(thermo_t* thermo, int mode=0, int log_level=0);
//! Returns the unity Lewis number approximation based diffusion
//! coefficients [m^2/s].
protected:
//! Reference temperature at which binary diffusivities are calculated
/*!
* These are the coefficients for calculating the diffusive mass fluxes
* from the species mass fraction gradients, computed as
*
* \f[
* D_{km} = \frac{\lambda}{\rho c_p}
* \f]
*
* @param[out] d Vector of diffusion coefficients for each species (m^2/s).
* length m_nsp.
* Units = K
*/
virtual void getMixDiffCoeffsMass(double* const d){
double Dm = thermalConductivity() / (m_thermo->density() * m_thermo->cp_mass());
for (size_t k = 0; k < m_nsp; k++) {
d[k] = Dm;
}
}
doublereal m_reftemp;
};
}
#endif

View file

@ -0,0 +1,162 @@
/**
* @file ConstantTransport.cpp
* Mixture-averaged transport properties for ideal gas mixtures.
*/
// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.
#include "cantera/transport/ConstantTransport.h"
#include "cantera/base/stringUtils.h"
using namespace std;
namespace Cantera
{
ConstantTransport::ConstantTransport() :
MixTransport(),
m_reftemp(300.0)
{
}
void ConstantTransport::init(ThermoPhase* thermo, int mode, int log_level)
{
MixTransport::init(thermo, mode, log_level);
// m_reftemp = thermo->temperature();
// cout << "check reference temperature" << m_reftemp << endl;
}
/*
void ConstantTransport::init(ThermoPhase* thermo, int mode, int log_level)
{
MixTransport::init(thermo, mode, log_level);
}
void ConstantTransport::getMobilities(doublereal* const mobil)
{
getMixDiffCoeffs(m_spwork.data());
doublereal c1 = ElectronCharge / (Boltzmann * m_temp);
for (size_t k = 0; k < m_nsp; k++) {
mobil[k] = c1 * m_spwork[k];
}
}
doublereal ConstantTransport::thermalConductivity()
{
update_T();
update_C();
if (!m_spcond_ok) {
updateCond_T();
}
if (!m_condmix_ok) {
doublereal sum1 = 0.0, sum2 = 0.0;
for (size_t k = 0; k < m_nsp; k++) {
sum1 += m_molefracs[k] * m_cond[k];
sum2 += m_molefracs[k] / m_cond[k];
}
m_lambda = 0.5*(sum1 + 1.0/sum2);
m_condmix_ok = true;
}
return m_lambda;
}
void ConstantTransport::getThermalDiffCoeffs(doublereal* const dt)
{
for (size_t k = 0; k < m_nsp; k++) {
dt[k] = 0.0;
}
}
void ConstantTransport::getSpeciesFluxes(size_t ndim, const doublereal* const grad_T,
size_t ldx, const doublereal* const grad_X,
size_t ldf, doublereal* const fluxes)
{
update_T();
update_C();
getMixDiffCoeffs(m_spwork.data());
const vector_fp& mw = m_thermo->molecularWeights();
const doublereal* y = m_thermo->massFractions();
doublereal rhon = m_thermo->molarDensity();
vector_fp sum(ndim,0.0);
for (size_t n = 0; n < ndim; n++) {
for (size_t k = 0; k < m_nsp; k++) {
fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
sum[n] += fluxes[n*ldf + k];
}
}
// add correction flux to enforce sum to zero
for (size_t n = 0; n < ndim; n++) {
for (size_t k = 0; k < m_nsp; k++) {
fluxes[n*ldf + k] -= y[k]*sum[n];
}
}
}
void ConstantTransport::update_T()
{
doublereal t = m_thermo->temperature();
if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
return;
}
if (t < 0.0) {
throw CanteraError("ConstantTransport::update_T",
"negative temperature {}", t);
}
GasTransport::update_T();
// temperature has changed, so polynomial fits will need to be redone.
m_spcond_ok = false;
m_bindiff_ok = false;
m_condmix_ok = false;
}
void ConstantTransport::update_C()
{
// signal that concentration-dependent quantities will need to be recomputed
// before use, and update the local mole fractions.
m_visc_ok = false;
m_condmix_ok = false;
m_thermo->getMoleFractions(m_molefracs.data());
// add an offset to avoid a pure species condition
for (size_t k = 0; k < m_nsp; k++) {
m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
}
}
void ConstantTransport::updateCond_T()
{
if (m_mode == CK_Mode) {
for (size_t k = 0; k < m_nsp; k++) {
m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
}
} else {
for (size_t k = 0; k < m_nsp; k++) {
m_cond[k] = m_sqrt_t * dot5(m_polytempvec, m_condcoeffs[k]);
}
}
m_spcond_ok = true;
m_condmix_ok = false;
}
*/
void ConstantTransport::update_T()
{
doublereal t = m_thermo->temperature();
if (m_reftemp == m_temp && m_nsp == m_thermo->nSpecies()) {
return;
}
if (t < 0.0) {
throw CanteraError("ConstantTransport::update_T",
"negative temperature {}", t);
}
m_thermo->setTemperature(m_reftemp);
GasTransport::update_T();
m_thermo->setTemperature(t);
// temperature has changed, so polynomial fits will need to be redone.
m_spcond_ok = false;
m_bindiff_ok = false;
m_condmix_ok = false;
}
}