Ejemplo n.º 1
0
  static void installAdsorbateThermoFromXML(std::string speciesName,
					    SpeciesThermo& sp, int k, 
					    const XML_Node& f) { 		
    vector_fp freqs;
    doublereal tmin, tmax, pref = OneAtm;
    int nfreq = 0;
    tmin = fpValue(f["Tmin"]);
    tmax = fpValue(f["Tmax"]);
    if (f.hasAttrib("P0")) {
      pref = fpValue(f["P0"]);
    }
    if (f.hasAttrib("Pref")) {
      pref = fpValue(f["Pref"]);
    }
    if (tmax == 0.0) tmax = 1.0e30;

    if (f.hasChild("floatArray")) {
      getFloatArray(f.child("floatArray"), freqs, false);
      nfreq = freqs.size(); 
    }
    for (int n = 0; n < nfreq; n++) {
      freqs[n] *= 3.0e10;
    }
    vector_fp coeffs(nfreq + 2);
    coeffs[0] = nfreq;
    coeffs[1] = getFloat(f, "binding_energy", "toSI");
    copy(freqs.begin(), freqs.end(), coeffs.begin() + 2);
    //posc = new Adsorbate(k, tmin, tmax, pref,  
    //    DATA_PTR(coeffs)); 
    (&sp)->install(speciesName, k, ADSORBATE, &coeffs[0], tmin, tmax, pref);
  }
Ejemplo n.º 2
0
  /*
   *   Import, construct, and initialize a phase
   *   specification from an XML tree into the current object.
   *
   * This routine is a precursor to constructPhaseXML(XML_Node*)
   * routine, which does most of the work.
   *
   * @param infile XML file containing the description of the
   *        phase
   *
   * @param id  Optional parameter identifying the name of the
   *            phase. If none is given, the first XML
   *            phase element will be used.
   */
  void MargulesVPSSTP::constructPhaseFile(std::string inputFile, std::string id) {

    if (inputFile.size() == 0) {
      throw CanteraError("MargulesVPSSTP:constructPhaseFile",
                         "input file is null");
    }
    string path = findInputFile(inputFile);
    std::ifstream fin(path.c_str());
    if (!fin) {
      throw CanteraError("MargulesVPSSTP:constructPhaseFile","could not open "
                         +path+" for reading.");
    }
    /*
     * The phase object automatically constructs an XML object.
     * Use this object to store information.
     */
    XML_Node &phaseNode_XML = xml();
    XML_Node *fxml = new XML_Node();
    fxml->build(fin);
    XML_Node *fxml_phase = findXMLPhase(fxml, id);
    if (!fxml_phase) {
      throw CanteraError("MargulesVPSSTP:constructPhaseFile",
                         "ERROR: Can not find phase named " +
                         id + " in file named " + inputFile);
    }
    fxml_phase->copy(&phaseNode_XML);
    constructPhaseXML(*fxml_phase, id);
    delete fxml;
  }
Ejemplo n.º 3
0
void Phase::addElement(const XML_Node& e)
{
    warn_deprecated("Phase::addElement(XML_Node&)",
                    "To be removed after Cantera 2.2.");
    doublereal weight = 0.0;
    if (e.hasAttrib("atomicWt")) {
        weight = fpValue(stripws(e["atomicWt"]));
    }
    int anum = 0;
    if (e.hasAttrib("atomicNumber")) {
        anum = atoi(stripws(e["atomicNumber"]).c_str());
    }
    string symbol = e["name"];
    doublereal entropy298 = ENTROPY298_UNKNOWN;
    if (e.hasChild("entropy298")) {
        XML_Node& e298Node = e.child("entropy298");
        if (e298Node.hasAttrib("value")) {
            entropy298 = fpValueCheck(stripws(e298Node["value"]));
        }
    }
    if (weight != 0.0) {
        addElement(symbol, weight, anum, entropy298);
    } else {
        addElement(symbol);
    }
}
/*********************************************************************
 *    Utility Functions
 *********************************************************************/
