Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
SpeciesList.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/ElementList.hpp>
23 #include <Reaktoro/Core/Species.hpp>
24 
25 namespace Reaktoro {
26 
29 {
30 public:
33 
35  SpeciesList(std::initializer_list<Species> species);
36 
38  SpeciesList(const Vec<Species>& species);
39 
41  SpeciesList(const StringList& formulas);
42 
44  auto append(const Species& species) -> void;
45 
47  auto data() const -> const Vec<Species>&;
48 
50  auto empty() const -> bool;
51 
53  auto size() const -> Index;
54 
56  auto elements() const -> ElementList;
57 
59  auto operator[](Index i) const -> const Species&;
60 
62  auto operator[](Index i) -> Species&;
63 
65  auto find(const String& name) const -> Index;
66 
68  auto findWithName(const String& name) const -> Index;
69 
71  auto findWithFormula(const ChemicalFormula& formula) const -> Index;
72 
74  auto findWithSubstance(const String& substance) const -> Index;
75 
77  auto index(const String& name) const -> Index;
78 
80  auto indexWithName(const String& name) const -> Index;
81 
83  auto indexWithFormula(const ChemicalFormula& formula) const -> Index;
84 
86  auto indexWithSubstance(const String& substance) const -> Index;
87 
89  auto front() const -> Species const& { return m_species.front(); }
90 
92  auto back() const -> Species const& { return m_species.back(); }
93 
95  auto get(const String& name) const -> const Species&;
96 
98  auto getWithName(const String& name) const -> const Species&;
99 
101  auto getWithFormula(const ChemicalFormula& formula) const -> const Species&;
102 
104  auto getWithSubstance(const String substance) const -> const Species&;
105 
107  auto withNames(const StringList& names) const -> SpeciesList;
108 
110  auto withFormulas(const StringList& formulas) const -> SpeciesList;
111 
113  auto withSubstances(const StringList& substances) const -> SpeciesList;
114 
117 
119  auto withCharge(real value) const -> SpeciesList;
120 
122  auto withTag(String tag) const -> SpeciesList;
123 
125  auto withoutTag(String tag) const -> SpeciesList;
126 
128  auto withTags(const StringList& tags) const -> SpeciesList;
129 
131  auto withoutTags(const StringList& tags) const -> SpeciesList;
132 
145  auto withElements(const StringList& symbols) const -> SpeciesList;
146 
160  auto withElementsOf(const StringList& formulas) const -> SpeciesList;
161 
163  operator Vec<Species>&();
164 
166  operator Vec<Species>const&() const;
167 
168 private:
170  Vec<Species> m_species;
171 
172 public:
174  template<typename InputIterator>
175  SpeciesList(InputIterator begin, InputIterator end) : m_species(begin, end) {}
176 
178  auto begin() const { return m_species.begin(); }
179 
181  auto begin() { return m_species.begin(); }
182 
184  auto end() const { return m_species.end(); }
185 
187  auto end() { return m_species.end(); }
188 
190  auto push_back(const Species& species) -> void { append(species); }
191 
193  template<typename Iterator, typename InputIterator>
194  auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void { m_species.insert(pos, begin, end); }
195 
198 };
199 
201 auto operator+(const SpeciesList& a, const SpeciesList& b) -> SpeciesList;
202 
203 } // namespace Reaktoro
A type used to represent the chemical formula of a chemical species.
Definition: ChemicalFormula.hpp:27
A type used as a collection of elements.
Definition: ElementList.hpp:28
A type used as a collection of species.
Definition: SpeciesList.hpp:29
SpeciesList()
Construct a default SpeciesList object.
auto withTag(String tag) const -> SpeciesList
Return all species with a given tag.
SpeciesList(InputIterator begin, InputIterator end)
Construct an SpeciesList object with given begin and end iterators.
Definition: SpeciesList.hpp:175
auto push_back(const Species &species) -> void
Append a new Species at the back of the container (for STL compatibility reasons).
Definition: SpeciesList.hpp:190
auto elements() const -> ElementList
Return the elements that compose the species in the collection sorted in ascending order of molar mas...
auto indexWithSubstance(const String &substance) const -> Index
Return the index of the first species with given substance name or throw a runtime error if not found...
auto getWithSubstance(const String substance) const -> const Species &
Return the species with a given substance name.
auto withElements(const StringList &symbols) const -> SpeciesList
Return all species with a certain elemental composition.
auto find(const String &name) const -> Index
Return the index of the first species with given unique name or the number of species if not found.
auto withSubstances(const StringList &substances) const -> SpeciesList
Return all species with given substance names.
auto withoutTag(String tag) const -> SpeciesList
Return all species without a given tag.
auto findWithName(const String &name) const -> Index
Return the index of the first species with given unique name or the number of species if not found.
auto indexWithFormula(const ChemicalFormula &formula) const -> Index
Return the index of the first species with equivalent formula or throw a runtime error if not found.
auto empty() const -> bool
Return true if there are no species in the collection.
auto withAggregateState(AggregateState state) const -> SpeciesList
Return all species with a given aggregate state.
auto getWithFormula(const ChemicalFormula &formula) const -> const Species &
Return the species with a given formula.
SpeciesList(std::initializer_list< Species > species)
Construct an SpeciesList object with given species.
auto front() const -> Species const &
Return the species at the front of the collection.
Definition: SpeciesList.hpp:89
auto indexWithName(const String &name) const -> Index
Return the index of the species with given unique name or throw a runtime error if not found.
auto data() const -> const Vec< Species > &
Return the internal collection of Species objects.
auto withNames(const StringList &names) const -> SpeciesList
Return all species with given names.
auto withElementsOf(const StringList &formulas) const -> SpeciesList
Return all species with a certain elemental composition.
auto findWithSubstance(const String &substance) const -> Index
Return the index of the first species with given substance name or the number of species if not found...
auto end()
Return end iterator of this SpeciesList instance (for STL compatibility reasons).
Definition: SpeciesList.hpp:187
auto get(const String &name) const -> const Species &
Return the species with a given name.
SpeciesList(const Vec< Species > &species)
Construct an SpeciesList object with given species.
auto withoutTags(const StringList &tags) const -> SpeciesList
Return all species without given tags.
auto append(const Species &species) -> void
Append a new species to the list of species.
auto findWithFormula(const ChemicalFormula &formula) const -> Index
Return the index of the first species with equivalent formula or the number of species if not found.
auto withCharge(real value) const -> SpeciesList
Return all species with a given charge.
auto withTags(const StringList &tags) const -> SpeciesList
Return all species with given tags.
auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void
Insert a container of Species objects into this SpeciesList instance (for STL compatibility reasons).
Definition: SpeciesList.hpp:194
auto begin() const
Return begin const iterator of this SpeciesList instance (for STL compatibility reasons).
Definition: SpeciesList.hpp:178
auto begin()
Return begin iterator of this SpeciesList instance (for STL compatibility reasons).
Definition: SpeciesList.hpp:181
SpeciesList(const StringList &formulas)
Construct an SpeciesList object with given species formulas.
auto withFormulas(const StringList &formulas) const -> SpeciesList
Return all species with given substance formulas.
auto getWithName(const String &name) const -> const Species &
Return the species with a given name.
auto end() const
Return end const iterator of this SpeciesList instance (for STL compatibility reasons).
Definition: SpeciesList.hpp:184
auto size() const -> Index
Return the number of species in the collection.
auto index(const String &name) const -> Index
Return the index of the first species with given unique name or throw a runtime error if not found.
auto back() const -> Species const &
Return the species at the back of the collection.
Definition: SpeciesList.hpp:92
A type used to represent a chemical species and its attributes.
Definition: Species.hpp:35
A class for representing a list of strings with special constructors.
Definition: StringList.hpp:28
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
AggregateState
The aggregate states of substances according to IUPAC.
Definition: AggregateState.hpp:32
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
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
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
auto operator+(const typename Derived::Scalar &scalar, const Eigen::MatrixBase< Derived > &mat) -> decltype((scalar+mat.array()).matrix())
Return the component-wise division of two matrices.
Definition: Matrix.hpp:774