Exemple #1
0
  // ## operation writeReactorInputFile(ReactionModel,ReactionTime,ReactionTime,SystemSnapshot)
  public boolean writeReactorInputFile(
      ReactionModel p_reactionModel,
      ReactionTime p_beginTime,
      ReactionTime p_endTime,
      SystemSnapshot p_beginStatus) {
    // #[ operation writeReactorInputFile(ReactionModel,ReactionTime,ReactionTime,SystemSnapshot)
    // construct "input" string
    String input = "<?xml version=\"1.0\" standalone=\"no\"?>" + "\n";

    String dir = System.getProperty("RMG.workingDirectory");
    if (!dir.endsWith("/")) dir += "/";
    String dtd = dir + "software/reactorModel/documentTypeDefinitions/reactorInput.dtd";
    input += "<!DOCTYPE reactorinput SYSTEM \"" + dtd + "\">" + "\n";

    input += "<reactorinput>" + "\n";
    input += "<header>" + "\n";
    input += "<title>Reactor Input File</title>" + "\n";
    input +=
        "<description>RMG-generated file used to call an external reactor model</description>"
            + "\n";
    input += "</header>" + "\n";
    input += "<inputvalues>" + "\n";
    input += "<integrationparameters>" + "\n";
    input += "<reactortype>" + reactorType + "</reactortype>" + "\n";
    input +=
        "<starttime units=\""
            + p_beginTime.getUnit()
            + "\">"
            + MathTool.formatDouble(p_beginTime.getTime(), 15, 6)
            + "</starttime>"
            + "\n";
    input +=
        "<endtime units=\""
            + p_endTime.getUnit()
            + "\">"
            + MathTool.formatDouble(p_endTime.getTime(), 15, 6)
            + "</endtime>"
            + "\n";
    //      input += "<starttime units=\"" + p_beginTime.unit + "\">" +
    // MathTool.formatDouble(p_beginTime.time,15,6) +  "</starttime>" + "\n";
    //      input += "<endtime units=\"" + p_endTime.unit + "\">" +
    // MathTool.formatDouble(p_endTime.time,15,6) +  "</endtime>" + "\n";
    input += "<rtol>" + rtol + "</rtol>" + "\n";
    input += "<atol>" + atol + "</atol>" + "\n";
    input += "</integrationparameters>" + "\n";
    input += "<chemistry>" + "\n";
    input += "</chemistry>" + "\n";
    input += "<systemstate>" + "\n";
    input +=
        "<temperature units=\"K\">"
            + MathTool.formatDouble(p_beginStatus.getTemperature().getK(), 15, 6)
            + "</temperature>"
            + "\n";
    input +=
        "<pressure units=\"Pa\">"
            + MathTool.formatDouble(p_beginStatus.getPressure().getPa(), 15, 6)
            + "</pressure>"
            + "\n";
    for (Iterator iter = p_beginStatus.getSpeciesStatus(); iter.hasNext(); ) {
      SpeciesStatus spcStatus = (SpeciesStatus) iter.next();
      Species thisSpecies = spcStatus.getSpecies();
      CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
      if (cerm.containsAsReactedSpecies(thisSpecies)) {
        String spcChemkinName = thisSpecies.getChemkinName();
        double concentration = spcStatus.getConcentration();
        input +=
            "<amount units=\"molPerCm3\" speciesid=\""
                + spcChemkinName
                + "\">"
                + concentration
                + "</amount>"
                + "\n";
      }
    }
    for (Iterator iter = p_beginStatus.getInertGas(); iter.hasNext(); ) {
      String name = (String) iter.next();
      double conc = p_beginStatus.getInertGas(name);
      if (conc != 0.0)
        input +=
            "<amount units=\"molPerCm3\" speciesid=\"" + name + "\">" + conc + "</amount>" + "\n";
    }
    input += "</systemstate>" + "\n";
    input += "</inputvalues>" + "\n";
    input += "</reactorinput>" + "\n";

    // write "input" string to file
    try {
      String file = "chemkin/reactorInput.xml";
      FileWriter fw = new FileWriter(file);
      fw.write(input);
      fw.close();
      return true;
    } catch (Exception e) {
      System.out.println("Error in writing reactorInput.xml!");
      System.out.println(e.getMessage());
      return false;
    }

    // #]
  }