void MaskellSolidSolnPhase::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
    if (id_.size() > 0 && phaseNode.id() != id_) {
        throw CanteraError("MaskellSolidSolnPhase::initThermoXML",
                           "phasenode and Id are incompatible");
    }

    /*
     * Check on the thermo field. Must have:
     * <thermo model="MaskellSolidSolution" />
     */
    if (phaseNode.hasChild("thermo")) {
        XML_Node& thNode = phaseNode.child("thermo");
        std::string mString = thNode.attrib("model");
        if (lowercase(mString) != "maskellsolidsolnphase") {
            throw CanteraError("MaskellSolidSolnPhase::initThermoXML",
                               "Unknown thermo model: " + mString);
        }

        /*
         * Parse the enthalpy of mixing constant
         */
        if (thNode.hasChild("h_mix")) {
            set_h_mix(fpValue(thNode.child("h_mix").value()));
        } else {
            throw CanteraError("MaskellSolidSolnPhase::initThermoXML",
                               "Mixing enthalpy parameter not specified.");
        }

        if (thNode.hasChild("product_species")) {
            std::string product_species_name = thNode.child("product_species").value();
            product_species_index = speciesIndex(product_species_name);
            if (product_species_index == static_cast<int>(npos)) {
                throw CanteraError("MaskellSolidSolnPhase::initThermoXML",
                                   "Species " + product_species_name + " not found.");
            }
            if (product_species_index == 0) {
                reactant_species_index = 1;
            } else {
                reactant_species_index = 0;
            }
        }
    } else {
        throw CanteraError("MaskellSolidSolnPhase::initThermoXML",
                           "Unspecified thermo model");
    }


    // Confirm that the phase only contains 2 species
    if (m_kk != 2) {
        throw CanteraError("MaskellSolidSolnPhase::initThermoXML",
                "MaskellSolidSolution model requires exactly 2 species.");
    }

    /*
     * Call the base initThermo, which handles setting the initial
     * state.
     */
    VPStandardStateTP::initThermoXML(phaseNode, id_);
}
Ejemplo n.º 5
0
  SurfPhase::SurfPhase(std::string infile, std::string id) :
    ThermoPhase(),
    m_n0(0.0),
    m_logn0(0.0),
    m_tmin(0.0),
    m_tmax(0.0),
    m_press(OneAtm),
    m_tlast(0.0) 
  {
    XML_Node* root = get_XML_File(infile);
    if (id == "-") id = "";
    XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id, root);
    if (!xphase) {
      throw CanteraError("SurfPhase::SurfPhase",
			 "Couldn't find phase name in file:" + id);
    }
    // Check the model name to ensure we have compatibility
    const XML_Node& th = xphase->child("thermo");
    string model = th["model"];
    if (model != "Surface" && model != "Edge") {
      throw CanteraError("SurfPhase::SurfPhase", 
			 "thermo model attribute must be Surface or Edge");
    }
    importPhase(*xphase, this);
  }
Ejemplo n.º 6
0
    status_t DLL_EXPORT ctbuildsolutionfromxml(char* src, integer* ixml, char* id, 
        integer* ith, integer* ikin, ftnlen lensrc, ftnlen lenid) {

        XML_Node* root = 0;
        if (*ixml > 0) root = _xml(ixml);

        thermo_t* t = _fth(ith);
        kinetics_t* k = _fkin(ikin);

        Kinetics& kin = *k;
        XML_Node *x, *r=0;
        if (root) r = &root->root();
	std::string srcS = f2string(src, lensrc);
	std::string idS  = f2string(id, lenid);
	if (srcS != "") {
           x = get_XML_Node(srcS, r);
	} else {
           x = get_XML_Node(idS, r);
	}
        // x = find_XML(f2string(src, lensrc), r, f2string(id,lenid), "", "phase");
        if (!x) return 0;
        importPhase(*x, t);
        kin.addPhase(*t);
        kin.init();
        installReactionArrays(*x, kin, x->id());
        t->setState_TP(300.0, OneAtm);
        if (r) {
            if (&x->root() != &r->root()) delete &x->root();
        }
        else delete &x->root();
        return 0;
    }
Ejemplo n.º 7
0
void PDSS_IonsFromNeutral::constructPDSSFile(VPStandardStateTP* tp, size_t spindex,
        const std::string& inputFile, const std::string& id)
{
    warn_deprecated("PDSS_IonsFromNeutral::constructPDSSFile",
                    "To be removed after Cantera 2.3.");
    if (inputFile.size() == 0) {
        throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
                           "input file is null");
    }
    std::string path = findInputFile(inputFile);
    ifstream fin(path);
    if (!fin) {
        throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile","could not open "
                           +path+" for reading.");
    }

    // The phase object automatically constructs an XML object. Use this object
    // to store information.
    XML_Node fxml;
    fxml.build(fin);
    XML_Node* fxml_phase = findXMLPhase(&fxml, id);
    if (!fxml_phase) {
        throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile",
                           "ERROR: Can not find phase named " +
                           id + " in file named " + inputFile);
    }

    XML_Node& speciesList = fxml_phase->child("speciesArray");
    XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
                                         &fxml_phase->root());
    const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex));
    constructPDSSXML(tp, spindex, *s, *fxml_phase, id);
}
Ejemplo n.º 8
0
void PDSS_IdealGas::constructPDSSFile(VPStandardStateTP* tp, size_t spindex,
                                      const std::string& inputFile,
                                      const std::string& id)
{
    warn_deprecated("PDSS_IdealGas::constructPDSSFile",
                    "To be removed after Cantera 2.3.");
    if (inputFile.size() == 0) {
        throw CanteraError("PDSS_IdealGas::constructPDSSFile",
                           "input file is null");
    }
    std::string path = findInputFile(inputFile);
    ifstream fin(path);
    if (!fin) {
        throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open "
                           +path+" for reading.");
    }
    /*
     * The phase object automatically constructs an XML object.
     * Use this object to store information.
     */

    XML_Node fxml;
    fxml.build(fin);
    XML_Node* fxml_phase = findXMLPhase(&fxml, id);
    if (!fxml_phase) {
        throw CanteraError("PDSS_IdealGas::constructPDSSFile",
                           "ERROR: Can not find phase named " +
                           id + " in file named " + inputFile);
    }
    constructPDSSXML(tp, spindex, *fxml_phase, id);
}
Ejemplo n.º 9
0
  void PDSS_IdealGas::constructPDSSFile(VPStandardStateTP *tp, int spindex,
					std::string inputFile, std::string id) {

    if (inputFile.size() == 0) {
      throw CanteraError("PDSS_IdealGas::constructPDSSFile",
			 "input file is null");
    }
    std::string path = findInputFile(inputFile);
    ifstream fin(path.c_str());
    if (!fin) {
      throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open "
			 +path+" for reading.");
    }
    /*
     * The phase object automatically constructs an XML object.
     * Use this object to store information.
     */

    XML_Node *fxml = new XML_Node();
    fxml->build(fin);
    XML_Node *fxml_phase = findXMLPhase(fxml, id);
    if (!fxml_phase) {
      throw CanteraError("PDSS_IdealGas::constructPDSSFile",
			 "ERROR: Can not find phase named " +
			 id + " in file named " + inputFile);
    }	
    constructPDSSXML(tp, spindex, *fxml_phase, id);
    delete fxml;
  }
