minor cleanup

This commit is contained in:
Dave Goodwin 2003-12-11 12:06:16 +00:00
parent 7b0be740bd
commit b9dd391712
7 changed files with 169 additions and 99 deletions

View file

@ -24,6 +24,7 @@
#pragma warning(disable:4503)
#endif
#include "../ThermoPhase.h"
#include "DustyGasTransport.h"
/**
@ -87,6 +88,8 @@ namespace Cantera {
m_d.resize(m_nsp, m_nsp);
m_dk.resize(m_nsp, 0.0);
m_x.resize(m_nsp);
//m_gradConc.resize(m_nsp);
//m_conc.resize(m_nsp);
// set flags all false
m_knudsen_ok = false;
@ -94,6 +97,7 @@ namespace Cantera {
// some work space
m_spwork.resize(m_nsp);
m_spwork2.resize(m_nsp);
}
@ -142,13 +146,66 @@ namespace Cantera {
}
}
void DustyGasTransport::getMolarFluxes(const double* grad_conc,
double grad_P, double* fluxes) {
// void DustyGasTransport::getMolarFluxes(const double* grad_conc,
// double grad_P, double* fluxes) {
// updateMultiDiffCoeffs();
// copy(grad_conc, grad_conc + m_nsp, m_spwork.begin());
// multiply(m_multidiff, m_spwork.begin(), fluxes);
// m_thermo->getConcentrations(m_spwork.begin());
// divide_each(m_spwork.begin(), m_spwork.end(), m_dk.begin());
// // if no permeability has been specified, use result for
// // close-packed spheres
// double b = 0.0;
// if (m_perm < 0.0) {
// double p = m_porosity;
// double d = m_diam;
// double t = m_tortuosity;
// b = p*p*p*d*d/(72.0*t*(1.0-p)*(1.0-p));
// }
// else {
// b = m_perm;
// }
// b *= grad_P / m_gastran->viscosity();
// scale(m_spwork.begin(), m_spwork.end(), m_spwork.begin(), b);
// increment(m_multidiff, m_spwork.begin(), fluxes);
// scale(fluxes, fluxes + m_nsp, fluxes, -1.0);
// }
void DustyGasTransport::getMolarFluxes(const doublereal* state1,
const doublereal* state2, double delta, double* fluxes) {
int k;
doublereal conc1, conc2;
doublereal* cbar = m_spwork.begin();
doublereal* gradc = m_spwork2.begin();
doublereal t1 = state1[0];
doublereal t2 = state2[0];
doublereal rho1 = state1[1];
doublereal rho2 = state2[1];
const doublereal* y1 = state1 + 2;
const doublereal* y2 = state2 + 2;
doublereal c1sum = 0.0, c2sum = 0.0;
for (k = 0; k < m_nsp; k++) {
conc1 = rho1*y1[k]/m_mw[k];
conc2 = rho2*y2[k]/m_mw[k];
cbar[k] = 0.5*(conc1 + conc2);
gradc[k] = (conc2 - conc1)/delta;
c1sum += conc1;
c2sum += conc2;
}
doublereal p1 = c1sum * GasConstant * state1[0];
doublereal p2 = c2sum * GasConstant * state2[0];
doublereal pbar = 0.5*(p1 + p2);
doublereal gradp = (p2 - p1)/delta;
doublereal tbar = 0.5*(t1 + t2);
m_thermo->setState_TPX(tbar, pbar, cbar);
updateMultiDiffCoeffs();
copy(grad_conc, grad_conc + m_nsp, m_spwork.begin());
multiply(m_multidiff, m_spwork.begin(), fluxes);
m_thermo->getConcentrations(m_spwork.begin());
divide_each(m_spwork.begin(), m_spwork.end(), m_dk.begin());
multiply(m_multidiff, gradc, fluxes);
divide_each(cbar, cbar + m_nsp, m_dk.begin());
// if no permeability has been specified, use result for
// close-packed spheres
@ -162,12 +219,13 @@ namespace Cantera {
else {
b = m_perm;
}
b *= grad_P / m_gastran->viscosity();
scale(m_spwork.begin(), m_spwork.end(), m_spwork.begin(), b);
increment(m_multidiff, m_spwork.begin(), fluxes);
b *= gradp / m_gastran->viscosity();
scale(cbar, cbar + m_nsp, cbar, b);
increment(m_multidiff, cbar, fluxes);
scale(fluxes, fluxes + m_nsp, fluxes, -1.0);
}
void DustyGasTransport::updateMultiDiffCoeffs() {
// see if temperature has changed
updateTransport_T();

View file

@ -46,19 +46,13 @@ namespace Cantera {
virtual void getMultiDiffCoeffs(int ld, doublereal* d);
virtual void getMolarFluxes(const doublereal* state1,
const doublereal* state2, doublereal delta,
doublereal* fluxes);
//-----------------------------------------------------------
// new methods added in this class
/// Get the molar gas species fluxes. These fluxes include
/// both the ordinary mass diffusion component
/// and the Darcy (pressure-driven) commponent.
void getMolarFluxes(const double* grad_conc,
double grad_P, double* fluxes);
/// Set the porosity (dimensionless)
void setPorosity(doublereal porosity) {
m_porosity = porosity;
@ -139,9 +133,19 @@ namespace Cantera {
// work space
vector_fp m_spwork;
vector_fp m_spwork2;
// concentration gradients
//vector_fp m_gradConc;
//vector_fp m_conc;
doublereal m_gradP; /// pressure gradient
bool m_knudsen_ok;
bool m_bulk_ok;
bool m_conc_set;
bool m_gradConc_set;
bool m_gradP_set;
doublereal m_porosity; /// porosity
doublereal m_tortuosity; /// tortuosity

View file

@ -18,6 +18,7 @@
#pragma warning(disable:4503)
#endif
#include "../ThermoPhase.h"
#include "MixTransport.h"
#include "utilities.h"

View file

@ -21,6 +21,8 @@
#pragma warning(disable:4503)
#endif
#include "../ThermoPhase.h"
#include "MultiTransport.h"
#include "ctlapack.h"
#include "../../ext/math/gmres.h"

View file

@ -17,6 +17,7 @@
#pragma warning(disable:4503)
#endif
#include "../ThermoPhase.h"
#include "SolidTransport.h"
#include "utilities.h"

View file

@ -1,6 +1,6 @@
/**
* @file TransportBase.h
* @brief Provides class Transport.
* Provides class Transport.
*/
/*
@ -9,48 +9,30 @@
* $Date$
*/
/**
* @example transport_example.cpp
* An example that illustrates use of all methods of class Transport.
*/
// Copyright 2001 California Institute of Technology
// Copyright 2001-2003 California Institute of Technology
#ifndef CT_TRANSPORTBASE_H
#define CT_TRANSPORTBASE_H
#include "../ct_defs.h"
#include "../ctexceptions.h"
#include "../Array.h"
#include "../stringUtils.h"
#include "../ThermoPhase.h"
namespace Cantera {
// exception class
class NotImplemented : public CanteraError {
public:
NotImplemented(string method) : CanteraError("Transport",
"\n\n\n**** Method "+method+" not implemented. ****\n"
"(Did you forget to specify a transport model?)\n\n\n") {}
};
class TransportParams;
const int CK_Mode = 10;
// types of transport models that can be constructed
const int cMulticomponent = 200;
const int CK_Multicomponent = 202;
const int CK_Multicomponent = 202;
const int cMixtureAveraged = 210;
const int CK_MixtureAveraged = 211;
const int cSolidTransport = 300;
const int cDustyGasTransport = 400;
const int cUserTransport = 500;
const int cFtnTransport = 600;
const int CK_MixtureAveraged = 211;
const int cSolidTransport = 300;
const int cDustyGasTransport = 400;
const int cUserTransport = 500;
const int cFtnTransport = 600;
class XML_Writer;
@ -91,10 +73,15 @@ namespace Cantera {
/**
* Returns an integer index number.
* Returns an integer index number. This is for internal use
* of Cantera, and may be removed in the future.
*/
int index() { return m_index; }
/**
* Set an integer index number. This is for internal use of
* Cantera, and may be removed in the future.
*/
void setIndex(int i) { m_index = i; }
@ -113,19 +100,10 @@ namespace Cantera {
/**
* The bulk viscosity in Pa-s. The contribution of the bulk
* viscosity to the stress tensor is usually negligible, since
* it multiplies \f$ \nabla\cdot{\bf v}.\f$ Therefore, it does
* not contribute to the stress in incompressible fluids;
* furthermore, kinetic theory shows that it is zero for ideal
* gas mixtures under typical conditions. It does influence
* certain aspects of sound propagation in liquids, and so it
* is included here. Most transport managers are likely to not
* implement this method (in which case an exception is thrown
* if it is invoked), or else return zero. Nevertheless, for
* applications where bulk viscosity is important, it is
* possible to create a transport manager that computes it by
* overloading this method.
* The bulk viscosity in Pa-s. The bulk viscosity is only
* non-zero in rare cases. Most transport managers either
* overload this method to return zero, or do not implement
* it, in which case an exception is thrown if called.
*/
virtual doublereal bulkViscosity()
{ return err("bulkViscosity"); }
@ -144,7 +122,9 @@ namespace Cantera {
{ return err("electricalConductivity"); }
/**
* Electrical mobilities. Units: [m^2/V/s].
* Electrical mobilities (m^2/V/s). Returns the mobilities of
* the species in array \c mobil. The array must be
* dimensioned at least as large as the number of species.
*/
virtual void getMobilities(doublereal* mobil)
{ err("getMobilities"); }
@ -161,8 +141,21 @@ namespace Cantera {
int ldf, doublereal* fluxes) { err("getSpeciesFluxes"); }
/**
* Get the molar fluxes [kmol/m^2/s], given the thermodynamic
* state at two nearby points. @param state1 Array of
* temperature, density, and mass fractions for state 1.
* @param state2 Array of temperature, density, and mass
* fractions for state 2. @param delta Distance from state 1
* to state 2 (m).
*/
virtual void getMolarFluxes(const doublereal* state1,
const doublereal* state2, doublereal delta,
doublereal* fluxes) { err("getMolarFluxes"); }
/**
* Thermal diffusion coefficients. Units: [kg/m/sec].
* Thermal diffusion coefficients [kg/m/sec].
* The thermal diffusion coefficient \f$ D^T_k \f$ is defined
* so that the diffusive mass flux of species k induced by the
* local temperature gradient is \f[ M_k J_k = -D^T_k \nabla
@ -178,7 +171,7 @@ namespace Cantera {
/**
* Binary diffusion coefficients. Units: [m^2/s].
* Binary diffusion coefficients [m^2/s].
*/
virtual void getBinaryDiffCoeffs(int ld, doublereal* d)
{ err("getBinaryDiffCoeffs"); }
@ -188,28 +181,22 @@ namespace Cantera {
* Multicomponent diffusion coefficients. Units: [m^2/s]. If
* the transport manager implements a multicomponent diffusion
* model, then this method returns the array of multicomponent
* diffusion coefficients.
* diffusion coefficients. Otherwise it throws an exception.
*/
virtual void getMultiDiffCoeffs(int ld, doublereal* d)
{ err("getMultiDiffCoeffs"); }
/**
* Mixture-averaged diffusion coefficients. Units: [m^2/s].
* If the transport manager implements a mixture-averaged
* diffusion model, then this method returns the array of
* mixture-averaged diffusion coefficients.
* Mixture-averaged diffusion coefficients [m^2/s]. If the
* transport manager implements a mixture-averaged diffusion
* model, then this method returns the array of
* mixture-averaged diffusion coefficients. Otherwise it
* throws an exception.
*/
virtual void getMixDiffCoeffs(doublereal* d)
{ err("getMixDiffCoeffs"); }
#ifdef INCL_CBAR
doublereal meanThermalSpeed(int k) const {
doublereal t = m_thermo->temperature();
doublereal mw = m_thermo->molecularWeight(k);
return sqrt(8.0 * GasConstant * t /(Pi * mw));
}
#endif
/**
* Set transport model parameters. This method may be
@ -222,7 +209,6 @@ namespace Cantera {
friend class TransportFactory;
/**
* Constructor. New transport managers should be created using
* TransportFactory, not by calling the constructor directly.
@ -241,7 +227,7 @@ namespace Cantera {
*/
/**
* called by TransportFactory to set parameters.
* Called by TransportFactory to set parameters.
*/
virtual bool init(TransportParams& tr)
{ err("init"); return false; }
@ -250,16 +236,8 @@ namespace Cantera {
/**
* Set the phase object.
*/
void setThermo(thermo_t& thermo) {
if (!ready()) {
m_thermo = &thermo;
m_nmin = m_thermo->nSpecies();
}
else
throw CanteraError("Transport::setThermo",
"the phase object cannot be changed after "
"the transport manager has been constructed.");
}
void setThermo(thermo_t& thermo);
/**
* Enable for use. Once finalize() has been called, the
@ -267,19 +245,14 @@ namespace Cantera {
* transport property, and no further modifications to the
* model parameters should be made.
*/
void finalize() {
if (!ready())
m_ready = true;
else
throw CanteraError("Transport::finalize",
"finalize has already been called.");
}
void finalize();
//@}
thermo_t* m_thermo; ///< pointer to the object representing the phase
bool m_ready; ///< true if finalize has been called
size_t m_nmin; ///< number of species
bool m_ready; ///< true if finalize has been called
size_t m_nmin; ///< number of species
int m_index;
@ -297,16 +270,14 @@ namespace Cantera {
* method, the base class method will be called, resulting in
* an exception being thrown.
*/
doublereal err(string msg) const {
throw NotImplemented(msg);
return 0.0;
}
doublereal err(string msg) const;
};
typedef Transport transport_t;
}
#endif

View file

@ -13,6 +13,7 @@
#pragma warning(disable:4503)
#endif
#include "../ThermoPhase.h"
// known transport models
#include "MultiTransport.h"
@ -60,6 +61,13 @@ namespace Cantera {
};
class NotImplemented : public CanteraError {
public:
NotImplemented(string method) : CanteraError("Transport",
"\n\n\n**** Method "+method+" not implemented. ****\n"
"(Did you forget to specify a transport model?)\n\n\n") {}
};
/////////////////////////// constants //////////////////////////
@ -68,6 +76,31 @@ namespace Cantera {
const doublereal FiveThirds = 5.0/3.0;
//////////////////// class Transport methods /////////////////////
void Transport::setThermo(thermo_t& thermo) {
if (!ready()) {
m_thermo = &thermo;
m_nmin = m_thermo->nSpecies();
}
else
throw CanteraError("Transport::setThermo",
"the phase object cannot be changed after "
"the transport manager has been constructed.");
}
void Transport::finalize() {
if (!ready())
m_ready = true;
else
throw CanteraError("Transport::finalize",
"finalize has already been called.");
}
doublereal Transport::err(string msg) const {
throw NotImplemented(msg);
return 0.0;
}
//////////////////// class TransportFactory methods //////////////