Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
PhaseList.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/Phase.hpp>
23 #include <Reaktoro/Core/SpeciesList.hpp>
24 
25 namespace Reaktoro {
26 
28 class PhaseList
29 {
30 public:
33 
35  PhaseList(std::initializer_list<Phase> phases);
36 
38  PhaseList(const Vec<Phase>& phases);
39 
41  auto append(const Phase& phase) -> void;
42 
44  auto data() const -> const Vec<Phase>&;
45 
47  auto empty() const -> bool;
48 
50  auto size() const -> Index;
51 
53  auto species() const -> SpeciesList;
54 
56  auto operator[](Index i) const -> const Phase&;
57 
59  auto operator[](Index i) -> Phase&;
60 
62  auto find(const String& name) const -> Index;
63 
65  auto findWithName(const String& name) const -> Index;
66 
68  auto findWithSpecies(Index index) const -> Index;
69 
71  auto findWithSpecies(const String& name) const -> Index;
72 
75 
77  auto findWithStateOfMatter(StateOfMatter option) const -> Index;
78 
80  auto index(const String& name) const -> Index;
81 
83  auto indexWithName(const String& name) const -> Index;
84 
87 
89  auto indexWithSpecies(const String& name) const -> Index;
90 
93 
96 
98  auto get(const String& name) const -> const Phase&;
99 
101  auto getWithName(const String& name) const -> const Phase&;
102 
104  auto withNames(const StringList& names) const -> PhaseList;
105 
108 
111 
113  auto numSpeciesUntilPhase(Index iphase) const -> Index;
114 
116  auto indicesPhasesArePure() const -> Indices;
117 
120 
123 
126 
128  auto indicesSpeciesInPhases(const Indices& iphases) const -> Indices;
129 
131  operator Vec<Phase>&();
132 
134  operator Vec<Phase>const&() const;
135 
136 private:
138  Vec<Phase> m_phases;
139 
140 public:
142  template<typename InputIterator>
143  PhaseList(InputIterator begin, InputIterator end) : m_phases(begin, end) {}
144 
146  auto begin() const { return m_phases.begin(); }
147 
149  auto begin() { return m_phases.begin(); }
150 
152  auto end() const { return m_phases.end(); }
153 
155  auto end() { return m_phases.end(); }
156 
158  auto push_back(const Phase& species) -> void { append(species); }
159 
161  template<typename Iterator, typename InputIterator>
162  auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void { m_phases.insert(pos, begin, end); }
163 
165  using value_type = Phase;
166 };
167 
169 auto operator+(const PhaseList& a, const PhaseList& b) -> PhaseList;
170 
171 } // namespace Reaktoro
A type used as a collection of phases.
Definition: PhaseList.hpp:29
auto indicesSpeciesInPhases(const Indices &iphases) const -> Indices
Return the indices of the species in the given phases.
auto getWithName(const String &name) const -> const Phase &
Return the phase with a given name.
auto numSpeciesUntilPhase(Index iphase) const -> Index
Return the number of species over all phases up to the one with given index.
auto find(const String &name) const -> Index
Return the index of the phase with given unique name or the number of phases if not found.
auto indexWithSpecies(Index index) const -> Index
Return the index of the phase containing the species with given index or throw a runtime error if not...
auto indexWithStateOfMatter(StateOfMatter option) const -> Index
Return the index of the first phase with given state of matter or throw a runtime error if not found.
auto push_back(const Phase &species) -> void
Append a new Phase at the back of the container (for STL compatibility reasons).
Definition: PhaseList.hpp:158
auto findWithName(const String &name) const -> Index
Return the index of the phase with given unique name or the number of phases if not found.
auto withStateOfMatter(StateOfMatter option) const -> PhaseList
Return all phases with given state of matter.
auto empty() const -> bool
Return true if there are no phases in the collection.
auto findWithSpecies(Index index) const -> Index
Return the index of the phase containing the species with given index or number of phases if not foun...
auto findWithAggregateState(AggregateState option) const -> Index
Return the index of the first phase with given aggregate state of species or the number of phases if ...
auto indicesSpeciesInPurePhases() const -> Indices
Return the indices of the species in phases with a single species.
auto indexWithName(const String &name) const -> Index
Return the index of the phase with given unique name or throw a runtime error if not found.
auto withNames(const StringList &names) const -> PhaseList
Return all phases with given names.
auto end()
Return end iterator of this PhaseList instance (for STL compatibility reasons).
Definition: PhaseList.hpp:155
auto species() const -> SpeciesList
Return the species that compose the phases in the collection.
auto get(const String &name) const -> const Phase &
Return the phase with a given name.
PhaseList(std::initializer_list< Phase > phases)
Construct an PhaseList object with given phases.
auto indexWithAggregateState(AggregateState option) const -> Index
Return the index of the first phase with given aggregate state of species or throw a runtime error if...
PhaseList()
Construct a default PhaseList object.
auto append(const Phase &phase) -> void
Append a new phase to the list of phase.
auto data() const -> const Vec< Phase > &
Return the internal collection of Phase objects.
auto indicesPhasesArePure() const -> Indices
Return the indices of the phases with a single species.
auto insert(Iterator pos, InputIterator begin, InputIterator end) -> void
Insert a container of Phase objects into this PhaseList instance (for STL compatibility reasons).
Definition: PhaseList.hpp:162
auto begin() const
Return begin const iterator of this PhaseList instance (for STL compatibility reasons).
Definition: PhaseList.hpp:146
auto indicesPhasesAreSolution() const -> Indices
Return the indices of the phases with more than one species.
auto begin()
Return begin iterator of this PhaseList instance (for STL compatibility reasons).
Definition: PhaseList.hpp:149
auto end() const
Return end const iterator of this PhaseList instance (for STL compatibility reasons).
Definition: PhaseList.hpp:152
auto withAggregateState(AggregateState option) const -> PhaseList
Return all phases whose species have the given aggregate state.
auto size() const -> Index
Return the number of phases in the collection.
auto index(const String &name) const -> Index
Return the index of the phase with given unique name or throw a runtime error if not found.
auto indicesSpeciesInSolutionPhases() const -> Indices
Return the indices of the species in phases with more than one species.
auto findWithStateOfMatter(StateOfMatter option) const -> Index
Return the index of the first phase with given state of matter or the number of phases if not found.
PhaseList(const Vec< Phase > &phases)
Construct an PhaseList object with given phases.
A type used to define a phase and its attributes.
Definition: Phase.hpp:33
A type used as a collection of species.
Definition: SpeciesList.hpp:29
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
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
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
StateOfMatter
The list of states of matter for phases.
Definition: StateOfMatter.hpp:27