Ejemplo n.º 10
0
void MineralEQ3::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
    /*
     * Find the Thermo XML node
     */
    if (!phaseNode.hasChild("thermo")) {
        throw CanteraError("HMWSoln::initThermoXML",
                           "no thermo XML node");
    }

    std::vector<const XML_Node*> xspecies = speciesData();
    const XML_Node* xsp = xspecies[0];

    XML_Node* aStandardState = 0;
    if (xsp->hasChild("standardState")) {
        aStandardState = &xsp->child("standardState");
    } else {
        throw CanteraError("MineralEQ3::initThermoXML",
                           "no standard state mode");
    }
    doublereal volVal = 0.0;
    string smodel = (*aStandardState)["model"];
    if (smodel != "constantVolume") {
        throw CanteraError("MineralEQ3::initThermoXML",
                           "wrong standard state mode");
    }
    if (aStandardState->hasChild("V0_Pr_Tr")) {
        XML_Node& aV = aStandardState->child("V0_Pr_Tr");
        string Aunits = "";
        double Afactor = toSI("cm3/gmol");
        if (aV.hasAttrib("units")) {
            Aunits = aV.attrib("units");
            Afactor = toSI(Aunits);
        }
        volVal = ctml::getFloat(*aStandardState, "V0_Pr_Tr");
        m_V0_pr_tr= volVal;
        volVal *= Afactor;
        m_speciesSize[0] = volVal;
    } else {
        throw CanteraError("MineralEQ3::initThermoXML",
                           "wrong standard state mode");
    }
    doublereal rho = molecularWeight(0) / volVal;
    setDensity(rho);

    const XML_Node& sThermo = xsp->child("thermo");
    const XML_Node& MinEQ3node = sThermo.child("MinEQ3");


    m_deltaG_formation_pr_tr =
        ctml::getFloatDefaultUnits(MinEQ3node, "DG0_f_Pr_Tr", "cal/gmol", "actEnergy");
    m_deltaH_formation_pr_tr =
        ctml::getFloatDefaultUnits(MinEQ3node, "DH0_f_Pr_Tr", "cal/gmol", "actEnergy");
    m_Entrop_pr_tr = ctml::getFloatDefaultUnits(MinEQ3node, "S0_Pr_Tr", "cal/gmol/K");
    m_a = ctml::getFloatDefaultUnits(MinEQ3node, "a", "cal/gmol/K");
    m_b = ctml::getFloatDefaultUnits(MinEQ3node, "b", "cal/gmol/K2");
    m_c = ctml::getFloatDefaultUnits(MinEQ3node, "c", "cal-K/gmol");

    convertDGFormation();
}
void MixtureFugacityTP::setStateFromXML(const XML_Node& state)
{
    int doTP = 0;
    string comp = ctml::getChildValue(state,"moleFractions");
    if (comp != "") {
        // not overloaded in current object -> phase state is not calculated.
        setMoleFractionsByName(comp);
        doTP = 1;
    } else {
        comp = ctml::getChildValue(state,"massFractions");
        if (comp != "") {
            // not overloaded in current object -> phase state is not calculated.
            setMassFractionsByName(comp);
            doTP = 1;
        }
    }
    double t = temperature();
    if (state.hasChild("temperature")) {
        t = ctml::getFloat(state, "temperature", "temperature");
        doTP = 1;
    }
    if (state.hasChild("pressure")) {
        double p = ctml::getFloat(state, "pressure", "pressure");
        setState_TP(t, p);
    } else if (state.hasChild("density")) {
        double rho = ctml::getFloat(state, "density", "density");
        setState_TR(t, rho);
    } else if (doTP) {
        double rho = Phase::density();
        setState_TR(t, rho);
    }
}
Ejemplo n.º 12
0
  void 
  VPSSMgr_ConstVol::initThermoXML(XML_Node& phaseNode, std::string id) {
    VPSSMgr::initThermoXML(phaseNode, id);
   
    XML_Node& speciesList = phaseNode.child("speciesArray");
    XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
					 &phaseNode.root());
    const vector<string>&sss = m_vptp_ptr->speciesNames();

    for (int k = 0; k < m_kk; k++) {
      const XML_Node* s =  speciesDB->findByAttr("name", sss[k]);
      if (!s) {
	throw CanteraError("VPSSMgr_ConstVol::initThermoXML",
			   "no species Node for species " + sss[k]);
      }
      const XML_Node *ss = s->findByName("standardState");
      if (!ss) {
	throw CanteraError("VPSSMgr_ConstVol::initThermoXML",
			   "no standardState Node for species " + s->name());
      }
      std::string model = (*ss)["model"];
      if (model != "constant_incompressible" && model != "constantVolume") {
	throw CanteraError("VPSSMgr_ConstVol::initThermoXML",
			   "standardState model for species isn't constant_incompressible: " + s->name());
      }
      m_Vss[k] = getFloat(*ss, "molarVolume", "toSI");
    }   
  }
