// ## 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(); // #] }
/** * Enrich portClassHier with class/interface names that map to a list of parent * classes/interfaces. For any class encountered, find its parents too.<br> * Also find the port types which have assignable schema classes. * * @param oper Operator to work on * @param portClassHierarchy In-Out param that contains a mapping of class/interface to its * parents * @param portTypesWithSchemaClasses Json that will contain all the ports which have any schema * classes. */ public void buildAdditionalPortInfo( JSONObject oper, JSONObject portClassHierarchy, JSONObject portTypesWithSchemaClasses) { try { JSONArray ports = oper.getJSONArray(OperatorDiscoverer.PORT_TYPE_INFO_KEY); for (int i = 0; i < ports.length(); i++) { JSONObject port = ports.getJSONObject(i); String portType = port.optString("type"); if (portType == null) { // skipping if port type is null continue; } if (typeGraph.size() == 0) { buildTypeGraph(); } try { // building port class hierarchy LinkedList<String> queue = Lists.newLinkedList(); queue.add(portType); while (!queue.isEmpty()) { String currentType = queue.remove(); if (portClassHierarchy.has(currentType)) { // already present in the json so we skip. continue; } List<String> immediateParents = typeGraph.getParents(currentType); if (immediateParents == null) { portClassHierarchy.put(currentType, Lists.<String>newArrayList()); continue; } portClassHierarchy.put(currentType, immediateParents); queue.addAll(immediateParents); } } catch (JSONException e) { LOG.warn("building port type hierarchy {}", portType, e); } // finding port types with schema classes if (portTypesWithSchemaClasses.has(portType)) { // already present in the json so skipping continue; } if (portType.equals("byte") || portType.equals("short") || portType.equals("char") || portType.equals("int") || portType.equals("long") || portType.equals("float") || portType.equals("double") || portType.equals("java.lang.String") || portType.equals("java.lang.Object")) { // ignoring primitives, strings and object types as this information is needed only for // complex types. continue; } if (port.has("typeArgs")) { // ignoring any type with generics continue; } boolean hasSchemaClasses = false; List<String> instantiableDescendants = typeGraph.getInstantiableDescendants(portType); if (instantiableDescendants != null) { for (String descendant : instantiableDescendants) { try { if (typeGraph.isInstantiableBean(descendant)) { hasSchemaClasses = true; break; } } catch (JSONException ex) { LOG.warn("checking descendant is instantiable {}", descendant); } } } portTypesWithSchemaClasses.put(portType, hasSchemaClasses); } } catch (JSONException e) { // should not reach this LOG.error("JSON Exception {}", e); throw new RuntimeException(e); } }