status_t phase_setmassfractionsbyname_(const integer* n, char* y, ftnlen leny) { try { ThermoPhase* p = _fph(n); p->setMassFractionsByName(f2string(y, leny)); } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t phase_getmassfractions_(const integer* n, doublereal* y) { try { ThermoPhase* p = _fph(n); p->getMassFractions(y); } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t phase_setmolefractionsbyname_(const integer* n, char* x, ftnlen lx) { try { ThermoPhase* p = _fph(n); p->setMoleFractionsByName(f2string(x, lx)); } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t phase_setmassfractionsbyname_(const integer* n, char* y, ftnlen leny) { try { ThermoPhase* p = _fph(n); compositionMap yy = parseCompString(f2string(y, leny), p->speciesNames()); p->setMassFractionsByName(yy); } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t phase_getmolecularweights_(const integer* n, doublereal* mw) { try { ThermoPhase* p = _fph(n); const vector_fp& wt = p->molecularWeights(); copy(wt.begin(), wt.end(), mw); } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t phase_setmolefractionsbyname_(const integer* n, char* x, ftnlen lx) { try { ThermoPhase* p = _fph(n); compositionMap xx = parseCompString(f2string(x, lx), p->speciesNames()); p->setMoleFractionsByName(xx); } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t DLL_EXPORT phase_setmolefractionsbyname_(const integer* n, char* x, ftnlen lx) { try { ThermoPhase* p = _fph(n); compositionMap xx; int nsp = p->nSpecies(); for (int nn = 0; nn < nsp; nn++) { xx[p->speciesName(nn)] = -1; } parseCompString(f2string(x, lx), xx); p->setMoleFractionsByName(xx); return 0; } catch (CanteraError) {handleError(); return -1;} }
//==================================================================================================================== void Kinetics::assignShallowPointers(const std::vector<thermo_t*> & tpVector) { size_t ns = tpVector.size(); if (ns != m_thermo.size()) { throw CanteraError(" Kinetics::assignShallowPointers", " Number of ThermoPhase objects arent't the same"); } for (size_t i = 0; i < ns; i++) { ThermoPhase *ntp = tpVector[i]; ThermoPhase *otp = m_thermo[i]; if (ntp->id() != otp->id()) { throw CanteraError(" Kinetics::assignShallowPointers", " id() of the ThermoPhase objects isn't the same"); } if (ntp->eosType() != otp->eosType()) { throw CanteraError(" Kinetics::assignShallowPointers", " eosType() of the ThermoPhase objects isn't the same"); } if (ntp->nSpecies() != otp->nSpecies()) { throw CanteraError(" Kinetics::assignShallowPointers", " Number of ThermoPhase objects isn't the same"); } m_thermo[i] = tpVector[i]; } }
status_t phase_setmolefractions_(const integer* n, double* x, const integer* norm) { try { ThermoPhase* p = _fph(n); if (*norm) { p->setMoleFractions(x); } else { p->setMoleFractions_NoNorm(x); } } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
status_t DLL_EXPORT phase_setmassfractionsbyname_(const integer* n, char* y, ftnlen leny) { try { ThermoPhase* p = _fph(n); compositionMap yy; int nsp = p->nSpecies(); for (int nn = 0; nn < nsp; nn++) { yy[p->speciesName(nn)] = -1; } parseCompString(f2string(y, leny), yy); p->setMassFractionsByName(yy); return 0; } catch (CanteraError) {handleError(); return -1;} }
status_t phase_setmassfractions_(const integer* n, doublereal* y, const integer* norm) { try { ThermoPhase* p = _fph(n); if (*norm) { p->setMassFractions(y); } else { p->setMassFractions_NoNorm(y); } } catch (...) { return handleAllExceptions(-1, ERR); } return 0; }
// The actual code is put into a function that // can be called from the main program. void simple_demo() { // Create a new phase ThermoPhase* gas = newPhase("h2o2.cti","ohmech"); // Set its state by specifying T (500 K) P (2 atm) and the mole // fractions. Note that the mole fractions do not need to sum to // 1.0 - they will be normalized internally. Also, the values for // any unspecified species will be set to zero. gas->setState_TPX(500.0, 2.0*OneAtm, "H2O:1.0, H2:8.0, AR:1.0"); // Print a summary report of the state of the gas cout << report(*gas) << endl; // Clean up delete gas; }
void IdealGasReactor::setThermoMgr(ThermoPhase& thermo) { //! @TODO: Add a method to ThermoPhase that indicates whether a given //! subclass is compatible with this reactor model if (thermo.eosType() != cIdealGas) { throw CanteraError("IdealGasReactor::setThermoMgr", "Incompatible phase type provided"); } Reactor::setThermoMgr(thermo); }
int main(int argc, char** argv) { #ifdef _MSC_VER _set_output_format(_TWO_DIGIT_EXPONENT); #endif try { IdealSolnGasVPSS gg("silane.xml", "silane"); ThermoPhase* g = ≫ cout.precision(4); g->setState_TPX(1500.0, 100.0, "SIH4:0.01, H2:0.99"); g->equilibrate("TP"); cout << g->report(true, 0.0) << endl; return 0; } catch (CanteraError& err) { std::cerr << err.what() << std::endl; cerr << "program terminating." << endl; return -1; } }
int main(int argc, char **argv) { int retn = 0; int i; try { char iFile[80]; strcpy(iFile, "HMW_NaCl.xml"); if (argc > 1) { strcpy(iFile, argv[1]); } double Cp0_R[20], pmCp[20]; //fileLog *fl = new fileLog("HMW_graph_1.log"); //setLogger(fl); HMWSoln *HMW = new HMWSoln(iFile, "NaCl_electrolyte"); /* * Load in and initialize the */ Cantera::ThermoPhase *solid = newPhase("NaCl_Solid.xml","NaCl(S)"); int nsp = HMW->nSpecies(); double acMol[100]; double act[100]; double mf[100]; double moll[100]; for (i = 0; i < 100; i++) { acMol[i] = 1.0; act[i] = 1.0; mf[i] = 0.0; act[i] = 0.0; } HMW->getMoleFractions(mf); string sName; TemperatureTable TTable(15, false, 273.15, 25., 0, 0); HMW->setState_TP(298.15, 1.01325E5); int i1 = HMW->speciesIndex("Na+"); int i2 = HMW->speciesIndex("Cl-"); //int i3 = HMW->speciesIndex("H2O(L)"); for (i = 0; i < nsp; i++) { moll[i] = 0.0; } HMW->setMolalities(moll); double ISQRT; double Is = 0.0; /* * Set the Pressure */ double pres = OneAtm; /* * Fix the molality */ Is = 6.146; ISQRT = sqrt(Is); moll[i1] = Is; moll[i2] = Is; HMW->setState_TPM(298.15, pres, moll); double Xmol[30]; HMW->getMoleFractions(Xmol); ThermoPhase *hmwtb = (ThermoPhase *)HMW; ThermoPhase *hmwtbDupl = hmwtb->duplMyselfAsThermoPhase(); //ThermoPhase *hmwtbDupl = 0; HMWSoln *HMW1 = HMW; HMWSoln *HMW2 = dynamic_cast<HMWSoln *>(hmwtbDupl); for (int itherms = 0; itherms < 2; itherms++) { if (itherms ==0) { HMW = HMW1; } else { HMW = HMW2; } /* * ThermoUnknowns */ double T; double Cp0_NaCl = 0.0, Cp0_Naplus = 0.0, Cp0_Clminus = 0.0, Delta_Cp0s = 0.0, Cp0_H2O = 0.0; double Cp_NaCl = 0.0, Cp_Naplus = 0.0, Cp_Clminus = 0.0, Cp_H2O = 0.0; double molarCp0; #ifdef DEBUG_HKM FILE *ttt; if (itherms ==0) { ttt = fopen("table1.csv","w"); } else { ttt = fopen("table2.csv","w"); } #endif printf("A_J/R: Comparison to Pitzer's book, p. 99, can be made.\n"); printf(" Agreement is within 12 pc \n"); printf("\n"); printf("Delta_Cp0: Heat Capacity of Solution per mole of salt (standard states)\n"); printf(" rxn for the ss heat of soln: " "NaCl(s) -> Na+(aq) + Cl-(aq)\n"); printf("\n"); printf("Delta_Cps: Delta heat Capacity of Solution per mole of salt\n"); printf(" rxn for heat of soln: " " n1 H2O(l,pure) + n2 NaCl(s) -> n2 MX(aq) + n1 H2O(l) \n"); printf(" Delta_Hs = (n1 h_H2O_bar + n2 h_MX_bar " "- n1 h_H2O_0 - n2 h_MX_0)/n2\n"); printf("\n"); printf("phiJ: phiJ, calculated from the program, is checked\n"); printf(" against analytical formula in J_standalone program.\n"); printf(" (comparison against Eq. 12, Silvester and Pitzer)\n"); /* * Create a Table of NaCl Enthalpy Properties as a Function * of the Temperature */ printf("\n\n"); printf(" T, Pres, Aphi, A_J/R," " Delta_Cp0," " Delta_Cps, J, phiJ," " MolarCp, MolarCp0\n"); printf(" Kelvin, bar, sqrt(kg/gmol), sqrt(kg/gmol)," " kJ/gmolSalt," " kJ/gmolSalt, kJ/gmolSoln, kJ/gmolSalt," " kJ/gmol, kJ/gmol\n"); #ifdef DEBUG_HKM fprintf(ttt,"T, Pres, A_J/R, Delta_Cp0, Delta_Cps, J, phiJ\n"); fprintf(ttt,"Kelvin, bar, sqrt(kg/gmol), kJ/gmolSalt, kJ/gmolSalt, kJ/gmolSoln," "kJ/gmolSalt\n"); #endif for (i = 0; i < TTable.NPoints + 1; i++) { if (i == TTable.NPoints) { T = 323.15; } else { T = TTable.T[i]; } /* * RT is in units of J/kmolK */ //double RT = GasConstant * T; /* * Make sure we are at the saturation pressure or above. */ double psat = HMW->satPressure(T); pres = OneAtm; if (psat > pres) pres = psat; HMW->setState_TPM(T, pres, moll); solid->setState_TP(T, pres); /* * Get the Standard State DeltaH */ solid->getCp_R(Cp0_R); Cp0_NaCl = Cp0_R[0] * GasConstant * 1.0E-6; HMW->getCp_R(Cp0_R); Cp0_H2O = Cp0_R[0] * GasConstant * 1.0E-6; Cp0_Naplus = Cp0_R[i1] * GasConstant * 1.0E-6; Cp0_Clminus = Cp0_R[i2] * GasConstant * 1.0E-6; /* * Calculate the standard state heat of solution * for NaCl(s) -> Na+ + Cl- * units: kJ/gmolSalt */ Delta_Cp0s = Cp0_Naplus + Cp0_Clminus - Cp0_NaCl; pmCp[0] = solid->cp_mole(); Cp_NaCl = pmCp[0] * 1.0E-6; HMW->getPartialMolarCp(pmCp); Cp_H2O = pmCp[0] * 1.0E-6; Cp_Naplus = pmCp[i1] * 1.0E-6; Cp_Clminus = pmCp[i2] * 1.0E-6; //double Delta_Cp_Salt = Cp_NaCl - (Cp_Naplus + Cp_Clminus); double molarCp = HMW->cp_mole() * 1.0E-6; /* * Calculate the heat capacity of solution for the reaction * NaCl(s) -> Na+ + Cl- */ double Delta_Cps = (Xmol[0] * Cp_H2O + Xmol[i1] * Cp_Naplus + Xmol[i2] * Cp_Clminus - Xmol[0] * Cp0_H2O - Xmol[i1] * Cp_NaCl); Delta_Cps /= Xmol[i1]; /* * Calculate the relative heat capacity, J, from the * partial molar quantities, units J/gmolSolutionK */ double J = (Xmol[0] * (Cp_H2O - Cp0_H2O) + Xmol[i1] * (Cp_Naplus - Cp0_Naplus) + Xmol[i2] * (Cp_Clminus - Cp0_Clminus)); /* * Calculate the apparent relative molal heat capacity, phiJ, * units of J/gmolSaltAddedK */ double phiJ = J / Xmol[i1]; double Aphi = HMW->A_Debye_TP(T, pres) / 3.0; //double AL = HMW->ADebye_L(T,pres); double AJ = HMW->ADebye_J(T, pres); for (int k = 0; k < nsp; k++) { Cp0_R[k] *= GasConstant * 1.0E-6; } molarCp0 = 0.0; for (int k = 0; k < nsp; k++) { molarCp0 += Xmol[k] * Cp0_R[k]; } if (i != TTable.NPoints+1) { printf("%13g, %13g, %13g, %13g, %13g, %13g, " "%13g, %13g, %13g, %13g\n", T, pres*1.0E-5, Aphi, AJ/GasConstant, Delta_Cp0s, Delta_Cps, J, phiJ, molarCp , molarCp0 ); #ifdef DEBUG_HKM fprintf(ttt,"%g, %g, %g, %g, %g, %g, %g\n", T, pres*1.0E-5, AJ/GasConstant, Delta_Cp0s, Delta_Cps, J, phiJ); #endif } } printf("Breakdown of Heat Capacity Calculation at 323.15 K, 1atm:\n"); printf(" Species MoleFrac Molal Cp0 " " partCp (partCp - Cp0)\n"); printf(" H2O(L)"); printf("%13g %13g %13g %13g %13g\n", Xmol[0], moll[0], Cp0_H2O , Cp_H2O, Cp_H2O-Cp0_H2O); printf(" Na+ "); printf("%13g %13g %13g %13g %13g\n", Xmol[i1], moll[i1], Cp0_Naplus , Cp_Naplus, Cp_Naplus -Cp0_Naplus); printf(" Cl- "); printf("%13g %13g %13g %13g %13g\n", Xmol[i2], moll[i2], Cp0_Clminus , Cp_Clminus, Cp_Clminus - Cp0_Clminus); printf(" NaCl(s)"); printf("%13g %13g %13g %13g\n", 1.0, Cp0_NaCl , Cp_NaCl, Cp_NaCl - Cp0_NaCl); #ifdef DEBUG_HKM fclose(ttt); #endif } delete HMW1; HMW = 0; delete hmwtbDupl; hmwtbDupl = 0; delete solid; solid = 0; Cantera::appdelete(); return retn; } catch (CanteraError) { printf("caught error\n"); showErrors(); Cantera::appdelete(); return -1; } }
int main(int argc, char** argv) { string infile; int i, k; int ioflag = 1; // look for command-line options if (argc > 1) { string tok; for (int j = 1; j < argc; j++) { tok = string(argv[j]); if (tok[0] == '-') { int nopt = static_cast<int>(tok.size()); for (int n = 1; n < nopt; n++) { if (tok[n] == 'h') { printUsage(); exit(0); } else if (tok[n] == 'd') { int lvl = 0; if (j < (argc - 1)) { string tokla = string(argv[j+1]); if (strlen(tokla.c_str()) > 0) { lvl = atoi(tokla.c_str()); n = nopt - 1; j += 1; ioflag = lvl; } } } else { printUsage(); exit(1); } } } else if (infile == "") { infile = tok; } else { printUsage(); exit(1); } } } if (infile == "") { infile = "diamond.cti"; } try { /*************************************************************/ /* * FILL IN THESE NAMES FOR EACH PROBLEM */ /* * ProblemNumber = 0 : diamond.cti * = 1 : haca.cti */ int ProblemNumber = 1; string gasPhaseName = "gas"; string bulkParticlePhaseName = "diamond"; string surfParticlePhaseName = "diamond_100"; if (ProblemNumber == 1) { gasPhaseName = "gas"; bulkParticlePhaseName = "soot"; surfParticlePhaseName = "soot_interface"; } /************************************************************/ XML_Node* xc = new XML_Node(); string path = findInputFile(infile); ctml::get_CTML_Tree(xc, path); XML_Node* const xg = (XML_Node*) findXMLPhase(xc, gasPhaseName); if (!xg) { printf("ERROR: Could not find gas phase named, %s, in file\n", gasPhaseName.c_str()); exit(-1); } ThermoPhase* gasTP = newPhase(*xg); size_t nspGas = gasTP->nSpecies(); cout << "Number of species = " << nspGas << endl; XML_Node* const xd = (XML_Node*) findXMLPhase(xc, bulkParticlePhaseName); if (!xd) { printf("ERROR: Could not find bulk phase named, %s, in file\n", bulkParticlePhaseName.c_str()); exit(-1); } ThermoPhase* bulkPhaseTP = newPhase(*xd); size_t nspBulk = bulkPhaseTP->nSpecies(); cout << "Number of species in bulk phase named " << bulkParticlePhaseName << " = " << nspBulk << endl; XML_Node* const xs = (XML_Node*) findXMLPhase(xc, surfParticlePhaseName); if (!xs) { printf("ERROR: Could not find surf Particle phase named," "%s, in file\n", surfParticlePhaseName.c_str()); exit(-1); } ThermoPhase* surfPhaseTP = newPhase(*xs); size_t nsp_d100 = surfPhaseTP->nSpecies(); cout << "Number of species in surface phase, " << surfParticlePhaseName << " = " << nsp_d100 << endl; vector<ThermoPhase*> phaseList; phaseList.push_back(gasTP); phaseList.push_back(bulkPhaseTP); phaseList.push_back(surfPhaseTP); InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); importKinetics(*xs, phaseList, iKin_ptr); size_t nr = iKin_ptr->nReactions(); cout << "Number of reactions = " << nr << endl; ofstream ofile("results2.txt"); // create a second copy of the same surface phase // (this is a made up problem btw to check the software capability) ThermoPhase* surfPhaseTP2 = newPhase(*xs); size_t nsp2 = surfPhaseTP2->nSpecies(); string pname = surfPhaseTP2->id(); cout << "Number of species in 2nd surface phase, " << pname << " = " << nsp2 << endl; vector<ThermoPhase*> phaseList2; phaseList2.push_back(gasTP); phaseList2.push_back(bulkPhaseTP); phaseList2.push_back(surfPhaseTP2); // create the second InterfaceKinetics object based on the // second surface phase. InterfaceKinetics* iKin2_ptr = new InterfaceKinetics(); importKinetics(*xs, phaseList2, iKin2_ptr); nr = iKin_ptr->nReactions(); cout << "Number of reactions = " << nr << endl; double x[MSSIZE], p = OneAtm; /* * Set the Gas State: * -> note that the states are set in the xml files too */ for (i = 0; i < MSSIZE; i++) { x[i] = 0.0; } if (ProblemNumber == 0) { x[0] = 0.0010; x[1] = 0.9888; x[2] = 0.0002; x[3] = 0.0100; p = 20.0*OneAtm/760.0; gasTP->setState_TPX(1200., p, x); } /* * Set the surface initial state * other problem numbers take their initial state from the xml files. */ for (i = 0; i < MSSIZE; i++) { x[i] = 0.0; } if (ProblemNumber == 0) { size_t i0 = surfPhaseTP->speciesIndex("c6H*"); if (i0 != npos) { x[i0] = 0.1; } size_t i1 = surfPhaseTP->speciesIndex("c6HH"); if (i1 != npos) { x[i1] = 0.9; } surfPhaseTP->setState_TX(1200., x); } /* * Set the bulk Phase State */ for (i = 0; i < MSSIZE; i++) { x[i] = 0.0; } if (ProblemNumber == 0) { x[0] = 1.0; bulkPhaseTP->setState_TPX(1200., p, x); } /* * Set-up the Surface Problem * This problem will consist of 2 identical InterfaceKinetics objects */ vector<InterfaceKinetics*> vecKinPtrs; vecKinPtrs.push_back(iKin_ptr); vecKinPtrs.push_back(iKin2_ptr); // Create the ImplicitSurfChem problem // Initialize it and call the pseudo steadystate capability. ImplicitSurfChem* surfaceProb = new ImplicitSurfChem(vecKinPtrs); surfaceProb->initialize(); surfaceProb->setIOFlag(ioflag); surfaceProb->solvePseudoSteadyStateProblem(); /* * Download the source terms for the rate equations */ double src[MSSIZE]; double src2[MSSIZE]; iKin_ptr->getNetProductionRates(src); iKin2_ptr->getNetProductionRates(src2); double sum = 0.0; if (ProblemNumber == 0) { double naH; for (k = 0; k < 13; k++) { if (k < 4) { naH = gasTP->nAtoms(k, 0); } else if (k == 4) { naH = 0; } else if (k > 4) { int itp = k - 5; naH = surfPhaseTP->nAtoms(itp, 0); } cout << k << " " << naH << " " ; if (fabs(src[k]) < 2.0E-17) { cout << " nil" << endl; } else { cout << src[k] << endl; } sum += naH * src[k]; } cout << "sum = " << sum << endl; } printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printSurf(cout, surfPhaseTP2, iKin2_ptr, src2) ; printGas(ofile, gasTP, iKin_ptr, src); printBulk(ofile, bulkPhaseTP, iKin_ptr, src); printSurf(ofile, surfPhaseTP, iKin_ptr, src) ; printSurf(ofile, surfPhaseTP2, iKin2_ptr, src2) ; /*****************************************************************************/ /* Now Tweak the inputs and do a quick calculation */ /****************************************************************************/ /* * Set the Gas State: * -> note that the states are set in the xml files too */ double pres = gasTP->pressure(); gasTP->getMoleFractions(x); double tmp = 0.3 * x[0]; double tmp2 = 0.3 * x[1]; if (tmp2 < tmp) { tmp = tmp2; } x[0] += tmp; x[1] -= tmp; gasTP->setState_PX(pres, x); surfaceProb->solvePseudoSteadyStateProblem(); iKin_ptr->getNetProductionRates(src); iKin2_ptr->getNetProductionRates(src2); printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printSurf(cout, surfPhaseTP2, iKin2_ptr, src2) ; /*****************************************************************************/ /* Now Tweak the inputs and do a quick calculation */ /****************************************************************************/ /* * Set the Gas State: * -> note that the states are set in the xml files too */ /* * Set the Gas State: * -> note that the states are set in the xml files too */ pres = gasTP->pressure(); double temp = gasTP->temperature(); temp += 95; gasTP->setState_TP(temp, pres); surfaceProb->solvePseudoSteadyStateProblem(); iKin_ptr->getNetProductionRates(src); iKin2_ptr->getNetProductionRates(src2); printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printSurf(cout, surfPhaseTP2, iKin2_ptr, src2) ; /*****************************************************************************/ /* Now Don't Tweak the inputs at all */ /****************************************************************************/ gasTP->setState_TP(temp, pres); surfaceProb->solvePseudoSteadyStateProblem(); iKin_ptr->getNetProductionRates(src); iKin2_ptr->getNetProductionRates(src2); printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printSurf(cout, surfPhaseTP2, iKin2_ptr, src2) ; delete surfaceProb; surfaceProb = 0; delete iKin_ptr; iKin_ptr = 0; delete iKin2_ptr; iKin2_ptr = 0; delete gasTP; gasTP = 0; delete bulkPhaseTP; bulkPhaseTP = 0; delete surfPhaseTP; surfPhaseTP = 0; delete surfPhaseTP2; surfPhaseTP2 = 0; delete xc; appdelete(); } catch (CanteraError& err) { std::cout << err.what() << std::endl; } return 0; }
int main(int argc, char** argv) { #if defined(_MSC_VER) && _MSC_VER < 1900 _set_output_format(_TWO_DIGIT_EXPONENT); #endif suppress_deprecation_warnings(); int numSucc = 0; int numFail = 0; int printLvl = 1; string inputFile = "HMW_NaCl.xml"; VCS_SOLVE::disableTiming(); /* * Process the command line arguments */ if (argc > 1) { string tok; for (int j = 1; j < argc; j++) { tok = string(argv[j]); if (tok[0] == '-') { int nopt = static_cast<int>(tok.size()); for (int n = 1; n < nopt; n++) { if (!strcmp(tok.c_str() + 1, "help_cmdfile")) { } else if (tok[n] == 'h') { printUsage(); exit(1); } else if (tok[n] == 'd') { printLvl = 2; int lvl = 2; if (j < (argc - 1)) { string tokla = string(argv[j+1]); if (strlen(tokla.c_str()) > 0) { lvl = atoi(tokla.c_str()); n = nopt - 1; j += 1; if (lvl >= 0) { printLvl = lvl; } } } } else { printUsage(); exit(1); } } } else if (inputFile == "HMW_NaCl.xml") { inputFile = tok; } else { printUsage(); exit(1); } } } try { int estimateEquil = -1; double T = 298.15; double pres = OneAtm; // Initialize the individual phases HMWSoln hmw(inputFile, ""); size_t kk = hmw.nSpecies(); vector_fp Xmol(kk, 0.0); size_t iH2OL = hmw.speciesIndex("H2O(L)"); Xmol[iH2OL] = 1.0; hmw.setState_TPX(T, pres, Xmol.data()); ThermoPhase* gas = newPhase("gas.xml"); kk = gas->nSpecies(); Xmol.resize(kk, 0.0); for (size_t i = 0; i < kk; i++) { Xmol[i] = 0.0; } size_t iN2 = gas->speciesIndex("N2"); Xmol[iN2] = 1.0; gas->setState_TPX(T, pres, Xmol.data()); StoichSubstance ss("NaCl_Solid.xml", ""); ss.setState_TP(T, pres); // Construct the multiphase object MultiPhase* mp = new MultiPhase(); mp->addPhase(&hmw, 2.0); mp->addPhase(gas, 4.0); mp->addPhase(&ss, 5.0); try { mp->equilibrate("TP", "vcs", 1e-9, 50000, 100, estimateEquil, printLvl); cout << *mp; numSucc++; } catch (CanteraError& err) { cout << *mp; std::cerr << err.what() << std::endl; cerr << "ERROR: MultiEquil equilibration step failed at " << " T = " << T << " Pres = " << pres << endl; cout << "ERROR: MultiEqiul equilibration step failed at " << " T = " << T << " Pres = " << pres << endl; exit(-1); } cout << "NUMBER OF SUCCESSES = " << numSucc << endl; cout << "NUMBER OF FAILURES = " << numFail << endl; return numFail; } catch (CanteraError& err) { std::cerr << err.what() << std::endl; cerr << "ERROR: program terminating due to unforeseen circumstances." << endl; return -1; } }
status_t DLL_EXPORT phase_getmolecularweights_(const integer* n, doublereal* mw) { ThermoPhase* p = _fph(n); const vector_fp& wt = p->molecularWeights(); copy(wt.begin(), wt.end(), mw); return 0; }
status_t DLL_EXPORT phase_getatomicweights_(const integer* n, doublereal* atw) { ThermoPhase* p = _fph(n); const vector_fp& wt = p->atomicWeights(); copy(wt.begin(), wt.end(), atw); return 0; }
int main(int argc, char** argv) { int i, k; string infile = "diamond.xml"; try { XML_Node *xc = new XML_Node(); string path = findInputFile(infile); ctml::get_CTML_Tree(xc, path); XML_Node * const xg = xc->findNameID("phase", "gas"); ThermoPhase *gasTP = newPhase(*xg); int nsp = gasTP->nSpecies(); cout << "Number of species = " << nsp << endl; XML_Node * const xd = xc->findNameID("phase", "diamond"); ThermoPhase *diamondTP = newPhase(*xd); int nsp_diamond = diamondTP->nSpecies(); cout << "Number of species in diamond = " << nsp_diamond << endl; XML_Node * const xs = xc->findNameID("phase", "diamond_100"); ThermoPhase *diamond100TP = newPhase(*xs); //SurfPhase *diamond100TP = new SurfPhase(*xs); int nsp_d100 = diamond100TP->nSpecies(); cout << "Number of species in diamond_100 = " << nsp_d100 << endl; vector<ThermoPhase *> phaseList; phaseList.push_back(gasTP); phaseList.push_back(diamondTP); phaseList.push_back(diamond100TP); InterfaceKinetics *iKin_ptr = new InterfaceKinetics(); importKinetics(*xs, phaseList, iKin_ptr); int nr = iKin_ptr->nReactions(); cout << "Number of reactions = " << nr << endl; double x[20]; for (i = 0; i < 20; i++) x[i] = 0.0; x[0] = 0.0010; x[1] = 0.9888; x[2] = 0.0002; x[3] = 0.0100; double p = 20.0*OneAtm/760.0; gasTP->setState_TPX(1200., p, x); for (i = 0; i < 20; i++) x[i] = 0.0; int i0 = diamond100TP->speciesIndex("c6H*"); x[i0] = 0.1; int i1 = diamond100TP->speciesIndex("c6HH"); x[i1] = 0.9; diamond100TP->setState_TX(1200., x); for (i = 0; i < 20; i++) x[i] = 0.0; x[0] = 1.0; diamondTP->setState_TPX(1200., p, x); iKin_ptr->advanceCoverages(100.); // Throw some asserts in here to test that they compile AssertTrace(p == p); AssertThrow(p == p, "main"); AssertThrowMsg(i == 20, "main", "are you kidding"); double src[20]; for (i = 0; i < 20; i++) src[i] = 0.0; iKin_ptr->getNetProductionRates(src); double sum = 0.0; double naH = 0.0; for (k = 0; k < 13; k++) { if (k < 4) { naH = gasTP->nAtoms(k, 0); } else if (k == 4) { naH = 0; } else if (k > 4) { int itp = k - 5; naH = diamond100TP->nAtoms(itp, 0); } cout << k << " " << naH << " " ; printDbl(src[k]); cout << endl; sum += naH * src[k]; } cout << "sum = "; printDbl(sum); cout << endl; double mwd = diamondTP->molecularWeight(0); double dens = diamondTP->density(); double gr = src[4] * mwd / dens; gr *= 1.0E6 * 3600.; cout << "growth rate = " << gr << " microns per hour" << endl; diamond100TP->getMoleFractions(x); cout << "Coverages:" << endl; for (k = 0; k < 8; k++) { cout << k << " " << diamond100TP->speciesName(k) << " " << x[k] << endl; } } catch (CanteraError) { showErrors(cout); } return 0; }
status_t DLL_EXPORT phase_setmassfractions_(const integer* n, doublereal* y, const integer* norm) { ThermoPhase* p = _fph(n); if (*norm) p->setMassFractions(y); else p->setMassFractions_NoNorm(y); return 0; }
int main(int argc, char** argv) { #ifdef _MSC_VER _set_output_format(_TWO_DIGIT_EXPONENT); #endif string infile; int ioflag = 1; int i, k; // look for command-line options if (argc > 1) { string tok; for (int j = 1; j < argc; j++) { tok = string(argv[j]); if (tok[0] == '-') { int nopt = static_cast<int>(tok.size()); for (int n = 1; n < nopt; n++) { if (tok[n] == 'h') { printUsage(); exit(0); } else if (tok[n] == 'd') { int lvl = 0; if (j < (argc - 1)) { string tokla = string(argv[j+1]); if (strlen(tokla.c_str()) > 0) { lvl = atoi(tokla.c_str()); n = nopt - 1; j += 1; ioflag = lvl; } } } else { printUsage(); exit(1); } } } else if (infile == "") { infile = tok; } else { printUsage(); exit(1); } } } if (infile == "") { infile = "diamond.cti"; } try { /*************************************************************/ /* * FILL IN THESE NAMES FOR EACH PROBLEM */ /* * ProblemNumber = 0 : diamond.cti * = 1 : haca.cti */ int ProblemNumber = 1; string gasPhaseName = "gas"; string bulkParticlePhaseName = "diamond"; string surfParticlePhaseName = "diamond_100"; if (ProblemNumber == 1) { gasPhaseName = "gas"; bulkParticlePhaseName = "soot"; surfParticlePhaseName = "soot_interface"; } /************************************************************/ XML_Node* xc = get_XML_File(infile); XML_Node* const xg = (XML_Node*) findXMLPhase(xc, gasPhaseName); if (!xg) { printf("ERROR: Could not find gas phase named, %s, in file\n", gasPhaseName.c_str()); exit(-1); } ThermoPhase* gasTP = newPhase(*xg); size_t nspGas = gasTP->nSpecies(); cout << "Number of species = " << nspGas << endl; XML_Node* const xd = (XML_Node*) findXMLPhase(xc, bulkParticlePhaseName); if (!xd) { printf("ERROR: Could not find bulk phase named, %s, in file\n", bulkParticlePhaseName.c_str()); exit(-1); } ThermoPhase* bulkPhaseTP = newPhase(*xd); size_t nspBulk = bulkPhaseTP->nSpecies(); cout << "Number of species in bulk phase named " << bulkParticlePhaseName << " = " << nspBulk << endl; XML_Node* const xs = (XML_Node*) findXMLPhase(xc, surfParticlePhaseName); if (!xs) { printf("ERROR: Could not find surf Particle phase named, %s, in file\n", surfParticlePhaseName.c_str()); exit(-1); } ThermoPhase* surfPhaseTP = newPhase(*xs); size_t nsp_d100 = surfPhaseTP->nSpecies(); cout << "Number of species in surface phase, " << surfParticlePhaseName << " = " << nsp_d100 << endl; vector<ThermoPhase*> phaseList; phaseList.push_back(gasTP); phaseList.push_back(bulkPhaseTP); phaseList.push_back(surfPhaseTP); InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); importKinetics(*xs, phaseList, iKin_ptr); size_t nr = iKin_ptr->nReactions(); cout << "Number of reactions = " << nr << endl; double x[MSSIZE], p = OneAtm; ofstream ofile("results.txt"); /* * Set the Gas State: * -> note that the states are set in the XML files too */ for (i = 0; i < MSSIZE; i++) { x[i] = 0.0; } if (ProblemNumber == 0) { x[0] = 0.0010; x[1] = 0.9888; x[2] = 0.0002; x[3] = 0.0100; p = 20.0*OneAtm/760.0; gasTP->setState_TPX(1200., p, x); } /* * Set the surface initial state */ for (i = 0; i < MSSIZE; i++) { x[i] = 0.0; } if (ProblemNumber == 0) { size_t i0 = surfPhaseTP->speciesIndex("c6H*"); if (i0 != npos) { x[i0] = 0.1; } size_t i1 = surfPhaseTP->speciesIndex("c6HH"); if (i1 != npos) { x[i1] = 0.9; } surfPhaseTP->setState_TX(1200., x); } /* * Set the bulk Phase State */ for (i = 0; i < MSSIZE; i++) { x[i] = 0.0; } if (ProblemNumber == 0) { x[0] = 1.0; bulkPhaseTP->setState_TPX(1200., p, x); } iKin_ptr->setIOFlag(ioflag); /* * Solve the Equation system */ //iKin_ptr->advanceCoverages(100.); iKin_ptr->solvePseudoSteadyStateProblem(); /* * Download the source terms for the rate equations */ double src[MSSIZE]; iKin_ptr->getNetProductionRates(src); double sum = 0.0; if (ProblemNumber == 0) { double naH; for (k = 0; k < 13; k++) { if (k < 4) { naH = gasTP->nAtoms(k, 0); } else if (k == 4) { naH = 0; } else if (k > 4) { int itp = k - 5; naH = surfPhaseTP->nAtoms(itp, 0); } cout << k << " " << naH << " " ; if (fabs(src[k]) < 2.0E-17) { cout << " nil" << endl; } else { cout << src[k] << endl; } sum += naH * src[k]; } cout << "sum = " << sum << endl; } printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printGas(ofile, gasTP, iKin_ptr, src); printBulk(ofile, bulkPhaseTP, iKin_ptr, src); printSurf(ofile, surfPhaseTP, iKin_ptr, src) ; /*****************************************************************************/ /* Now Tweak the inputs and do a quick calculation */ /****************************************************************************/ /* * Set the Gas State: * -> note that the states are set in the XML files too */ double pres = gasTP->pressure(); gasTP->getMoleFractions(x); double tmp = 0.3 * std::min(x[0], x[1]); x[0] += tmp; x[1] -= tmp; gasTP->setState_PX(pres, x); iKin_ptr->solvePseudoSteadyStateProblem(); iKin_ptr->getNetProductionRates(src); printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printGas(ofile, gasTP, iKin_ptr, src); printBulk(ofile, bulkPhaseTP, iKin_ptr, src); printSurf(ofile, surfPhaseTP, iKin_ptr, src) ; /*****************************************************************************/ /* Now Tweak the inputs and do a quick calculation */ /****************************************************************************/ /* * Set the Gas State: * -> note that the states are set in the XML files too */ /* * Set the Gas State: * -> note that the states are set in the XML files too */ pres = gasTP->pressure(); double temp = gasTP->temperature(); temp += 95; gasTP->setState_TP(temp, pres); iKin_ptr->solvePseudoSteadyStateProblem(); iKin_ptr->getNetProductionRates(src); printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printGas(ofile, gasTP, iKin_ptr, src); printBulk(ofile, bulkPhaseTP, iKin_ptr, src); printSurf(ofile, surfPhaseTP, iKin_ptr, src) ; /*****************************************************************************/ /* Now Don't Tweak the inputs at all */ /****************************************************************************/ gasTP->setState_TP(temp, pres); iKin_ptr->solvePseudoSteadyStateProblem(); iKin_ptr->getNetProductionRates(src); printGas(cout, gasTP, iKin_ptr, src); printBulk(cout, bulkPhaseTP, iKin_ptr, src); printSurf(cout, surfPhaseTP, iKin_ptr, src) ; printGas(ofile, gasTP, iKin_ptr, src); printBulk(ofile, bulkPhaseTP, iKin_ptr, src); printSurf(ofile, surfPhaseTP, iKin_ptr, src) ; delete iKin_ptr; delete gasTP; gasTP = 0; delete bulkPhaseTP; bulkPhaseTP = 0; delete surfPhaseTP; surfPhaseTP = 0; appdelete(); } catch (CanteraError& err) { std::cout << err.what() << std::endl; return 1; } return 0; }
int main(int argc, char** argv) { #if defined(_MSC_VER) && _MSC_VER < 1900 _set_output_format(_TWO_DIGIT_EXPONENT); #endif if (argc != 2) { cout << "Error: no input file specified.\n" "Choose either 'diamond.cti' or 'diamond_blessed.xml" << endl; exit(-1); } std::string infile(argv[1]); int i, k; try { XML_Node* xc = get_XML_File(infile); XML_Node* const xg = xc->findNameID("phase", "gas"); ThermoPhase* gasTP = newPhase(*xg); size_t nsp = gasTP->nSpecies(); cout.precision(4); cout << "Number of species = " << nsp << endl; XML_Node* const xd = xc->findNameID("phase", "diamond"); ThermoPhase* diamondTP = newPhase(*xd); size_t nsp_diamond = diamondTP->nSpecies(); cout << "Number of species in diamond = " << nsp_diamond << endl; XML_Node* const xs = xc->findNameID("phase", "diamond_100"); ThermoPhase* diamond100TP = newPhase(*xs); size_t nsp_d100 = diamond100TP->nSpecies(); cout << "Number of species in diamond_100 = " << nsp_d100 << endl; vector<ThermoPhase*> phaseList { gasTP, diamondTP, diamond100TP }; InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); importKinetics(*xs, phaseList, iKin_ptr); size_t nr = iKin_ptr->nReactions(); cout << "Number of reactions = " << nr << endl; double x[20]; for (i = 0; i < 20; i++) { x[i] = 0.0; } x[0] = 0.0010; x[1] = 0.9888; x[2] = 0.0002; x[3] = 0.0100; double p = 20.0*OneAtm/760.0; gasTP->setState_TPX(1200., p, x); for (i = 0; i < 20; i++) { x[i] = 0.0; } size_t i0 = diamond100TP->speciesIndex("c6H*"); x[i0] = 0.1; size_t i1 = diamond100TP->speciesIndex("c6HH"); x[i1] = 0.9; diamond100TP->setState_TX(1200., x); for (i = 0; i < 20; i++) { x[i] = 0.0; } x[0] = 1.0; diamondTP->setState_TPX(1200., p, x); iKin_ptr->advanceCoverages(100.); // Throw some asserts in here to test that they compile AssertTrace(p == p); AssertThrow(p == p, "main"); AssertThrowMsg(i == 20, "main", "are you kidding"); double src[20]; for (i = 0; i < 20; i++) { src[i] = 0.0; } iKin_ptr->getNetProductionRates(src); double sum = 0.0; double naH = 0.0; for (k = 0; k < 13; k++) { if (k < 4) { naH = gasTP->nAtoms(k, 0); } else if (k == 4) { naH = 0; } else if (k > 4) { int itp = k - 5; naH = diamond100TP->nAtoms(itp, 0); } cout << k << " " << naH << " " ; printDbl(src[k]); cout << endl; sum += naH * src[k]; } cout << "sum = "; printDbl(sum); cout << endl; double mwd = diamondTP->molecularWeight(0); double dens = diamondTP->density(); double gr = src[4] * mwd / dens; gr *= 1.0E6 * 3600.; cout << "growth rate = " << gr << " microns per hour" << endl; diamond100TP->getMoleFractions(x); cout << "Coverages:" << endl; for (k = 0; k < 8; k++) { cout << k << " " << diamond100TP->speciesName(k) << " " << x[k] << endl; } } catch (CanteraError& err) { std::cout << err.what() << std::endl; } return 0; }
/* * @param th ThermoPhase object to create a report about * @param show_thermo Boolean indicating whether the thermo functions * of the phase should be written out * * @return Returns a string containing the report */ std::string report(const ThermoPhase& th, const bool show_thermo) { return th.report(show_thermo); }
void initializeElements() { test_phase.addElement("A", 1.); test_phase.addElement("B", 2.); test_phase.addElement("C", 3.); }
int main(int argc, char** argv) { #ifdef _MSC_VER _set_output_format(_TWO_DIGIT_EXPONENT); #endif try { if (argc != 2) { cout << "Error: no input file specified.\n" "Choose either 'noxNeg.cti' or 'noxNeg_blessed.xml" << endl; exit(-1); } std::string infile(argv[1]); size_t i; double x[20]; double cdot[20], ddot[20]; XML_Node* xc = new XML_Node(); string path = findInputFile(infile); ctml::get_CTML_Tree(xc, path); XML_Node* const xg = xc->findNameID("phase", "air"); ThermoPhase* gasTP = newPhase(*xg); size_t nsp = gasTP->nSpecies(); cout << "Number of species = " << nsp << endl; vector<ThermoPhase*> phaseList; phaseList.push_back(gasTP); GasKinetics* iKin_ptr = new GasKinetics(); importKinetics(*xg, phaseList, iKin_ptr); size_t nr = iKin_ptr->nReactions(); cout << "Number of reactions = " << nr << endl; size_t iH = gasTP->speciesIndex("H"); size_t iO2 = gasTP->speciesIndex("O2"); size_t iH2O = gasTP->speciesIndex("H2O"); size_t iNH = gasTP->speciesIndex("NH"); size_t iNO = gasTP->speciesIndex("NO"); size_t iN2O = gasTP->speciesIndex("N2O"); for (i = 0; i < nsp; i++) { x[i] = 0.0; } x[iH2O] = 1.0 /2.0; x[iH] = 0.2 /2.0; x[iO2] = 0.3 /2.0; x[iNH] = 0.05/2.0; x[iNO] = 0.05/2.0; x[iN2O] = 0.05/2.0; double p = OneAtm; gasTP->setState_TPX(2000., p, x); double src[20]; for (i = 0; i < 20; i++) { src[i] = 0.0; } iKin_ptr->getNetProductionRates(src); for (i = 0; i < nsp; i++) { string sSt = gasTP->speciesName(i); printf("rop [ %.4d:%s ] = %.5g \n", (int) i, sSt.c_str(), src[i]); } size_t nReactions = iKin_ptr->nReactions(); cout << "number of reactions = " << nReactions << endl; double fwd_rop[20]; double rev_rop[20]; iKin_ptr->getFwdRatesOfProgress(fwd_rop); iKin_ptr->getRevRatesOfProgress(rev_rop); for (i = 0; i < nReactions; i++) { printf("fwd_rop[%3d] = %13g rev_rop[%3d] = %13g\n", (int) i, fwd_rop[i], (int) i, rev_rop[i]); } iKin_ptr->getCreationRates(cdot); iKin_ptr->getDestructionRates(ddot); return 0; } catch (CanteraError& err) { std::cerr << err.what() << std::endl; cerr << "program terminating." << endl; return -1; } }
status_t DLL_EXPORT phase_getmassfractions_(const integer* n, doublereal* y) { ThermoPhase* p = _fph(n); p->getMassFractions(y); return 0; }
void set_TP(double T, double P) { T_ = T; RT_ = GasConstant / 4184.0 * T; P_ = P; thermo_->setState_TP(T_, P_); }
int main(int argc, char** argv) { int i; //double ca[10]; std::string ctv = CANTERA_VERSION; bool canHandle = ctversionCanHandle(ctv); try { string id; Cantera::PrintCtrl pc; XML_Node *xc = new XML_Node(); string path = findInputFile("ReactionSurf.xml"); ctml::get_CTML_Tree(xc, path); XML_Node * const xg = xc->findNameID("phase", "reaction_surface"); if (!xg) { throw CanteraError("couldn't find file", ""); } ThermoPhase *surfTP = newPhase(*xg); ThermoPhase *gasTP = newPhase("gas.xml", ""); //IdealGasPhase *gasTP = new IdealGasPhase("gas.xml", ""); string s_cao_s = "CaO_Solid.xml"; id = "CaO(S)"; Cantera::ThermoPhase *cao_s = Cantera::newPhase(s_cao_s, id); string s_caco3_s = "CaCO3_Solid.xml"; id = "CaCO3(S)"; Cantera::ThermoPhase *caco3_s = Cantera::newPhase(s_caco3_s, id); string s_c_s = "C_Solid.xml"; id = "C(S)"; Cantera::ThermoPhase *c_s = Cantera::newPhase(s_c_s, id); string s_fe3o4_s = "Fe3O4_Solid.xml"; id = "Fe3O4(S)"; Cantera::ThermoPhase *fe3o4_s = Cantera::newPhase(s_fe3o4_s, id); string s_feo_s = "FeO_Solid.xml"; id = "FeO(S)"; Cantera::ThermoPhase *feo_s = Cantera::newPhase(s_feo_s, id); string s_fe_s = "Fe_Solid.xml"; id = "Fe(S)"; Cantera::ThermoPhase *fe_s = Cantera::newPhase(s_fe_s, id); // string s_reactSurf = "ReactionSurf.xml"; // id = "reaction_surface"; //Cantera::ThermoPhase *surfTP = Cantera::newPhase(s_reactSurf, id); vector<ThermoPhase *> phaseList; phaseList.push_back(gasTP); phaseList.push_back(cao_s); phaseList.push_back(caco3_s); phaseList.push_back(c_s); phaseList.push_back(fe3o4_s); phaseList.push_back(feo_s); phaseList.push_back(fe_s); phaseList.push_back(surfTP); InterfaceKinetics *iKin_ptr = new InterfaceKinetics(); importKinetics(*xg, phaseList, iKin_ptr); // int nr = iKin_ptr->nReactions(); double x[20]; for (i = 0; i < 20; i++) x[i] = 0.0; double mll[20]; for (i = 0; i < 20; i++) mll[i] = 0.0; //int ikca0 = iKin_ptr->kineticsSpeciesIndex("CaO(S)"); //int ikcaco3 = iKin_ptr->kineticsSpeciesIndex("CaCO3(S)"); //int ikco2 = iKin_ptr->kineticsSpeciesIndex("CO2"); int igco2 = gasTP->speciesIndex("CO2"); int igo2 = gasTP->speciesIndex("O2"); int ign2 = gasTP->speciesIndex("N2"); mll[igco2] = 0.2; mll[igo2] = 0.1; mll[ign2] = 0.7; double Temp = 1000.; gasTP->setState_TPX(Temp, OneAtm, mll); double p = 20.0*OneAtm/760.0; for (i = 0; i < 20; i++) x[i] = 0.0; for (i = 0; i < 20; i++) x[i] = 0.0; x[0] = 1.0; // Set the bath gas of TempK and 1 atm cao_s->setState_TP(Temp, OneAtm); caco3_s->setState_TP(Temp, OneAtm); c_s->setState_TP(Temp, OneAtm); fe3o4_s->setState_TP(Temp, OneAtm); surfTP->setState_TP(Temp, OneAtm); // Throw some asserts in here to test that they compile AssertTrace(p == p); AssertThrow(p == p, "main"); AssertThrowMsg(i == 20, "main", "are you kidding"); double src[20]; for (i = 0; i < 20; i++) src[i] = 0.0; //iKin_ptr->getNetProductionRates(src); double deltaG[20], deltaGSS[20]; // Preamble printf("==========================================================================\n"); printf(" StoichSolidKinetics Test \n"); printf("==========================================================================\n"); printf(" Tests for the proper behavior of heterogeneous reactions \n"); printf(" when phases may or may not exist:\n"); printf(" CaCO3(s) = CO2(g) + CaO(s) \n"); printf("\n\n"); for (int ktrials = 0; ktrials < 2; ktrials++) { iKin_ptr->getDeltaSSGibbs(deltaGSS); cout << " deltaGSS = "; pc.pr_de(deltaGSS[0], 4, 13); cout << "\n"; iKin_ptr->getDeltaGibbs(deltaG); cout << " deltaG = "; pc.pr_de(deltaG[0], 4, 13); cout << "\n"; double mu[10]; gasTP->getChemPotentials(mu); double mu_CO2 = mu[igco2]; cout << " mu_CO2(g) = "; pc.pr_de(mu_CO2, 4, 13); cout << "\n"; cao_s->getGibbs_RT(mu); double mu_cao = mu[0] * GasConstant * Temp; cout << " mu_cao(s) = "; pc.pr_de(mu_cao, 4, 13); cout << "\n"; caco3_s->getChemPotentials(mu); double mu_caco3 = mu[0]; cout << " mu_caco3 = "; pc.pr_de(mu_caco3, 4, 13); cout << "\n"; double deltaG_calc = mu_CO2 + mu_cao - mu_caco3; cout << " deltaG_calc = "; pc.pr_de(deltaG_calc, 4, 13); cout << "\n"; double act[20]; gasTP->getActivities(act); double act_CO2 = act[igco2]; cout << " act_CO2 = "; pc.pr_de(act_CO2, 4, 13); cout << "\n"; cao_s->getActivities(act); cout << " act_cao(s) = "; pc.pr_de(act[0], 4, 13); cout << "\n"; caco3_s->getActivities(act); cout << " act_caco3(s) = "; pc.pr_de(act[0], 4, 13); cout << "\n"; vector<double> Rfwd(5); vector<double> Rrev(5); vector<double> Rnet(5); printf("==========================================================================\n"); printf(" OK base problem assuming that all phases exist:\n"); printf("==========================================================================\n"); iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet)); cout << "ROP_net = "; pc.pr_de(Rnet[0], 4, 13); cout << endl; iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd)); cout << "ROP_forward = "; pc.pr_de(Rfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev)); cout << "ROP_reverse = "; pc.pr_de(Rrev[0], 4, 13); cout << endl; double kfwd[5]; iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd)); cout << " kfwd = "; pc.pr_de(kfwd[0], 4, 13); cout << endl; double krev[5]; iKin_ptr->getRevRateConstants(DATA_PTR(krev)); cout << " krev = "; pc.pr_de(krev[0], 4, 13); cout << endl; #if defined (CANTERA_VERSION_18_LTD) || defined (CANTERA_VERSION_18_XXX) printf("==========================================================================\n"); printf(" OK Changing the problem setting CaO(S) phase to nonexistent:\n"); printf("==========================================================================\n"); int ip_cao = iKin_ptr->phaseIndex("CaO(S)"); iKin_ptr->setPhaseExistence(ip_cao, false); iKin_ptr->setPhaseStability(ip_cao, true); iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet)); cout << "ROP_net = "; pc.pr_de(Rnet[0], 4, 13); cout << endl; iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd)); cout << "ROP_forward = "; pc.pr_de(Rfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev)); cout << "ROP_reverse = "; pc.pr_de(Rrev[0], 4, 13); cout << endl; iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd)); cout << " kfwd = "; pc.pr_de(kfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRateConstants(DATA_PTR(krev)); cout << " krev = "; pc.pr_de(krev[0], 4, 13); cout << endl; printf("==========================================================================\n"); printf(" OK Changing the problem setting CaCO3(S) phase to nonexistent:\n"); printf("==========================================================================\n"); int ip_caco3 = iKin_ptr->phaseIndex("CaCO3(S)"); iKin_ptr->setPhaseExistence(ip_caco3, false); iKin_ptr->setPhaseStability(ip_caco3, true); iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet)); cout << "ROP_net = "; pc.pr_de(Rnet[0], 4, 13); cout << endl; iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd)); cout << "ROP_forward = "; pc.pr_de(Rfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev)); cout << "ROP_reverse = "; pc.pr_de(Rrev[0], 4, 13); cout << endl; iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd)); cout << " kfwd = "; pc.pr_de(kfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRateConstants(DATA_PTR(krev)); cout << " krev = "; pc.pr_de(krev[0], 4, 13); cout << endl; printf("==========================================================================\n"); printf(" OK Changing the problem setting CaO(S) phase to existent, CaCO3 nonexistent:\n"); printf("==========================================================================\n"); iKin_ptr->setPhaseExistence(ip_cao, true); iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet)); cout << "ROP_net = "; pc.pr_de(Rnet[0], 4, 13); cout << endl; iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd)); cout << "ROP_forward = "; pc.pr_de(Rfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev)); cout << "ROP_reverse = "; pc.pr_de(Rrev[0], 4, 13); cout << endl; iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd)); cout << " kfwd = "; pc.pr_de(kfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRateConstants(DATA_PTR(krev)); cout << " krev = "; pc.pr_de(krev[0], 4, 13); cout << endl; printf("==========================================================================\n"); printf(" OK Changing the problem setting Gas phase to nonexistent, CaCO3 nonexistent:\n"); printf("==========================================================================\n"); int ip_gas = iKin_ptr->phaseIndex("air"); iKin_ptr->setPhaseExistence(ip_gas, false); iKin_ptr->setPhaseStability(ip_gas, true); iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet)); cout << "ROP_net = "; pc.pr_de(Rnet[0], 4, 13); cout << endl; iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd)); cout << "ROP_forward = "; pc.pr_de(Rfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev)); cout << "ROP_reverse = "; pc.pr_de(Rrev[0], 4, 13); cout << endl; iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd)); cout << " kfwd = "; pc.pr_de(kfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRateConstants(DATA_PTR(krev)); cout << " krev = "; pc.pr_de(krev[0], 4, 13); cout << endl; printf("==========================================================================\n"); printf(" OK Changing the problem setting to all phases existing:\n"); printf("==========================================================================\n"); iKin_ptr->setPhaseExistence(ip_gas, true); iKin_ptr->setPhaseExistence(ip_cao, true); iKin_ptr->setPhaseExistence(ip_caco3, true); iKin_ptr->getNetRatesOfProgress(DATA_PTR(Rnet)); cout << "ROP_net = "; pc.pr_de(Rnet[0], 4, 13); cout << endl; iKin_ptr->getFwdRatesOfProgress(DATA_PTR(Rfwd)); cout << "ROP_forward = "; pc.pr_de(Rfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRatesOfProgress(DATA_PTR(Rrev)); cout << "ROP_reverse = "; pc.pr_de(Rrev[0], 4, 13); cout << endl; iKin_ptr->getFwdRateConstants(DATA_PTR(kfwd)); cout << " kfwd = "; pc.pr_de(kfwd[0], 4, 13); cout << endl; iKin_ptr->getRevRateConstants(DATA_PTR(krev)); cout << " krev = "; pc.pr_de(krev[0], 4, 13); cout << endl; #endif if (ktrials == 0) { printf("==========================================================================\n"); printf(" OK Changing the problem setting so that forward rate if faster:\n"); printf("==========================================================================\n"); mll[igco2] = 0.002; mll[igo2] = 0.1; mll[ign2] = 0.898; gasTP->setState_TPX(Temp, OneAtm, mll); } } printf("==========================================================================\n"); } catch (CanteraError) { showErrors(cout); } return 0; }
status_t DLL_EXPORT phase_setmolefractions_(const integer* n, double* x, const integer* norm) { ThermoPhase* p = _fph(n); if (*norm) p->setMoleFractions(x); else p->setMoleFractions_NoNorm(x); return 0; }