Ejemplo n.º 13
0
void LatticeSolidPhase::setParametersFromXML(const XML_Node& eosdata)
{
    eosdata._require("model","LatticeSolid");
    XML_Node& la = eosdata.child("LatticeArray");
    std::vector<XML_Node*> lattices = la.getChildren("phase");
    size_t nl = lattices.size();
    m_nlattice = nl;
    for (size_t n = 0; n < nl; n++) {
        XML_Node& i = *lattices[n];
        m_lattice.push_back((LatticePhase*)newPhase(i));
    }
    std::vector<string> pnam;
    std::vector<string> pval;
    XML_Node& ls = eosdata.child("LatticeStoichiometry");
    int np = ctml::getPairs(ls, pnam, pval);
    theta_.resize(nl);
    for (int i = 0; i < np; i++) {
        double val = fpValueCheck(pval[i]);
        bool found = false;
        for (size_t j = 0; j < nl; j++) {
            ThermoPhase& tp = *(m_lattice[j]);
            string idj = tp.id();
            if (idj == pnam[i]) {
                theta_[j] = val;
                found = true;
                break;
            }
        }
        if (!found) {
            throw CanteraError("", "not found");
        }
    }

}
Ejemplo n.º 14
0
/**
 * constructPDSSXML:
 *
 * Initialization of a PDSS_ConstVol object using an
 * xml file.
 *
 * This routine is a precursor to initThermo(XML_Node*)
 * routine, which does most of the work.
 *
 * @param infile XML file containing the description of the
 *        phase
 *
 * @param id  Optional parameter identifying the name of the
 *            phase. If none is given, the first XML
 *            phase element will be used.
 */
