More checks against user input errors in the XML file.
This commit is contained in:
parent
33c8065a7c
commit
5c73809c25
3 changed files with 64 additions and 57 deletions
|
|
@ -526,52 +526,56 @@ namespace Cantera {
|
|||
}
|
||||
|
||||
|
||||
void Elements::addElementsFromXML(const XML_Node& phase) {
|
||||
|
||||
// get the declared element names
|
||||
XML_Node& elements = phase.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("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]);
|
||||
}
|
||||
}
|
||||
void Elements::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;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* subscribe(), unsubscribe(), and reportSubscriptions():
|
||||
|
|
|
|||
|
|
@ -200,11 +200,9 @@ namespace Cantera {
|
|||
* Calculate the constant pressure heat capacity
|
||||
* in mks units of J kmol-1 K-1
|
||||
*/
|
||||
doublereal
|
||||
PDSS_HKFT::cp_mole() const {
|
||||
doublereal PDSS_HKFT::cp_mole() const {
|
||||
|
||||
double pbar = m_pres * 1.0E-5;
|
||||
|
||||
double c1term = m_c1;
|
||||
|
||||
double c2term = m_c2 / (m_temp - 228.) / (m_temp - 228.);
|
||||
|
|
@ -256,10 +254,8 @@ namespace Cantera {
|
|||
double Cp_calgmol = c1term + c2term + a3term + a4term + yterm + xterm + otterm;
|
||||
|
||||
// Convert to Joules / kmol
|
||||
double Cp = Cp_calgmol * 1.0E3 * 4.184;
|
||||
return Cp;
|
||||
|
||||
|
||||
doublereal Cp = Cp_calgmol * 1.0E3 * 4.184;
|
||||
return Cp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -260,10 +260,10 @@ namespace Cantera {
|
|||
|
||||
// Check the the supplied XML node in fact represents a
|
||||
// phase.
|
||||
if (phase.name() != "phase")
|
||||
if (phase.name() != "phase") {
|
||||
throw CanteraError("importPhase",
|
||||
"Current const XML_Node is not a phase element.");
|
||||
|
||||
"Current const XML_Node named, " + phase.name() + ", is not a phase element.");
|
||||
}
|
||||
|
||||
// set the id attribute of the phase to the 'id' attribute
|
||||
// in the XML tree.
|
||||
|
|
@ -275,7 +275,7 @@ namespace Cantera {
|
|||
int idim = intValue(phase["dim"]);
|
||||
if (idim < 1 || idim > 3)
|
||||
throw CanteraError("importPhase",
|
||||
"unphysical number of dimensions: "+phase["dim"]);
|
||||
"phase, " + th->id() + ", has unphysical number of dimensions: " + phase["dim"]);
|
||||
th->setNDim(idim);
|
||||
}
|
||||
else {
|
||||
|
|
@ -288,6 +288,9 @@ namespace Cantera {
|
|||
if (phase.hasChild("thermo")) {
|
||||
const XML_Node& eos = phase.child("thermo");
|
||||
th->setParametersFromXML(eos);
|
||||
} else {
|
||||
throw CanteraError("importPhase",
|
||||
" phase, " + th->id() + ", XML_Node does not have a \"thermo\" XML_Node");
|
||||
}
|
||||
|
||||
VPStandardStateTP *vpss_ptr = 0;
|
||||
|
|
@ -296,7 +299,7 @@ namespace Cantera {
|
|||
vpss_ptr = dynamic_cast <VPStandardStateTP *>(th);
|
||||
if (vpss_ptr == 0) {
|
||||
throw CanteraError("importPhase",
|
||||
"phase was VPSS, but dynamic cast failed");
|
||||
"phase, " + th->id() + ", was VPSS, but dynamic cast failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +314,6 @@ namespace Cantera {
|
|||
***************************************************************/
|
||||
th->addElementsFromXML(phase);
|
||||
|
||||
|
||||
/***************************************************************
|
||||
* Add the species.
|
||||
*
|
||||
|
|
@ -323,6 +325,11 @@ namespace Cantera {
|
|||
vector<XML_Node*> sparrays;
|
||||
phase.getChildren("speciesArray", sparrays);
|
||||
int jsp, nspa = static_cast<int>(sparrays.size());
|
||||
if (nspa == 0) {
|
||||
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(nspa,0);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue