Reaktoro
A unified framework for modeling chemically reactive systems
Utils.hpp
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 #pragma once
19 
20 // C++ includes
21 #include <string>
22 #include <vector>
23 
24 // Reaktoro includes
25 #include <Reaktoro/Common/ChemicalScalar.hpp>
26 #include <Reaktoro/Common/ChemicalVector.hpp>
27 #include <Reaktoro/Common/Index.hpp>
28 #include <Reaktoro/Math/Matrix.hpp>
29 
30 namespace Reaktoro {
31 
33 template<typename NamedValues>
34 auto names(const NamedValues& values) -> std::vector<std::string>;
35 
37 template<typename ChargedValues>
38 auto charges(const ChargedValues& values) -> Vector;
39 
41 template<typename SpeciesValues>
42 auto molarMasses(const SpeciesValues& species) -> Vector;
43 
46 {
47  const auto nspecies = n.size();
48  if(nspecies == 1)
49  return ones(n);
50  const ChemicalScalar nt = sum(n);
51  if(nt != 0.0) return n/nt;
52  else return zeros(n);
53 }
54 
55 } // namespace Reaktoro
56 
57 #include "Utils.hxx"
auto names(const NamedValues &values) -> std::vector< std::string >
Return the names of the entries in a container.
Definition: Utils.hxx:22
A template base class to represent a chemical scalar and its partial derivatives.
Definition: ChemicalScalar.hpp:49
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
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
A type that describes temperature in units of K.
Definition: ChemicalVector.hpp:377
auto zeros(const ChemicalVectorBase< V, T, P, N > &v) -> ChemicalVectorBase< decltype(zeros(0)), decltype(zeros(0)), decltype(zeros(0)), decltype(zeros(0, 0))>
Return a ChemicalVectorBase expression representing zeros with same dimension of given vector.
Definition: ChemicalVector.hpp:361
auto moleFractions(Composition n) -> ChemicalVector
Return the mole fractions of the species.
Definition: Utils.hpp:45
auto ones(const ChemicalVectorBase< V, T, P, N > &v) -> ChemicalVectorBase< decltype(ones(0)), decltype(zeros(0)), decltype(zeros(0)), decltype(zeros(0, 0))>
Return a ChemicalVectorBase expression representing ones with same dimension of given vector.
Definition: ChemicalVector.hpp:369
auto charges(const ChargedValues &values) -> Vector
Return the electrical charges of all species in a list of species.