void PDSS_ConstVol::constructPDSSXML(VPStandardStateTP *tp, int spindex,
                                     const XML_Node& speciesNode,
                                     const XML_Node& phaseNode, bool spInstalled) {
    PDSS::initThermo();
    SpeciesThermo &sp = m_tp->speciesThermo();
    m_p0 = sp.refPressure(m_spindex);

    if (!spInstalled) {
        throw CanteraError("PDSS_ConstVol::constructPDSSXML", "spInstalled false not handled");
    }

    const XML_Node *ss = speciesNode.findByName("standardState");
    if (!ss) {
        throw CanteraError("PDSS_ConstVol::constructPDSSXML",
                           "no standardState Node for species " + speciesNode.name());
    }
    std::string model = (*ss)["model"];
    if (model != "constant_incompressible") {
        throw CanteraError("PDSS_ConstVol::initThermoXML",
                           "standardState model for species isn't constant_incompressible: " + speciesNode.name());
    }

    m_constMolarVolume = getFloat(*ss, "molarVolume", "toSI");

    std::string id = "";
    // initThermoXML(phaseNode, id);
}
Ejemplo n.º 15
0
MetalSHEelectrons::MetalSHEelectrons(const std::string& infile, std::string id_) :
    SingleSpeciesTP(),
    xdef_(0)
{
    XML_Node* root;
    if (infile == "MetalSHEelectrons_default.xml") {
        xdef_ = MetalSHEelectrons::makeDefaultXMLTree();
        root = xdef_;
    } else {
        root = get_XML_File(infile);
    }
    if (id_ == "-") {
        id_ = "";
    }
    XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
    if (!xphase) {
        throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
                           "Couldn't find phase name in file:" + id_);
    }
    // Check the model name to ensure we have compatibility
    const XML_Node& th = xphase->child("thermo");
    std::string model = th["model"];
    if (model != "MetalSHEelectrons") {
        throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
                           "thermo model attribute must be MetalSHEelectrons");
    }
    importPhase(*xphase, this);
}
Ejemplo n.º 16
0
void VPSSMgr_Water_HKFT::initThermoXML(XML_Node& phaseNode,
                                       const std::string& id)
{
    VPSSMgr::initThermoXML(phaseNode, id);
    XML_Node& speciesList = phaseNode.child("speciesArray");
    XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"],
                                         &phaseNode.root());
    m_waterSS->setState_TP(300., OneAtm);
    m_Vss[0] = (m_waterSS->density()) / m_vptp_ptr->molecularWeight(0);

    for (size_t k = 1; k < m_kk; k++) {
        string name = m_vptp_ptr->speciesName(k);
        const XML_Node* s = speciesDB->findByAttr("name", name);
        if (!s) {
            throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
                               "No species Node for species " + name);
        }
        const XML_Node* ss = s->findByName("standardState");
        if (!ss) {
            throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
                               "No standardState Node for species " + name);
        }
        std::string model = lowercase(ss->attrib("model"));
        if (model != "hkft") {
            throw CanteraError("VPSSMgr_Water_HKFT::initThermoXML",
                               "Standard state model for a solute species isn't "
                               "the HKFT standard state model: " + name);
        }
    }
}
Ejemplo n.º 17
0
void ThermoPhase::initThermoXML(XML_Node& phaseNode, const std::string& id)
{
    if (phaseNode.hasChild("state")) {
        setStateFromXML(phaseNode.child("state"));
    }
    xMol_Ref.resize(m_kk);
    getMoleFractions(&xMol_Ref[0]);
}
Ejemplo n.º 18
0
 XML_Node* getByTitle(const Cantera::XML_Node& node, const std::string &title) {
   XML_Node* s = node.findByAttr("title", title);
   if (!s) return 0;
   if (s->parent() == &node) {
     return s;
   }
   return 0;
 }
