Exemple #1
1
  // ## operation writeChemkinSpecies(ReactionModel,SystemSnapshot)
  public static String writeChemkinSpecies(
      ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) {
    // #[ operation writeChemkinSpecies(ReactionModel,SystemSnapshot)

    StringBuilder result = new StringBuilder();
    result.append("SPECIES\n");

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    // write inert gas
    for (Iterator iter = p_beginStatus.getInertGas(); iter.hasNext(); ) {
      String name = (String) iter.next();
      result.append('\t' + name + '\n');
    }

    // write species
    for (Iterator iter = cerm.getSpecies(); iter.hasNext(); ) {
      Species spe = (Species) iter.next();
      result.append('\t' + spe.getChemkinName() + '\n');
    }

    result.append("END\n");

    return result.toString();

    // #]
  }
Exemple #2
0
  // ## operation writeChemkinReactions(ReactionModel)
  // 10/26/07 gmagoon: changed to take temperature as parameter (it doesn't seem like this method is
  // currently used anywhere)
  public static String writeChemkinReactions(
      ReactionModel p_reactionModel, Temperature p_temperature) {
    // #[ operation writeChemkinReactions(ReactionModel)
    StringBuilder result = new StringBuilder();
    result.append("REACTIONS	KCAL/MOLE\n");
    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    LinkedHashSet all = cerm.getReactedReactionSet();

    HashSet hs = new HashSet();
    int numfor = 0;
    int numrev = 0;
    int numdup = 0;
    int numnorev = 0;
    for (Iterator iter = all.iterator(); iter.hasNext(); ) {
      Reaction rxn = (Reaction) iter.next();
      if (rxn.isForward()) {
        result.append(
            " "
                + rxn.toChemkinString(p_temperature)
                + "\n"); // 10/26/07 gmagoon: changed to avoid use of Global.temperature
        //	result.append(" " + rxn.toChemkinString(Global.temperature) + "\n");

      }
    }

    result.append("END\n");

    return result.toString();

    // #]
  }
Exemple #3
0
  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();

    // #]
  }
Exemple #4
0
  // ## operation writeChemkinInputFile(ReactionModel,SystemSnapshot)
  public static void writeChemkinInputFile(
      final ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) {
    // #[ operation writeChemkinInputFile(ReactionModel,SystemSnapshot)

    StringBuilder result = new StringBuilder();
    result.append(writeChemkinHeader());
    result.append(writeChemkinElement());
    double start = System.currentTimeMillis();
    result.append(writeChemkinSpecies(p_reactionModel, p_beginStatus));
    result.append(writeChemkinThermo(p_reactionModel));
    Global.chemkinThermo = Global.chemkinThermo + (System.currentTimeMillis() - start) / 1000 / 60;
    start = System.currentTimeMillis();
    result.append(
        writeChemkinPdepReactions(
            p_reactionModel, p_beginStatus)); // 10/26/07 gmagoon: changed to pass p_beginStatus
    // result.append(writeChemkinPdepReactions(p_reactionModel));
    Global.chemkinReaction =
        Global.chemkinReaction + (System.currentTimeMillis() - start) / 1000 / 60;

    String dir = System.getProperty("RMG.workingDirectory");
    if (!dir.endsWith("/")) dir += "/";
    dir += "software/reactorModel/";
    String file = "chemkin/chem.inp";

    try {
      FileWriter fw = new FileWriter(file);
      fw.write(result.toString());
      fw.close();
    } catch (Exception e) {
      System.out.println("Error in writing chemkin input file chem.inp!");
      System.out.println(e.getMessage());
      System.exit(0);
    }

    if (PDepRateConstant.getMode() == Mode.CHEBYSHEV
        || PDepRateConstant.getMode() == Mode.PDEPARRHENIUS
        || PDepRateConstant.getMode() == Mode.RATE) {
      StringBuilder gridOfRateCoeffs = new StringBuilder();
      gridOfRateCoeffs.append(writeGridOfRateCoeffs(p_reactionModel));
      String newFile = "chemkin/tableOfRateCoeffs.txt";
      try {
        FileWriter fw = new FileWriter(newFile);
        fw.write(gridOfRateCoeffs.toString());
        fw.close();
      } catch (Exception e) {
        System.out.println("Error in writing tableOfRateCoeffs.txt");
        System.out.println(e.getMessage());
        System.exit(0);
      }
    }

    // #]
  }
