[Transport] Replace transport_log.xml with regular text logging

Write plain text to the common Cantera logger to be more consistent with the
verbose/debug logging from other parts of Cantera. This simplifies several of
the transport initialization functions, and eliminates the need for class
XML_Writer.
This commit is contained in:
Ray Speth 2014-06-20 18:44:59 +00:00
parent 284c0d0345
commit a470502932
15 changed files with 120 additions and 390 deletions

View file

@ -1,121 +0,0 @@
#ifndef CT_XML_WRITER
#define CT_XML_WRITER
// Note: this class is only used by TransportFactory, and is likely to
// go away a a future date.
#include <iostream>
namespace Cantera
{
////////////////////// XML_Writer //////////////////////////
class XML_Writer
{
public:
XML_Writer(std::ostream& output_) :
m_s(output_), _indent(" "), _level(0) {}
virtual ~XML_Writer() {}
std::ostream& m_s;
std::string _indent;
int _level;
std::ostream& output() {
return m_s;
}
std::string XML_filter(const std::string& name) {
int ns = static_cast<int>(name.size());
std::string nm(name);
for (int m = 0; m < ns; m++)
if (name[m] == ' '
|| name[m] == '('
|| name[m] == ')') {
nm[m] = '_';
}
return nm;
}
/**
* XML_comment()
*
* Add a comment element to the current XML output file
* Comment elements start with <!-- and end with -->
* Comments are indented according to the current lvl,
* _level
*
* input
* ---------
* s : Output stream containing the XML file
* comment : Reference to a string containing the comment
*/
void XML_comment(std::ostream& s, const std::string& comment) {
for (int n = 0; n < _level; n++) {
s << _indent;
}
s << "<!--" << comment << "-->" << std::endl;
}
void XML_open(std::ostream& s, const std::string& tag, const std::string& p = "") {
for (int n = 0; n < _level; n++) {
s << _indent;
}
_level++;
s << "<" << XML_filter(tag) << p << ">" << std::endl;
}
void XML_close(std::ostream& s, const std::string& tag) {
_level--;
for (int n = 0; n < _level; n++) {
s << _indent;
}
s << "</" << XML_filter(tag) << ">" << std::endl;
}
template<class T>
void XML_item(std::ostream& s, const std::string& tag, T value) {
for (int n = 0; n < _level; n++) {
s << _indent;
}
s << "<" << XML_filter(tag) << ">"
<< value << "</" << tag << ">" << std::endl;
}
template<class iter>
void XML_writeVector(std::ostream& s, const std::string& indent,
const std::string& name, size_t vsize, iter v) {
int ni;
for (ni = 0; ni < _level; ni++) {
s << _indent;
}
s << "<" << XML_filter(name) << "> ";
size_t n = vsize;
size_t n5 = n/5;
size_t i, j, k = 0;
for (j = 0; j < n5; j++) {
for (i = 0; i < 5; i++) {
s << v[k] << (k+1 < n ? ", " : "");
k++;
}
if (j+1 < n5) {
s << std::endl;
for (ni = 0; ni < _level; ni++) {
s << _indent;
}
}
}
for (i = k; i < n; i++) {
s << v[k] << (k+1 < n ? ", " : "");
k++;
}
s << "</" << XML_filter(name) << ">" << std::endl;
}
};
}
#endif

View file

