Reaktoro
A unified framework for modeling chemically reactive systems
Utils.hxx
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2018 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 // C++ includes
19 namespace Reaktoro {
20 
21 template<typename NamedValues>
22 auto names(const NamedValues& values) -> std::vector<std::string>
23 {
24  std::vector<std::string> names;
25  names.reserve(values.size());
26  for(const auto& entry : values)
27  names.push_back(entry.name());
28  return names;
29 }
30 
31 template<typename SpeciesValues>
32 auto charges(const SpeciesValues& species) -> Vector
33 {
34  Vector charges(species.size());
35  for(unsigned i = 0; i < species.size(); ++i)
36  charges[i] = species[i].charge();
37  return charges;
38 }
39 
40 template<typename SpeciesValues>
41 auto molarMasses(const SpeciesValues& species) -> Vector
42 {
43  Vector molar_masses(species.size());
44  for(unsigned i = 0; i < species.size(); ++i)
45  molar_masses[i] = species[i].molarMass();
46  return molar_masses;
47 }
48 
49 } // namespace Reaktoro
auto names(const NamedValues &values) -> std::vector< std::string >
Return the names of the entries in a container.
Definition: Utils.hxx:22
auto molarMasses(const SpeciesValues &species) -> Vector
Return the molar masses of all species in a list of species (in units of kg/mol)
Definition: Utils.hxx:41
auto molarMass(const std::map< std::string, double > &elements) -> double
Calculate the molar mass of a chemical compound (in units of kg/mol).
Definition: ElementUtils.cpp:184
auto charge(const std::string &formula) -> double
Extract the electrical charge of a chemical formula.
Definition: ElementUtils.cpp:197
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto charges(const ChargedValues &values) -> Vector
Return the electrical charges of all species in a list of species.