Exemple #5
0
  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();
  }
Exemple #6
0
  public static void writeChemkinInputFile(ReactionSystem rs) {
    // #[ operation writeChemkinInputFile(ReactionModel,SystemSnapshot)

    StringBuilder result = new StringBuilder();
    result.append(writeChemkinHeader());
    result.append(writeChemkinElement());
    double start = System.currentTimeMillis();
    result.append(writeChemkinSpecies(rs.reactionModel, rs.initialStatus));
    result.append(writeChemkinThermo(rs.reactionModel));
    Global.chemkinThermo = Global.chemkinThermo + (System.currentTimeMillis() - start) / 1000 / 60;
    start = System.currentTimeMillis();
    result.append(writeChemkinPdepReactions(rs));
    Global.chemkinReaction =
        Global.chemkinReaction + (System.currentTimeMillis() - start) / 1000 / 60;

    String dir = System.getProperty("RMG.workingDirectory");
    if (!dir.endsWith("/")) dir += "/";
    dir += "software/reactorModel/";
    String file = "chemkin/chem.inp";

    try {
      FileWriter fw = new FileWriter(file);
      fw.write(result.toString());
      fw.close();
    } catch (Exception e) {
      System.out.println("Error in writing chemkin input file chem.inp!");
      System.out.println(e.getMessage());
      System.exit(0);
    }

    // #]
  }
