Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ElementalComposition.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 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 // Reaktoro includes
21 #include <Reaktoro/Common/Types.hpp>
22 #include <Reaktoro/Core/Element.hpp>
23 
24 namespace Reaktoro {
25 
28 {
29 public:
32 
34  ElementalComposition(std::initializer_list<Pair<Element, double>> const& elements);
35 
38 
41 
43  auto size() const -> Index;
44 
46  auto symbols() const -> Strings;
47 
49  auto coefficients() const -> Vec<double>;
50 
52  auto coefficient(const String& symbol) const -> double;
53 
55  auto molarMass() const -> double;
56 
58  auto repr() const -> String;
59 
61  operator Pairs<Element, double>() const;
62 
64  operator Pairs<String, double>() const;
65 
67  operator String() const;
68 
69 private:
71  Pairs<Element, double> m_elements;
72 
74  double m_molar_mass = {};
75 
76 public:
78  inline auto begin() const { return m_elements.begin(); }
79 
81  inline auto begin() { return m_elements.begin(); }
82 
84  inline auto end() const { return m_elements.end(); }
85 
87  inline auto end() { return m_elements.end(); }
88 };
89 
91 auto operator!=(const ElementalComposition& l, const ElementalComposition& r) -> bool;
92 
94 auto operator==(const ElementalComposition& l, const ElementalComposition& r) -> bool;
95 
96 } // namespace Reaktoro
A type used to define a element and its attributes.
Definition: Element.hpp:28
A type used to describe the elemental composition of chemical species.
Definition: ElementalComposition.hpp:28
auto molarMass() const -> double
Return the molar mass of the elemental composition (in kg/mol).
auto repr() const -> String
Return a string representation of the elemental composition.
auto symbols() const -> Strings
Return the symbols of the elements.
ElementalComposition(std::initializer_list< Pair< Element, double >> const &elements)
Construct an ElementalComposition object with given elements and respective coefficients.
auto end()
Return end iterator of this ElementalComposition instance (for STL compatibility reasons).
Definition: ElementalComposition.hpp:87
ElementalComposition(Pairs< String, double > const &elements)
Construct an ElementalComposition object with given element symbols and respective coefficients.
ElementalComposition(Pairs< Element, double > const &elements)
Construct an ElementalComposition object with given elements and respective coefficients.
ElementalComposition()
Construct a default ElementalComposition object.
auto coefficients() const -> Vec< double >
Return the coefficients of the elements.
auto begin() const
Return begin const iterator of this ElementalComposition instance (for STL compatibility reasons).
Definition: ElementalComposition.hpp:78
auto begin()
Return begin iterator of this ElementalComposition instance (for STL compatibility reasons).
Definition: ElementalComposition.hpp:81
auto coefficient(const String &symbol) const -> double
Return the coefficient of an element symbol in the elemental composition.
auto end() const
Return end const iterator of this ElementalComposition instance (for STL compatibility reasons).
Definition: ElementalComposition.hpp:84
auto size() const -> Index
Return the number of elements.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Vec< Pair< T, U > > Pairs
Convenient alias for std::vector<std::pair<T, U>>.
Definition: Types.hpp:90
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
std::pair< T, U > Pair
Convenient alias for std::pair<T, U>.
Definition: Types.hpp:86
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
std::vector< std::string > Strings
Convenient alias for std::vector<String>.
Definition: Types.hpp:55
auto operator!=(const ElementalComposition &l, const ElementalComposition &r) -> bool
Return true if two ElementalComposition objects are different.
auto operator==(const ChemicalFormula &lhs, const ChemicalFormula &rhs) -> bool
Compare two ChemicalFormula objects for equality.