Ejemplo n.º 19
0
void IdealMolalSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
    MolalityVPSSTP::initThermoXML(phaseNode, id_);

    if (id_.size() > 0 && phaseNode.id() != id_) {
        throw CanteraError("IdealMolalSoln::initThermo",
                           "phasenode and Id are incompatible");
    }

    // Find the Thermo XML node
    if (!phaseNode.hasChild("thermo")) {
        throw CanteraError("IdealMolalSoln::initThermo",
                           "no thermo XML node");
    }
    XML_Node& thermoNode = phaseNode.child("thermo");

    // Possible change the form of the standard concentrations
    if (thermoNode.hasChild("standardConc")) {
        XML_Node& scNode = thermoNode.child("standardConc");
        setStandardConcentrationModel(scNode["model"]);
    }

    if (thermoNode.hasChild("activityCoefficients")) {
        XML_Node& acNode = thermoNode.child("activityCoefficients");
        std::string modelString = acNode.attrib("model");
        if (modelString != "IdealMolalSoln") {
            throw CanteraError("IdealMolalSoln::initThermoXML",
                               "unknown ActivityCoefficient model: " + modelString);
        }
        if (acNode.hasChild("idealMolalSolnCutoff")) {
            XML_Node& ccNode = acNode.child("idealMolalSolnCutoff");
            modelString = ccNode.attrib("model");
            if (modelString != "") {
                setCutoffModel(modelString);
                if (ccNode.hasChild("gamma_o_limit")) {
                    IMS_gamma_o_min_ = getFloat(ccNode, "gamma_o_limit");
                }
                if (ccNode.hasChild("gamma_k_limit")) {
                    IMS_gamma_k_min_ = getFloat(ccNode, "gamma_k_limit");
                }
                if (ccNode.hasChild("X_o_cutoff")) {
                    IMS_X_o_cutoff_ = getFloat(ccNode, "X_o_cutoff");
                }
                if (ccNode.hasChild("c_0_param")) {
                    IMS_cCut_ = getFloat(ccNode, "c_0_param");
                }
                if (ccNode.hasChild("slope_f_limit")) {
                    IMS_slopefCut_ = getFloat(ccNode, "slope_f_limit");
                }
                if (ccNode.hasChild("slope_g_limit")) {
                    IMS_slopegCut_ = getFloat(ccNode, "slope_g_limit");
                }
            }
        } else {
            setCutoffModel("none");
        }
    }
}
Ejemplo n.º 20
0
int main()
{
    XML_Document pars;
    pars.addDecleration();
    XML_Node    files;
    XML_Attrib  files_attrib;

    pars.addNode(files, "Files");
    files.addAttribute(files_attrib, "dummy", "foobar.com");

    XML_Node file, path, name;
    for(int i=0; i<10; ++i)
    {
        files.addChild(file, "File");
        file.addChild(path, "Path", "File_Path");
        file.addChild(name, "Name", "File_Name");

        cout << file.name() << " -> " << file.value() << endl;
        cout << path.name() << " -> " << path.value() << endl;
        cout << name.name() << " -> " << name.value() << endl;
        
    }

    file.removeChild(name);
    pars.save("example2.xml");

    return 0;
    
    // xml_document<> doc;
    // xml_node<>* decl = doc.allocate_node(node_declaration);
    // decl->append_attribute(doc.allocate_attribute("version", "1.0"));
    // decl->append_attribute(doc.allocate_attribute("encoding", "UTF-8"));
    // doc.append_node(decl);  



    // xml_node<> *files = doc.allocate_node(node_element, "Files");
    // doc.append_node(files);
    // xml_attribute<> *attr = doc.allocate_attribute("dummy", "google.com");
    // files->append_attribute(attr);

    // for(int i = 0;i<10;++i)
    // {
    //     xml_node<> *file = doc.allocate_node(node_element, "File");
    //     files->append_node(file);

    //     xml_node<> *path = doc.allocate_node(node_element, "Path","File_path");
    //     file->append_node(path);
    //     xml_node<> *name = doc.allocate_node(node_element, "Name","File_name");
    //     file->append_node(name);
    // }

    // std::ofstream myfile;
    // myfile.open ("example.xml");
    // myfile << doc;
    // //print(std::cout, doc, 0);
    // return 0;
};
Ejemplo n.º 21
0
bool getOptionalModel(const XML_Node& parent, const std::string& nodeName,
                      std::string& modelName)
{
    if (parent.hasChild(nodeName)) {
        modelName = parent.child(nodeName)["model"];
        return true;
    }
    return false;
}
Ejemplo n.º 22
0
  /**
   * constructPDSSXML:
   *
   * Initialization of a PDSS_IonsFromNeutral object using an
   * xml file.
 
   * @param id  Optional parameter identifying the name of the
   *            phase. If none is given, the first XML
   *            phase element will be used.
   */
  void PDSS_IonsFromNeutral::constructPDSSXML(VPStandardStateTP *tp, int spindex, 
					      const XML_Node& speciesNode,
					      const XML_Node& phaseNode, std::string id) {
    const XML_Node *tn = speciesNode.findByName("thermo");
    if (!tn) {
      throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
                         "no thermo Node for species " + speciesNode.name());
    }
    std::string model = lowercase((*tn)["model"]);
    if (model != "ionfromneutral") {
      throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
                         "thermo model for species isn't IonsFromNeutral: "
                         + speciesNode.name());
    } 
    const XML_Node *nsm = tn->findByName("neutralSpeciesMultipliers");
    if (!nsm) {
      throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML",
                         "no Thermo::neutralSpeciesMultipliers Node for species " + speciesNode.name());
    }

    IonsFromNeutralVPSSTP *ionPhase = dynamic_cast<IonsFromNeutralVPSSTP *>(tp);
    if (!ionPhase) {
      throw CanteraError("PDSS_IonsFromNeutral::constructPDSSXML", "Dynamic cast failed");
    }
    neutralMoleculePhase_ = ionPhase->neutralMoleculePhase_;

    std::vector<std::string> key;
    std::vector<std::string> val;

    /*
     * 
     */
    numMult_ = ctml::getPairs(*nsm,  key, val);
    idNeutralMoleculeVec.resize(numMult_);
    factorVec.resize(numMult_);
    tmpNM.resize(neutralMoleculePhase_->nSpecies());

    for (int i = 0; i < numMult_; i++) {
      idNeutralMoleculeVec[i] = neutralMoleculePhase_->speciesIndex(key[i]);
      factorVec[i] =  fpValueCheck(val[i]);
    }
    specialSpecies_ = 0;
    const XML_Node *ss = tn->findByName("specialSpecies");
    if (ss) {
      specialSpecies_ = 1;
    }
   const XML_Node *sss = tn->findByName("secondSpecialSpecies");
    if (sss) {
      specialSpecies_ = 2;
    }
    add2RTln2_ = true;
    if (specialSpecies_ == 1) {
      add2RTln2_ = false;
    }
  
  }