@ -37,6 +37,15 @@ std::string int2str(const int n, const std::string& fmt="%d");
*/
std::string int2str(const size_t n);
//! Convert a vector to a string (separated by commas)
/*!
* @param v vector to be converted
* @param fmt Format to be used (printf style) for each element
* @param sep Separator
*/
std::string vec2str(const vector_fp& v, const std::string& fmt="%g",
const std::string& sep=", ");
//! Strip the leading and trailing white space from a string
/*!
* The command isprint() is used to determine printable characters.

View file

@ -12,7 +12,6 @@
#include "TransportParams.h"
#include "LiquidTransportData.h"
#include "cantera/base/xml.h"
#include "cantera/base/XML_Writer.h"
namespace Cantera
{

View file

@ -11,7 +11,6 @@
#include "LiquidTransportData.h"
#include "LiquidTranInteraction.h"
#include "cantera/base/xml.h"
#include "cantera/base/XML_Writer.h"
namespace Cantera
{

View file

@ -97,9 +97,6 @@ protected:
//! Minimum temperatures for parameter fits
// doublereal tmin;
//! Pointer to the xml tree describing the implementation of transport for this object
// XML_Writer* xml;
//! Log level
// int log_level;

View file

@ -57,9 +57,6 @@ const int cWaterTransport = 721;
const int cPecosTransport = 900;
//! \endcond
// forward reference
class XML_Writer;
//! The diffusion fluxes must be referenced to a particular reference
//! fluid velocity.
/*!

View file

@ -126,9 +126,6 @@ public:
* @param mode Chemkin compatible mode or not. This alters the specification of the
* collision integrals. defaults to no.
* @param log_level Defaults to zero, no logging
*
* In DEBUG_MODE, this routine will create the file transport_log.xml
* and write informative information to it.
*/
virtual void initTransport(Transport* tr, thermo_t* thermo, int mode=0, int log_level=0);
@ -141,9 +138,6 @@ public:
* @param tr Pointer to the Transport manager
* @param thermo Pointer to the ThermoPhase object
* @param log_level Defaults to zero, no logging
*
* In DEBUG_MODE, this routine will create the file transport_log.xml
* and write informative information to it.
*/
virtual void initLiquidTransport(Transport* tr, thermo_t* thermo, int log_level=0);
@ -157,9 +151,6 @@ private:
* @param tr Pointer to the Transport manager
* @param thermo Pointer to the ThermoPhase object
* @param log_level Defaults to zero, no logging
*
* In DEBUG_MODE, this routine will create the file transport_log.xml
* and write informative information to it.
*/
virtual void initSolidTransport(Transport* tr, thermo_t* thermo, int log_level=0);
@ -274,21 +265,16 @@ private:
* \f]
*
* @param tr Reference to the GasTransportParams object that will contain the results.
* @param logfile Reference to an ostream that will contain log information when in
* DEBUG_MODE
* @param integrals interpolator for the collision integrals
*/
void fitProperties(GasTransportParams& tr, MMCollisionInt& integrals,
std::ostream& logfile);
void fitProperties(GasTransportParams& tr, MMCollisionInt& integrals);
//! Generate polynomial fits to collision integrals
/*!
* @param logfile Reference to an ostream that will contain log information when in
* DEBUG_MODE
* @param tr Reference to the GasTransportParams object that will contain the results.
* @param integrals interpolator for the collision integrals
*/
void fitCollisionIntegrals(std::ostream& logfile, GasTransportParams& tr,
void fitCollisionIntegrals(GasTransportParams& tr,
MMCollisionInt& integrals);
//! Prepare to build a new kinetic-theory-based transport manager for low-density gases
@ -297,7 +283,6 @@ private:
*
* Uses polynomial fits to Monchick & Mason collision integrals. store then in tr
*
* @param flog Reference to the ostream for writing log info
* @param transport_database Reference to a vector of pointers containing the
* transport database for each species
* @param thermo Pointer to the %ThermoPhase object
@ -306,27 +291,25 @@ private:
* @param log_level log level
* @param tr GasTransportParams structure to be filled up with information
*/
void setupMM(std::ostream& flog, const std::vector<const XML_Node*> &transport_database,
void setupMM(const std::vector<const XML_Node*> &transport_database,
thermo_t* thermo, int mode, int log_level, GasTransportParams& tr);
//! Prepare to build a new transport manager for liquids assuming that
//! viscosity transport data is provided in Arrhenius form.
/*!
* @param flog Reference to the ostream for writing log info
* @param thermo Pointer to the %ThermoPhase object
* @param log_level log level
* @param trParam LiquidTransportParams structure to be filled up with information
*/
void setupLiquidTransport(std::ostream& flog, thermo_t* thermo, int log_level, LiquidTransportParams& trParam);
void setupLiquidTransport(thermo_t* thermo, int log_level, LiquidTransportParams& trParam);
//! Prepare to build a new transport manager for solids
/*!
* @param flog Reference to the ostream for writing log info
* @param thermo Pointer to the %ThermoPhase object
* @param log_level log level
* @param trParam SolidTransportData structure to be filled up with information
*/
void setupSolidTransport(std::ostream& flog, thermo_t* thermo, int log_level, SolidTransportData& trParam);
void setupSolidTransport(thermo_t* thermo, int log_level, SolidTransportData& trParam);
//! Second-order correction to the binary diffusion coefficients
/*!

View file

@ -13,8 +13,6 @@
namespace Cantera
{
class XML_Writer;
//! Base structure to hold transport model parameters.
/*!
* This structure is used by TransportFactory.
@ -52,9 +50,6 @@ public:
//! Mode parameter
int mode_;
//! Pointer to the xml tree describing the implementation of transport for this object
XML_Writer* xml;
//! Log level
int log_level;
};

View file

@ -37,7 +37,7 @@ t = ThermoPhase(node);
k = Kinetics(node,t);
s.kin = k;
s.th = t;
tr = Transport(node,t,'default',4);
tr = Transport(node,t,'default',0);
s.tr = tr;
s = class(s,'Solution',t,k,tr);

View file

@ -55,6 +55,22 @@ std::string int2str(const size_t n)
return ss.str();
}
std::string vec2str(const vector_fp& v, const std::string& fmt,
const std::string& sep)
{
char buf[64];
std::stringstream o;
for (size_t i = 0; i < v.size(); i++) {
SNPRINTF(buf, 63, fmt.c_str(), v[i]);
o << v[i];
if (i != v.size() - 1) {
o << sep;
}
}
return o.str();
}
std::string lowercase(const std::string& s)
{
std::string lc(s);

View file

@ -6,8 +6,8 @@
#include "MMCollisionInt.h"
#include "cantera/base/utilities.h"
#include "cantera/numerics/polyfit.h"
#include "cantera/base/xml.h"
#include "cantera/base/XML_Writer.h"
#include "cantera/base/stringUtils.h"
#include "cantera/base/global.h"
#include <cstdio>
@ -224,24 +224,12 @@ MMCollisionInt::~MMCollisionInt()
{
}
void MMCollisionInt::init(XML_Writer* xml, doublereal tsmin, doublereal tsmax, int log_level)
void MMCollisionInt::init(doublereal tsmin, doublereal tsmax, int log_level)
{
ostream* logfile = 0;
if (DEBUG_MODE_ENABLED) {
if (!xml) {
throw CanteraError("MMCollisionInt::init", "pointer to xml file is zero");
}
logfile = &xml->output();
m_xml = xml;
} else {
m_xml = 0;
log_level = 0;
}
m_loglevel = log_level;
if (DEBUG_MODE_ENABLED && m_loglevel > 0) {
m_xml->XML_comment(*logfile, "Collision Integral Polynomial Fits");
writelog("Collision Integral Polynomial Fits\n");
}
char p[200];
m_nmin = -1;
m_nmax = -1;
@ -258,76 +246,61 @@ void MMCollisionInt::init(XML_Writer* xml, doublereal tsmin, doublereal tsmax, i
m_nmax = 36;
}
if (DEBUG_MODE_ENABLED && m_loglevel > 0) {
m_xml->XML_item(*logfile, "Tstar_min", tstar[m_nmin + 1]);
m_xml->XML_item(*logfile, "Tstar_max", tstar[m_nmax + 1]);
writelogf("T*_min = %g\n", tstar[m_nmin + 1]);
writelogf("T*_max = %g\n", tstar[m_nmax + 1]);
}
m_logTemp.resize(37);
doublereal rmserr, e22 = 0.0, ea = 0.0, eb = 0.0, ec = 0.0;
if (DEBUG_MODE_ENABLED && m_loglevel > 0) {
m_xml->XML_open(*logfile, "dstar_fits");
m_xml->XML_comment(*logfile, "Collision integral fits at each "
"tabulated T* vs. delta*.\n"
"These polynomial fits are used to interpolate between "
"columns (delta*)\n in the Monchick and Mason tables."
" They are only used for nonzero delta*.");
writelog("Collision integral fits at each tabulated T* vs. delta*.\n"
"These polynomial fits are used to interpolate between "
"columns (delta*)\n in the Monchick and Mason tables."
" They are only used for nonzero delta*.\n");
if (log_level < 4) {
m_xml->XML_comment(*logfile,
"polynomial coefficients not printed (log_level < 4)");
writelog("polynomial coefficients not printed (log_level < 4)\n");
}
}
string indent = " ";
for (int i = 0; i < 37; i++) {
m_logTemp[i] = log(tstar[i+1]);
vector_fp c(DeltaDegree+1);
rmserr = fitDelta(0, i, DeltaDegree, DATA_PTR(c));
if (DEBUG_MODE_ENABLED && log_level > 3) {
sprintf(p, " Tstar=\"%12.6g\"", tstar[i+1]);
m_xml->XML_open(*logfile, "dstar_fit", p);
m_xml->XML_item(*logfile, "Tstar", tstar[i+1]);
m_xml->XML_writeVector(*logfile, indent, "omega22",
c.size(), DATA_PTR(c));
writelogf("\ndelta* fit at T* = %.6g\n", tstar[i+1]);
writelog("omega22 = [" + vec2str(c) + "]\n");
}
m_o22poly.push_back(c);
e22 = std::max(e22, rmserr);
rmserr = fitDelta(1, i, DeltaDegree, DATA_PTR(c));
m_apoly.push_back(c);
if (DEBUG_MODE_ENABLED && log_level > 3)
m_xml->XML_writeVector(*logfile, indent, "astar",
c.size(), DATA_PTR(c));
if (DEBUG_MODE_ENABLED && log_level > 3) {
writelog("A* = [" + vec2str(c) + "]\n");
}
ea = std::max(ea, rmserr);
rmserr = fitDelta(2, i, DeltaDegree, DATA_PTR(c));
m_bpoly.push_back(c);
if (DEBUG_MODE_ENABLED && log_level > 3)
m_xml->XML_writeVector(*logfile, indent, "bstar",
c.size(), DATA_PTR(c));
if (DEBUG_MODE_ENABLED && log_level > 3) {
writelog("B* = [" + vec2str(c) + "]\n");
}
eb = std::max(eb, rmserr);
rmserr = fitDelta(3, i, DeltaDegree, DATA_PTR(c));
m_cpoly.push_back(c);
if (DEBUG_MODE_ENABLED && log_level > 3) {
m_xml->XML_writeVector(*logfile, indent, "cstar",
c.size(), DATA_PTR(c));
writelog("C* = [" + vec2str(c) + "]\n");
}
ec = std::max(ec, rmserr);
if (DEBUG_MODE_ENABLED && log_level > 3) {
m_xml->XML_close(*logfile, "dstar_fit");
}
if (DEBUG_MODE_ENABLED && log_level > 0) {
sprintf(p,
"max RMS errors in fits vs. delta*:\n"
" omega_22 = %12.6g \n"
" A* = %12.6g \n"
" B* = %12.6g \n"
" C* = %12.6g \n", e22, ea, eb, ec);
m_xml->XML_comment(*logfile, p);
m_xml->XML_close(*logfile, "dstar_fits");
writelogf("max RMS errors in fits vs. delta*:\n"
" omega_22 = %12.6g \n"
" A* = %12.6g \n"
" B* = %12.6g \n"
" C* = %12.6g \n", e22, ea, eb, ec);
}
}
}
@ -457,12 +430,11 @@ doublereal MMCollisionInt::cstar(double ts, double deltastar)
DATA_PTR(values));
}
void MMCollisionInt::fit_omega22(ostream& logfile, int degree,
doublereal deltastar, doublereal* o22)
void MMCollisionInt::fit_omega22(int degree, doublereal deltastar,
doublereal* o22)
{
int i, n = m_nmax - m_nmin + 1;
int ndeg=0;
string indent = " ";
vector_fp values(n);
doublereal rmserr;
vector_fp w(n);
@ -478,20 +450,16 @@ void MMCollisionInt::fit_omega22(ostream& logfile, int degree,
rmserr = polyfit(n, logT, DATA_PTR(values),
DATA_PTR(w), degree, ndeg, 0.0, o22);
if (DEBUG_MODE_ENABLED && m_loglevel > 0 && rmserr > 0.01) {
char p[100];
sprintf(p, "Warning: RMS error = %12.6g in omega_22 fit"
"with delta* = %12.6g\n", rmserr, deltastar);
m_xml->XML_comment(logfile, p);
writelogf("Warning: RMS error = %12.6g in omega_22 fit"
"with delta* = %12.6g\n", rmserr, deltastar);
}
}
void MMCollisionInt::fit(ostream& logfile, int degree,
doublereal deltastar, doublereal* a, doublereal* b, doublereal* c)
void MMCollisionInt::fit(int degree, doublereal deltastar,
doublereal* a, doublereal* b, doublereal* c)
{
int i, n = m_nmax - m_nmin + 1;
int ndeg=0;
//char s[100];
string indent = " ";
vector_fp values(n);
doublereal rmserr;
vector_fp w(n);
@ -529,29 +497,22 @@ void MMCollisionInt::fit(ostream& logfile, int degree,
rmserr = polyfit(n, logT, DATA_PTR(values),
DATA_PTR(w), degree, ndeg, 0.0, c);
if (DEBUG_MODE_ENABLED && m_loglevel > 2) {
char p[100];
sprintf(p, " dstar=\"%12.6g\"", deltastar);
m_xml->XML_open(logfile, "tstar_fit", p);
writelogf("\nT* fit at delta* = %.6g\n", deltastar);
m_xml->XML_writeVector(logfile, indent, "astar", degree+1, a);
writelog("astar = [" + vec2str(vector_fp(a, a+degree+1))+ "]\n");
if (rmserr > 0.01) {
sprintf(p, "Warning: RMS error = %12.6g for A* fit", rmserr);
m_xml->XML_comment(logfile, p);
writelogf("Warning: RMS error = %12.6g for A* fit\n", rmserr);
}
m_xml->XML_writeVector(logfile, indent, "bstar", degree+1, b);
writelog("bstar = [" + vec2str(vector_fp(b, b+degree+1))+ "]\n");
if (rmserr > 0.01) {
sprintf(p, "Warning: RMS error = %12.6g for B* fit", rmserr);
m_xml->XML_comment(logfile, p);
writelogf("Warning: RMS error = %12.6g for B* fit\n", rmserr);
}
m_xml->XML_writeVector(logfile, indent, "cstar", degree+1, c);
writelog("cstar = [" + vec2str(vector_fp(c, c+degree+1))+ "]\n");
if (rmserr > 0.01) {
sprintf(p, "Warning: RMS error = %12.6g for C* fit", rmserr);
m_xml->XML_comment(logfile, p);
writelogf("Warning: RMS error = %12.6g for C* fit\n", rmserr);
}
m_xml->XML_close(logfile, "tstar_fit");
}
}

View file

@ -12,8 +12,6 @@
namespace Cantera
{
class XML_Writer;
//! Calculation of Collision integrals
/*!
* This class provides functions that
@ -30,22 +28,20 @@ public:
//! Initialize the object for calculation
/*!
* @param xml Pointer to the log file that will receive the debug
* output messages
* @param tsmin Minimum value of Tstar to carry out the fitting
* @param tsmax Maximum value of Tstar to carry out the fitting
* @param loglevel Set the loglevel for the object. The default
* loglevel is zero, indicating no output.
*/
void init(XML_Writer* xml, doublereal tsmin, doublereal tsmax, int loglevel = 0);
void init(doublereal tsmin, doublereal tsmax, int loglevel = 0);
doublereal omega22(double ts, double deltastar);
doublereal astar(double ts, double deltastar);
doublereal bstar(double ts, double deltastar);
doublereal cstar(double ts, double deltastar);
void fit(std::ostream& logfile, int degree, doublereal deltastar,
void fit(int degree, doublereal deltastar,
doublereal* astar, doublereal* bstar, doublereal* cstar);
void fit_omega22(std::ostream& logfile, int degree, doublereal deltastar, doublereal* om22);
void fit_omega22(int degree, doublereal deltastar, doublereal* om22);
doublereal omega11(double ts, double deltastar) {
return omega22(ts, deltastar)/astar(ts, deltastar);
}
@ -89,9 +85,6 @@ private:
int m_nmax;
//! XML_Writer pointer
XML_Writer* m_xml;
//! loglevel
int m_loglevel;
};

View file

@ -21,7 +21,6 @@
#include "MMCollisionInt.h"
#include "cantera/base/xml.h"
#include "cantera/base/XML_Writer.h"
#include "cantera/transport/TransportParams.h"
#include "cantera/transport/LiquidTransportParams.h"
#include "cantera/transport/LiquidTranInteraction.h"
@ -410,7 +409,7 @@ Transport* TransportFactory::newTransport(thermo_t* phase, int log_level)
return newTransport(transportModel, phase,log_level);
}
void TransportFactory::setupMM(std::ostream& flog, const std::vector<const XML_Node*> &transport_database,
void TransportFactory::setupMM(const std::vector<const XML_Node*> &transport_database,
thermo_t* thermo, int mode, int log_level, GasTransportParams& tr)
{
@ -502,25 +501,25 @@ void TransportFactory::setupMM(std::ostream& flog, const std::vector<const XML_N
// initialize the collision integral calculator for the desired
// T* range
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_open(flog, "collision_integrals");
writelog("*** collision_integrals ***\n");
}
MMCollisionInt integrals;
integrals.init(tr.xml, tstar_min, tstar_max, log_level);
fitCollisionIntegrals(flog, tr, integrals);
integrals.init(tstar_min, tstar_max, log_level);
fitCollisionIntegrals(tr, integrals);
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_close(flog, "collision_integrals");
writelog("*** end of collision_integrals ***\n");
}
// make polynomial fits
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_open(flog, "property fits");
writelog("*** property fits ***\n");
}
fitProperties(tr, integrals, flog);
fitProperties(tr, integrals);
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_close(flog, "property fits");
writelog("*** end of property fits ***\n");
}
}
void TransportFactory::setupLiquidTransport(std::ostream& flog, thermo_t* thermo, int log_level,
void TransportFactory::setupLiquidTransport(thermo_t* thermo, int log_level,
LiquidTransportParams& trParam)
{
@ -564,7 +563,7 @@ void TransportFactory::setupLiquidTransport(std::ostream& flog, thermo_t* thermo
}
void TransportFactory::setupSolidTransport(std::ostream& flog, thermo_t* thermo, int log_level,
void TransportFactory::setupSolidTransport(thermo_t* thermo, int log_level,
SolidTransportData& trParam)
{
const XML_Node* phase_database = &thermo->xml();
@ -602,31 +601,13 @@ void TransportFactory::initTransport(Transport* tran,
const std::vector<const XML_Node*> & transport_database = thermo->speciesData();
GasTransportParams trParam;
#ifdef DEBUG_MODE
if (log_level == 0) {
m_verbose = 0;
}
ofstream flog("transport_log.xml");
trParam.xml = new XML_Writer(flog);
if (m_verbose) {
trParam.xml->XML_open(flog, "transport");
}
#else
// create the object, but don't associate it with a file
std::ostream& flog(std::cout);
#endif
// set up Monchick and Mason collision integrals
setupMM(flog, transport_database, thermo, mode, log_level, trParam);
setupMM(transport_database, thermo, mode, log_level, trParam);
// do model-specific initialization
tran->initGas(trParam);
#ifdef DEBUG_MODE
if (m_verbose) {
trParam.xml->XML_close(flog, "transport");
}
// finished with log file
flog.close();
#endif
return;
}
void TransportFactory::initLiquidTransport(Transport* tran,
@ -634,27 +615,9 @@ void TransportFactory::initLiquidTransport(Transport* tran,
int log_level)
{
LiquidTransportParams trParam;
#ifdef DEBUG_MODE
ofstream flog("transport_log.xml");
trParam.xml = new XML_Writer(flog);
if (m_verbose) {
trParam.xml->XML_open(flog, "transport");
}
#else
// create the object, but don't associate it with a file
std::ostream& flog(std::cout);
#endif
setupLiquidTransport(flog, thermo, log_level, trParam);
setupLiquidTransport(thermo, log_level, trParam);
// do model-specific initialization
tran->initLiquid(trParam);
#ifdef DEBUG_MODE
if (m_verbose) {
trParam.xml->XML_close(flog, "transport");
}
// finished with log file
flog.close();
#endif
return;
}
void TransportFactory::initSolidTransport(Transport* tran,
@ -662,38 +625,13 @@ void TransportFactory::initSolidTransport(Transport* tran,
int log_level)
{
SolidTransportData trParam;
//setup output
#ifdef DEBUG_MODE
ofstream flog("transport_log.xml");
trParam.xml = new XML_Writer(flog);
if (m_verbose) {
trParam.xml->XML_open(flog, "transport");
}
#else
// create the object, but don't associate it with a file
std::ostream& flog(std::cout);
#endif
//real work next two statements
setupSolidTransport(flog, thermo, log_level, trParam);
setupSolidTransport(thermo, log_level, trParam);
// do model-specific initialization
tran->initSolid(trParam);
#ifdef DEBUG_MODE
if (m_verbose) {
trParam.xml->XML_close(flog, "transport");
}
// finished with log file
flog.close();
#endif
return;
}
void TransportFactory::fitCollisionIntegrals(ostream& logfile,
GasTransportParams& tr,
MMCollisionInt& integrals)
void TransportFactory::fitCollisionIntegrals(GasTransportParams& tr,
MMCollisionInt& integrals)
{
vector_fp::iterator dptr;
doublereal dstar;
@ -704,11 +642,11 @@ void TransportFactory::fitCollisionIntegrals(ostream& logfile,
// Chemkin fits to sixth order polynomials
int degree = (mode == CK_Mode ? 6 : COLL_INT_POLY_DEGREE);
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_open(logfile, "tstar_fits");
tr.xml->XML_comment(logfile, "fits to A*, B*, and C* vs. log(T*).\n"
"These are done only for the required dstar(j,k) values.");
writelog("tstar_fits\n"
"fits to A*, B*, and C* vs. log(T*).\n"
"These are done only for the required dstar(j,k) values.\n\n");
if (tr.log_level < 3) {
tr.xml->XML_comment(logfile, "*** polynomial coefficients not printed (log_level < 3) ***");
writelog("*** polynomial coefficients not printed (log_level < 3) ***\n");
}
}
for (i = 0; i < nsp; i++) {
@ -730,9 +668,9 @@ void TransportFactory::fitCollisionIntegrals(ostream& logfile,
if (dptr == tr.fitlist.end()) {
vector_fp ca(degree+1), cb(degree+1), cc(degree+1);
vector_fp co22(degree+1);
integrals.fit(logfile, degree, dstar,
integrals.fit(degree, dstar,
DATA_PTR(ca), DATA_PTR(cb), DATA_PTR(cc));
integrals.fit_omega22(logfile, degree, dstar,
integrals.fit_omega22(degree, dstar,
DATA_PTR(co22));
tr.omega22_poly.push_back(co22);
tr.astar_poly.push_back(ca);
@ -750,9 +688,6 @@ void TransportFactory::fitCollisionIntegrals(ostream& logfile,
tr.poly[j][i] = tr.poly[i][j];
}
}
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_close(logfile, "tstar_fits");
}
}
void TransportFactory::getTransportData(const std::vector<const XML_Node*> &xspecies,
@ -1156,7 +1091,7 @@ void TransportFactory::getSolidTransportData(const XML_Node& transportNode,
}
void TransportFactory::fitProperties(GasTransportParams& tr,
MMCollisionInt& integrals, std::ostream& logfile)
MMCollisionInt& integrals)
{
doublereal tstar;
int ndeg = 0;
@ -1186,23 +1121,18 @@ void TransportFactory::fitProperties(GasTransportParams& tr,
// fit the pure-species viscosity and thermal conductivity for
// each species
if (DEBUG_MODE_ENABLED && tr.log_level < 2 && m_verbose) {
tr.xml->XML_comment(logfile,
"*** polynomial coefficients not printed (log_level < 2) ***");
writelog("*** polynomial coefficients not printed (log_level < 2) ***\n");
}
doublereal sqrt_T, visc, err, relerr,
mxerr = 0.0, mxrelerr = 0.0, mxerr_cond = 0.0, mxrelerr_cond = 0.0;
if (DEBUG_MODE_ENABLED && m_verbose) {
tr.xml->XML_open(logfile, "viscosity");
tr.xml->XML_comment(logfile,"Polynomial fits for viscosity");
writelog("Polynomial fits for viscosity:\n");
if (mode == CK_Mode) {
tr.xml->XML_comment(logfile,"log(viscosity) fit to cubic "
"polynomial in log(T)");
writelog("log(viscosity) fit to cubic polynomial in log(T)\n");
} else {
char s[100];
sprintf(s, "viscosity/sqrt(T) fit to "
"polynomial of degree %d in log(T)",degree);
tr.xml->XML_comment(logfile,s);
writelogf("viscosity/sqrt(T) fit to polynomial of degree "
"%d in log(T)", degree);
}
}
@ -1317,51 +1247,34 @@ void TransportFactory::fitProperties(GasTransportParams& tr,
tr.condcoeffs.push_back(c2);
if (DEBUG_MODE_ENABLED && tr.log_level >= 2 && m_verbose) {
tr.xml->XML_writeVector(logfile, " ", tr.thermo->speciesName(k),
c.size(), DATA_PTR(c));
writelog(tr.thermo->speciesName(k) + ": [" + vec2str(c) + "]\n");
}
}
if (DEBUG_MODE_ENABLED && m_verbose) {
char s[100];
sprintf(s, "Maximum viscosity absolute error: %12.6g", mxerr);
tr.xml->XML_comment(logfile,s);
sprintf(s, "Maximum viscosity relative error: %12.6g", mxrelerr);
tr.xml->XML_comment(logfile,s);
tr.xml->XML_close(logfile, "viscosity");
writelogf("Maximum viscosity absolute error: %12.6g\n", mxerr);
writelogf("Maximum viscosity relative error: %12.6g\n", mxrelerr);
tr.xml->XML_open(logfile, "conductivity");
tr.xml->XML_comment(logfile,"Polynomial fits for conductivity");
writelog("\nPolynomial fits for conductivity:\n");
if (mode == CK_Mode)
tr.xml->XML_comment(logfile,"log(conductivity) fit to cubic "
"polynomial in log(T)");
writelog("log(conductivity) fit to cubic polynomial in log(T)");
else {
sprintf(s, "conductivity/sqrt(T) fit to "
"polynomial of degree %d in log(T)",degree);
tr.xml->XML_comment(logfile,s);
writelogf("conductivity/sqrt(T) fit to "
"polynomial of degree %d in log(T)", degree);
}
if (tr.log_level >= 2)
for (size_t k = 0; k < tr.nsp_; k++) {
tr.xml->XML_writeVector(logfile, " ", tr.thermo->speciesName(k),
degree+1, DATA_PTR(tr.condcoeffs[k]));
writelog(tr.thermo->speciesName(k) + ": [" +
vec2str(tr.condcoeffs[k]) + "]\n");
}
sprintf(s, "Maximum conductivity absolute error: %12.6g", mxerr_cond);
tr.xml->XML_comment(logfile,s);
sprintf(s, "Maximum conductivity relative error: %12.6g", mxrelerr_cond);
tr.xml->XML_comment(logfile,s);
tr.xml->XML_close(logfile, "conductivity");
writelogf("Maximum conductivity absolute error: %12.6g\n", mxerr_cond);
writelogf("Maximum conductivity relative error: %12.6g\n", mxrelerr_cond);
// fit the binary diffusion coefficients for each species pair
tr.xml->XML_open(logfile, "binary_diffusion_coefficients");
tr.xml->XML_comment(logfile, "binary diffusion coefficients");
writelogf("\nbinary diffusion coefficients:\n");
if (mode == CK_Mode)
tr.xml->XML_comment(logfile,"log(D) fit to cubic "
"polynomial in log(T)");
writelog("log(D) fit to cubic polynomial in log(T)");
else {
sprintf(s, "D/T**(3/2) fit to "
"polynomial of degree %d in log(T)",degree);
tr.xml->XML_comment(logfile,s);
writelogf("D/T**(3/2) fit to polynomial of degree %d in log(T)",degree);
}
}
@ -1419,20 +1332,16 @@ void TransportFactory::fitProperties(GasTransportParams& tr,
}
tr.diffcoeffs.push_back(c);
if (DEBUG_MODE_ENABLED && tr.log_level >= 2 && m_verbose) {
tr.xml->XML_writeVector(logfile, " ", tr.thermo->speciesName(k)
+ "__"+tr.thermo->speciesName(j), c.size(), DATA_PTR(c));
writelog(tr.thermo->speciesName(k) + "__" +
tr.thermo->speciesName(j) + ": [" + vec2str(c) + "]\n");
}
}
}
if (DEBUG_MODE_ENABLED && m_verbose) {
char s[100];
sprintf(s,"Maximum binary diffusion coefficient absolute error:"
" %12.6g", mxerr);
tr.xml->XML_comment(logfile,s);
sprintf(s, "Maximum binary diffusion coefficient relative error:"
"%12.6g", mxrelerr);
tr.xml->XML_comment(logfile,s);
tr.xml->XML_close(logfile, "binary_diffusion_coefficients");
writelogf("Maximum binary diffusion coefficient absolute error:"
" %12.6g\n", mxerr);
writelogf("Maximum binary diffusion coefficient relative error:"
"%12.6g", mxrelerr);
}
}

View file

@ -7,9 +7,6 @@
#include "cantera/transport/TransportParams.h"
#ifdef DEBUG_MODE
#include "cantera/base/XML_Writer.h"
#endif
using namespace std;
namespace Cantera
@ -23,16 +20,12 @@ TransportParams::TransportParams() :
tmax(1000000.),
tmin(10.),
mode_(0),
xml(0),
log_level(-1)
{
}
TransportParams::~TransportParams()
{
#ifdef DEBUG_MODE
delete xml;
#endif
}
GasTransportParams::GasTransportParams() :

View file

@ -11,7 +11,7 @@ using namespace Cantera;
int main(int argc, char** argv)
{
try {
int log_level = 3;
int log_level = 0;
std::auto_ptr<ThermoPhase> g(newPhase("h2o2.xml", "ohmech"));
auto_ptr<Transport> tran(newTransportMgr("DustyGas", g.get(), log_level));