From e463b77fa211812152b927171d5135769c4811ac Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 8 Apr 2008 20:19:26 +0000 Subject: [PATCH] Added an endl printing capability to writelog(). Some systems differentiate between endl and \n when it comes to flushing the output. Added C++ printing utilities --- Cantera/src/base/LogPrintCtrl.cpp | 158 ++++++++++++++++ Cantera/src/base/LogPrintCtrl.h | 178 ++++++++++++++++++ Cantera/src/base/Makefile.in | 6 +- Cantera/src/base/PrintCtrl.cpp | 248 +++++++++++++++++++++++++ Cantera/src/base/PrintCtrl.h | 217 ++++++++++++++++++++++ Cantera/src/base/global.h | 7 + Cantera/src/base/logger.h | 9 + Cantera/src/base/misc.cpp | 25 ++- Cantera/src/equil/vcs_internal.h | 1 + Cantera/src/equil/vcs_solve_TP.cpp | 97 ++++++---- Cantera/src/equil/vcs_util.cpp | 2 +- Cantera/src/numerics/DAE_solvers.cpp | 1 + Cantera/src/numerics/IDA_Solver.cpp | 2 +- Cantera/src/numerics/IDA_Solver.h | 3 +- Cantera/src/transport/SolidTransport.h | 3 +- 15 files changed, 913 insertions(+), 44 deletions(-) create mode 100644 Cantera/src/base/LogPrintCtrl.cpp create mode 100644 Cantera/src/base/LogPrintCtrl.h create mode 100644 Cantera/src/base/PrintCtrl.cpp create mode 100644 Cantera/src/base/PrintCtrl.h diff --git a/Cantera/src/base/LogPrintCtrl.cpp b/Cantera/src/base/LogPrintCtrl.cpp new file mode 100644 index 000000000..34cef0ba6 --- /dev/null +++ b/Cantera/src/base/LogPrintCtrl.cpp @@ -0,0 +1,158 @@ +/** + * @file LogPrintCtrl.cpp + * Declarations for a simple class that augments the logfile printing capabilities + * (see \ref Cantera::LogPrintCtrl). + */ +/* + * $Author$ + * $Revision$ + * $Date$ + */ +/* + * Copywrite 2004 Sandia Corporation. Under the terms of Contract + * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government + * retains certain rights in this software. + * See file License.txt for licensing information. + */ + +#include + +#include +#include + +#include "LogPrintCtrl.h" +#include "global.h" + +using namespace std; + +namespace Cantera { + + LogPrintCtrl::LogPrintCtrl(int Ndec) : + m_ffss(0), + m_pc(0) + { + m_ffss = new std::ostream(m_os.rdbuf()); + m_pc = new PrintCtrl(*m_ffss, Ndec); + } + + LogPrintCtrl::~LogPrintCtrl() { + delete m_pc; + delete m_ffss; + } + + // Print a double using scientific notation + /* + * Prints a double using scientific notation in a + * fixed number of spaces + * + * + * @param d double to be printed + * @param w Number of spaces to use + * @param p Precision + * + * + */ + void LogPrintCtrl::pr_de_c10(const double din, int p, const int wMin, + const int wMax) { + m_pc->pr_de_c10(din, p, wMin, wMax); + writelog(m_os.str()); + m_os.str(""); + } + + // Print a double using scientific notation + /* + * Prints a double using scientific notation in a + * fixed number of spaces. Rounding of the last digit is carried out + * by the standard c++ printing utilities. + * + * @param d double to be printed + * @param w Number of spaces to use + * @param p Precision + */ + void LogPrintCtrl::pr_de(const double d, int sigDigIn, const int wMinIn, + const int wMaxIn) { + m_pc->pr_de(d, sigDigIn, wMinIn, wMaxIn); + writelog(m_os.str()); + m_os.str(""); + } + + // Croup a double at a certain decade level + /* + * This routine will crop a floating point number at a certain + * decade lvl. In other words everything below a power of 10^Ndec + * will be deleted. + * Note, it currently does not do rounding of the last digit. + * + * @param d Double to be cropped + * @param nSig Number of significant digits + * example: + * d = 1.1305E-15; + * Ndec = -16; + * This routine will return 1.1E-15 + * + * d = 8.0E-17 + * Ndec = -16 + * This routine will return 0.0 + */ + double LogPrintCtrl::cropAbs10(const double d, int Ndec) const { + return m_pc->cropAbs10(d, Ndec); + } + + // Crop a double at a certain number of significant digits + /* + * This routine will crop a floating point number at a certain + * number of significant digits. Note, it currently does + * rounding up of the last digit. + * + * example: + * d = 1.0305E-15; + * nsig = 3; + * This routine will return 1.03E-15 + */ + double LogPrintCtrl::cropSigDigits(const double d, int nSig) const { + return m_pc->cropSigDigits(d, nSig); + } + + // Set the default value of N decade + /* + * @param Ndec new value of Ndec + * + * @return returns the old value of Ndec + */ + int LogPrintCtrl::setNdec(int Ndec) { + return m_pc->setNdec(Ndec); + } + + // Set the default significant digits to output + /* + * @param nSigDigits new value of the sig digits + * + * @return returns the old value of Ndec + */ + int LogPrintCtrl::setSigDigits(int nSigDigits) { + return m_pc->setSigDigits(nSigDigits); + } + + // Set the default minimum width + /* + * @param wmin Default minimum width + * + * @return returns the old default + */ + int LogPrintCtrl::setWmin(int wmin) { + return m_pc->setWmin(wmin); + } + + + // Set the default maximum width + /* + * @param wmin Default maximum width + * + * @return returns the old default + */ + int LogPrintCtrl::setWmax(int wmax) { + return m_pc->setWmax(wmax); + } + + +} diff --git a/Cantera/src/base/LogPrintCtrl.h b/Cantera/src/base/LogPrintCtrl.h new file mode 100644 index 000000000..77ba7c8ce --- /dev/null +++ b/Cantera/src/base/LogPrintCtrl.h @@ -0,0 +1,178 @@ +/** + * @file LogPrintCtrl.h + * Declarations for a simple class that augments the logfile printing capabilities + * (see \ref Cantera::LogPrintCtrl). + */ +/* + * $Author$ + * $Revision$ + * $Date$ + */ +/* + * Copywrite 2004 Sandia Corporation. Under the terms of Contract + * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government + * retains certain rights in this software. + * See file License.txt for licensing information. + */ + +#ifndef CT_LOGPRINTCTRL_H +#define CT_LOGPRINTCTRL_H + +#include + +#include "PrintCtrl.h" + +namespace Cantera { + + //! This class provides some printing and cropping utilities + //! for writing to the logfile. + /*! + * This class writes its output to Cantera's logfile + * utility. It's a wrapper around PrintCtrl object. + * First, we direct PrintCtrl to write to a string + * and then we redirect the string to the logfile utility. + * This is a first cut, and it's pretty much a kluge. + * The logfile utility, however, demands a string, and this + * is what I came up with. + * + * @ingroup globalUtilFuncs + * + */ + class LogPrintCtrl { + public: + + //! Constructor + /*! + * This also serves to initialize the ticks within the object + * + * @param coutProxy This is a reference to the ostream + * to use for all IO from ths object. + * @param Ndec value of Ndec. Defaults to -1000, i.e., + * no decade cropping + */ + LogPrintCtrl(int Ndec = -1000); + + //! Destructor + ~LogPrintCtrl(); + + //! Print a double using scientific notation + /*! + * Prints a double using scientific notation in a + * fixed number of spaces. + * + * The precision of the number will be adjusted to + * fit into the maximum space. + * + * @param d double to be printed + * @param sigDigits Number of significant digits + * (-1 = default, means to use the default + * number for the object, which is initially + * set to 13. + * @param wMin Minimum number of spaces to print out + * @param wMax Maximum number of spaces to print out + */ + void pr_de(const double d, int sigDigits = -1, + const int wMin = -1, const int wMax = -1); + + //! Print a double using scientific notation cropping + //! decade values + /*! + * Prints a double using scientific notation in a + * fixed number of spaces. This routine also crops + * number below the default decade level. + * + * The precision of the number will be adjusted to + * fit into the maximum space. + * + * @param d double to be printed + * @param sigDigits Number of significant digits + * (-1 = default, means to use the default + * number for the object, which is initially + * set to 13. + * @param wMin Minimum number of spaces to print out + * @param wMax Maximum number of spaces to print out + */ + void pr_de_c10(const double d, int sigDigits = -1, + const int wMin = -1, const int wMax = -1); + + //! Crop a double at a certain number of significant digits + /*! + * This routine will crop a floating point number at a certain + * number of significant digits. Note, it does + * rounding up of the last digit. + * + * @param d Double to be cropped + * @param sigDigits Number of significant digits + * example: + * d = 1.0305E-15; + * nsig = 3; + * This routine will return 1.03E-15 + */ + double cropSigDigits(const double d, int sigDigits) const; + + //! Crop a double at a certain decade level + /*! + * This routine will crop a floating point number at a certain + * decade lvl. In other words everything below a power of 10^Ndec + * will be deleted. + * Note, it does rounding up of the last digit. + * + * @param d Double to be cropped + * @param nDecades Number of significant digits + * example: + * d = 1.1305E-15; + * nDecades = -16; + * This routine will return 1.1E-15 + * + * d = 8.0E-17 + * nDecades = -16 + * This routine will return 0.0 + */ + double cropAbs10(const double d, const int nDecades) const; + + //! Set the default value of N decade + /*! + * @param nDecades new value of Ndec + * + * @return returns the old value of Ndec + */ + int setNdec(int nDecades); + + + //! Set the default significant digits to output + /*! + * @param sigDigits new value of the sig digits + * + * @return returns the old value of Ndec + */ + int setSigDigits(int sigDigits); + + //! Set the default minimum width + /*! + * @param wMin Default minimum width + * + * @return returns the old default + */ + int setWmin(int wMin); + + //! Set the default maximum width + /*! + * @param wMax Default maximum width + * + * @return returns the old default + */ + int setWmax(int wMax); + + + private: + std::ostringstream m_os; + std::ostream *m_ffss; + PrintCtrl *m_pc; + + + + }; +} + +#endif + diff --git a/Cantera/src/base/Makefile.in b/Cantera/src/base/Makefile.in index 8b3267691..bb3dc57ee 100644 --- a/Cantera/src/base/Makefile.in +++ b/Cantera/src/base/Makefile.in @@ -26,11 +26,13 @@ PIC_FLAG=@PIC@ CXX_FLAGS = @CXXFLAGS@ $(LOCAL_DEFS) $(CXX_OPT) $(PIC_FLAG) $(DEBUG_FLAG) -BASE_OBJ = ct2ctml.o ctml.o misc.o plots.o stringUtils.o xml.o clockWC.o +BASE_OBJ = ct2ctml.o ctml.o misc.o plots.o stringUtils.o xml.o clockWC.o\ + PrintCtrl.o LogPrintCtrl.o BASE_H = ct_defs.h ctexceptions.h logger.h XML_Writer.h \ ctml.h plots.h stringUtils.h xml.h config.h utilities.h \ - Array.h vec_functions.h global.h FactoryBase.h clockWC.h + Array.h vec_functions.h global.h FactoryBase.h clockWC.h \ + PrintCtrl.h LogPrintCtrl.h CXX_INCLUDES = -I. @CXX_INCLUDES@ LIB = @buildlib@/libctbase.a diff --git a/Cantera/src/base/PrintCtrl.cpp b/Cantera/src/base/PrintCtrl.cpp new file mode 100644 index 000000000..75b0f5cd0 --- /dev/null +++ b/Cantera/src/base/PrintCtrl.cpp @@ -0,0 +1,248 @@ +/** + * @file PrintCtrl.cpp + * Definitions for a simple class that augments the streams printing capabilities + * (see \ref Cantera::PrintCtrl). + */ +/* + * $Author$ + * $Revision$ + * $Date$ + */ +/* + * Copywrite 2004 Sandia Corporation. Under the terms of Contract + * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government + * retains certain rights in this software. + * See file License.txt for licensing information. + */ + +#include + +#include +#include + +#include "PrintCtrl.h" + +using namespace std; + +namespace Cantera { + + PrintCtrl::PrintCtrl(std::ostream &coutProxy, int Ndec) : + m_cout(coutProxy), + m_Ndec(Ndec), + m_precision(12), + m_wMin(9), + m_wMax(19) + { + + } + + // Print a double using scientific notation + /* + * Prints a double using scientific notation in a + * fixed number of spaces + * + * + * @param d double to be printed + * @param w Number of spaces to use + * @param p Precision + * + * + */ + void PrintCtrl::pr_de_c10(const double din, int p, const int wMin, + const int wMax) { + double d = cropAbs10(din, m_Ndec); + pr_de(d, p, wMin, wMax); + } + + // Print a double using scientific notation + /* + * Prints a double using scientific notation in a + * fixed number of spaces. Rounding of the last digit is carried out + * by the standard c++ printing utilities. + * + * @param d double to be printed + * @param w Number of spaces to use + * @param p Precision + */ + void PrintCtrl::pr_de(const double d, int sigDigIn, const int wMinIn, + const int wMaxIn) { + int p = m_precision; + if (sigDigIn != -1) { + p = sigDigIn-1; + if (p < 0) p = 0; + } + + int wMin = m_wMin; + if (wMinIn != -1) { + wMin = wMinIn; + if (wMin < 1) wMin = 1; + } + + int wMax = m_wMax; + if (wMaxIn != -1) { + wMax = wMaxIn; + if (wMax < 1) wMax = 1; + } + + if (wMin > wMax) wMax = wMin; + + // Have to do the wMax ourselves, since C++ doesn't seem to + // have a streams manipulator to do this !?! + double dfabs = fabs(d); + // This is the normal length assuming no sign and an 1.0E+04 + // formated exponented + int requestedLength = 6 + p; + if (d < 0.0) { + requestedLength++; + } + if (dfabs < 9.9999999999E-99) { + requestedLength++; + } + if (dfabs > 9.9999999999E99) { + requestedLength++; + } + if (requestedLength > wMax) { + p -= (requestedLength - wMax); + if (p < 0) p = 0; + } + + // Set to upper case and scientific notation + m_cout.setf(ios_base::scientific | ios_base::uppercase); + int wold = m_cout.width(wMin); + int pold = m_cout.precision(p); + + m_cout << d; + // Return the precision to the previous value; + m_cout.precision(pold); + m_cout.unsetf(ios_base::scientific); + + // Return width to original + m_cout.width(wold); + } + + // Croup a double at a certain decade level + /* + * This routine will crop a floating point number at a certain + * decade lvl. In other words everything below a power of 10^Ndec + * will be deleted. + * Note, it currently does not do rounding of the last digit. + * + * @param d Double to be cropped + * @param nSig Number of significant digits + * example: + * d = 1.1305E-15; + * Ndec = -16; + * This routine will return 1.1E-15 + * + * d = 8.0E-17 + * Ndec = -16 + * This routine will return 0.0 + */ + double PrintCtrl::cropAbs10(const double d, int Ndec) const { + if (Ndec < -301 || Ndec > 301) { + return d; + } + double sgn = 1.0; + if (d < 0.0) sgn = -1.0; + double dfabs = fabs(d); + double pdec = pow(10.0, (double) Ndec); + if (dfabs < pdec) { + return 0.0; + } + double dl10 = log10(dfabs); + int N10 = (int) dl10; + if (dl10 > -0.0) { + N10 += 1; + } + int nsig = N10 - Ndec; + double retn = cropSigDigits(d, nsig); + return retn; + } + + // Crop a double at a certain number of significant digits + /* + * This routine will crop a floating point number at a certain + * number of significant digits. Note, it currently does + * rounding up of the last digit. + * + * example: + * d = 1.0305E-15; + * nsig = 3; + * This routine will return 1.03E-15 + */ + double PrintCtrl::cropSigDigits(const double d, int nSig) const { + if (nSig <=0) nSig = 1; + if (nSig >=10) nSig = 10; + double sgn = 1.0; + if (d < 0.0) sgn = -1.0; + double dfabs = fabs(d); + double dl10 = log10(dfabs); + int N10 = (int) dl10; + if (dl10 > -0.0) { + N10 += 1; + } + int E10 = -N10 + nSig ; + double pfabs = dfabs * pow(10.0, (double) E10); + pfabs *= (1.0 + 1.0E-14); + long int nfabs = (long int) pfabs; + double remainder = pfabs - nfabs; + if (remainder > 0.5) { + nfabs++; + } + double paltabs = (double) nfabs; + double daltabs = paltabs * pow(10.0, (double) -E10); + return (sgn * daltabs); + } + + // Set the default value of N decade + /* + * @param Ndec new value of Ndec + * + * @return returns the old value of Ndec + */ + int PrintCtrl::setNdec(int Ndec) { + int nold = m_Ndec; + m_Ndec = Ndec; + return nold; + } + + // Set the default significant digits to output + /* + * @param nSigDigits new value of the sig digits + * + * @return returns the old value of Ndec + */ + int PrintCtrl::setSigDigits(int nSigDigits) { + int nold = m_precision + 1; + m_precision = nSigDigits - 1; + if (m_precision < 0) m_precision = 0; + return nold; + } + + // Set the default minimum width + /* + * @param wmin Default minimum width + * + * @return returns the old default + */ + int PrintCtrl::setWmin(int wmin) { + int nold = m_wMin; + m_wMin = wmin; + return nold; + } + + + // Set the default maximum width + /* + * @param wmin Default maximum width + * + * @return returns the old default + */ + int PrintCtrl::setWmax(int wmax) { + int nold = m_wMax; + m_wMax = wmax; + return nold; + } + + +} diff --git a/Cantera/src/base/PrintCtrl.h b/Cantera/src/base/PrintCtrl.h new file mode 100644 index 000000000..11e321b33 --- /dev/null +++ b/Cantera/src/base/PrintCtrl.h @@ -0,0 +1,217 @@ +/** + * @file PrintCtrl.h + * Declarations for a simple class that augments the streams printing capabilities + * (see \ref Cantera::PrintCtrl). + */ +/* + * $Author$ + * $Revision$ + * $Date$ + */ +/* + * Copywrite 2004 Sandia Corporation. Under the terms of Contract + * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government + * retains certain rights in this software. + * See file License.txt for licensing information. + */ + +#ifndef CT_PRINTCTRL_H +#define CT_PRINTCTRL_H + +#include + +namespace Cantera { + + //! This class provides some printing and cropping utilities + /*! + * The class is used to provide some formatting options for + * printing out real numbers to files and to standard output. + * Specifically, it can make sure that a max and min field + * width is honored when conducting IO of numbers and strings. + * Basically, its the spot to house all wrappers around + * commonly used printing facilities. + * + * It can also handle cropping of numbers below a certain + * decade level. This is useful for IO for testing purposes. + * For example, if you don't care about anything below + * 1.0E-20, you can set up the IO so that it won't print out + * any digits below 1.0E-20, even digits that are in numbers + * greater than 1.0E-20. In other words the number + * + * 1.12345E-19 + * + * whould be cropped to the value + * + * 1.1000E-19 + * + * The class wraps aroud a single std::ostream class. It's + * cropping functions are also available as a "double" + * conversion utility. + * + * + * @ingroup globalUtilFuncs + * + */ + class PrintCtrl { + public: + + //! Constructor + /*! + * This also serves to initialize the ticks within the object + * + * @param coutProxy This is a reference to the ostream + * to use for all IO from ths object. + * @param Ndec value of Ndec. Defaults to -1000, i.e., + * no decade cropping + */ + PrintCtrl(std::ostream &coutProxy = std::cout, int Ndec = -1000); + + //! Print a double using scientific notation + /*! + * Prints a double using scientific notation in a + * fixed number of spaces. + * + * The precision of the number will be adjusted to + * fit into the maximum space. + * + * @param d double to be printed + * @param sigDigits Number of significant digits + * (-1 = default, means to use the default + * number for the object, which is initially + * set to 13. + * @param wMin Minimum number of spaces to print out + * @param wMax Maximum number of spaces to print out + */ + void pr_de(const double d, int sigDigits = -1, + const int wMin = -1, const int wMax = -1); + + //! Print a double using scientific notation cropping + //! decade values + /*! + * Prints a double using scientific notation in a + * fixed number of spaces. This routine also crops + * number below the default decade level. + * + * The precision of the number will be adjusted to + * fit into the maximum space. + * + * @param d double to be printed + * @param sigDigits Number of significant digits + * (-1 = default, means to use the default + * number for the object, which is initially + * set to 13. + * @param wMin Minimum number of spaces to print out + * @param wMax Maximum number of spaces to print out + */ + void pr_de_c10(const double d, int sigDigits = -1, + const int wMin = -1, const int wMax = -1); + + //! Crop a double at a certain number of significant digits + /*! + * This routine will crop a floating point number at a certain + * number of significant digits. Note, it does + * rounding up of the last digit. + * + * @param d Double to be cropped + * @param sigDigits Number of significant digits + * example: + * d = 1.0305E-15; + * nsig = 3; + * This routine will return 1.03E-15 + */ + double cropSigDigits(const double d, int sigDigits) const; + + //! Crop a double at a certain decade level + /*! + * This routine will crop a floating point number at a certain + * decade lvl. In other words everything below a power of 10^Ndec + * will be deleted. + * Note, it does rounding up of the last digit. + * + * @param d Double to be cropped + * @param nDecades Number of significant digits + * example: + * d = 1.1305E-15; + * nDecades = -16; + * This routine will return 1.1E-15 + * + * d = 8.0E-17 + * nDecades = -16 + * This routine will return 0.0 + */ + double cropAbs10(const double d, const int nDecades) const; + + //! Set the default value of N decade + /*! + * @param nDecades new value of Ndec + * + * @return returns the old value of Ndec + */ + int setNdec(int nDecades); + + + //! Set the default significant digits to output + /*! + * @param sigDigits new value of the sig digits + * + * @return returns the old value of Ndec + */ + int setSigDigits(int sigDigits); + + //! Set the default minimum width + /*! + * @param wMin Default minimum width + * + * @return returns the old default + */ + int setWmin(int wMin); + + //! Set the default maximum width + /*! + * @param wMax Default maximum width + * + * @return returns the old default + */ + int setWmax(int wMax); + + + private: + + //! This is the ostream to send all output from the object + /*! + * It defaults to cout + */ + std::ostream &m_cout; + + //! Default decade level to use for decade cropping + /*! + * This is initially set to -1000, which means that + * no cropping will be carried out + */ + int m_Ndec; + + //! default precision level to use in printing + /*! + * This actually is one less than the number of significant digits. + * + * Initially set to 12 + */ + int m_precision; + + //! default minimimum field width + /*! + * Initially, this is set to 9 + */ + int m_wMin; + + //! Default maximum field width + /*! + * Initially this is set to 19 + */ + int m_wMax; + + }; +} + +#endif + diff --git a/Cantera/src/base/global.h b/Cantera/src/base/global.h index 11991fd4c..f51ff8f54 100755 --- a/Cantera/src/base/global.h +++ b/Cantera/src/base/global.h @@ -300,6 +300,13 @@ namespace Cantera { */ void writelogf(const char* fmt,...); + //! Write an end of line character to the screen and flush output + /*! + * Some implementations differentiate between \n and endl in + * terms of when the output is flushed. + */ + void writelogendl(); + //! Write an error message and terminate execution. /*! * @param msg Error message to be written to the screen. diff --git a/Cantera/src/base/logger.h b/Cantera/src/base/logger.h index c1940bc09..5597fa667 100644 --- a/Cantera/src/base/logger.h +++ b/Cantera/src/base/logger.h @@ -59,6 +59,15 @@ namespace Cantera { std::cout << msg; } + //! Write an end of line character and flush output. + /*! + * Some systems treat endl and \n differently. The endl + * statement causes a flushing of stdout to the screen. + */ + virtual void writeendl() { + std::cout << std::endl; + } + //! Write an error message and quit. /*! * The default behavior is diff --git a/Cantera/src/base/misc.cpp b/Cantera/src/base/misc.cpp index d6f64e8c2..b4b5fb1ef 100755 --- a/Cantera/src/base/misc.cpp +++ b/Cantera/src/base/misc.cpp @@ -257,7 +257,7 @@ namespace Cantera { * * @ingroup errorhandling */ - void logErrors() ; + void logErrors(); //! Write a message to the screen. /*! @@ -268,7 +268,10 @@ namespace Cantera { * @param msg c++ string to be written to the screen * @ingroup textlogs */ - void writelog(const std::string& msg) ; + void writelog(const std::string& msg); + + //! Write an end of line and flush output + void writelogendl(); //! Write a message to the screen. /*! @@ -697,6 +700,13 @@ namespace Cantera { */ void writelog(const std::string& msg) { pMessenger->writelog(msg); } + + //! Write an endl to the screen and flush output + /*! + * @ingroup textlogs + */ + void writelogendl() { pMessenger->writelogendl(); } + //! Write a message to the screen. /*! * The string may be of any @@ -1513,7 +1523,12 @@ protected: void Application::Messages::writelog(const char* pszmsg) { logwriter->write( pszmsg ) ; } - + + // Write an endl to the screen and flush output + void Application::Messages::writelogendl() { + logwriter->writeendl(); + } + // Write a message to the screen using printf format void writelogf(const char* fmt,...) { enum { BUFSIZE = 2048 } ; @@ -1534,6 +1549,10 @@ protected: va_end(args) ; } + void writelogendl() { + app()->writelogendl(); + } + // Write an error message and terminate execution. test. // @ingroup textlogs void error(const std::string& msg) { diff --git a/Cantera/src/equil/vcs_internal.h b/Cantera/src/equil/vcs_internal.h index 006096df5..07d8e7fe2 100644 --- a/Cantera/src/equil/vcs_internal.h +++ b/Cantera/src/equil/vcs_internal.h @@ -31,6 +31,7 @@ namespace VCSnonideal { * We can replace this with printf easily */ #define plogf Cantera::writelogf +#define plogendl() Cantera::writelogendl() //! Global hook for turning on and off time printing. /*! diff --git a/Cantera/src/equil/vcs_solve_TP.cpp b/Cantera/src/equil/vcs_solve_TP.cpp index 0b7dd6b88..634427e84 100644 --- a/Cantera/src/equil/vcs_solve_TP.cpp +++ b/Cantera/src/equil/vcs_solve_TP.cpp @@ -302,15 +302,16 @@ namespace VCSnonideal { } else { plogf(" Unknown"); } - plogf(" \n"); + plogendl(); } } for (i = 0; i < m_numSpeciesTot; ++i) { if (soln[i] < 0.0) { plogf("On Input species %-12s has a " - "negative MF, setting it small\n", - SpName[i].c_str()); + "negative MF, setting it small", + SpName[i].c_str()); + plogendl(); soln[i] = VCS_DELETE_SPECIES_CUTOFF; } } @@ -366,7 +367,8 @@ namespace VCSnonideal { #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { plogf(" --- Minor species changed to major: "); - plogf("%-12s\n", SpName[kspec].c_str()); + plogf("%-12s", SpName[kspec].c_str()); + plogendl(); } #endif } @@ -379,7 +381,8 @@ namespace VCSnonideal { if (! vcs_elabcheck(0)) { #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { - plogf(" --- Element Abundance check failed\n"); + plogf(" --- Element Abundance check failed"); + plogendl(); } #endif vcs_elcorr(VCS_DATA_PTR(sm), VCS_DATA_PTR(wx)); @@ -388,7 +391,8 @@ namespace VCSnonideal { #ifdef DEBUG_MODE else { if (vcs_debug_print_lvl >= 2) { - plogf(" --- Element Abundance check passed\n"); + plogf(" --- Element Abundance check passed"); + plogendl(); } } #endif @@ -652,9 +656,10 @@ namespace VCSnonideal { sprintf(ANOTE,"minor species not considered"); if (vcs_debug_print_lvl >= 2) { plogf(" --- "); plogf("%-12s", SpName[kspec].c_str()); - plogf("%3d%11.4E%11.4E%11.4E | %s\n", + plogf("%3d%11.4E%11.4E%11.4E | %s", spStatus[irxn], soln[kspec], wt[kspec], ds[kspec], ANOTE); + plogendl(); } #endif continue; @@ -686,8 +691,9 @@ namespace VCSnonideal { /*******************************************************************/ #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { - plogf(" --- Delete minor species in multispec phase: %-12s\n", + plogf(" --- Delete minor species in multispec phase: %-12s", SpName[kspec].c_str()); + plogendl(); } #endif ds[kspec] = 0.0; @@ -734,9 +740,10 @@ namespace VCSnonideal { sprintf(ANOTE, "major species is converged"); if (vcs_debug_print_lvl >= 2) { plogf(" --- "); plogf("%-12s", SpName[kspec].c_str()); - plogf("%3d%11.4E%11.4E%11.4E | %s\n", + plogf("%3d%11.4E%11.4E%11.4E | %s", spStatus[irxn], soln[kspec], wt[kspec], ds[kspec], ANOTE); + plogendl(); } #endif continue; @@ -810,7 +817,8 @@ namespace VCSnonideal { #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { plogf(" --- Major species changed to minor: "); - plogf("%-12s\n", SpName[kspec].c_str()); + plogf("%-12s", SpName[kspec].c_str()); + plogendl(); } #endif spStatus[irxn] = VCS_SPECIES_MINOR; @@ -904,7 +912,8 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { if (spStatus[irxn] >= 0) { plogf(" --- SS species changed to zeroedss: "); - plogf("%-12s\n", SpName[kspec].c_str()); + plogf("%-12s", SpName[kspec].c_str()); + plogendl(); } } #endif @@ -950,7 +959,8 @@ namespace VCSnonideal { #ifdef DEBUG_MODE if (fabs(ds[kspec] -dx) > 1.0E-14*(fabs(ds[kspec]) + fabs(dx) + 1.0E-32)) { plogf(" ds[kspec] = %20.16g dx = %20.16g , kspec = %d\n", ds[kspec], dx, kspec); - plogf("we have a problem!\n"); + plogf("we have a problem!"); + plogendl(); exit(-1); } #endif @@ -980,9 +990,10 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { wt[kspec] = soln[kspec] + ds[kspec]; plogf(" --- "); plogf("%-12.12s", SpName[kspec].c_str()); - plogf("%3d%11.4E%11.4E%11.4E | %s\n", + plogf("%3d%11.4E%11.4E%11.4E | %s", spStatus[irxn], soln[kspec], wt[kspec], ds[kspec], ANOTE); + plogendl(); } L_MAIN_LOOP_END_NO_PRINT: ; #endif @@ -992,11 +1003,13 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { for (k = 0; k < m_numComponents; k++) { plogf(" --- "); plogf("%-12.12s", SpName[k].c_str()); - plogf(" c%11.4E%11.4E%11.4E |\n", + plogf(" c%11.4E%11.4E%11.4E |", soln[k], soln[k]+ds[k], ds[k]); } + plogendl(); plogf(" "); vcs_print_line("-", 80); - plogf(" --- Finished Main Loop\n"); + plogf(" --- Finished Main Loop"); + plogendl(); } #endif /*************************************************************************/ @@ -1036,7 +1049,8 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { plogf(" --- Reduction in step size due to component "); plogf("%s", SpName[ll].c_str()); - plogf(" going negative = %11.3E\n", par); + plogf(" going negative = %11.3E", par); + plogendl(); } #endif for (i = 0; i < m_numSpeciesTot; ++i) { @@ -1061,8 +1075,9 @@ namespace VCSnonideal { for (kspec = 0; kspec < m_numSpeciesTot; ++kspec) { wt[kspec] = soln[kspec] + ds[kspec]; if (wt[kspec] < 0.0 && (SpeciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE)) { - plogf("vcs_solve_TP: ERROR on step change wt[%d:%s]: %g < 0.0\n", + plogf("vcs_solve_TP: ERROR on step change wt[%d:%s]: %g < 0.0", kspec, SpName[kspec].c_str(), wt[kspec]); + plogendl(); exit(-1); } } @@ -1141,9 +1156,10 @@ namespace VCSnonideal { dgl[l1], dg[l1]); } plogf(" ---"); print_space(56); - plogf("Norms of Delta G():%14.6E%14.6E\n", + plogf("Norms of Delta G():%14.6E%14.6E", l2normdg(VCS_DATA_PTR(dgl)), l2normdg(VCS_DATA_PTR(dg))); + plogendl(); plogf(" --- Phase_Name Moles(after update)\n"); plogf(" --- "); vcs_print_line("-", 50); @@ -1152,11 +1168,13 @@ namespace VCSnonideal { plogf(" --- %18s = %15.7E\n", Vphase->PhaseName.c_str(), TPhMoles1[iph]); } plogf(" "); vcs_print_line("-", 103); - plogf(" --- Total Dimensionless Gibbs Free Energy = %15.7E\n", + plogf(" --- Total Dimensionless Gibbs Free Energy = %15.7E", vcs_Total_Gibbs(VCS_DATA_PTR(wt), VCS_DATA_PTR(m_gibbsSpecies), VCS_DATA_PTR(TPhMoles1))); + plogendl(); if (m_VCount->Its > 150) { - plogf(" --- Troublesome solve\n"); + plogf(" --- Troublesome solve"); + plogendl(); } #ifdef DEBUG_MODE #ifdef DEBUG_NOT @@ -1227,7 +1245,8 @@ namespace VCSnonideal { plogf(" Total Dimensionless Gibbs Free Energy = %15.7E\n", vcs_Total_Gibbs(VCS_DATA_PTR(soln), VCS_DATA_PTR(m_gibbsSpecies), VCS_DATA_PTR(TPhMoles))); - plogf(" -----------------------------------------------------\n"); + plogf(" -----------------------------------------------------"); + plogendl(); } /*************************************************************************/ /******************* RESET VALUES AT END OF ITERATION ********************/ @@ -1300,7 +1319,8 @@ namespace VCSnonideal { if (soldel) { #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 1) { - plogf(" --- Setting microscopic phase %d to zero\n", iph); + plogf(" --- Setting microscopic phase %d to zero", iph); + plogendl(); } #endif justDeletedMultiPhase = TRUE; @@ -1332,7 +1352,8 @@ namespace VCSnonideal { */ plogf(" DELETION OF MULTISPECIES PHASE. "); plogf("Convergence to number of positive n(i) less than C.\n"); - plogf("Check results to follow carefully. \n\n"); + plogf("Check results to follow carefully. \n"); + plogendl(); goto L_RETURN_BLOCK; } } @@ -1348,7 +1369,8 @@ namespace VCSnonideal { if (! vcs_elabcheck(0)) { #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { - plogf(" - failed -> redoing element abundances.\n"); + plogf(" - failed -> redoing element abundances."); + plogendl(); } #endif vcs_elcorr(VCS_DATA_PTR(sm), VCS_DATA_PTR(wx)); @@ -1359,7 +1381,8 @@ namespace VCSnonideal { #ifdef DEBUG_MODE else { if (vcs_debug_print_lvl >= 2) { - plogf(" - passed\n"); + plogf(" - passed"); + plogendl(); } } #endif @@ -1395,8 +1418,9 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { plogf(" --- Get a new basis because %s", SpName[l].c_str()); plogf(" is larger than comp %s", SpName[j].c_str()); - plogf(" and share nonzero stoic: %-9.1f\n", + plogf(" and share nonzero stoic: %-9.1f", sc[i][j]); + plogendl(); } #endif goto L_COMPONENT_CALC; @@ -1413,8 +1437,9 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { plogf(" --- Get a new basis because %s", SpName[l].c_str()); plogf(" has dg < 0.0 and comp %s has zero mole num", SpName[j].c_str()); - plogf(" and share nonzero stoic: %-9.1f\n", + plogf(" and share nonzero stoic: %-9.1f", sc[i][j]); + plogendl(); } #endif goto L_COMPONENT_CALC; @@ -1437,8 +1462,9 @@ namespace VCSnonideal { plogf("%s", SpName[l].c_str()); plogf(" is larger than comp "); plogf("%s", SpName[j].c_str()); - plogf(" and share nonzero stoic: %-9.1f\n", + plogf(" and share nonzero stoic: %-9.1f", sc[i][j]); + plogendl(); } #endif goto L_COMPONENT_CALC; @@ -1453,8 +1479,9 @@ namespace VCSnonideal { if (vcs_debug_print_lvl >= 2) { plogf(" --- Get a new basis because %s", SpName[l].c_str()); plogf(" has dg < 0.0 and comp %s has zero mole num", SpName[j].c_str()); - plogf(" and share nonzero stoic: %-9.1f\n", + plogf(" and share nonzero stoic: %-9.1f", sc[i][j]); + plogendl(); } #endif goto L_COMPONENT_CALC; @@ -1468,7 +1495,8 @@ namespace VCSnonideal { } #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { - plogf(" --- Check for an optimum basis passed\n"); + plogf(" --- Check for an optimum basis passed"); + plogendl(); } #endif /*************************************************************************/ @@ -1588,7 +1616,8 @@ namespace VCSnonideal { } #ifdef DEBUG_MODE if (vcs_debug_print_lvl >= 2) { - plogf(" MAJOR SPECIES CONVERGENCE achieved\n"); + plogf(" MAJOR SPECIES CONVERGENCE achieved"); + plogendl(); } #endif } @@ -1596,7 +1625,8 @@ namespace VCSnonideal { else { if (vcs_debug_print_lvl >= 2) { plogf(" MAJOR SPECIES CONVERGENCE achieved " - "(because there are no major species)\n"); + "(because there are no major species)"); + plogendl(); } } #endif @@ -1772,7 +1802,8 @@ namespace VCSnonideal { plogf(" --- vcs_solve_tp: RANGE SPACE ERROR ENCOUNTERED\n"); plogf(" --- vcs_solve_tp: - Giving up on NE Element Abundance satisfaction \n"); plogf(" --- vcs_solve_tp: - However, NC Element Abundance criteria is satisfied \n"); - plogf(" --- vcs_solve_tp: - Returning the calculated equilibrium condition \n"); + plogf(" --- vcs_solve_tp: - Returning the calculated equilibrium condition "); + plogendl(); } #endif rangeErrorFound = 1; diff --git a/Cantera/src/equil/vcs_util.cpp b/Cantera/src/equil/vcs_util.cpp index 31d2311d1..517ce1487 100644 --- a/Cantera/src/equil/vcs_util.cpp +++ b/Cantera/src/equil/vcs_util.cpp @@ -390,7 +390,7 @@ namespace VCSnonideal { if (string) { for (int j = 0; j < num; j++) plogf("%s", string); } - plogf("\n"); + plogendl(); } /***************************************************************************/ diff --git a/Cantera/src/numerics/DAE_solvers.cpp b/Cantera/src/numerics/DAE_solvers.cpp index 80d8a2a1e..4e0c2d7c7 100644 --- a/Cantera/src/numerics/DAE_solvers.cpp +++ b/Cantera/src/numerics/DAE_solvers.cpp @@ -2,6 +2,7 @@ #include "ct_defs.h" #include "DAE_Solver.h" +// DAE_DEVEL is turned off at the current time #ifdef DAE_DEVEL #ifdef HAS_SUNDIALS diff --git a/Cantera/src/numerics/IDA_Solver.cpp b/Cantera/src/numerics/IDA_Solver.cpp index 0458477b3..eec7f9226 100644 --- a/Cantera/src/numerics/IDA_Solver.cpp +++ b/Cantera/src/numerics/IDA_Solver.cpp @@ -210,7 +210,7 @@ namespace Cantera { // pass a pointer to func in m_data - m_fdata = new FuncData(&func, func.nparams()); + m_fdata = new ResidData(&func, func.nparams()); flag = IDASetRdata(m_ida_mem, (void*)m_fdata); if (flag != IDA_SUCCESS) diff --git a/Cantera/src/numerics/IDA_Solver.h b/Cantera/src/numerics/IDA_Solver.h index c28b4999d..59546d991 100644 --- a/Cantera/src/numerics/IDA_Solver.h +++ b/Cantera/src/numerics/IDA_Solver.h @@ -28,7 +28,7 @@ namespace Cantera { */ class IDA_Err : public CanteraError { public: - IDA_Err(std::string msg) : CanteraError("IDA_Solver", msg){} + IDA_Err(std::string msg) : CanteraError("IDA_Solver", msg){} }; @@ -60,7 +60,6 @@ namespace Cantera { virtual void setBandedLinearSolver(int m_upper, int m_lower); virtual void setMaxTime(doublereal tmax); - virtual void setMaxStepSize(doublereal dtmax); virtual void setMaxOrder(int n); diff --git a/Cantera/src/transport/SolidTransport.h b/Cantera/src/transport/SolidTransport.h index 9d913d06d..6507c417c 100644 --- a/Cantera/src/transport/SolidTransport.h +++ b/Cantera/src/transport/SolidTransport.h @@ -44,8 +44,7 @@ namespace Cantera { class SolidTransport : public Transport { public: - - virtual ~SolidTransport() {} +virtual ~SolidTransport() {} virtual int model() { return cSolidTransport; }