public static String writeChemkinPdepReactions(ReactionSystem rs) { // #[ operation writeChemkinReactions(ReactionModel) StringBuilder result = new StringBuilder(); result.append("REACTIONS KCAL/MOLE\n"); LinkedList rList = new LinkedList(); LinkedList troeList = new LinkedList(); LinkedList tbrList = new LinkedList(); LinkedList duplicates = new LinkedList(); LinkedList lindeList = new LinkedList(); if (rs.dynamicSimulator instanceof JDASPK) { rList = ((JDASPK) rs.dynamicSimulator).rList; troeList = ((JDASPK) rs.dynamicSimulator).troeList; tbrList = ((JDASPK) rs.dynamicSimulator).thirdBodyList; duplicates = ((JDASPK) rs.dynamicSimulator).duplicates; lindeList = ((JDASPK) rs.dynamicSimulator).lindemannList; } else if (rs.dynamicSimulator instanceof JDASSL) { rList = ((JDASSL) rs.dynamicSimulator).rList; troeList = ((JDASSL) rs.dynamicSimulator).troeList; tbrList = ((JDASSL) rs.dynamicSimulator).thirdBodyList; duplicates = ((JDASSL) rs.dynamicSimulator).duplicates; lindeList = ((JDASSL) rs.dynamicSimulator).lindemannList; } for (Iterator iter = rList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); // 10/26/07 gmagoon: changed to avoid use of Global.temperature; I am using // getPresentTemperature for the time being; it is possible that // getInitialStatus.getTemperature or something similar may be more appropriate result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = troeList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = tbrList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = duplicates.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n\tDUP\n"); // result.append(r.toChemkinString(Global.temperature)+"\n\tDUP\n"); } for (Iterator iter = lindeList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); } result.append("END\n"); return result.toString(); // #] }
// ## operation getMatchedFunctionalGroup(LinkedList) public LinkedList getMatchedFunctionalGroup(LinkedList p_reactants) { // #[ operation getMatchedFunctionalGroup(LinkedList) LinkedList fgCollection = new LinkedList(); boolean found = false; Iterator r_iter = p_reactants.iterator(); while (r_iter.hasNext()) { found = false; Object o = r_iter.next(); ChemGraph cg = null; if (o instanceof Species) cg = ((Species) r_iter.next()).getChemGraph(); else cg = (ChemGraph) o; Iterator t_iter = reactantTree.iterator(); while (t_iter.hasNext()) { HierarchyTree t = (HierarchyTree) t_iter.next(); Stack s = t.findMatchedPath(cg); if (s != null && !s.isEmpty()) { found = true; fgCollection.add(s); } } if (!found) { // System.out.println("can't find matched path: " + cg.toString()); // System.exit(0); return null; } } return fgCollection; // #] }
public static String writeGridOfRateCoeffs(ReactionModel p_reactionModel) { StringBuilder result = new StringBuilder(); LinkedList pDepList = new LinkedList(); CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel; for (Iterator iter = PDepNetwork.getNetworks().iterator(); iter.hasNext(); ) { PDepNetwork pdn = (PDepNetwork) iter.next(); for (ListIterator pdniter = pdn.getNetReactions().listIterator(); pdniter.hasNext(); ) { PDepReaction rxn = (PDepReaction) pdniter.next(); if (cerm.categorizeReaction(rxn) != 1) continue; // check if this reaction is not already in the list and also check if this reaction has a // reverse reaction // which is already present in the list. if (rxn.getReverseReaction() == null) rxn.generateReverseReaction(); if (!rxn.reactantEqualsProduct() && !pDepList.contains(rxn) && !pDepList.contains(rxn.getReverseReaction())) { pDepList.add(rxn); } } } Temperature[] tempsUsedInFame = PDepRateConstant.getTemperatures(); int numTemps = tempsUsedInFame.length; Pressure[] pressUsedInFame = PDepRateConstant.getPressures(); int numPress = pressUsedInFame.length; for (int i = 0; i < numTemps; i++) { for (int j = 0; j < numPress; j++) { result.append( "T=" + tempsUsedInFame[i].getK() + "K,P=" + pressUsedInFame[j].getBar() + "bar\t"); } result.append("\n"); } result.append("\n"); for (Iterator iter = pDepList.iterator(); iter.hasNext(); ) { PDepReaction r = (PDepReaction) iter.next(); result.append(r.toString() + "\n"); double[][] rates = new double[numTemps][numPress]; rates = r.getPDepRate().getRateConstants(); for (int i = 0; i < numTemps; i++) { for (int j = 0; j < numPress; j++) { result.append(rates[i][j] + "\t"); } result.append("\n"); } result.append("\n"); } return result.toString(); }
// ## operation writeChemkinReactions(ReactionModel) public static String writeChemkinPdepReactions( ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) { // #[ operation writeChemkinReactions(ReactionModel) StringBuilder result = new StringBuilder(); // result.append("REACTIONS KCAL/MOLE\n"); String reactionHeader = ""; String units4Ea = ArrheniusKinetics.getEaUnits(); if (units4Ea.equals("cal/mol")) reactionHeader = "CAL/MOL\t"; else if (units4Ea.equals("kcal/mol")) reactionHeader = "KCAL/MOL\t"; else if (units4Ea.equals("J/mol")) reactionHeader = "JOULES/MOL\t"; else if (units4Ea.equals("kJ/mol")) reactionHeader = "KJOULES/MOL\t"; else if (units4Ea.equals("Kelvins")) reactionHeader = "KELVINS\t"; String units4A = ArrheniusKinetics.getAUnits(); if (units4A.equals("moles")) reactionHeader += "MOLES\n"; else if (units4A.equals("molecules")) reactionHeader += "MOLECULES\n"; result.append("REACTIONS\t" + reactionHeader); LinkedList pDepList = new LinkedList(); LinkedList nonPDepList = new LinkedList(); LinkedList duplicates = new LinkedList(); CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel; // first get troe and thirdbodyreactions for (Iterator iter = cerm.getReactionSet().iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); /* * 1Jul2009-MRH: * Added extra set of parenthesis. Before, if the rxn was reverse but an instance of * TROEReaction, it would also be added to the pDepList, resulting in RMG reporting * both rxns (forward and reverse) in the chem.inp file, w/o a DUP tag. Furthermore, * both rxns were given the same set of Arrhenius parameters. Running this in * Chemkin-v4.1.1 resulted in an error. */ if (r.isForward() && (r instanceof ThirdBodyReaction || r instanceof TROEReaction || r instanceof LindemannReaction)) { pDepList.add(r); } } for (Iterator iter = PDepNetwork.getNetworks().iterator(); iter.hasNext(); ) { PDepNetwork pdn = (PDepNetwork) iter.next(); for (ListIterator pdniter = pdn.getNetReactions().listIterator(); pdniter.hasNext(); ) { PDepReaction rxn = (PDepReaction) pdniter.next(); if (cerm.categorizeReaction(rxn) != 1) continue; // check if this reaction is not already in the list and also check if this reaction has a // reverse reaction // which is already present in the list. if (rxn.getReverseReaction() == null) rxn.generateReverseReaction(); if (!rxn.reactantEqualsProduct() && !pDepList.contains(rxn) && !pDepList.contains(rxn.getReverseReaction())) { pDepList.add(rxn); } } } LinkedList removeReactions = new LinkedList(); for (Iterator iter = p_reactionModel.getReactionSet().iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); boolean presentInPDep = false; if (r.isForward() && !(r instanceof ThirdBodyReaction) && !(r instanceof TROEReaction) && !(r instanceof LindemannReaction)) { Iterator r_iter = pDepList.iterator(); while (r_iter.hasNext()) { Reaction pDepr = (Reaction) r_iter.next(); if (pDepr.equals(r)) { // removeReactions.add(pDepr); // duplicates.add(pDepr); // if (!r.hasAdditionalKinetics()){ // duplicates.add(r); // presentInPDep = true; // } presentInPDep = true; nonPDepList.add(r); } } if (!presentInPDep) nonPDepList.add(r); } } for (Iterator iter = removeReactions.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); pDepList.remove(r); } for (Iterator iter = pDepList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); // 6Jul2009-MRH: // Pass both system temperature and pressure to function toChemkinString. // The only PDepKineticsModel that uses the passed pressure is RATE result.append( r.toChemkinString(p_beginStatus.getTemperature(), p_beginStatus.getPressure()) + "\n"); // 10/26/07 gmagoon: eliminating use of Global.temperature; **** I use // beginStatus here, which may or may not be appropriate // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = nonPDepList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append( r.toChemkinString(p_beginStatus.getTemperature(), p_beginStatus.getPressure()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = duplicates.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append( r.toChemkinString(p_beginStatus.getTemperature(), p_beginStatus.getPressure()) + "\n\tDUP\n"); // result.append(r.toChemkinString(Global.temperature)+"\n\tDUP\n"); } result.append("END\n"); return result.toString(); // #] }
// ## operation getReactants() public Iterator getReactants() { // #[ operation getReactants() Iterator iter = reactants.iterator(); return iter; // #] }