Ejemplo n.º 23
0
Phase& Phase::operator=(const Phase& right)
{
    // Check for self assignment.
    if (this == &right) {
        return *this;
    }

    // Handle our own data
    m_kk = right.m_kk;
    m_ndim = right.m_ndim;
    m_undefinedElementBehavior = right.m_undefinedElementBehavior;
    m_temp = right.m_temp;
    m_dens = right.m_dens;
    m_mmw = right.m_mmw;
    m_ym = right.m_ym;
    m_y = right.m_y;
    m_molwts = right.m_molwts;
    m_rmolwts = right.m_rmolwts;
    m_stateNum = -1;

    m_speciesNames = right.m_speciesNames;
    m_speciesComp = right.m_speciesComp;
    m_speciesCharge = right.m_speciesCharge;
    m_speciesSize = right.m_speciesSize;
    m_mm = right.m_mm;
    m_atomicWeights = right.m_atomicWeights;
    m_atomicNumbers = right.m_atomicNumbers;
    m_elementNames = right.m_elementNames;
    m_entropy298 = right.m_entropy298;
    m_elem_type = right.m_elem_type;

    // This is a little complicated. -> Because we delete m_xml in the
    // destructor, we own m_xml completely, and we need to have our own
    // individual copies of the XML data tree in each object
    if (m_xml) {
        XML_Node* rroot = &m_xml->root();
        delete rroot;
        m_xml = 0;
    }
    if (right.m_xml) {
        XML_Node *rroot = &right.m_xml->root();
        XML_Node *root_xml = new XML_Node();
        rroot->copy(root_xml);
        m_xml = findXMLPhase(root_xml, right.m_xml->id());
        if (!m_xml) {
          throw CanteraError("Phase::operator=()", "Confused: Couldn't find original phase " + right.m_xml->id());
        }
        if (&m_xml->root() != root_xml) {
          throw CanteraError("Phase::operator=()", "confused: root changed");
        }
    }
    m_id = right.m_id;
    m_name = right.m_name;
    return *this;
}
Ejemplo n.º 24
0
doublereal getFloat(const XML_Node& parent,
                    const std::string& name,
                    const std::string& type)
{
    if (!parent.hasChild(name))
        throw CanteraError("getFloat (called from XML Node \"" +
                           parent.name() + "\"): ",
                           "no child XML element named \"" + name + "\" exists");
    const XML_Node& node = parent.child(name);
    return getFloatCurrent(node, type);
}
void MixedSolventElectrolyte::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
    if ((int) id_.size() > 0 && phaseNode.id() != id_) {
        throw CanteraError("MixedSolventElectrolyte::initThermoXML",
            "phasenode and Id are incompatible");
    }

    /*
     * Check on the thermo field. Must have:
     * <thermo model="MixedSolventElectrolyte" />
     */
    if (!phaseNode.hasChild("thermo")) {
        throw CanteraError("MixedSolventElectrolyte::initThermoXML",
                           "no thermo XML node");
    }
    XML_Node& thermoNode = phaseNode.child("thermo");
    string mString = thermoNode.attrib("model");
    if (lowercase(mString) != "mixedsolventelectrolyte") {
        throw CanteraError("MixedSolventElectrolyte::initThermoXML",
            "Unknown thermo model: " + mString);
    }

    /*
     * Go get all of the coefficients and factors in the
     * activityCoefficients XML block
     */
    if (thermoNode.hasChild("activityCoefficients")) {
        XML_Node& acNode = thermoNode.child("activityCoefficients");
        mString = acNode.attrib("model");
        if (lowercase(mString) != "margules") {
            throw CanteraError("MixedSolventElectrolyte::initThermoXML",
                               "Unknown activity coefficient model: " + mString);
        }
        for (size_t i = 0; i < acNode.nChildren(); i++) {
            XML_Node& xmlACChild = acNode.child(i);
            /*
             * Process a binary salt field, or any of the other XML fields
             * that make up the Pitzer Database. Entries will be ignored
             * if any of the species in the entry isn't in the solution.
             */
            if (lowercase(xmlACChild.name()) == "binaryneutralspeciesparameters") {
                readXMLBinarySpecies(xmlACChild);

            }
        }
    }

    /*
     * Go down the chain
     */
    MolarityIonicVPSSTP::initThermoXML(phaseNode, id_);


}
Ejemplo n.º 26
0
void getString(const XML_Node& node, const std::string& titleString, std::string& valueString,
               std::string& typeString)
{
    XML_Node* s = getByTitle(node, titleString);
    if (s && s->name() == "string") {
        valueString = s->value();
        typeString = s->attrib("type");
    } else {
        valueString = "";
        typeString = "";
    }
}
Ejemplo n.º 27
0
  /* 
   *   This function will read a child node to the current XML node, with the
   *   name "string". It must have a title attribute, named titleString, and the body
   *   of the XML node will be read into the valueString output argument.
   *
   *  Example:  
   *
   * Code snipet:
   *       @verbatum
   const XML_Node &node;
   getString(XML_Node& node, std::string titleString, std::string valueString, 
   std::string typeString);
   @endverbatum
   *
   *  Reads the following the snippet in the XML file:
   *  @verbatum
   <string title="titleString" type="typeString">
     valueString
   <\string>
   @endverbatum
   *
   *   @param node          reference to the XML_Node object of the parent XML element
   *   @param titleString   String name of the title attribute of the child node
   *   @param valueString   Value string that is found in the child node. output variable
   *   @param typeString    String type. This is an optional output variable
   */
  void getString(const Cantera::XML_Node& node, const std::string &titleString, std::string& valueString, 
		 std::string& typeString) {
    valueString = "";
    typeString = "";
    XML_Node* s = getByTitle(node, titleString);
    if (s) 
      if (s->name() == "string") {
	valueString = (*s).value();
	typeString = (*s)["type"];
	return;
      }
  }
