Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Species.cpp
2 
8 #include "cantera/base/ctml.h"
9 #include <iostream>
10 #include <limits>
11 
12 namespace Cantera {
13 
14 Species::Species()
15  : charge(0.0)
16  , size(1.0)
17 {
18 }
19 
20 Species::Species(const std::string& name_, const compositionMap& comp_,
21  double charge_, double size_)
22  : name(name_)
23  , composition(comp_)
24  , charge(charge_)
25  , size(size_)
26 {
27 }
28 
29 Species::~Species()
30 {
31 }
32 
33 Species::Species(const Species& other)
34  : name(other.name)
35  , composition(other.composition)
36  , charge(other.charge)
37  , size(other.size)
38  , transport(other.transport)
39 {
40  if (other.thermo) {
41  thermo.reset(other.thermo->duplMyselfAsSpeciesThermoInterpType());
42  }
43 }
44 
45 Species& Species::operator=(const Species& other)
46 {
47  if (this == &other) {
48  return *this;
49  }
50  name = other.name;
51  composition = other.composition;
52  charge = other.charge;
53  size = other.size;
54  transport = other.transport;
55  if (other.thermo) {
56  thermo.reset(other.thermo->duplMyselfAsSpeciesThermoInterpType());
57  }
58  return *this;
59 }
60 
61 shared_ptr<Species> newSpecies(const XML_Node& species_node)
62 {
63  std::string name = species_node["name"];
64  compositionMap comp = parseCompString(species_node.child("atomArray").value());
65  shared_ptr<Species> s(new Species(name, comp));
66  if (species_node.hasChild("charge")) {
67  s->charge = getFloat(species_node, "charge");
68  }
69  if (species_node.hasChild("size")) {
70  s->size = getFloat(species_node, "size");
71  }
72  s->thermo.reset(newSpeciesThermoInterpType(species_node.child("thermo")));
73 
74  // Read transport data, if provided
75  if (species_node.hasChild("transport")) {
76  s->transport = newTransportData(species_node.child("transport"));
77  s->transport->validate(*s);
78  }
79 
80  return s;
81 }
82 
83 std::vector<shared_ptr<Species> > getSpecies(const XML_Node& node)
84 {
85  std::vector<shared_ptr<Species> > all_species;
86  std::vector<XML_Node*> species_nodes =
87  node.child("speciesData").getChildren("species");
88 
89  for (std::vector<XML_Node*>::iterator iter = species_nodes.begin();
90  iter != species_nodes.end();
91  ++iter)
92  {
93  all_species.push_back(newSpecies(**iter));
94  }
95  return all_species;
96 }
97 
98 }
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:149
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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:83
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:573
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
std::string name
The name of the species.
Definition: Species.h:35
shared_ptr< Species > newSpecies(const XML_Node &species_node)
Create a new Species object from a 'species' XML_Node.
Definition: Species.cpp:61
double charge
The electrical charge on the species, in units of the elementary charge.
Definition: Species.h:42
compositionMap composition
The elemental composition of the species.
Definition: Species.h:39
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:563
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.
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:469
Header for factory to build instances of classes that manage the standard-state thermodynamic propert...
double size
The effective size [m] of the species.
Definition: Species.h:45
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:194
Contains data about a single chemical species.
Definition: Species.h:21
Declaration for class Cantera::Species.
shared_ptr< SpeciesThermoInterpType > thermo
Thermodynamic data for the species.
Definition: Species.h:50
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 'transport' XML_Node.
void getChildren(const std::string &name, std::vector< XML_Node * > &children) const
Get a vector of pointers to XML_Node containing all of the children of the current node which matches...
Definition: xml.cpp:915