Exemple #7
0
  // ## operation writeChemkinThermo(ReactionModel)
  public static String writeChemkinThermo(ReactionModel p_reactionModel) {
    // #[ operation writeChemkinThermo(ReactionModel)
    /*
     String thermoHeader = "! neon added by pey (20/6/04) - used thermo for Ar\n";
    thermoHeader += "Ne                120186Ne  1               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02500000E+02 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader += "-0.07453750E+04 0.04366001E+02 0.02500000E+02 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader += " 0.00000000E+00 0.00000000E+00-0.07453750E+04 0.04366001E+02                   4\n";
    thermoHeader += "N2                121286N   2               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02926640e+02 0.01487977e-01-0.05684761e-05 0.01009704e-08-0.06753351e-13    2\n";
    thermoHeader += "-0.09227977e+04 0.05980528e+02 0.03298677e+02 0.01408240e-01-0.03963222e-04    3\n";
    thermoHeader += " 0.05641515e-07-0.02444855e-10-0.01020900e+05 0.03950372e+02                   4\n";
    thermoHeader += "Ar                120186Ar  1               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02500000e+02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00    2\n";
    thermoHeader += "-0.07453750e+04 0.04366001e+02 0.02500000e+02 0.00000000e+00 0.00000000e+00    3\n";
    thermoHeader += " 0.00000000e+00 0.00000000e+00-0.07453750e+04 0.04366001e+02                   4\n";
         */
    // #]
    String thermoHeader =
        "! The first four sets of polynomial coefficients (Ar, N2, Ne, He) are from         \n";
    thermoHeader +=
        "! THIRD MILLENIUM IDEAL GAS AND CONDENSED PHASE THERMOCHEMICAL DATABASE FOR     \n";
    thermoHeader +=
        "! COMBUSTION WITH UPDATES FROM ACTIVE THERMOCHENICAL TABLES                     \n";
    thermoHeader +=
        "! Authors: Alexander Burcat and Branko Ruscic                                   \n";
    thermoHeader +=
        "!                                                                               \n";
    thermoHeader +=
        "! The rest of the species are estimated by RMG (http://rmg.mit.edu/)            \n";
    // thermoHeader += "! Ar HF298=0.  REF=C.E. Moore 'Atomic Energy Levels' NSRDS-NBS 35 (1971)
    // p.211  \n";
    // thermoHeader += "! NASA Glen (former Lewis) Research Center   (1988)
    //    \n";
    thermoHeader +=
        "Ar                L 6/88Ar  1               G   200.000  6000.000 1000.        1\n";
    thermoHeader +=
        " 0.25000000E+01 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader +=
        "-0.74537500E+03 0.43796749E+01 0.25000000E+01 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader +=
        " 0.00000000E+00 0.00000000E+00-0.74537500E+03 0.43796749E+01                   4\n";
    // thermoHeader += "! N2  HF298= 0.0 KJ  REF=TSIV  Max Lst Sq Error Cp @ 6000 K 0.29%
    //    \n";
    thermoHeader +=
        "N2                G 8/02N   2               G   200.000  6000.000 1000.        1\n";
    thermoHeader +=
        " 2.95257637E+00 1.39690040E-03-4.92631603E-07 7.86010195E-11-4.60755204E-15    2\n";
    thermoHeader +=
        "-9.23948688E+02 5.87188762E+00 3.53100528E+00-1.23660988E-04-5.02999433E-07    3\n";
    thermoHeader +=
        " 2.43530612E-09-1.40881235E-12-1.04697628E+03 2.96747038E+00                   4\n";
    // thermoHeader += "!Ne    HF298= 0.0 KJ REF=McBride, Heimel, Ehlers & Gordon
    //    \n";
    // thermoHeader += "!                'Thermodynamic Properties to 6000 K...' NASA SP-3001
    // (1963)   \n";
    thermoHeader +=
        "Ne                L10/90Ne  1               G    200.0   6000.00  1000.0       1\n";
    thermoHeader +=
        " 0.25000000E 01 0.00000000E 00 0.00000000E 00 0.00000000E 00 0.00000000E 00    2\n";
    thermoHeader +=
        "-0.74537500E 03 0.33553227E 01 0.25000000E 01 0.00000000E 00 0.00000000E 00    3\n";
    thermoHeader +=
        " 0.00000000E 00 0.00000000E 00-0.74537498E 03 0.33553227E 01                   4\n";
    // thermoHeader += "7440-59-7
    //    \n";
    // thermoHeader += "He  HF298=0.0 KJ  REF=McBride, Heimel, Ehlers & Gordon "Thermodynamic
    // Properties\n";
    // thermoHeader += "to 6000K ..." NASA SP-3001 1963.
    //    \n";
    thermoHeader +=
        "He REF ELEMENT    L10/90HE 1.   0.   0.   0.G   200.000  6000.000  B   4.00260 1\n";
    thermoHeader +=
        " 2.50000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader +=
        "-7.45375000E+02 9.28723974E-01 2.50000000E+00 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader +=
        " 0.00000000E+00 0.00000000E+00-7.45375000E+02 9.28723974E-01 0.00000000E+00    4\n\n";

    StringBuilder result = new StringBuilder();
    result.append("THERMO ALL\n");
    result.append("   300.000  1000.000  5000.000\n");
    result.append(thermoHeader);

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
    for (Iterator iter = cerm.getSpecies(); iter.hasNext(); ) {
      Species spe = (Species) iter.next();

      if (spe.getNasaThermoSource() != null) {
        result.append("!" + spe.getNasaThermoSource() + "\n");
      }
      result.append(spe.getNasaThermoData() + "\n");
    }
    result.append("END\n");

    // Added by Amrit for Richard's liquid phase chemkin code 05/21/2009
    result.append("\n");

    return result.toString();

    // #]
  }
Exemple #8
0
  // ## 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();

    // #]
  }