From 3ea77c5187842a212f70b7e37d1cf53ae68a3e10 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Thu, 31 May 2007 23:51:49 +0000 Subject: [PATCH] Fixed a UMR in Reaction.h that was causing optimized versions of ck2cti to hang or seg fault sometimes. Added some exceptions that captures cases where the thermo parameters for a molecule were not found in the database. Now, an error exit occurs, instead of before, where misc garbage but written to the output file. --- Cantera/src/converters/Reaction.h | 11 ++++++++--- Cantera/src/converters/RxnSpecies.h | 2 ++ Cantera/src/converters/ck2ct.cpp | 28 ++++++++++++++++++++++++---- Cantera/src/converters/ckr_defs.h | 2 ++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Cantera/src/converters/Reaction.h b/Cantera/src/converters/Reaction.h index 077419fa9..c626ea87e 100755 --- a/Cantera/src/converters/Reaction.h +++ b/Cantera/src/converters/Reaction.h @@ -93,13 +93,18 @@ namespace ckr { ////////////////////////////////////////////////////////////////////////// - + + //! Specifies the Units for all reactions /** - * Specifies the units for all reactions. + * The default units are Cal per gmol for the activivation units + * and the default number type is assumed to be gmol. */ - class ReactionUnits { public: + ReactionUnits() : + ActEnergy(ckr::Cal_per_Mole), + Quantity(ckr::Moles) { } + int ActEnergy; ///< Activation energy unit flag int Quantity; ///< Moles or molecules unit flag }; diff --git a/Cantera/src/converters/RxnSpecies.h b/Cantera/src/converters/RxnSpecies.h index 1725ebc33..e49b46a79 100755 --- a/Cantera/src/converters/RxnSpecies.h +++ b/Cantera/src/converters/RxnSpecies.h @@ -27,6 +27,8 @@ namespace ckr { */ class RxnSpecies { public: + RxnSpecies() : + number(0) {} string name; //!< The name of the object. double number; //!< The number of units (molecules, etc.). grouplist_t groups; diff --git a/Cantera/src/converters/ck2ct.cpp b/Cantera/src/converters/ck2ct.cpp index 555da827c..be2d65d2d 100644 --- a/Cantera/src/converters/ck2ct.cpp +++ b/Cantera/src/converters/ck2ct.cpp @@ -190,11 +190,15 @@ namespace pip { } /** - * addSpecies(): + * Write out a species cti block to the output file. * */ static void addSpecies(FILE* f, string idtag, const ckr::Species& sp) { string spname = sp.name; + if (spname.size() == 0) { + throw CanteraError("addSpecies", + "Species name is empty"); + } fprintf(f,"\nspecies(name = \"%s\",\n",spname.c_str()); int nel = static_cast(sp.elements.size()); int m, num; @@ -226,6 +230,18 @@ namespace pip { } fprintf(f," atoms = \"%s\",\n", str.c_str()); + if (sp.lowCoeffs.size() == 0) { + throw CanteraError("addSpecies", + "Low Nasa Thermo Polynomial was not found"); + } + if (sp.highCoeffs.size() == 0) { + throw CanteraError("addSpecies", + "High Nasa Thermo Polynomial was not found"); + } + if (sp.tlow >= sp.thigh) { + throw CanteraError("addSpecies", + "Low temp limit is greater or equal to high temp limit"); + } addNASA(f, sp.lowCoeffs, sp.highCoeffs, sp.tlow, sp.tmid, sp.thigh); @@ -277,7 +293,10 @@ namespace pip { else { if (rxn.kf.type == ckr::Arrhenius) { fprintf(f," [%10.5E, %g, %g]", rxn.kf.A, rxn.kf.n, rxn.kf.E); - } + } else { + throw CanteraError("addReaction", + "unknown kf_type to reaction: " + int2str(rxn.kf.type)); + } } // reaction orders @@ -346,7 +365,7 @@ namespace pip { doublereal version = 1.0; fprintf(f, "units(length = \"cm\", time = \"s\", quantity = \"mol\", "); - string e_unit; + string e_unit = " "; int eunit = r.units.ActEnergy; if (eunit == ckr::Cal_per_Mole) e_unit = "cal/mol"; @@ -443,7 +462,7 @@ namespace pip { } } - +/* static int fixtext(string infile, string outfile) { ifstream fin(infile.c_str()); ofstream fout(outfile.c_str()); @@ -474,6 +493,7 @@ namespace pip { fout.close(); return 0; } +*/ int convert_ck(const char* in_file, const char* db_file, const char* tr_file, const char* id_tag, bool debug, bool validate) { diff --git a/Cantera/src/converters/ckr_defs.h b/Cantera/src/converters/ckr_defs.h index b2475151d..5d00622ed 100755 --- a/Cantera/src/converters/ckr_defs.h +++ b/Cantera/src/converters/ckr_defs.h @@ -67,6 +67,8 @@ namespace ckr { /** @name Activation Energy Units * These constants specify the supported units for the activation energy of * a reaction + * The default is to assume Cal_per_Mole for unspecified units in the activation energy + * as this was the original default */ //@{ const int Cal_per_Mole = 1,