本文整理汇总了C++中XML_Node类的典型用法代码示例。如果您正苦于以下问题:C++ XML_Node类的具体用法?C++ XML_Node怎么用?C++ XML_Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XML_Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: installAdsorbateThermoFromXML
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);
}
示例2: CanteraError
/*
* 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;
}
示例3: warn_deprecated
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);
}
}
示例4: CanteraError
/*********************************************************************
* 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_);
}
示例5: ThermoPhase
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);
}
示例6: ctbuildsolutionfromxml
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;
}
示例7: warn_deprecated
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);
}
示例8: warn_deprecated
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);
}
示例9: CanteraError
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;
}
示例10: CanteraError
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();
}
示例11: setStateFromXML
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);
}
}
示例12: get_XML_NameID
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");
}
}
示例13: setParametersFromXML
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");
}
}
}
示例14: CanteraError
/**
* 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);
}
示例15: SingleSpeciesTP
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);
}