Cantera  2.4.0
Species.cpp
1 // This file is part of Cantera. See License.txt in the top-level directory or
2 // at http://www.cantera.org/license.txt for license and copyright information.
3 
10 #include "cantera/base/ctml.h"
11 #include <iostream>
12 #include <limits>
13 
14 namespace Cantera {
15 
16 Species::Species()
17  : charge(0.0)
18  , size(1.0)
19 {
20 }
21 
22 Species::Species(const std::string& name_, const compositionMap& comp_,
23  double charge_, double size_)
24  : name(name_)
25  , composition(comp_)
26  , charge(charge_)
27  , size(size_)
28 {
29 }
30 
31 Species::~Species()
32 {
33 }
34 
35 shared_ptr<Species> newSpecies(const XML_Node& species_node)
36 {
37  std::string name = species_node["name"];
38  compositionMap comp = parseCompString(species_node.child("atomArray").value());
39  auto s = make_shared<Species>(name, comp);
40  if (species_node.hasChild("charge")) {
41  s->charge = getFloat(species_node, "charge");
42  }
43  if (species_node.hasChild("size")) {
44  s->size = getFloat(species_node, "size");
45  }
46  s->thermo.reset(newSpeciesThermoInterpType(species_node.child("thermo")));
47 
48  // Read transport data, if provided
49  if (species_node.hasChild("transport")) {
50  s->transport = newTransportData(species_node.child("transport"));
51  s->transport->validate(*s);
52  }
53 
54  // Extra data used for some electrolyte species
55  if (species_node.hasChild("stoichIsMods")) {
56  s->extra["weak_acid_charge"] = getFloat(species_node, "stoichIsMods");
57  }
58 
59  if (species_node.hasChild("electrolyteSpeciesType")) {
60  s->extra["electrolyte_species_type"] = species_node.child("electrolyteSpeciesType").value();
61  }
62 
63  // Extra data optionally used by LatticePhase
64  const XML_Node* stdstate = species_node.findByName("standardState");
65  if (stdstate && stdstate->findByName("molarVolume")) {
66  s->extra["molar_volume"] = getFloat(*stdstate, "molarVolume", "toSI");
67  }
68 
69  // Extra data possibly used by IonsFromNeutralVPSSTP
70  const XML_Node* thermo = species_node.findByName("thermo");
71  if (thermo && thermo->attrib("model") == "IonFromNeutral") {
72  if (thermo->hasChild("specialSpecies")) {
73  s->extra["special_species"] = true;
74  }
75  }
76 
77  return s;
78 }
79 
80 std::vector<shared_ptr<Species> > getSpecies(const XML_Node& node)
81 {
82  std::vector<shared_ptr<Species> > all_species;
83  for (const auto& spnode : node.child("speciesData").getChildren("species")) {
84  all_species.push_back(newSpecies(*spnode));
85  }
86  return all_species;
87 }
88 
89 }
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:149
std::vector< XML_Node * > getChildren(const std::string &name) const
Get a vector of pointers to XML_Node containing all of the children of the current node which match t...
Definition: xml.cpp:864
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
const XML_Node * findByName(const std::string &nm, int depth=100000) const
This routine carries out a recursive search for an XML node based on the name of the node...
Definition: xml.cpp:695
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
std::vector< shared_ptr< Species > > getSpecies(const XML_Node &node)
Generate Species objects for all <species> nodes in an XML document.
Definition: Species.cpp:80
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
shared_ptr< Species > newSpecies(const XML_Node &species_node)
Create a new Species object from a &#39;species&#39; XML_Node.
Definition: Species.cpp:35
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:449
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
Definition: stringUtils.cpp:60
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
Contains declarations for string manipulation functions within Cantera.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:164
Declaration for class Cantera::Species.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
shared_ptr< TransportData > newTransportData(const XML_Node &transport_node)
Create a new TransportData object from a &#39;transport&#39; XML_Node.