Cantera  2.3.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 Species::Species(const Species& other)
36  : name(other.name)
37  , composition(other.composition)
38  , charge(other.charge)
39  , size(other.size)
40  , transport(other.transport)
41 {
42  warn_deprecated("Species copy constructor",
43  "To be removed after Cantera 2.3.");
44  if (other.thermo) {
45  thermo.reset(other.thermo->duplMyselfAsSpeciesThermoInterpType());
46  }
47 }
48 
50 {
51  warn_deprecated("Species assignment operator",
52  "To be removed after Cantera 2.3.");
53  if (this == &other) {
54  return *this;
55  }
56  name = other.name;
57  composition = other.composition;
58  charge = other.charge;
59  size = other.size;
60  transport = other.transport;
61  if (other.thermo) {
62  thermo.reset(other.thermo->duplMyselfAsSpeciesThermoInterpType());
63  }
64  return *this;
65 }
66 
67 shared_ptr<Species> newSpecies(const XML_Node& species_node)
68 {
69  std::string name = species_node["name"];
70  compositionMap comp = parseCompString(species_node.child("atomArray").value());
71  auto s = make_shared<Species>(name, comp);
72  if (species_node.hasChild("charge")) {
73  s->charge = getFloat(species_node, "charge");
74  }
75  if (species_node.hasChild("size")) {
76  s->size = getFloat(species_node, "size");
77  }
78  s->thermo.reset(newSpeciesThermoInterpType(species_node.child("thermo")));
79 
80  // Read transport data, if provided
81  if (species_node.hasChild("transport")) {
82  s->transport = newTransportData(species_node.child("transport"));
83  s->transport->validate(*s);
84  }
85 
86  return s;
87 }
88 
89 std::vector<shared_ptr<Species> > getSpecies(const XML_Node& node)
90 {
91  std::vector<shared_ptr<Species> > all_species;
92  for (const auto& spnode : node.child("speciesData").getChildren("species")) {
93  all_species.push_back(newSpecies(*spnode));
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
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...
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:89
Species & operator=(const Species &other)
Definition: Species.cpp:49
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:39
shared_ptr< Species > newSpecies(const XML_Node &species_node)
Create a new Species object from a &#39;species&#39; XML_Node.
Definition: Species.cpp:67
double charge
The electrical charge on the species, in units of the elementary charge.
Definition: Species.h:46
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:449
compositionMap composition
The elemental composition of the species.
Definition: Species.h:43
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.
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
double size
The effective size of the species.
Definition: Species.h:50
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:178
Contains data about a single chemical species.
Definition: Species.h:23
Declaration for class Cantera::Species.
shared_ptr< SpeciesThermoInterpType > thermo
Thermodynamic data for the species.
Definition: Species.h:55
Namespace for the Cantera kernel.
Definition: application.cpp:29
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.