Ejemplo n.º 28
0
void TransportFactory::getSolidTransportData(const XML_Node& transportNode,
        XML_Node& log,
        const std::string phaseName,
        SolidTransportData& trParam)
{
    try {

        size_t num = transportNode.nChildren();
        for (size_t iChild = 0; iChild < num; iChild++) {
            //tranTypeNode is a type of transport property like viscosity
            XML_Node& tranTypeNode = transportNode.child(iChild);
            std::string nodeName = tranTypeNode.name();

            ThermoPhase* temp_thermo = trParam.thermo;

            //tranTypeNode contains the interaction model
            switch (m_tranPropMap[nodeName]) {
            case TP_IONCONDUCTIVITY:
                trParam.ionConductivity = newLTP(tranTypeNode, phaseName,
                                                 m_tranPropMap[nodeName],
                                                 temp_thermo);
                break;
            case TP_THERMALCOND:
                trParam.thermalConductivity = newLTP(tranTypeNode, phaseName,
                                                     m_tranPropMap[nodeName],
                                                     temp_thermo);
                break;
            case TP_DEFECTDIFF:
                trParam.defectDiffusivity = newLTP(tranTypeNode, phaseName,
                                                   m_tranPropMap[nodeName],
                                                   temp_thermo);
                break;
            case TP_DEFECTCONC:
                trParam.defectActivity = newLTP(tranTypeNode, phaseName,
                                                m_tranPropMap[nodeName],
                                                temp_thermo);
                break;
            case TP_ELECTCOND:
                trParam.electConductivity = newLTP(tranTypeNode, phaseName,
                                                   m_tranPropMap[nodeName],
                                                   temp_thermo);
                break;
            default:
                throw CanteraError("getSolidTransportData","unknown transport property: " + nodeName);

            }
        }
    } catch (CanteraError) {
        showErrors(std::cout);
    }
    return;
}
Ejemplo n.º 29
0
XML_Node* MetalSHEelectrons::makeDefaultXMLTree()
{
    XML_Node* xtop = new XML_Node("ctml", 0);
    XML_Node& xv = xtop->addChild("validate");
    xv.addAttribute("reactions", "yes");
    xv.addAttribute("species", "yes");

    XML_Node& xp = xtop->addChild("phase");
    xp.addAttribute("dim", "3");
    xp.addAttribute("id", "MetalSHEelectrons");
    XML_Node& xe = xp.addChild("elementArray", "E");
    xe.addAttribute("datasrc", "elements.xml");
    XML_Node& xs = xp.addChild("speciesArray", "she_electron");
    xs.addAttribute("datasrc", "#species_Metal_SHEelectrons");
    XML_Node& xt = xp.addChild("thermo");
    xt.addAttribute("model", "metalSHEelectrons");
    XML_Node& xtr = xp.addChild("transport");
    xtr.addAttribute("model", "none");
    XML_Node& xk = xp.addChild("kinetics");
    xk.addAttribute("model", "none");

    XML_Node& xsd = xtop->addChild("speciesData");
    xsd.addAttribute("id", "species_Metal_SHEelectrons");

    XML_Node& xsp = xsd.addChild("species");
    xsp.addAttribute("name", "she_electron");
    xsp.addChild("atomArray", "E:1");
    xsp.addChild("charge", "-1");
    XML_Node& xspt = xsp.addChild("thermo");

    XML_Node& xN1 = xspt.addChild("NASA");
    xN1.addAttribute("Tmax", "1000.");
    xN1.addAttribute("Tmin", "200.");
    xN1.addAttribute("P0", "100000.0");
    XML_Node& xF1 = xsd.addChild("floatArray",
                                 "1.172165560E+00,   3.990260375E-03,  -9.739075500E-06, "
                                 "1.007860470E-08, -3.688058805E-12, -4.589675865E+02,  3.415051190E-01");
    xF1.addAttribute("name", "coeffs");
    xF1.addAttribute("size", "7");

    XML_Node& xN2 = xspt.addChild("NASA");
    xN2.addAttribute("Tmax", "6000.");
    xN2.addAttribute("Tmin", "1000.");
    xN2.addAttribute("P0", "100000.0");
    XML_Node& xF2 = xsd.addChild("floatArray",
                                 "1.466432895E+00,  4.133039835E-04, -7.320116750E-08, 7.705017950E-12,"
                                 "-3.444022160E-16, -4.065327985E+02, -5.121644350E-01");
    xF2.addAttribute("name", "coeffs");
    xF2.addAttribute("size", "7");

    return xtop;
}
Ejemplo n.º 30
0
 void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, std::string id) {
   /*
    * Find the Thermo XML node
    */
   if (!phaseNode.hasChild("thermo")) {
     throw CanteraError("StoichSubstanceSSTP::initThermoXML",
                        "no thermo XML node");
   }
   XML_Node &tnode = phaseNode.child("thermo");
   double dens = getFloatDefaultUnits(tnode, "density", "kg/m3");
   setDensity(dens);
   SingleSpeciesTP::initThermoXML(phaseNode, id);
 }