本文整理汇总了C++中XML_Node::root方法的典型用法代码示例。如果您正苦于以下问题:C++ XML_Node::root方法的具体用法?C++ XML_Node::root怎么用?C++ XML_Node::root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML_Node
的用法示例。
在下文中一共展示了XML_Node::root方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CanteraError
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");
}
}
示例2: 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;
}
示例3: installElements
void installElements(Phase& th, const XML_Node& phaseNode)
{
// get the declared element names
if (!phaseNode.hasChild("elementArray")) {
throw CanteraError("installElements",
"phase XML node doesn't have \"elementArray\" XML Node");
}
XML_Node& elements = phaseNode.child("elementArray");
vector<string> enames;
getStringArray(elements, enames);
// // element database defaults to elements.xml
string element_database = "elements.xml";
if (elements.hasAttrib("datasrc")) {
element_database = elements["datasrc"];
}
XML_Node* doc = get_XML_File(element_database);
XML_Node* dbe = &doc->child("elementData");
XML_Node& root = phaseNode.root();
XML_Node* local_db = 0;
if (root.hasChild("elementData")) {
local_db = &root.child("elementData");
}
for (size_t i = 0; i < enames.size(); i++) {
// Find the element data
XML_Node* e = 0;
if (local_db) {
e = local_db->findByAttr("name",enames[i]);
}
if (!e) {
e = dbe->findByAttr("name",enames[i]);
}
if (!e) {
throw CanteraError("addElementsFromXML","no data for element "
+enames[i]);
}
// Add the element
doublereal weight = 0.0;
if (e->hasAttrib("atomicWt")) {
weight = fpValue(e->attrib("atomicWt"));
}
int anum = 0;
if (e->hasAttrib("atomicNumber")) {
anum = intValue(e->attrib("atomicNumber"));
}
string symbol = e->attrib("name");
doublereal entropy298 = ENTROPY298_UNKNOWN;
if (e->hasChild("entropy298")) {
XML_Node& e298Node = e->child("entropy298");
if (e298Node.hasAttrib("value")) {
entropy298 = fpValueCheck(e298Node["value"]);
}
}
th.addElement(symbol, weight, anum, entropy298);
}
}
示例4: initThermoXML
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);
}
}
}
示例5: addElementsFromXML
void Phase::addElementsFromXML(const XML_Node& phase)
{
// get the declared element names
if (! phase.hasChild("elementArray")) {
throw CanteraError("Elements::addElementsFromXML",
"phase xml node doesn't have \"elementArray\" XML Node");
}
XML_Node& elements = phase.child("elementArray");
vector<string> enames;
ctml::getStringArray(elements, enames);
// // element database defaults to elements.xml
string element_database = "elements.xml";
if (elements.hasAttrib("datasrc")) {
element_database = elements["datasrc"];
}
XML_Node* doc = get_XML_File(element_database);
XML_Node* dbe = &doc->child("ctml/elementData");
XML_Node& root = phase.root();
XML_Node* local_db = 0;
if (root.hasChild("ctml")) {
if (root.child("ctml").hasChild("elementData")) {
local_db = &root.child("ctml/elementData");
}
}
int nel = static_cast<int>(enames.size());
int i;
string enm;
XML_Node* e = 0;
for (i = 0; i < nel; i++) {
e = 0;
if (local_db) {
//writelog("looking in local database.");
e = local_db->findByAttr("name",enames[i]);
//if (!e) writelog(enames[i]+" not found.");
}
if (!e) {
e = dbe->findByAttr("name",enames[i]);
}
if (e) {
addUniqueElement(*e);
} else {
throw CanteraError("addElementsFromXML","no data for element "
+enames[i]);
}
}
}
示例6: buildSolutionFromXML
int buildSolutionFromXML(char* src, int ixml, char* id,
int ith, int ikin)
{
try {
XML_Node* root = 0;
if (ixml > 0) {
root = &XmlCabinet::item(ixml);
}
ThermoPhase& t = ThermoCabinet::item(ith);
Kinetics& kin = KineticsCabinet::item(ikin);
XML_Node* r = 0;
if (root) {
r = &root->root();
}
XML_Node* x = get_XML_Node(src, r);
if (!x) {
return false;
}
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;
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}
示例7: setXMLdata
void Phase::setXMLdata(XML_Node& xmlPhase)
{
XML_Node* xroot = &xmlPhase.root();
XML_Node *root_xml = new XML_Node();
xroot->copy(root_xml);
if (m_xml) {
XML_Node *rOld = &m_xml->root();
delete rOld;
m_xml = 0;
}
m_xml = findXMLPhase(root_xml, xmlPhase.id());
if (!m_xml) {
throw CanteraError("Phase::setXMLdata()", "XML 'phase' node not found");
}
if (&m_xml->root() != root_xml) {
throw CanteraError("Phase::setXMLdata()", "Root XML node not found");
}
}
示例8: ctbuildsolutionfromxml
status_t ctbuildsolutionfromxml(char* src, integer* ixml, char* id,
integer* ith, integer* ikin, ftnlen lensrc, ftnlen lenid)
{
try {
XML_Node* root = 0;
if (*ixml > 0) {
root = _xml(ixml);
}
thermo_t* t = _fth(ith);
Kinetics* 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);
}
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();
}
} catch (...) {
return handleAllExceptions(-1, ERR);
}
return 0;
}
示例9: CanteraError
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");
}
}
示例10: initThermoXML
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_);
}
示例11: importPhase
//.........这里部分代码省略.........
//
// Species definitions may be imported from multiple sources. For each one,
// a speciesArray element must be present.
vector<XML_Node*> sparrays = phase.getChildren("speciesArray");
if (ssConvention != cSS_CONVENTION_SLAVE && sparrays.empty()) {
throw CanteraError("importPhase",
"phase, " + th->id() + ", has zero \"speciesArray\" XML nodes.\n"
+ " There must be at least one speciesArray nodes "
"with one or more species");
}
vector<XML_Node*> dbases;
vector_int sprule(sparrays.size(),0);
// Default behavior when importing from CTI/XML is for undefined elements to
// be treated as an error
th->throwUndefinedElements();
// loop over the speciesArray elements
for (size_t jsp = 0; jsp < sparrays.size(); jsp++) {
const XML_Node& speciesArray = *sparrays[jsp];
// If the speciesArray element has a child element
//
// <skip element="undeclared">
//
// then set sprule[jsp] to 1, so that any species with an undeclared
// element will be quietly skipped when importing species. Additionally,
// if the skip node has the following attribute:
//
// <skip species="duplicate">
//
// then duplicate species names will not cause Cantera to throw an
// exception. Instead, the duplicate entry will be discarded.
if (speciesArray.hasChild("skip")) {
const XML_Node& sk = speciesArray.child("skip");
string eskip = sk["element"];
if (eskip == "undeclared") {
sprule[jsp] = 1;
}
string dskip = sk["species"];
if (dskip == "duplicate") {
sprule[jsp] += 10;
}
}
// Get a pointer to the node containing the species definitions for the
// species declared in this speciesArray element. This may be in the
// local file containing the phase element, or may be in another file.
XML_Node* db = get_XML_Node(speciesArray["datasrc"], &phase.root());
if (db == 0) {
throw CanteraError("importPhase()",
" Can not find XML node for species database: "
+ speciesArray["datasrc"]);
}
// add this node to the list of species database nodes.
dbases.push_back(db);
}
// Now, collect all the species names and all the XML_Node * pointers for
// those species in a single vector. This is where we decide what species
// are to be included in the phase. The logic is complicated enough that we
// put it in a separate routine.
std::vector<XML_Node*> spDataNodeList;
std::vector<std::string> spNamesList;
vector_int spRuleList;
formSpeciesXMLNodeList(spDataNodeList, spNamesList, spRuleList,
sparrays, dbases, sprule);
size_t nsp = spDataNodeList.size();
if (ssConvention == cSS_CONVENTION_SLAVE && nsp > 0) {
throw CanteraError("importPhase()", "For Slave standard states, "
"number of species must be zero: {}", nsp);
}
for (size_t k = 0; k < nsp; k++) {
XML_Node* s = spDataNodeList[k];
AssertTrace(s != 0);
if (spRuleList[k]) {
th->ignoreUndefinedElements();
}
th->addSpecies(newSpecies(*s));
if (vpss_ptr) {
const XML_Node* const ss = s->findByName("standardState");
std::string ss_model = (ss) ? ss->attrib("model") : "ideal-gas";
unique_ptr<PDSS> kPDSS(newPDSS(ss_model));
kPDSS->setParametersFromXML(*s);
vpss_ptr->installPDSS(k, std::move(kPDSS));
}
th->saveSpeciesData(k, s);
}
// Done adding species. Perform any required subclass-specific
// initialization.
th->initThermo();
// Perform any required subclass-specific initialization that requires the
// XML phase object
std::string id = "";
th->initThermoXML(phase, id);
}
示例12: importPhase
//.........这里部分代码省略.........
for (size_t jsp = 0; jsp < sparrays.size(); jsp++) {
const XML_Node& speciesArray = *sparrays[jsp];
// If the speciesArray element has a child element
//
// <skip element="undeclared">
//
// then set sprule[jsp] to 1, so that any species with an undeclared
// element will be quietly skipped when importing species. Additionally,
// if the skip node has the following attribute:
//
// <skip species="duplicate">
//
// then duplicate species names will not cause Cantera to throw an
// exception. Instead, the duplicate entry will be discarded.
if (speciesArray.hasChild("skip")) {
const XML_Node& sk = speciesArray.child("skip");
string eskip = sk["element"];
if (eskip == "undeclared") {
sprule[jsp] = 1;
}
string dskip = sk["species"];
if (dskip == "duplicate") {
sprule[jsp] += 10;
}
}
// Get a pointer to the node containing the species
// definitions for the species declared in this
// speciesArray element. This may be in the local file
// containing the phase element, or may be in another
// file.
XML_Node* db = get_XML_Node(speciesArray["datasrc"], &phase.root());
if (db == 0) {
throw CanteraError("importPhase()",
" Can not find XML node for species database: "
+ speciesArray["datasrc"]);
}
// add this node to the list of species database nodes.
dbases.push_back(db);
}
// Now, collect all the species names and all the XML_Node * pointers
// for those species in a single vector. This is where we decide what
// species are to be included in the phase.
// The logic is complicated enough that we put it in a separate routine.
std::vector<XML_Node*> spDataNodeList;
std::vector<std::string> spNamesList;
std::vector<int> spRuleList;
formSpeciesXMLNodeList(spDataNodeList, spNamesList, spRuleList,
sparrays, dbases, sprule);
// Decide whether the the phase has a variable pressure ss or not
SpeciesThermo* spth = 0;
VPSSMgr* vp_spth = 0;
if (ssConvention == cSS_CONVENTION_TEMPERATURE) {
// Create a new species thermo manager. Function
// 'newSpeciesThermoMgr' looks at the species in the database
// to see what thermodynamic property parameterizations are
// used, and selects a class that can handle the
// parameterizations found.
spth = newSpeciesThermoMgr(spDataNodeList);
// install it in the phase object
示例13: initThermoXML
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_);
}