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); }
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); } } }
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"); } }
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); }
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); }
ThermoPhase* newPhase(const std::string& infile, std::string id) { XML_Node* root = get_XML_File(infile); if (id == "-") { id = ""; } XML_Node* xphase = get_XML_NameID("phase", "#"+id, root); if (!xphase) { throw CanteraError("newPhase", "Couldn't find phase named \"" + id + "\" in file, " + infile); } return newPhase(*xphase); }
ThermoPhase* newPhase(std::string infile, std::string id) { 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("newPhase", "Couldn't find phase named \"" + id + "\" in file, " + infile); } if (xphase) return newPhase(*xphase); else return (ThermoPhase *) 0; }
IdealSolnGasVPSS::IdealSolnGasVPSS(std::string infile, std::string id) : VPStandardStateTP(), m_idealGas(0), m_formGC(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("newPhase", "Couldn't find phase named \"" + id + "\" in file, " + infile); } importPhase(*xphase, this); }
/* * @param infile name of the input file * @param id name of the phase id in the file. * If this is blank, the first phase in the file is used. */ electrodeElectron::electrodeElectron(std::string infile, std::string id) : StoichSubstanceSSTP() { 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("electrodeElectron::electrodeElectron", "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 != "electrodeElectron") { throw CanteraError("electrodeElectron::electrodeElectron", "thermo model attribute must be electrodeElectron"); } importPhase(*xphase, this); }
StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, std::string id_) { 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("StoichSubstanceSSTP::StoichSubstanceSSTP", "Couldn't find phase name in file:" + id_); } // Check the model name to ensure we have compatibility std::string model = xphase->child("thermo")["model"]; if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") { throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP", "thermo model attribute must be StoichSubstance"); } importPhase(*xphase, this); }
void VPSSMgr_Water_ConstVol::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()); const vector<string>&sss = m_vptp_ptr->speciesNames(); if (!m_waterSS) { throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML", "bad dynamic cast"); } 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++) { const XML_Node* s = speciesDB->findByAttr("name", sss[k]); if (!s) { throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML", "no species Node for species " + sss[k]); } const XML_Node* ss = s->findByName("standardState"); if (!ss) { std::string sName = s->operator[]("name"); throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML", "no standardState Node for species " + sName); } std::string model = (*ss)["model"]; if (model != "constant_incompressible") { std::string sName = s->operator[]("name"); throw CanteraError("VPSSMgr_Water_ConstVol::initThermoXML", "standardState model for species isn't " "constant_incompressible: " + sName); } m_Vss[k] = ctml::getFloat(*ss, "molarVolume", "toSI"); } }
void LatticePhase::initThermoXML(XML_Node& phaseNode, const std::string& id_) { if (!id_.empty() && id_ != phaseNode.id()) { throw CanteraError("LatticePhase::initThermoXML", "ids don't match"); } // Check on the thermo field. Must have: // <thermo model="Lattice" /> if (phaseNode.hasChild("thermo")) { XML_Node& thNode = phaseNode.child("thermo"); std::string mString = thNode.attrib("model"); if (lowercase(mString) != "lattice") { throw CanteraError("LatticePhase::initThermoXML", "Unknown thermo model: " + mString); } } else { throw CanteraError("LatticePhase::initThermoXML", "Unspecified thermo model"); } // Now go get the molar volumes. use the default if not found XML_Node& speciesList = phaseNode.child("speciesArray"); XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"], &phaseNode.root()); for (size_t k = 0; k < m_kk; k++) { m_speciesMolarVolume[k] = m_site_density; XML_Node* s = speciesDB->findByAttr("name", speciesName(k)); if (!s) { throw CanteraError(" LatticePhase::initThermoXML", "database problems"); } XML_Node* ss = s->findByName("standardState"); if (ss && ss->findByName("molarVolume")) { m_speciesMolarVolume[k] = getFloat(*ss, "molarVolume", "toSI"); } } // Call the base initThermo, which handles setting the initial state. ThermoPhase::initThermoXML(phaseNode, id_); }
/* * @param infile name of the input file * @param id name of the phase id in the file. * If this is blank, the first phase in the file is used. */ FixedChemPotSSTP::FixedChemPotSSTP(std::string infile, std::string id) : SingleSpeciesTP(), chemPot_(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("FixedChemPotSSTP::FixedChemPotSSTP", "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 != "StoichSubstance" && model != "StoichSubstanceSSTP" && model != "FixedChemPot") { throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP", "thermo model attribute must be FixedChemPot or StoichSubstance"); } importPhase(*xphase, this); }
bool buildSolutionFromXML(XML_Node& root, const std::string& id, const std::string& nm, ThermoPhase* th, Kinetics* kin) { XML_Node* x = get_XML_NameID(nm, string("#")+id, &root); if (!x) { return false; } // Fill in the ThermoPhase object by querying the const XML_Node tree // located at x. importPhase(*x, th); // Create a vector of ThermoPhase pointers of length 1 having the current th // ThermoPhase as the entry. std::vector<ThermoPhase*> phases{th}; // Fill in the kinetics object k, by querying the const XML_Node tree // located by x. The source terms and eventually the source term vector will // be constructed from the list of ThermoPhases in the vector, phases. importKinetics(*x, phases, kin); return true; }
/* * * This routine is a precursor to constructPDSSXML(XML_Node*) * routine, which does most of the work. * * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object * This object must have already been malloced. * * @param spindex Species index within the phase * * @param inputFile 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_IonsFromNeutral::constructPDSSFile(VPStandardStateTP* tp, size_t spindex, const std::string& inputFile, const std::string& id) { if (inputFile.size() == 0) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile", "input file is null"); } std::string path = findInputFile(inputFile); ifstream fin(path.c_str()); 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 = new XML_Node(); 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 vector<string>&sss = tp->speciesNames(); const XML_Node* s = speciesDB->findByAttr("name", sss[spindex]); constructPDSSXML(tp, spindex, *s, *fxml_phase, id); delete fxml; }
void IdealSolidSolnPhase::initThermoXML(XML_Node& phaseNode, const std::string& id_) { if (id_.size() > 0 && phaseNode.id() != id_) { throw CanteraError("IdealSolidSolnPhase::initThermoXML", "phasenode and Id are incompatible"); } /* * Check on the thermo field. Must have: * <thermo model="IdealSolidSolution" /> */ if (phaseNode.hasChild("thermo")) { XML_Node& thNode = phaseNode.child("thermo"); string mString = thNode.attrib("model"); if (lowercase(mString) != "idealsolidsolution") { throw CanteraError("IdealSolidSolnPhase::initThermoXML", "Unknown thermo model: " + mString); } } else { throw CanteraError("IdealSolidSolnPhase::initThermoXML", "Unspecified thermo model"); } /* * Form of the standard concentrations. Must have one of: * * <standardConc model="unity" /> * <standardConc model="molar_volume" /> * <standardConc model="solvent_volume" /> */ if (phaseNode.hasChild("standardConc")) { XML_Node& scNode = phaseNode.child("standardConc"); string formStringa = scNode.attrib("model"); string formString = lowercase(formStringa); if (formString == "unity") { m_formGC = 0; } else if (formString == "molar_volume") { m_formGC = 1; } else if (formString == "solvent_volume") { m_formGC = 2; } else { throw CanteraError("IdealSolidSolnPhase::initThermoXML", "Unknown standardConc model: " + formStringa); } } else { throw CanteraError("IdealSolidSolnPhase::initThermoXML", "Unspecified standardConc model"); } /* * Initialize all of the lengths now that we know how many species * there are in the phase. */ initLengths(); /* * Now go get the molar volumes */ XML_Node& speciesList = phaseNode.child("speciesArray"); XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"], &phaseNode.root()); for (size_t k = 0; k < m_kk; k++) { XML_Node* s = speciesDB->findByAttr("name", speciesName(k)); XML_Node* ss = s->findByName("standardState"); m_speciesMolarVolume[k] = getFloat(*ss, "molarVolume", "toSI"); } /* * Call the base initThermo, which handles setting the initial * state. */ ThermoPhase::initThermoXML(phaseNode, id_); }